-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.moon
190 lines (141 loc) · 3.76 KB
/
main.moon
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
require "lovekit.all"
reloader = require "lovekit.reloader"
g = love.graphics
import timer, keyboard, audio from love
import concat from table
require "lovekit.screen_snap"
-- snapper = ScreenSnap!
require "autotile"
require "attack"
require "enemy"
require "effects"
require "levels.all"
p = (str, ...) -> g.print str\lower!, ...
-- prints lines of text over time
class Printer extends Sequence
rate: 0.1
line_height: 8
new: (str) =>
@line = 1
@char = 1
@lines = split str, "\n"
super ->
while @line <= #@lines
wait @rate
@char += 1
if @char > #@lines[@line]
@char = 1
@line += 1
-- all done
@line = #@lines
@char = #@lines[@line]
draw: (x, y) =>
for i=1,@line
text = @lines[i]
text = text\sub 1, @char if i == @line
p text, x, y + i * @line_height
class Player extends Entity
watch_class self
w: 8, h: 4
ox: 1, oy: 8
alive: true
__tostring: => concat { "<Player: ", tostring(@box), ">" }
state_names: {
walk: {"walk_up", "walk_up", "walk_down", "walk_down"}
stand: {"stand_up", "stand_up", "stand_down", "stand_down"}
}
new: (...) =>
super ...
@sprite = Spriter imgfy"img/sprite.png", 10, 13, 3
@last_direction = "down"
@cur_attack = nil
@weapon = Spear self
with @sprite
@anim = StateAnim "stand_down", {
stand_down: \seq {5}
stand_up: \seq {8}
stand_right: \seq {11}
stand_left: \seq {11}, 0, true
walk_down: \seq {3, 4}, 0.25
walk_up: \seq {6, 7}, 0.25
walk_right: \seq {9, 10}, 0.25
walk_left: \seq {9, 10}, 0.25, true
}
attack: =>
@weapon\try_attack!
take_hit: (enemy) =>
return if @hit
@hit = Flash!
draw: =>
if @last_direction == "up"
@weapon\draw! if @weapon
@draw_player!
else
@draw_player!
@weapon\draw! if @weapon
draw_player: =>
@hit\before! if @hit
@anim\draw @box.x - @ox, @box.y - @oy
@hit\after! if @hit
update: (dt) =>
base = if @velocity\is_zero! then
"stand"
else
@last_direction = @velocity\direction_name!
"walk"
dir = @last_direction or "down"
@anim\set_state base .. "_" .. dir
@weapon\update dt if @weapon
@anim\update dt
if @hit
@hit = nil unless @hit\update dt
super dt
true -- still alive
hello = Printer "hello\nworld!\n\nahehfehf\n\nAHHHHHFeefh\n\n...\nhelp me"
class Game
new: =>
@viewport = Viewport scale: 3
-- g.setLineWidth 1/@viewport.screen.scale
@player = Player nil, 42, 64
@set_world Level self
set_world: (world) =>
@world = world
@player.world = @world
world.entities\add @player
draw: =>
@viewport\apply!
@viewport\center_on @player
@world\draw!
-- p "I & you Lee! Forever Yours, Leafo.", 0,0
-- hello\draw 10, 10
@viewport\pop!
p tostring(timer.getFPS!), 2, 2
update: (dt) =>
reloader\update dt
@player.velocity = movement_vector 120
@world\update dt
hello\update dt
snapper\tick dt if snapper
on_key: (key, code) =>
switch key
when " "
print @player
when "x"
@player\attack!
export fonts = {}
load_font = (img, chars)->
font_image = imgfy img
g.newImageFont font_image.tex, chars
love.load = ->
-- g.setBackgroundColor 61, 52, 47
g.setBackgroundColor 61/2, 52/2, 47/2
fonts.main = load_font "img/font.png", [[ abcdefghijklmnopqrstuvwxyz-1234567890!.,:;'"?$&]]
fonts.damage = load_font "img/font2.png", [[ 1234567890]]
g.setFont fonts.main
game = Game!
dispatch = Dispatcher game
dispatch\bind love
love.mousepressed = (x,y, button) ->
x, y = game.viewport\unproject x, y
print "mouse", x, y, button
print game.world.map