-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebasDibujo.py
More file actions
121 lines (99 loc) · 2.67 KB
/
pruebasDibujo.py
File metadata and controls
121 lines (99 loc) · 2.67 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
'''
Tarea 2
Autor: Rodrigo Llull Torres
'''
import os
import random
import math
from init_pygame import *
from init_opengl import *
from OpenGL.GLUT import *
from Cordillera import Cordillera
from Fondo import Fondo
from Arbol import Arbol
from Rayo import Rayo
from Nube import Nube
# Se inicializan Pygame y OpenGL
os.environ["SDL_VIDEO_CENTERED"]= "1" # centra la pantalla
ancho= 800
alto= 600
init_pygame(ancho, alto, "Pruebas de dibujo")
init_opengl(ancho, alto)
objs= []
arboles= []
rayos= []
nubes= []
fondo= Fondo(ancho, alto)
cordillera= Cordillera(ancho, alto)
objs.append(fondo)
objs.append(cordillera)
reloj= pygame.time.Clock()
FPS= 6.0
for i in range(10):
suelo= cordillera.getPuntosBorde()
arbol= Arbol(suelo, alto)
arboles.append(arbol)
for i in range(4):
nube= Nube(ancho, alto)
nubes.append(nube)
def lanzarRayo():
if arboles != []:
al= random.randint(0, len(arboles)-1)
arbol= arboles[al]
arbol.atacar(1)
al= random.randint(0, len(nubes)-1)
nube= nubes[al]
rayo= Rayo(nube.getPosicion(), arbol.getBlanco())
rayos.append(rayo)
if arbol.estaDebilitado():
arboles.remove(arbol)
print('Atacaste al árbol de blanco '+str(arbol.getBlanco()[0])+','+str(arbol.getBlanco()[1]))
else:
print("No hay árboles")
def lanzarMuchosRayos():
al= random.randint(2, 10)
if al <= len(arboles):
for i in range(al):
lanzarRayo()
else:
for i in arboles:
lanzarRayo()
run= True
dibujarPunto= False
while run:
for event in pygame.event.get():
if event.type == QUIT:
run= False
elif event.type == KEYDOWN:
if event.key == K_q:
run= False
elif event.key == K_a:
arbol= Arbol(suelo, alto)
arboles.append(arbol)
elif event.key == K_SPACE:
lanzarRayo()
dibujarPunto= True
elif event.key == K_m:
lanzarMuchosRayos()
# Dibujaremos algo de prueba
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # limpia la pantalla
reloj.tick(FPS)
fondo.dibujar()
cordillera.dibujar()
if arboles != []:
for arbol in arboles:
arbol.dibujar()
if rayos != []:
for rayo in rayos:
rayo.dibujar()
rayo.actualizar(1/FPS)
if rayo.estaDebilitado():
rayos.remove(rayo)
for nube in nubes:
nube.dibujar()
nube.actualizar()
if glutSwapBuffers:
glutSwapBuffers()
pygame.display.flip()
pygame.quit()