-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox.py
114 lines (102 loc) · 4.77 KB
/
sandbox.py
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
import sys
import pygame
from Entities.Objects.text_object import TextObject
from Entities.background import Background
from Entities.hero import Hero
from static import RIGHT, bg_images_paths, scale_screen_resolution, hero_sprites_paths
def main():
"""
None -> None
This function sets hero,background and creates the methods for controlling and commanding hero.
"""
pygame.init()
window = pygame.display.set_mode((1536, 864), pygame.FULLSCREEN)
pygame.display.set_caption('FAR')
background = Background(bg_images_paths, scale_screen_resolution,
window)
background.draw()
hero = Hero(hero_sprites_paths, 0, 0, 100, 125, 100,
20,
40, background)
hero.draw(RIGHT)
clock = pygame.time.Clock()
playing = True
while playing:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
playing = False
break
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
moving = True
while moving:
if hero.coordinates[0] < window.get_width() - hero.width - 10:
hero.move(hero.speed, 0)
for stop_event in pygame.event.get():
if (stop_event.type == pygame.KEYUP and stop_event.key == event.key) or hero.winner:
if hero.winner:
hero.move(1, 0)
hero.winner = False
moving = False
break
elif event.key == pygame.K_LEFT:
moving = True
while moving:
if hero.coordinates[0] >= 10:
hero.move(-hero.speed, 0)
for stop_event in pygame.event.get():
if (stop_event.type == pygame.KEYUP and stop_event.key == event.key) or hero.winner:
if hero.winner:
hero.move(-1, 0)
hero.winner = False
moving = False
break
elif event.key == pygame.K_UP:
moving = True
while moving:
if hero.coordinates[1] >= 5:
hero.move(0, -hero.speed)
for stop_event in pygame.event.get():
if (stop_event.type == pygame.KEYUP and stop_event.key == event.key) or hero.winner:
if hero.winner:
hero.move(0, 1)
hero.winner = False
moving = False
break
elif event.key == pygame.K_DOWN:
moving = True
while moving:
if hero.coordinates[1] < window.get_height() - hero.height:
hero.move(0, hero.speed)
for stop_event in pygame.event.get():
if (stop_event.type == pygame.KEYUP and stop_event.key == event.key) or hero.winner:
if hero.winner:
hero.move(0, -1)
hero.winner = False
moving = False
break
elif event.key == pygame.K_ESCAPE:
playing = False
break
if len(background.enemies) == 0:
background.current_level += 1
if background.current_level == 4:
pygame.display.flip()
window.fill((0, 0, 0))
win_obj = TextObject(
780, 444, lambda: 'YOU ARE PROMOTED', (0, 255, 0, 1), 'Consolas', 70)
win_obj.draw(window, centralized=True)
pygame.display.update()
pygame.time.delay(2000)
pygame.display.quit()
pygame.quit()
sys.exit()
else:
hero.coordinates = [0, 0]
background.set_enemies_strength()
background.draw(background.current_level)
hero.move(1, 0)
pygame.display.update()
if __name__ == '__main__':
main()