Repository navigation
Expand file tree
/
Copy pathMain.py
More file actions
60 lines (46 loc) · 1.45 KB
/
Copy pathMain.py
File metadata and controls
60 lines (46 loc) · 1.45 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
import pygame
from entidades.jugador import Jugador
from entidades.enemigo import Enemigo
from motor.mapa import Mapa
pygame.init()
ANCHO, ALTO = 800, 600
pantalla = pygame.display.set_mode((ANCHO, ALTO))
clock = pygame.time.Clock()
mapa = Mapa(ANCHO, ALTO)
jugador = Jugador(400, 300)
enemigos = [Enemigo(100, 100), Enemigo(700, 200), Enemigo(200, 500)]
proyectiles = []
ejecutando = True
while ejecutando:
for event in pygame.event.get():
if event.type == pygame.QUIT:
ejecutando = False
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
destino = pygame.mouse.get_pos()
proyectiles.append(jugador.disparar(destino))
teclas = pygame.key.get_pressed()
jugador.mover(teclas)
# Actualizar enemigos
for enemigo in enemigos:
enemigo.actualizar(jugador)
# Actualizar proyectiles
for p in proyectiles:
p.actualizar()
# Colisiones proyectil-enemigo
for p in proyectiles[:]:
for e in enemigos[:]:
if (e.pos - p.pos).length() < e.radio + p.radio:
if e.recibir_daño(20):
enemigos.remove(e)
proyectiles.remove(p)
break
pantalla.fill((30, 30, 30))
mapa.dibujar(pantalla)
jugador.dibujar(pantalla)
for e in enemigos:
e.dibujar(pantalla)
for p in proyectiles:
p.dibujar(pantalla)
pygame.display.flip()
clock.tick(60)
pygame.quit()