-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo.rb
154 lines (139 loc) · 3.92 KB
/
jogo.rb
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
$LOAD_PATH << '.'
require 'gosu'
require 'jogador'
require 'flecha'
require 'urso'
class Jogo01 < Gosu::Window
@@formato = [3, 1.0, 1.0, 0xff1a1757] #acessado na mensagem de fim
def initialize
super(1024,600,false)
self.caption = "Female Killer"
@imagem_fundo = Gosu::Image.new(self, "images/grama.gif", true)
@pos_x_background = 0
@aux = 0
@jogador = Jogador.new(self)
@urso = Array.new
@flecha = Array.new
@font = Gosu::Font.new(self, Gosu::default_font_name, 30)
@estado = "INICIO"
@imagem_nome = Gosu::Image.new(self, "images/female.png", true)
@imagem_menu = Gosu::Image.new(self, "images/bravep.png", true)
@start = Gosu::Image.new(self, "images/Start.png", true)
@restart = Gosu::Image.new(self, "images/Restart.png", true)
@cursor = Gosu::Image.new(self, "images/cursor.png",true)
#cria flecha
for i in 0..10 do
@flecha << Flecha.new(@jogador, self)
end
#cria urso
for i in 0..5 do
@urso << Urso.new(self)
end
end
def draw
@imagem_fundo.draw(@pos_x_background,0,0)
if @estado == "INICIO" then draw_inicio
elsif @estado == "JOGANDO" then draw_jogando
elsif @estado == "FIM" then draw_fim
end
end
def draw_inicio
@imagem_nome.draw(90,-90,1)
@imagem_menu.draw(-60,0,0)
@cursor.draw(mouse_x, mouse_y, 2)
@start.draw(353,250,1) #posição da imagem
end
def draw_jogando
@jogador.draw()
for urso in @urso do
urso.draw
end
for flecha in @flecha do
flecha.draw()
end
@font.draw("Placar: #{@jogador.placar}", 10, 10, 3, 1.0, 1.0, 0xffff4500) #desenhando o placar no jogo
end
def draw_fim
@imagem_menu.draw(0,0,0)
@cursor.draw(mouse_x, mouse_y, 2)
@restart.draw(353,250,1) #posição da imagem
msg = "FIM DE JOGO, VOCE FEZ #{@jogador.placar} PONTOS"
x = self.width / 2 - @font.text_width(msg,1) / 2
@font.draw(msg, x, self.height/4, *@@formato)
end
def update
if @estado =="JOGANDO" then update_jogando end
end
def update_jogando
if ( button_down?(Gosu::Button::KbRight) ) then
@jogador.girar_direita
end
if ( button_down?(Gosu::Button::KbLeft) ) then
@jogador.girar_esquerda
end
if ( button_down?(Gosu::Button::KbUp) ) then
@jogador.acelerar
@aux = @aux+1
end
if (button_down?(Gosu::Button::KbDown)) then
@jogador.desacelerar
@aux = @aux+1
end
if (button_down?(Gosu::Button::KbSpace)) then
for flecha in @flecha do
flecha.atirar
flecha.deleta_flecha(@flecha, @jogador)
end
end
@jogador.update
#movimenta o background
if (@aux >= 1) then
@pos_x_background = @pos_x_background - 5
if(@pos_x_background<(-1024))then
@pos_x_background = 0
end
end
#cria novos ursos
if (rand(20) < 10 && @urso.size < 5) then
@urso.push(Urso.new(self))
end
for i in 0..@urso.size-1 do
@urso[i].update(@flecha,@jogador,@urso) unless @urso[i].nil?
end
for flecha in @flecha do
flecha.update
end
@jogador.mover
@estado = @jogador.morrer(@urso)
end
#checar estado final, e return ao jogo caso o restart esteja pressed
def button_up(id)
if @estado == "INICIO"
if (mouse_x > 353) && (mouse_x < 671) && (mouse_y > 250) && (mouse_y < 344) && (id == Gosu::MsLeft)
@estado = "JOGANDO"
end
end
if @estado == "FIM"
if (mouse_x > 353) && (mouse_x < 671) && (mouse_y > 250) && (mouse_y < 344) && (id == Gosu::MsLeft)
@estado = "JOGANDO"
zerar_valores
end
end
end
def zerar_valores
@aux = 0
@flecha = Array.new
@jogador.lives = 0
@jogador.placar = 0
@urso = Array.new
@jogador = Jogador.new(self)
@jogador.angulo = 0.0
for i in 0..10 do
@flecha << Flecha.new(@jogador, self)
end
#cria urso
for i in 0..5 do
@urso << Urso.new(self)
end
end
end