-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjects.bak
More file actions
39 lines (37 loc) · 2.24 KB
/
objects.bak
File metadata and controls
39 lines (37 loc) · 2.24 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
(define (bubble x y size speed color)
(define (dispatch comm val) ; 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 'update-x) (set! x val)]
[(equal? comm 'update-y) (set! y val)]
[(equal? comm 'size) size]
[(equal? comm 'speed) speed]
[(equal? comm 'color) color]
[(equal? comm 'draw) (circle size "solid" color)]
[else (error "bubble: unknown command --" comm)]))
dispatch)
(define (player x y)
(define direction 'up)
(define (dispatch comm)
(cond [(equal? comm 'move-left) (if (< x 1) x (begin (set! x (- x 5)) (set! direction 'left)))]
[(equal? comm 'move-right) (if (> x 1068) x (begin (set! x (+ x 5)) (set! direction 'right)))]
[(equal? comm 'position) x]
[(equal? comm 'dir) direction]
[(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) ; 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 (dispatch comm)
(cond [(equal? comm 'x) x]
[(equal? comm 'y) y]
[(equal? comm 'is-shooting?) (if (equal? shooting 'no) #f #t)]
[(equal? comm 'start-shooting) (if (equal? shooting 'no) (begin (play arrowSound) (set! shooting 'yes)) "shooting")] ; need to debug this, if statement doesn't seem to read properly
[(equal? comm 'stop-shooting) (set! shooting 'no)]
[(equal? comm 'update) (begin (set! x (p1 'position)) (set! y (- y 10)))]
[(equal? comm 'reset) (begin (set! y orig-y) (set! shooting 'no))]
[else (error "hook: unknown command --" comm)]))
dispatch)