-
Notifications
You must be signed in to change notification settings - Fork 0
/
jogabilijogo.nelua
142 lines (106 loc) · 4.23 KB
/
jogabilijogo.nelua
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
require 'confs'
require 'nene.core'
require 'nene.colors'
require 'nene.math'
require 'nene.texture'
require 'nene.font'
require 'nene.text_texture'
require 'entities'
local Vec2 = Math.Vec2
local ok, nene = Nene.init("Jogabilijogo 2021", Confs.window_size.w, Confs.window_size.h) --, nil, nil, SDL_WINDOW_FULLSCREEN)
check(ok)
defer nene:terminate() end
local screen: Texture = Texture.create_texture(nene, Confs.screen_size.w, Confs.screen_size.h, nil, SDL_TEXTUREACCESS_TARGET)
defer screen:destroy() end
local protagonist_tex, ok = Texture.load(nene, 'res/arts/characters/player.png')
check(ok, 'could not load player texture')
defer protagonist_tex:destroy() end
local projectile_tex, ok = Texture.load(nene, 'res/arts/characters/bullet.png')
check(ok, 'could not load projectile texture')
defer projectile_tex:destroy() end
local enemy_tex, ok = Texture.load(nene, 'res/arts/characters/enemy.png')
check(ok, 'could not load enemy texture')
defer enemy_tex:destroy() end
local aim_tex, ok = Texture.load(nene, 'res/arts/characters/aim.png')
check(ok, 'could not load aim texture')
defer aim_tex:destroy() end
local bg_tex, ok = Texture.load(nene, 'res/arts/characters/scenary.png')
check(ok, 'could not load scenary bg texture')
defer bg_tex:destroy() end
local heart_tex, ok = Texture.load(nene, 'res/arts/characters/heart.png')
check(ok, 'could not load heart texture')
defer heart_tex:destroy() end
local monogram24, ok = Font.load('res/monogram_extended.ttf', 24)
check(ok, 'could not load "monogram_extended.ttf, 24"')
defer monogram24:destroy() end
local monogram48, ok = Font.load('res/monogram_extended.ttf', 48)
check(ok, 'could not load "monogram_extended.ttf, 48"')
defer monogram48:destroy() end
local ammo_counter_texts: [11]TextTexture = {
TextTexture.new(nene, '0', monogram24),
TextTexture.new(nene, '1', monogram24),
TextTexture.new(nene, '2', monogram24),
TextTexture.new(nene, '3', monogram24),
TextTexture.new(nene, '4', monogram24),
TextTexture.new(nene, '5', monogram24),
TextTexture.new(nene, '6', monogram24),
TextTexture.new(nene, '7', monogram24),
TextTexture.new(nene, '8', monogram24),
TextTexture.new(nene, '9', monogram24),
TextTexture.new(nene, '10', monogram24),
}
defer
for i = 0, < #ammo_counter_texts do
ammo_counter_texts[i]:destroy()
end
end
local you_lost: TextTexture = TextTexture.new(nene, 'You lost', monogram48)
defer you_lost:destroy() end
local you_won: TextTexture = TextTexture.new(nene, 'You Won!', monogram48)
defer you_won:destroy() end
local protagonist = Entities.Protagonist.init(protagonist_tex, projectile_tex, heart_tex)
local last_enemy_spawn = 0_uint32
local enemies: [10]Entities.Enemy = {}
local enemies_destroyed, enemies_spawned = 0_u8, 0_byte
local function spawn_enemy()
for i = 0, < #enemies do
if not enemies[i].active then
enemies[i] = Entities.Enemy.init(enemy_tex, nene.current_time)
last_enemy_spawn = nene.current_time
enemies_spawned = enemies_spawned + 1
return
end
end
end
SDL_ShowCursor(SDL_DISABLE)
repeat
nene:poll_events()
if (protagonist.life_points > 0 and protagonist.pos.y < Confs.screen_size.h) or enemies_destroyed >= Confs.enemies_count then
if nene.current_time - last_enemy_spawn > Confs.enemy_spawn_interval and enemies_spawned < Confs.enemies_count then
spawn_enemy()
end
protagonist:update(nene)
for i = 0, < #enemies do
enemies[i]:update(protagonist, &enemies_destroyed, nene)
end
end
nene:set_render_target(screen:get())
nene:render_clear(Color{33, 37, 36})
if enemies_destroyed >= Confs.enemies_count then
you_won:draw(nene, {0, 0})
elseif protagonist.life_points > 0 and protagonist.pos.y < Confs.screen_size.h then
bg_tex:draw(nene, nil, nil, {Confs.playable_space.margin, 0})
protagonist:draw(nene)
for i = 0, < #enemies do
enemies[i]:draw(nene)
end
ammo_counter_texts[protagonist.ammo]:draw(nene, nene.mouse_pos * 0.5 + Vec2{ 8, -16 })
local aimx, aimy = math.ifloor(nene.mouse_pos.x * 0.5 - aim_tex.width / 2), math.ifloor(nene.mouse_pos.y * 0.5 - aim_tex.height / 2)
aim_tex:draw(nene, nil, nil, {aimx, aimy})
else
you_lost:draw(nene, {0,0})
end
nene:set_render_target(nil)
screen:draw(nene)
nene:render_present()
until nene.quit