summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <jakob@memeware.net>2018-10-25 10:43:46 -0400
committerJakob L. Kreuze <jakob@memeware.net>2018-10-25 10:43:46 -0400
commite5053056ad7a223466c8e56df7b63279458d2867 (patch)
tree33a5231c1d64b114136596aa75f16e8058b1927c
parentc60fe418289e4eb3f058fd43bcfdd2ad17c5eac2 (diff)
Majority of gameplay is implemented at this point
-rw-r--r--game.fnl59
-rw-r--r--maps/babysteps.fnl3
-rw-r--r--maps/babysteps.pngbin0 -> 217 bytes
-rw-r--r--maps/sandbox.fnl4
-rw-r--r--maps/sandbox.pngbin245 -> 182 bytes
-rw-r--r--player.fnl14
-rw-r--r--slimeball.fnl8
-rw-r--r--world.fnl16
8 files changed, 81 insertions, 23 deletions
diff --git a/game.fnl b/game.fnl
index 4dfa9c4..b9d4e69 100644
--- a/game.fnl
+++ b/game.fnl
@@ -20,35 +20,80 @@
(local slimeball (require :slimeball))
(local world (require :world))
-(local current-player (player.new))
-(local current-world (world.new "sandbox" current-player))
-(local current-camera (camera.new current-world screen-width screen-height))
-(: current-world :position-player-at 128 128)
+(local map-order ["sandbox" "babysteps"])
+
+(var screen-alpha 1)
+(var welcome-message-y (- (: (love.graphics.getFont) :getHeight)))
+(var welcome-message-timer 64)
+(local welcome-message-goal-y (: (love.graphics.getFont) :getHeight))
+
+(var current-player nil)
+(var current-world nil)
+(var current-camera nil)
+
+(fn next-map []
+ (set screen-alpha 1)
+ (set welcome-message-y (- (: (love.graphics.getFont) :getHeight)))
+ (set welcome-message-timer 64)
+
+ (let [map-name (table.remove map-order 1)]
+ (set current-player (player.new))
+ (set current-world (world.new map-name current-player))
+ (set current-camera (camera.new current-world screen-width screen-height))
+ (~= nil map-name)))
+
+(next-map)
+
+(fn draw-fade-in-mask []
+ (let [(r g b a) (love.graphics.getColor)]
+ (love.graphics.setColor 0 0 0 screen-alpha)
+ (love.graphics.rectangle "fill" 0 0 screen-width screen-height)
+ (love.graphics.setColor r g b a))
+ (when (< 0 screen-alpha)
+ (set screen-alpha (- screen-alpha 0.05))))
+
+(fn draw-welcome-message []
+ (when (< 0 welcome-message-timer)
+ (let [msg (string.format "Welcome to %s" (. current-world :name))
+ x (/ (- screen-width (: (love.graphics.getFont) :getWidth msg)) 2)]
+ (love.graphics.print msg x welcome-message-y))
+ (when (< welcome-message-y welcome-message-goal-y)
+ (set welcome-message-y (+ welcome-message-y 1)))
+ (when (= welcome-message-y welcome-message-goal-y)
+ (set welcome-message-timer (- welcome-message-timer 1)))))
(fn draw [message]
(let [camera-x (. current-camera :x-pos)
camera-y (. current-camera :y-pos)]
- (: current-world :draw camera-x camera-y screen-width screen-height)))
+ (: current-world :draw camera-x camera-y screen-width screen-height))
+ (draw-welcome-message)
+ (draw-fade-in-mask))
(fn update [dt set-mode]
(: current-world :update dt)
(: current-player :update dt)
(let [(camera-x camera-y) (: current-camera :focus-on-object current-player dt)]
(tset current-camera :x-pos camera-x)
- (tset current-camera :y-pos camera-y)))
+ (tset current-camera :y-pos camera-y))
+
+ (when (= (. current-world :surfaces-slimed) (. current-world :surfaces-total))
+ ;; if (next-map) returns nil, set-mode to endgame
+ (next-map)))
(fn keypressed [key set-mode]
(when (= key "x")
(: current-world :add-slimeball (slimeball.new current-player)))
(let [method (if (= key "right") :move-right
(= key "left") :move-left
+ (= key "up") :face-upwards
(= key "z") :jump)]
(when method
(: current-player method))))
(fn keyreleased [key set-mode]
(let [method (if (= key "right") :stop-right
- (= key "left") :stop-left)]
+ (= key "left") :stop-left
+ (= key "up") :face-normal)]
(when method
(: current-player method))))
diff --git a/maps/babysteps.fnl b/maps/babysteps.fnl
new file mode 100644
index 0000000..155b23b
--- /dev/null
+++ b/maps/babysteps.fnl
@@ -0,0 +1,3 @@
+{:name "Baby Steps"
+ :player-spawn-x 32
+ :player-spawn-y (* 6 32)}
diff --git a/maps/babysteps.png b/maps/babysteps.png
new file mode 100644
index 0000000..a7c532b
--- /dev/null
+++ b/maps/babysteps.png
Binary files differ
diff --git a/maps/sandbox.fnl b/maps/sandbox.fnl
index a0a2221..156c79a 100644
--- a/maps/sandbox.fnl
+++ b/maps/sandbox.fnl
@@ -1 +1,3 @@
-{:name "The Sandbox"}
+{:name "The Sandbox"
+ :player-spawn-x 32
+ :player-spawn-y 32}
diff --git a/maps/sandbox.png b/maps/sandbox.png
index 4aade9c..e0e40c8 100644
--- a/maps/sandbox.png
+++ b/maps/sandbox.png
Binary files differ
diff --git a/player.fnl b/player.fnl
index 013000a..9b8509a 100644
--- a/player.fnl
+++ b/player.fnl
@@ -75,6 +75,12 @@
(tset player :x-vel (- (* 8 x-normal) (. player :x-vel)))
(tset player :y-vel (- (math.abs (* 8 y-normal)) (. player :y-vel))))
+(fn face-upwards [player]
+ (tset player :action :sliming-up true))
+
+(fn face-normal [player]
+ (tset player :action :sliming-up false))
+
(local player-sheet
{:img (love.graphics.newImage "art/swanky.png")
:orientation-offset 128
@@ -137,9 +143,6 @@
:x-vel 0
:y-vel 0
- :cur-health 5
- :max-health 5
-
:orientation :right
:animation-x-offset 0
:animation-y-offset 0
@@ -149,7 +152,8 @@
:action {:jump false
:right false
- :left false}
+ :left false
+ :sliming-up false}
:next-position next-position
:next-x-vel next-x-vel
@@ -164,6 +168,8 @@
:stop-left stop-left
:jump jump
:bounce bounce
+ :face-upwards face-upwards
+ :face-normal face-normal
:draw draw-player
:update update-player-animations})
diff --git a/slimeball.fnl b/slimeball.fnl
index 7243aba..058763e 100644
--- a/slimeball.fnl
+++ b/slimeball.fnl
@@ -51,8 +51,12 @@
(- player-x player-width))
:y-pos player-y
- :x-vel (if (= :right orientation) 128 (- 128))
- :y-vel 0
+ :x-vel (if (. player :action :sliming-up)
+ 0
+ (if (= :right orientation) 128 (- 128)))
+ :y-vel (if (. player :action :sliming-up)
+ (- 128)
+ 0)
:next-position next-position
:update update-slimeball
diff --git a/world.fnl b/world.fnl
index a43eb95..152fa62 100644
--- a/world.fnl
+++ b/world.fnl
@@ -91,14 +91,10 @@
(draw-tile tile screen-x screen-y))))))))
(fn draw-hud [world screen-width screen-height]
- (let [cur-health (. world :player :cur-health)
- max-health (. world :player :max-health)
- font-height (: (love.graphics.getFont) :getHeight)
+ (let [font-height (: (love.graphics.getFont) :getHeight)
surfaces-slimed (. world :surfaces-slimed)
surfaces-total (. world :surfaces-total)
- health-msg (string.format "h: %d/%d" cur-health max-health)
- slime-msg (string.format "s: %d/%d" surfaces-slimed surfaces-total)]
- (love.graphics.print health-msg 0 (- screen-height (* 2 font-height)))
+ slime-msg (string.format "%d/%d" surfaces-slimed surfaces-total)]
(love.graphics.print slime-msg 0 (- screen-height font-height))))
(fn draw-object [object camera-x camera-y]
@@ -313,7 +309,8 @@
;; Touching bottom of surface.
(when (< 0 y-normal)
- (slime-tile world other :bottom))
+ (slime-tile world other :bottom)
+ (tset player :y-vel 0))
;; Touching left of surface.
(when (> 0 x-normal)
@@ -340,13 +337,14 @@
res (load-tiles (love.image.newImageData tiles-path))
res (lume.extend res {:player player})
res (lume.extend res {:slimeballs []})
- res (lume.extend res {:surfaces-slimed 0 :meta (load-meta meta-path)})
+ res (lume.extend res {:surfaces-slimed 0})
+ res (lume.extend res (load-meta meta-path))
res (lume.extend res {:surfaces-total (count-surfaces res)})
res (lume.extend res {:collision-map (new-collision-map res player)})
- res (lume.extend res {:position-player-at position-player-at})
res (lume.extend res {:add-slimeball add-slimeball})
res (lume.extend res {:draw draw-world})
res (lume.extend res {:update update-world})]
+ (position-player-at res (. res :player-spawn-x) (. res :player-spawn-y))
res))
{:tile-sheet tile-sheet