-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.lua
More file actions
104 lines (96 loc) · 2.99 KB
/
draw.lua
File metadata and controls
104 lines (96 loc) · 2.99 KB
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
function _draw()
cls()
if app_state == GAME_PLAYING then
draw_map()
draw_player()
draw_enemies()
draw_bullets()
draw_despawn_sprites()
end
print_text_by_game_state()
end
function draw_map()
for row_index=1,MAP_ROW_COUNT do
row = map[row_index]
for col_index=1,MAP_COL_COUNT do
draw_tile_in_index(row[col_index], row_index, col_index)
end
end
end
function draw_tile_in_index(tile_identifier, row_index, col_index)
if tile_identifier == GRASS_TYPE then
sprite_index = GRASS_TILE_SPRITE
elseif tile_identifier == SAND_TYPE then
sprite_index = SAND_TILE_SPRITE
else
sprite_index = WATER_TILE_SPRITE
end
x = world_from_tile_axis(col_index)
y = world_from_tile_axis(row_index)
spr(sprite_index, x, y)
end
function draw_player()
if player.form == GRASS_TYPE then
if player.heading_direction == UP then
sprite_index = PLAYER_GRASS_BACK_SPRITE
else
sprite_index = PLAYER_GRASS_SPRITE
end
end
if player.form == SAND_TYPE then
if player.heading_direction == UP then
sprite_index = PLAYER_SAND_BACK_SPRITE
else
sprite_index = PLAYER_SAND_SPRITE
end
end
if player.form == WATER_TYPE then
if player.heading_direction == UP then
sprite_index = PLAYER_WATER_BACK_SPRITE
elseif player.heading_direction == DOWN then
sprite_index = PLAYER_WATER_FORWARD_SPRITE
elseif player.heading_direction == LEFT then
sprite_index = PLAYER_WATER_LEFT_SPRITE
else
sprite_index = PLAYER_WATER_RIGHT_SPRITE
end
end
spr(sprite_index, world_from_tile_axis(player.col), world_from_tile_axis(player.row))
end
function draw_enemies()
for enemy in all(enemies) do
draw_enemy(enemy)
end
end
function draw_enemy(enemy)
if enemy.type == GRASS_TYPE then
sprite_index = ENEMY_GRASS_SPRITE
elseif enemy.type == SAND_TYPE then
sprite_index = ENEMY_SAND_SPRITE
elseif enemy.type == WATER_TYPE then
sprite_index = ENEMY_WATER_SPRITE
else
sprite_index = ENEMY_NEUTRAL_SPRITE
end
spr(sprite_index, world_from_tile_axis(enemy.col), world_from_tile_axis(enemy.row))
end
function draw_bullets()
for bullet in all(bullets) do
draw_bullet(bullet)
end
end
function draw_bullet(bullet)
if bullet.type == GRASS_TYPE then
sprite_index = GRASS_BULLET_SPRITE
elseif bullet.type == SAND_TYPE then
sprite_index = SAND_BULLET_SPRITE
elseif bullet.type == WATER_TYPE then
sprite_index = WATER_BULLET_SPRITE
end
spr(sprite_index, world_from_tile_axis(bullet.col), world_from_tile_axis(bullet.row))
end
function draw_despawn_sprites()
for despawn_sprite in all(despawn_sprites) do
spr(despawn_sprite.sprite, world_from_tile_axis(despawn_sprite.col), world_from_tile_axis(despawn_sprite.row))
end
end