Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions Space_Cute_2d/explosion.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,12 @@ def draw(self):
glDisable(GL_TEXTURE_2D)

if time() - self.start >= EXPLOSION_FRAME:
if not self.type == "player":
self.quadro += 1
self.start = time()

if self.quadro >= EXPLOSION_FRAMES:
self.quadro = 0
self.dead = True
else:
self.quadro += 1
self.start = time()

if self.quadro >= EXPLOSION_FRAMES:
self.quadro = 0
self.dead = True
self.quadro += 1
self.start = time()

if self.quadro >= EXPLOSION_FRAMES:
self.quadro = 0
self.dead = True
Comment on lines -73 to +78
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Explode.draw refactored with the following changes:


# Move o objeto
def move_me(self, x, y):
Expand Down
94 changes: 48 additions & 46 deletions Space_Cute_2d/main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def __init__(self, parent):
self.explosion_queue = Queue_rotative()
self.propellant_queue = Queue_rotative()
self.power_queue = Queue_rotative()
self.animation_explosion = [None for i in range (EXPLOSION_FRAMES)]
self.animation_propellant_enemy = [None for i in range (PROPELLANT_FRAMES)]
self.img_planets = [None for i in range (10)]
self.animation_explosion = [None for _ in range (EXPLOSION_FRAMES)]
self.animation_propellant_enemy = [None for _ in range (PROPELLANT_FRAMES)]
self.img_planets = [None for _ in range (10)]
Comment on lines -147 to +149
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.__init__ refactored with the following changes:

self.img_nave_azul = None
self.img_nave_amarela = None
self.img_nave_preta = None
Expand All @@ -166,35 +166,35 @@ def __init__(self, parent):
# Inicializa as filas de pre carregamentos
def init_queue(self):

for i in range (20):
for _ in range (20):
new = Enemy()
self.enemy_queue.push(new)

for i in range (50):
for _ in range (50):
new = Asteroide()
self.asteroid_queue.push(new)

for i in range(100):
for _ in range(100):
new = Shoot()
self.bullets_queue.push(new)

for i in range(10):
for _ in range(10):
new = Flor()
self.flowers_queue.push(new)

for i in range(10):
for _ in range(10):
new = Planeta()
self.planets_queue.push(new)

for i in range(50):
for _ in range(50):
new = Explode()
self.explosion_queue.push(new)

for i in range(30):
for _ in range(30):
new = Propellant()
self.propellant_queue.push(new)

for i in range(20):
for _ in range(20):
Comment on lines -169 to +197
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.init_queue refactored with the following changes:

new = Power_up()
self.power_queue.push(new)

Expand All @@ -221,13 +221,16 @@ def initializeGL(self):
self.imageID_back = self.loadImage("img/Background.png")

for i in range(EXPLOSION_FRAMES):
self.animation_explosion[i] = self.loadImage("img/explosion/Comp" + str(i) + ".png")
self.animation_explosion[i] = self.loadImage(f"img/explosion/Comp{str(i)}.png")

for i in range(PROPELLANT_FRAMES):
self.animation_propellant_enemy[i] = self.loadImage("img/fire/Comp" + str(i) + ".png")
self.animation_propellant_enemy[i] = self.loadImage(
f"img/fire/Comp{str(i)}.png"
)


for i in range (10):
self.img_planets[i] = self.loadImage("img/planets/planeta" +str(i) + ".png")
self.img_planets[i] = self.loadImage(f"img/planets/planeta{str(i)}.png")
Comment on lines -224 to +233
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.initializeGL refactored with the following changes:


self.img_nave_amarela = self.loadImage("img/nave4.png")
self.img_nave_azul = self.loadImage("img/nave1.png")
Expand Down Expand Up @@ -366,7 +369,7 @@ def paintGL(self):
# Desenha os ornamentos ( "Flores" )
# e retira os objetos "mortos" retornando eles para a fila
for obj in self.ornaments:
if not obj == None:
if obj is not None:
Comment on lines -369 to +372
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.paintGL refactored with the following changes:

if obj.dead:
if isinstance(obj, Flor):
self.flowers_queue.push(obj)
Expand Down Expand Up @@ -395,7 +398,7 @@ def paintGL(self):
# e retira os objetos mortos retornando ele para a fila
# e instancia uma explosao no lugar
for obj in self.in_scene:
if not obj == None:
if obj is not None:
if obj.dead:
if isinstance(obj, Enemy):
new_explosion = self.explosion_queue.pop()
Expand All @@ -419,9 +422,8 @@ def paintGL(self):
elif isinstance(obj, Power_up):
self.power_queue.push(obj)
self.in_scene.remove(obj)
if isinstance(obj, Nave):
if obj.shooting:
self.create_shoot(obj.move_x + obj.position_x)
if isinstance(obj, Nave) and obj.shooting:
self.create_shoot(obj.move_x + obj.position_x)
obj.draw()
obj.act()
obj.check_dead()
Expand All @@ -430,7 +432,7 @@ def paintGL(self):
for obj_A in self.in_scene:
if isinstance(obj_A, Asteroide):
for obj_B in self.in_scene:
if not (obj_A == obj_B):
if obj_A != obj_B:
if isinstance(obj_B, Nave) and self.collide(obj_B, obj_A):
ui.down_life()
obj_A.dead = True
Expand Down Expand Up @@ -464,46 +466,46 @@ def paintGL(self):

obj_A.elapsed_shoot_time = 0
for obj_B in self.in_scene:
if not (obj_A == obj_B):
if obj_A != obj_B:
if isinstance(obj_B, Nave) and self.collide(obj_B, obj_A):
ui.down_life()
obj_A.dead = True
elif isinstance(obj_B, Shoot) and self.collide(obj_B, obj_A):
if not obj_B.is_enemy:
obj_A.dead = True
if self.hack:
obj_B.dead = False
else:
obj_B.dead = True
obj_B.dead = not self.hack
self.sound_explosion.play()
ui.up_point(10)
if ui.score % 1000 == 0:
self.sound_1000pts.play()
elif isinstance(obj_A, Shoot):
if obj_A.is_enemy:
for obj_B in self.in_scene:
if not (obj_A == obj_B):
if isinstance(obj_B, Nave) and self.collide(obj_B, obj_A):
ui.down_life()
obj_A.dead = True
if (
obj_A != obj_B
and isinstance(obj_B, Nave)
and self.collide(obj_B, obj_A)
):
ui.down_life()
obj_A.dead = True
elif isinstance(obj_A, Nave):
if self.speed:
obj_A.speed = 3
else:
obj_A.speed = 0
obj_A.speed = 3 if self.speed else 0
for obj_B in self.in_scene:
if not (obj_A == obj_B):
if isinstance(obj_B, Power_up) and self.collide(obj_B, obj_A):
obj_B.dead = True
self.sound_power.play()
if obj_B.skin == 0:
ui.up_life()
elif obj_B.skin == 1:
self.hack = True
self.elapsed_time_power_shoot = 0
elif obj_B.skin == 2:
self.speed = True
self.elapsed_time_power_speed = 0
if (
obj_A != obj_B
and isinstance(obj_B, Power_up)
and self.collide(obj_B, obj_A)
):
obj_B.dead = True
self.sound_power.play()
if obj_B.skin == 0:
ui.up_life()
elif obj_B.skin == 1:
self.hack = True
self.elapsed_time_power_shoot = 0
elif obj_B.skin == 2:
self.speed = True
self.elapsed_time_power_speed = 0

self.spawn_asteroide()
self.spawn_inimigos()
Expand Down Expand Up @@ -554,7 +556,7 @@ def spawn_planets(self):

# Retorna um tamanho aleatorio para os planetas
def rand_tam(self):
return float(str(randint(0, 2)) +"."+ str(randint(1, 5)))
return float(f"{str(randint(0, 2))}.{str(randint(1, 5))}")
Comment on lines -557 to +559
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main.rand_tam refactored with the following changes:


# Retorna um tamanho aleatorio para as estrelas
def rand_tam_star(self):
Expand Down
Loading