summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corridor.fnl136
-rw-r--r--src/player.fnl34
2 files changed, 117 insertions, 53 deletions
diff --git a/src/corridor.fnl b/src/corridor.fnl
index a0ad593..d6aef59 100644
--- a/src/corridor.fnl
+++ b/src/corridor.fnl
@@ -9,66 +9,104 @@
(> x max) max
x))
-(fn camera-trans-amt [player-x]
- (- (clamp (- player-x 320)
- 0 400)))
+(fn draw-rectangle [mode x1 y1 x2 y2]
+ ; instead of width and height
+ (love.graphics.polygon mode
+ x1 y1 x2 y1
+ x2 y2 x1 y2))
-(fn centre-pos [player-x]
- ; a bit hacky
- (+ 320 (- (camera-trans-amt player-x))))
+(local WIDTH 640)
+(local HALFWIDTH (/ WIDTH 2))
-(local window-depth-x 15)
-(local window-depth-y 10)
-(local window-prlx-fact 0.04)
-(fn draw-window [x y w h cpos]
- (love.graphics.setColor 0.9 0.9 0.9)
- (love.graphics.rectangle :fill x y w h)
- (love.graphics.setColor 0 0 0)
- (love.graphics.setLineWidth 4)
- (love.graphics.rectangle :line x y w h)
-
- (let [centre (+ x (/ w 2))
- offset (- centre cpos)
- movt (* offset window-prlx-fact)
- left* (+ movt x window-depth-x)
- right* (+ movt (- (+ x w) window-depth-x))
- left (math.max left* x)
- right (math.min right* (+ x w))]
- (love.graphics.rectangle :line
- left
- (+ window-depth-y y)
- (- right left)
- (- h (* 2 window-depth-y)))))
+(local border-left -30)
+(local border-right 1520)
+
+(fn effective-ppos-x [player-x]
+ (let [threshold-left (+ border-left HALFWIDTH)
+ threshold-right (- border-right HALFWIDTH)]
+ (clamp player-x threshold-left threshold-right)))
+
+(fn trans-amt-x [player-x]
+ (let [eff (effective-ppos-x player-x)]
+ (- HALFWIDTH eff)))
-
-
- ;(love.graphics.rectangle :line
- ; (+ (* left-offset window-depth-x) x)
- ; (+ window-depth-y y)
- ; (- w (* 2 (* right-offset window-depth-x)))
- ; (- h (* 2 window-depth-y))))
+
+(fn draw-stars []
+ (love.graphics.setColor 0.05 0.05 0.2)
+ (love.graphics.rectangle :fill border-left 0 (- border-right border-left) 480)
+ (math.randomseed 69420)
+ (love.graphics.setColor 1 1 1)
+ (for [i 1 200]
+ (let [sz (math.random 3 10)
+ x (math.random border-left border-right)
+ y (math.random 0 480)
+ c (- 0.7 (* 0.3 (math.random)))]
+ (love.graphics.setColor 1 1 c)
+ (love.graphics.rectangle :fill x y sz sz))))
(fn make [font]
- (local title (love.graphics.newText font :corridor))
+ (local title (love.graphics.newText font "corridor A2"))
(local player (player.make))
+ (local windows [[10 100 400 80]
+ [600 100 400 80]
+ [1050 50 800 300]])
+
+
+ (fn draw-windows []
+ (love.graphics.stencil (fn []
+ (each [_ [x y w h] (pairs windows)]
+ (love.graphics.rectangle :fill x y w h))
+ :replace 1))
+ (love.graphics.setStencilTest :greater 0)
+ ; stil hacky
+ (love.graphics.push)
+ (let [cpos (trans-amt-x player.x)]
+ (love.graphics.translate (* -0.75 cpos) 0))
+ (draw-stars)
+ (love.graphics.pop)
+
+ (love.graphics.setStencilTest)
+ (love.graphics.setColor 0 0 0)
+ (love.graphics.setLineWidth 7)
+ (each [_ [x y w h] (pairs windows)]
+ (love.graphics.rectangle :line x y w h)))
+
+
(fn draw []
(love.graphics.setColor 0 0 0)
- (love.graphics.print (..
- :+px " " player.x "\n"
- :-px " " (- 320 player.x) "\n"
- :cta " " (camera-trans-amt player.x) "\n"
- :cps " " (centre-pos player.x))
- 6 20)
- (love.graphics.translate (camera-trans-amt player.x) 0)
+
+ (fn dbg-print [...]
+ ; bad
+ (var out {})
+ (for [i 1 (select :# ...) 2]
+ (table.insert out (..
+ (select i ...)
+ " "
+ (select (+ i 1) ...))))
+ (let [txt (table.concat out "\n")]
+ (love.graphics.print txt 6 28)
+ (love.graphics.print txt 500 400)))
+
+ (dbg-print
+ :x player.x
+ :y player.y)
+
+
+
+
+
+
+ (love.graphics.translate (trans-amt-x player.x) 0)
+
(love.graphics.setColor 0.8 0.8 0.8)
(love.graphics.setLineWidth 10)
- (love.graphics.rectangle :line 30 250 980 200)
+ (draw-rectangle :line 0 250 1000 450)
- (let [c (centre-pos player.x)]
- (draw-window 300 100 300 80 c)
- (draw-window 630 100 300 80 c))
-
- ;(love.graphics.draw title (- 610 (title:getWidth)) -10)
+ (draw-windows)
+
+ (love.graphics.draw title 0 10)
+
+
(player:draw))
(fn update [dt]
diff --git a/src/player.fnl b/src/player.fnl
index 9ba457a..53ceb59 100644
--- a/src/player.fnl
+++ b/src/player.fnl
@@ -17,20 +17,46 @@
world (if ?world ?world
{:move (fn move [_1 _2 tx ty] (values tx ty))})]
(when (not= sf 0)
+ (if (> vx 0) (set self.left false)
+ (< vx 0) (set self.left true))
(let [vx (/ vx sf)
vy (/ vy sf)
tx (+ self.x (* vx dt speed))
ty (+ self.y (* vy dt speed))
(ax ay) (world:move :player tx ty)]
- (tset self :x ax)
- (tset self :y ay)))))
+ (set self.x ax)
+ (set self.y ay)))))
(fn C.draw [self]
+ (love.graphics.push)
+ (love.graphics.translate self.x self.y)
+ (if self.left
+ (love.graphics.scale -1 1))
+ (love.graphics.scale 0.1)
+
(love.graphics.setColor 0.91 0.62 0)
- (love.graphics.rectangle :fill self.x self.y 10 10))
+ (love.graphics.circle :fill 0 0 150)
+ (love.graphics.setColor 1 1 1)
+ (love.graphics.setLineWidth 4)
+ (love.graphics.circle :line 0 0 150)
+
+
+ (love.graphics.setColor 0 0 0)
+ (love.graphics.circle :fill 30 -80 20)
+ (love.graphics.circle :fill 100 -80 20)
+
+ (love.graphics.setLineWidth 20)
+ (love.graphics.line 40 50 0 70)
+ (love.graphics.line 120 50 150 70)
+
+
+ (love.graphics.pop))
+
+
+
(fn make []
- (let [s {:x 170 :y 150}]
+ (let [s {:x 170 :y 150 :left false}]
(setmetatable s C)
s))