-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
193 lines (148 loc) · 5.18 KB
/
main.py
File metadata and controls
193 lines (148 loc) · 5.18 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import pgzrun
import random
WIDTH = 800
HEIGHT = 400
game_over = False
score = 0
show_instructions = True
show_menu = True
sound_on = True
class Player:
def __init__(self):
self.images = ["run1", "run2", "run3"]
self.image_index = 0
self.actor = Actor(self.images[self.image_index], (100, 300))
self.vel_x = 0
self.vel_y = 0
self.gravity = 0.5
self.on_ground = True
self.speed = 3
self.idle_images = ["idle1", "idle2"]
self.idle_index = 0
def update(self):
if game_over or show_instructions or show_menu:
self.idle_index = (self.idle_index + 0.05) % len(self.idle_images)
self.actor.image = self.idle_images[int(self.idle_index)]
return
self.vel_y += self.gravity
self.actor.y += self.vel_y
if self.actor.y >= 300:
self.actor.y = 300
self.vel_y = 0
self.on_ground = True
self.actor.x += self.vel_x
self.actor.x = max(0, min(self.actor.x, WIDTH))
self.image_index = (self.image_index + 0.1) % len(self.images)
self.actor.image = self.images[int(self.image_index)]
def jump(self):
if self.on_ground:
self.vel_y = -26
self.on_ground = False
if sound_on:
sounds.jump.play()
def move_left(self):
self.vel_x = -self.speed
def move_right(self):
self.vel_x = self.speed
def stop(self):
self.vel_x = 0
def draw(self):
self.actor.draw()
class Enemy:
def __init__(self, x, y, image):
self.images = [image]
self.image_index = 0
self.actor = Actor(self.images[self.image_index], (x, y))
self.speed = random.choice([-3, 3])
self.direction = random.choice([-1, 1])
def update(self):
if game_over or show_instructions or show_menu:
return
self.actor.x += self.speed * self.direction
if self.actor.x < 50 or self.actor.x > WIDTH - 50:
self.direction *= -1
def draw(self):
self.actor.draw()
enemies = [Enemy(random.randint(400, WIDTH), 300, "enemy1"), Enemy(random.randint(400, WIDTH), 300, "enemy2")]
player = Player()
class NPC:
def __init__(self, x, y):
self.actor = Actor("npc", (x, y))
self.speed = 2
self.direction = 1
def update(self):
if game_over or show_instructions or show_menu:
return
self.actor.x += self.speed * self.direction
if self.actor.x < 200 or self.actor.x > WIDTH - 200:
self.direction *= -1
def draw(self):
self.actor.draw()
npc = NPC(600, 300)
def update():
global game_over, score
if show_instructions or show_menu:
return
player.update()
npc.update()
for enemy in enemies:
enemy.update()
if player.actor.colliderect(enemy.actor):
game_over = True
if sound_on:
sounds.hit.play()
if not game_over:
score += 1
def draw():
screen.clear()
screen.fill((173, 216, 230))
if show_menu:
screen.draw.text("RUNNER GAME", (250, 50), fontsize=40, color="black")
screen.draw.text("1. Oyuna Başla (BAS 'S')", (250, 150), fontsize=30, color="black")
screen.draw.text("2. Ses Aç/Kapat (BAS 'M')", (250, 200), fontsize=30, color="black")
screen.draw.text("3. Çıkış (BAS 'Q')", (250, 250), fontsize=30, color="black")
elif show_instructions:
screen.draw.text("Oyunu başlatmak için SPACE tuşuna bas!", (200, 300), fontsize=30, color="black")
screen.draw.text("Zıplarken ileri gitmek için sağa veya sola basılı tutun!", (150, 340), fontsize=25,
color="black")
screen.draw.text("Not: Kadın karakterler düşman değildir!", (150, 380), fontsize=25, color="black")
screen.draw.text("Not 2: Feminist değilim! :)", (150, 410), fontsize=25, color="black")
elif game_over:
screen.draw.text("Oyun Bitti! Skor: " + str(score), (300, 180), fontsize=30, color="black")
screen.draw.text("Tekrar başlatmak için SPACE tuşuna bas", (200, 220), fontsize=20, color="black")
else:
player.draw()
for enemy in enemies:
enemy.draw()
npc.draw()
screen.draw.text("Skor: " + str(score), (10, 10), fontsize=20, color="black")
def on_key_down(key):
global show_instructions, game_over, score, show_menu, sound_on
if show_menu:
if key == keys.S:
show_menu = False
elif key == keys.M:
sound_on = not sound_on
elif key == keys.Q:
exit()
return
if show_instructions:
show_instructions = False
return
if game_over and key == keys.SPACE:
game_over = False
score = 0
player.actor.x, player.actor.y = 100, 300
for enemy in enemies:
enemy.actor.x = random.randint(400, WIDTH)
return
if key == keys.SPACE:
player.jump()
if key == keys.LEFT:
player.move_left()
if key == keys.RIGHT:
player.move_right()
def on_key_up(key):
if key in (keys.LEFT, keys.RIGHT):
player.stop()
pgzrun.go()