summaryrefslogtreecommitdiff
path: root/src/corridor.fnl
blob: a0ad593cfb65d072ca0d376090eeeb25019aa82a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;; corridor
;; maybe make this generic enough to have multiple
;; corridors with the same code, eventually

(local player (require :src.player))

(fn clamp [x min max]
    (if (< x min) min
        (> x max) max
        x))

(fn camera-trans-amt [player-x]
    (- (clamp (- player-x 320)
           0 400)))

(fn centre-pos [player-x]
    ; a bit hacky
    (+ 320 (- (camera-trans-amt player-x))))

(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)))))

    	
     
     ;(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 make [font]
    (local title (love.graphics.newText font :corridor))
    (local player (player.make))
    (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)
        (love.graphics.setColor 0.8 0.8 0.8)
        (love.graphics.setLineWidth 10)
        (love.graphics.rectangle :line 30 250  980 200)
        
        (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)
        (player:draw))
    
    (fn update [dt]
        (player:update dt))

    {: draw
     : update})

{: make}