-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActividades con PyGame
90 lines (63 loc) · 1.75 KB
/
Actividades con PyGame
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
== Dibujando con un circulo ==
Archivo <code>juego.py</code>, para ejecutar con comando <code>python juego.py</code> en Terminal:
<code><pre>
#!/usr/bin/env python
import pygame
import sys
pygame.init()
modes = pygame.display.list_modes()
print modes
s = pygame.display.set_mode(modes[0], pygame.FULLSCREEN)
x = 100
y = 200
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
sys.exit(0)
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
sys.exit(0)
if pygame.key.get_pressed()[pygame.K_RIGHT]:
x = x + 1
if pygame.key.get_pressed()[pygame.K_LEFT]:
x = x - 1
if pygame.key.get_pressed()[pygame.K_UP]:
y = y - 1
if pygame.key.get_pressed()[pygame.K_DOWN]:
y = y + 1
pygame.draw.circle(s, (255, 255, 0), (x, y), 50)
pygame.display.update()
</pre></code>
== Una serpiente que mueve ==
<code><pre>
#!/usr/bin/env python
import pygame
import sys
import math
pygame.init()
modes = pygame.display.list_modes()
print modes
s = pygame.display.set_mode(modes[0], pygame.FULLSCREEN)
x = 100
y = 200
a = 0
worm = []
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
sys.exit(0)
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
sys.exit(0)
if len(worm) > 100:
pygame.draw.circle(s, (0, 0, 0), worm.pop(), 50)
if pygame.key.get_pressed()[pygame.K_RIGHT]:
a = a + 1
if pygame.key.get_pressed()[pygame.K_LEFT]:
a = a - 1
x = x + math.cos(a/180.0*math.pi)
y = y + math.sin(a/180.0*math.pi)
pygame.draw.circle(s, (255, 255, 0), (x, y), 50)
worm.insert(0, (x, y))
pygame.display.update()
</pre></code>