Skip to content

Commit

Permalink
Fix snail and algae bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandevai committed Apr 26, 2020
1 parent 1783050 commit 4207dc8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/main.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@
(tset *player*
:hurt (fn [self damage]
(when (and (not= self.state :hurt) (not= *game-state* "game-over"))
(dec self.health (math.max 1 (r (- damage 5) damage)))
(dec self.health 0)
;(dec self.health (math.max 1 (r (- damage 5) damage)))
(if (<= self.health 0)
(do (global *time-elapsed* 0)
(set self.state :dead)
Expand Down Expand Up @@ -1339,10 +1340,11 @@
(for [i (+ camtile 30) (+ camtile 60) 1]
;; Tries to find a bottom free location
(for [j 10 16 1]
(when (and (> (mget i j) 127) (= (mget i (- j 1)) 0))
(when (and (> (mget i j) 127) (= (mget i (- j 1)) 0) (not= i *last-snail-x*))
(spawn-enemy (or ?enemy :snail)
(- (* (- i camtile -1) 8) (% (math.abs *cam*.x) 8))
(+ (* (- j 1) 8) 4))
(global *last-snail-x* i)
(set found-tile true)
(lua :break)))
(when found-tile (lua :break)))))
Expand Down Expand Up @@ -1397,6 +1399,8 @@
(global *active-spawners* 0)
(global *spawner* { :enemy :simple-fish :delay 30 :duration 5 :finished false })

;; Avoids overlapping snails
(global *last-snail-x* 0)
(set *spawner*.update
(fn [self ?delay ?x ?y ?enemy]
(when (= (% *tick* (or ?delay self.delay)) 0)
Expand Down Expand Up @@ -1558,12 +1562,13 @@
;; Draws algae with a parallax factor pfactor
(fn draw-algae [pfactor]
(local positions [ 0 15 32 39 47 56 62 79 83 98 107 113 125 132 147 153 165 169 177 182 189 198 213 224 232 240 ])
(local sprites [ 51 54 51 52 52 53 54 51 54 53 51 53 51 53 54 52 54 52 51 60 54 78 79 51 52 54 ])
(local sprites [ 51 54 51 52 52 53 54 51 54 53 51 53 51 53 54 52 54 52 51 53 54 52 54 51 52 54 ])

(for [i 1 (math.min (length positions) (length sprites)) 1]
(for [i 1 26 1]
;(for [i 1 15 1]
(local pos (. positions i))
(trace (length positions))
(trace (length sprites))
;(trace (length positions))
;(trace (length sprites))
(loop-spr (. sprites i) pos (+ 136 (% pos 8)) 1 5 pfactor 0 (% pos 2))))

;; Draws background decoration
Expand Down

0 comments on commit 4207dc8

Please sign in to comment.