-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjects.rkt
More file actions
241 lines (199 loc) · 8.05 KB
/
objects.rkt
File metadata and controls
241 lines (199 loc) · 8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#lang racket
(require lang/posn)
(require 2htdp/image)
(require 2htdp/universe)
(require racket/trace) ; was trying to use this to debug, nothing seems to write until after the window created by big-bang closes though.
(require rsound)
;sprites from http://vignette2.wikia.nocookie.net/finalfantasy/images/2/2f/FF6_iOS_Ghost_Sprites.png/revision/latest?cb=20140908174159
(provide my-hook)
(provide p1)
(provide initialize-level)
(provide bubble-list)
(provide delete-popped-bubbles)
(define (delete-popped-bubbles)
(set! bubble-list (filter (lambda (x) (not (x 'popped?))) bubble-list)))
(define arrowSound (rs-read "arrow.wav"));read in the arrow sound to be played upon shooting
;;(define popSound (rs-read "popped.wav"))
(define (bubble x y size color x-dir y-dir)
(define popped? #f)
(define y-vel (* -1 size))
(define (size-picker)
(cond
[(equal? size 1) 8]
[(equal? size 2) 16]
[(equal? size 3) 32]
[(equal? size 4) 64]
[(equal? size 5) 60]
[else size]))
(define (my-posn)
(make-posn x y))
(define (top-left-x)
(- x (size-picker)))
(define (top-left-y)
(- y (size-picker)))
(define (bottom-right-x)
(+ x (size-picker)))
(define (bottom-right-y)
(+ y (size-picker)))
(define (collision-bubble)
(begin
;;(play popSound)
(set! popped? #t)
(if (> size 1)
(bubble-split)
void)))
(define (bubble-split)
(begin
(set! bubble-list (cons
(bubble x y (- size 1) color 0 y-dir)
(cons (bubble x y (- size 1) color 1 y-dir)
bubble-list)))))
(define (change-y dist)
(begin(set! y (+ y dist))
(if (< dist 0)
(set! y-dir 0)
(set! y-dir 1))))
(define (change-x dist)
(begin(set! x (+ x dist))
(if (< dist 0)
(set! x-dir 0)
(set! x-dir 1))))
(define (update-y)
(unless (<= y (- GROUND (size-picker)))
(set! y-vel (* -6 size)))
(if (<= y (+ 0 (* 2 (size-picker))))
(set! y-vel 2)
(set! y-vel (+ (/ size 6) y-vel)))
(set! y (+ y y-vel))
)
(define GROUND 630)
(define (dispatch comm) ; couldn't figure out how to do an optional arg (val only needed in update case)
(cond [(equal? comm 'x) x]
[(equal? comm 'y) y]
[(equal? comm 'GROUND) GROUND]
[(equal? comm 'go-left)(change-x -2)]
[(equal? comm 'go-right)(change-x 2)]
[(equal? comm 'go-up) (change-y -4)]
[(equal? comm 'go-down)(change-y 4)]
[(equal? comm 'update-y) (update-y)]
[(equal? comm 'col-arrow)(collision-bubble)]
[(equal? comm 'size) size]
[(equal? comm 'size-picker) (size-picker)]
[(equal? comm 'color) color]
[(equal? comm 'x-dir) x-dir]
[(equal? comm 'y-dir) y-dir]
[(equal? comm 'my-posn) (my-posn)]
[(equal? comm 'popped?) popped?]
[(equal? comm 'top-left-x) (top-left-x)]
[(equal? comm 'top-left-y) (top-left-y)]
[(equal? comm 'bottom-right-x) (bottom-right-x)]
[(equal? comm 'bottom-right-y) (bottom-right-y)]
[(equal? comm 'draw) (overlay
(circle (- (size-picker) 2) "solid" color)
(circle (size-picker) "solid" "white"))]
[else (error "bubble: unknown command --" comm)]))
dispatch)
(define (player x y)
(define direction 'up)
(define width 30)
(define height 50)
(define orig-x 15)
(define (center-x)
(+ x (/ width 2)))
(define (center-y)
(+ y (/ height 2)))
(define (top-left-x)
x)
(define (top-left-y)
y)
(define (bottom-right-x)
(+ x width))
(define (bottom-right-y)
(+ y height))
(define (my-posn)
(make-posn x y))
(define (dispatch comm)
(cond [(equal? comm 'move-left) (if (< (- x (/ width 2)) 1) x (begin (set! x (- x 5)) (set! direction 'left)))]
[(equal? comm 'move-right) (if (> (+ x (/ width 2)) 1068) x (begin (set! x (+ x 5)) (set! direction 'right)))]
[(equal? comm 'position) x]
[(equal? comm 'dir) direction]
[(equal? comm 'my-posn) (my-posn)]
[(equal? comm 'reset-posn) (set! x orig-x)]
[(equal? comm 'top-left-x) (top-left-x)]
[(equal? comm 'top-left-y) (top-left-y)]
[(equal? comm 'bottom-right-x) (bottom-right-x)]
[(equal? comm 'bottom-right-y) (bottom-right-y)]
[(equal? comm 'center-x) (center-x)]
[(equal? comm 'center-y) (center-y)]
[(equal? comm 'face-up) (set! direction 'up)]
[(equal? comm 'shoot) (if (my-hook 'is-shooting?) ;if it's not shot yet, let start shot. otherwise ignore.
(my-hook 'start-shooting)
"currently shooting")] ; will eventually shoot a grappling hook to top of screen. for now it shoots the sprite since I can't figure out how to draw multiple sprites yet.
[else (error "player: unknown command --" comm)]))
dispatch)
(define (hook x y shooting)
(define height 20)
(define width 14)
(define (top-left-x)
(- x (/ width 2)))
(define (top-left-y)
(- y (/ height 2)))
(define (bottom-right-x)
(+ x (/ width 2)))
; will eventually be second object that needs an x and y since it will be shot to pop bubbles
(define orig-y y) ;save what to reset y value to when it reaches the top of the screen
(define (my-posn)
(make-posn x y))
(define (dispatch comm)
(cond [(equal? comm 'x) x]
[(equal? comm 'y) y]
[(equal? comm 'my-posn) (my-posn)]
[(equal? comm 'is-shooting?) (if (equal? shooting 'no) #f #t)]
[(equal? comm 'start-shooting) (if (equal? shooting 'no) (begin (play arrowSound) (set! shooting 'yes) (set! x (p1 'position))) "shooting")] ; need to debug this, if statement doesn't seem to read properly
[(equal? comm 'stop-shooting) (set! shooting 'no)]
[(equal? comm 'update) (set! y (- y 10))]
[(equal? comm 'reset) (begin (set! y orig-y) (set! shooting 'no))]
[(equal? comm 'top-left-x)(top-left-x)]
[(equal? comm 'top-left-y)(top-left-y)]
[(equal? comm 'bottom-right-x)(bottom-right-x)]
[else (error "hook: unknown command --" comm)]))
dispatch)
(define p1 (player 15 630))
(define my-hook (hook 0 600 'no))
;(define bubble1 (bubble 0 550 1 "blue" 1 1))
;(define bubble2 (bubble 0 400 2 "red" 1 1))
;(define bubble3 (bubble 0 200 3 "yellow" 1 1))
;(define (bubble x y size color x-dir y-dir)
(define (level-1)
(list (bubble 200 550 1 "blue" 1 1)
(bubble 200 400 2 "red" 1 1)
(bubble 200 200 3 "yellow" 1 1)))
(define (level-2)
(list (bubble 200 550 1 "purple" 1 1)
(bubble 200 500 1 "purple" 1 1)
(bubble 200 400 2 "indigo" 1 1)
(bubble 200 200 3 "blue" 1 1)))
(define (level-3)
(list (bubble 200 550 1 "orange" 1 1)
(bubble 400 550 1 "orange" 1 1)
(bubble 600 550 1 "orange" 1 1)
(bubble 300 200 2 "red" 1 1)
(bubble 500 200 2 "red" 1 1)
(bubble 400 400 3 "yellow" 1 1)))
(define (level-4)
(list (bubble 300 300 3 "purple" 1 1)
(bubble 400 300 3 "purple" 1 1)
(bubble 500 300 3 "purple" 1 1)))
(define (level-5)
(list (bubble 200 550 4 "black" 1 1)
(bubble 600 550 4 "black" 1 1)))
(define bubble-list (level-1))
(define (initialize-level n)
(begin (p1 'reset-posn)
(my-hook 'reset)
(cond [(= n 1) (set! bubble-list (level-1))]
[(= n 2) (set! bubble-list (level-2))]
[(= n 3) (set! bubble-list (level-3))]
[(= n 4) (set! bubble-list (level-4))]
[(= n 5) (set! bubble-list (level-5))]
[else (error "max level reached")])))