summaryrefslogtreecommitdiff
path: root/player.fnl
diff options
context:
space:
mode:
authorJakob L. Kreuze <jakob@memeware.net>2018-10-23 20:03:24 -0400
committerJakob L. Kreuze <jakob@memeware.net>2018-10-23 20:03:24 -0400
commitd2a4535049a9feccb611e6a7b80c872075de0b96 (patch)
tree57ffe4c6c6c56bcb245a30b03570648b357a2555 /player.fnl
parent0ecfdef4d6d9de2b26208349e5f6e5ca631110dc (diff)
Breaking everything with major (but necessary to address bugs in last commit) refactoring
Diffstat (limited to 'player.fnl')
-rw-r--r--player.fnl76
1 files changed, 76 insertions, 0 deletions
diff --git a/player.fnl b/player.fnl
new file mode 100644
index 0000000..250b70c
--- /dev/null
+++ b/player.fnl
@@ -0,0 +1,76 @@
+;;;; Copyright (C) 2018 Jakob L. Kreuze, All Rights Reserved.
+;;;;
+;;;; This file is part of slime-the-world.
+;;;;
+;;;; slime-the-world is free software: you can redistribute it and/or modify it
+;;;; under the terms of the GNU General Public License as published by the Free
+;;;; Software Foundation, either version 3 of the License, or (at your option)
+;;;; any later version.
+;;;;
+;;;; slime-the-world is distributed in the hope that it will be useful, but
+;;;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+;;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+;;;; more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License along
+;;;; with slime-the-world. If not, see <http://www.gnu.org/licenses/>.
+
+(local draw (require :draw))
+
+(fn move-right [player]
+ (tset player :orientation :right)
+ (tset player :action :right true)
+ (tset player :action :left false)
+ (tset player :x-vel (/ (. player :x-vel) 2)))
+
+(fn move-left [player]
+ (tset player :orientation :left)
+ (tset player :action :left true)
+ (tset player :action :right false)
+ (tset player :x-vel (/ (. player :x-vel) 2)))
+
+(fn position-at [player x y]
+ (tset player :x-pos x)
+ (tset player :y-pos y))
+
+(local player-sheet
+ {:img (love.graphics.newImage "art/swanky.png")
+ :orientation-offset 128
+ :width 24 :height 22
+ :padding-x 8 :padding-y 10})
+
+(fn draw-player [player x y]
+ (draw.tile x y player-sheet 0 0))
+
+;; Returns a new player object.
+(fn new-player []
+ {:width (. player-sheet :width)
+ :height (. player-sheet :height)
+
+ :goal-x-vel 128
+ :goal-y-vel 128
+
+ :x-pos 0
+ :y-pos 0
+
+ :x-vel 0
+ :y-vel 0
+
+ :orientation :right
+ ;; :frame 0
+ ;; :frame-delay 4
+ ;; :frame-timer 4
+
+ :grounded false
+
+ :action {:jump false
+ :right false
+ :left false}
+
+ :position-at position-at
+ :move-right move-right
+ :move-left move-left
+
+ :draw draw-player})
+
+{:new new-player}