-
Notifications
You must be signed in to change notification settings - Fork 1
/
random position every second
60 lines (51 loc) · 1.3 KB
/
random position every second
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 pyglet
import random
window = pyglet.window.Window()
had_direction_step = 1
def tik(t):
global had_direction_step
screen_x, screen_y = window.get_size()
had.x += had_direction_step
if had.x >= screen_x - had.width:
had_direction_step = -1
elif had.x == 0:
had_direction_step = 1
def go_random_position(self):
screen_x, screen_y = window.get_size()
had2.x = random.randint(0, screen_x)
had2.y = random.randint(0, screen_y)
def zpracuj_text(text):
if text == 'd':
had.x += 40
if text == 'w':
had.y += 40
if text == 'e':
had.rotation += 20
if text == 'a':
had.x -= 40
if text == 's':
had.y -= 40
if text == 'q':
had.rotation -= 20
def klik(x, y, tlacitko, mod):
if mod == 0:
had2.x = x
had2.y = y
else:
had2.rotation -= 25
def vykresli():
window.clear()
had.draw()
had2.draw()
window.push_handlers(
on_text=zpracuj_text,
on_draw=vykresli,
on_mouse_press=klik,
)
obrazek = pyglet.image.load('had.png')
obrazek2 = pyglet.image.load('had2.png')
had = pyglet.sprite.Sprite(obrazek)
had2 = pyglet.sprite.Sprite(obrazek2)
pyglet.clock.schedule_interval(tik, 1/30)
pyglet.clock.schedule_interval(go_random_position, 1)
pyglet.app.run()