summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heyllama.scm67
-rw-r--r--llama.tmx20
2 files changed, 54 insertions, 33 deletions
diff --git a/heyllama.scm b/heyllama.scm
index f9abaa6..6eca177 100644
--- a/heyllama.scm
+++ b/heyllama.scm
@@ -12,11 +12,16 @@
(define-class <animal> (<object>)
(pos #:init-keyword #:pos
- #:getter get-pos)
+ #:getter get-pos
+ #:setter set-pos!)
(size #:init-keyword #:size
#:getter get-size)
+ (falling #:init-value #t
+ #:getter is-falling?
+ #:setter set-falling!)
+
(draw-offset #:init-keyword #:draw-offset
#:getter get-draw-offset)
@@ -133,12 +138,23 @@
(rect-xy moved-small-rect))))
+(define (vertical-overlap a b)
+ (or (> (rect-right b) (rect-left a) (rect-left b))
+ (> (rect-right b) (rect-right a) (rect-left b))))
+
+
+(define (rect-above a b)
+ (>= (rect-bottom a) (rect-top b)))
+
+
(define (update tstep)
(let ((x-vel 0.0))
- (define (slide-llama-only a b)
- (if (eq? a 'llama) slide #f))
+ (when (and (key-pressed? 'space)
+ (not (is-falling? llama)))
+ (set-y-vel! llama 8.0)
+ (set-falling! llama #t))
(when (key-pressed? 'right)
(set-face-direction! llama 1)
@@ -146,7 +162,8 @@
(set-animation-step! llama
(floor-remainder
(+ (get-animation-step llama) -1)
- 16)))
+ 16))
+ (set-falling! llama #t))
(when (key-pressed? 'left)
(set-face-direction! llama -1)
@@ -154,7 +171,8 @@
(set-animation-step! llama
(floor-remainder
(- (get-animation-step llama) 1)
- 16)))
+ 16))
+ (set-falling! llama #t))
(vec2-add! (get-pos llama)
#v(x-vel 0.0))
@@ -162,26 +180,31 @@
(grid-move grid
'llama
(get-pos llama)
- slide-llama-only))
+ (lambda (a b)
+ (if (eq? a 'llama)
+ (lambda (item item-rect other other-rect goal)
+ (slide item item-rect other other-rect goal))
+ #f))))
;; Gravity
- (define (slide-llama-only-and-zero-yvel a b)
- (if (eq? a 'llama)
- (lambda (item item-rect other other-rect goal)
- (set-y-vel! llama 0.0)
- (slide item item-rect other other-rect goal))
- #f))
+ (when (is-falling? llama)
+ (vec2-add! (get-pos llama) #v(0.0 (get-y-vel llama)))
+ (set-y-vel! llama (- (get-y-vel llama) 0.4))
- (set-y-vel! llama
- (- (get-y-vel llama) 0.4))
+ (grid-move grid
+ 'llama
+ (get-pos llama)
+ (lambda (a b)
+ (if (eq? a 'llama)
+ (lambda (item item-rect other other-rect goal)
+ (when (vertical-overlap item-rect other-rect)
+ (set-y-vel! llama 0.0)
+ (when (rect-above item-rect other-rect)
+ (set-falling! llama #f)))
+ (slide item item-rect other other-rect goal))
+ #f))))
- (vec2-add! (get-pos llama)
- #v(0.0 (get-y-vel llama)))
- (grid-move grid
- 'llama
- (get-pos llama)
- slide-llama-only-and-zero-yvel)
;; Ensure llama is near centre of screen
(let ((fovea (make-rect 150.0 100.0 450.0 350.0))
@@ -193,9 +216,7 @@
(define (key-press key scancode modifier repeat?)
(case key
((q) (abort-game))
- ((f1) (set! show-hitboxes (not show-hitboxes)))
- ((space) (unless repeat?
- (set-y-vel! llama 8.0)))))
+ ((f1) (set! show-hitboxes (not show-hitboxes)))))
(run-game #:window-title "Hey Llama!"
diff --git a/llama.tmx b/llama.tmx
index be9c354..937d0a0 100644
--- a/llama.tmx
+++ b/llama.tmx
@@ -11,10 +11,10 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,2,2,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,0,0,1,2,2,2,2,2,2,3,7,7,7,7,7,7,7,7,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -24,13 +24,13 @@
</data>
</layer>
<objectgroup id="2" name="object-layer">
- <object id="3" name="ground" x="0" y="384.667" width="960" height="126.667"/>
+ <object id="3" name="ground" x="0" y="385.667" width="955.5" height="125.667"/>
<object id="5" name="startwall" x="152" y="-1.33333" width="16" height="512"/>
- <object id="8" x="1024" y="382.667" width="258.667" height="129.333"/>
+ <object id="8" x="1028.5" y="385.667" width="254.167" height="126.333"/>
<object id="9" x="1280" y="354.667" width="289.333" height="157.333"/>
- <object id="11" x="1346.67" y="254.667" width="88" height="28"/>
- <object id="12" x="1506.67" y="189.333" width="184" height="29.3333"/>
- <object id="13" x="1732" y="254.667" width="89.3333" height="28"/>
- <object id="14" x="1858.67" y="290" width="474.667" height="26.6667"/>
+ <object id="11" x="1350.5" y="290.333" width="84" height="23"/>
+ <object id="12" x="1513" y="227" width="141.833" height="21.8333"/>
+ <object id="13" x="1736" y="257.667" width="81.8333" height="21"/>
+ <object id="14" x="1927.5" y="290" width="402.333" height="22.6667"/>
</objectgroup>
</map>