Repository navigation
Expand file tree
/
Copy pathMainGame.py
More file actions
209 lines (185 loc) · 6.67 KB
/
Copy pathMainGame.py
File metadata and controls
209 lines (185 loc) · 6.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import random
import sys
from tkinter import messagebox
import pygame
from tkinter import *
pygame.init()
class Plat:
def __init__(self, x, y):
self.x = x
self.y = y
# Tanımlar
Rmavi = (119, 224, 255)
Rsiyah = (0, 0, 0)
GENISLIK = 500
YUKSEKLIK = 700
arkaplanRengi = Rmavi
oyuncuResmi = pygame.transform.scale(pygame.image.load('assest/karakter.png'), (80, 80))
platformResmi = pygame.transform.scale(pygame.image.load('assest/platform.png'), (80, 10))
ziplamaSes = pygame.mixer.Sound("assest/ziplama.mp3")
superZiplamaSes = pygame.mixer.Sound("assest/superJump.mp3")
gameoverSes = pygame.mixer.Sound("assest/gameover.mp3")
genel_font = pygame.font.Font('assest/futurab.ttf', 16)
fps = 60
oyuncuIsmi = "Oyuncu1"
root = Tk()
root.title('İsim Girişi')
root.geometry("300x75+300+200")
def retrieve_input():
global oyuncuIsmi
oyuncuIsmi = textBox.get("1.0", "end-1c")
messagebox.showinfo('Hoş Geldiniz.',f'İsminiz {oyuncuIsmi} olarak belirlendi.\nEğer arkaplan rengi hoşunuza gitmezse \'C\' tuşuna basınız.')
root.destroy()
print(oyuncuIsmi)
baslik = Label(root, text='İsminizi Giriniz')
baslik.pack()
textBox = Text(root, height=1, width=20)
textBox.pack()
tus = Button(root, height=1, width=10, text="Giriş", command=lambda: retrieve_input())
tus.pack()
mainloop()
def seviyeAdi(seviye):
switcher = {
0: "easy",
1: "normal",
2: "hard",
3: "extreme",
}
return switcher.get(seviye,"nothing")
def arkaplanRengiDegistir():
global arkaplanRengi
arkaplanRengi = (random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255))
# EKRAN
ekran = pygame.display.set_mode((GENISLIK, YUKSEKLIK))
pygame.display.set_caption('Among Platforms')
# Platformlar
platformlar = [Plat(random.randrange(0, GENISLIK - 80), random.randrange(0, YUKSEKLIK)) for i in range(10)]
# Baslangıç Değerleri
x = 200
y = 100
dy = 0.0
h = 200
ziplama = -20
# puanlar
puan = 0
ziplamaPuan = 0
renkPuan = 0
platformPuan = 0
# # #
tickCheck = 0
superZiplamaHakki = 0
superZiplamaUseTime = 0
gameOver = False
while True:
tickCheck += 1
if tickCheck == 60:
tickCheck = 0
pygame.time.Clock().tick(fps)
olaylar = pygame.event.get()
for olay in olaylar:
if olay.type == pygame.QUIT:
pygame.quit()
sys.exit()
ekran.fill(arkaplanRengi)
if not gameOver:
for platform in platformlar:
ekran.blit(platformResmi, (platform.x, platform.y))
# karakter zeminin en altına indiğinde game over
if y > YUKSEKLIK:
gameoverSes.play()
gameOver = True
# oyuncunun sağa sola hareketi #
tuslar = pygame.key.get_pressed()
if tuslar[pygame.K_LEFT]:
x -= 10
oyuncuResmi = pygame.transform.flip(pygame.transform.scale(pygame.image.load('assest/karakter.png'), (80, 80)),True,False)
if tuslar[pygame.K_RIGHT]:
x += 10
oyuncuResmi = pygame.transform.scale(pygame.image.load('assest/karakter.png'), (80, 80))
if x < -40:
x = -40
if x > GENISLIK - 40:
x = GENISLIK - 40
# platformların aşağı yönde hareketi #
if y < h:
y = h
for platform in platformlar:
platform.y = platform.y - dy
if platform.y > YUKSEKLIK:
platform.y = 0
platform.x = random.randrange(0, GENISLIK - 80)
puan += 1
ziplamaPuan += 1
renkPuan += 1
platformPuan += 1
# platformalın her 90 puanda azalması #
if len(platformlar) >= 5:
if platformPuan == 90:
platformlar.pop()
platformPuan = 0
# ekran reniginin her 30 puanda değişmesi
if renkPuan == 30:
arkaplanRengiDegistir()
renkPuan = 0
# beğenilmeyen arkaplan renginin c tuşuna basarak değiştirilmesi #
if tuslar[pygame.K_c] and tickCheck % 10 == 0:
arkaplanRengiDegistir()
# Süper Zıplama #
if ziplamaPuan == 60:
superZiplamaHakki += 1
ziplamaPuan = 0
if tuslar[pygame.K_SPACE] and superZiplamaHakki > 0 and tickCheck % 10 == 0:
ziplama = -30
superZiplamaHakki -= 1
superZiplamaUseTime = 180
if ziplama < -20 and superZiplamaUseTime > 0:
superZiplamaUseTime -= 1
if ziplama < -20 and superZiplamaUseTime == 0:
ziplama = -20
dy += .7
y += dy
# karakterin platformlar ile teması #
for platform in platformlar:
if (x + 60 > platform.x) and (x + 20 < platform.x + 72) and (y + 74 > platform.y) and (y + 74 < platform.y + 20) and dy > 0:
if superZiplamaUseTime>0:
superZiplamaSes.play()
else:
ziplamaSes.play()
dy = ziplama
# EKRANDA YAZACAK YAZILAR #
yaziSkor = genel_font.render("Puan " + str(puan), 1, (0, 0, 0))
yaziSuperZiplama = genel_font.render("Süper Zıplama Hakkı " + str(superZiplamaHakki), 1, (0, 0, 0))
yaziSuperZiplamaTime = genel_font.render("Süper Zıplama Süresi " + str(superZiplamaUseTime), 1, (0, 0, 0))
yaziZorlukSeviyesi = genel_font.render("Seviye: " + seviyeAdi((len(platformlar)-10)*(-1)), 1, (0, 0, 0))
# YAZILARIN EKRANA YAZDIRILMASI #
ekran.blit(yaziSkor, (GENISLIK - 10 - yaziSkor.get_width(), 10))
ekran.blit(yaziSuperZiplama, (10, 10))
if superZiplamaUseTime > 0:
ekran.blit(yaziSuperZiplamaTime, (10, 30))
ekran.blit(yaziZorlukSeviyesi,(10,50))
ekran.blit(oyuncuResmi, (x, y))
else:
yaziGameOver = genel_font.render("GAME OVER", 1, (0, 0, 0))
yaziReset = genel_font.render("yeniden oynamak için 'Boşluk' tuşuna basınız", 1, (0, 0, 0))
yaziGameOverPuan = genel_font.render(oyuncuIsmi + "'nin puanı " + str(puan), 1, (0, 0, 0))
ekran.blit(yaziGameOver, (170, 300))
ekran.blit(yaziGameOverPuan, (160, 330))
ekran.blit(yaziReset, (50, 550))
tuslar = pygame.key.get_pressed()
if tuslar[pygame.K_SPACE]:
x = 200
y = 100
dy = 0.0
h = 200
ziplama = -20
# puanlar
puan = 0
ziplamaPuan = 0
platformPuan = 0
renkPuan = 0
# # #
superZiplamaHakki = 0
superZiplamaUseTime = 0
gameOver = False
platformlar = [Plat(random.randrange(0, GENISLIK - 80), random.randrange(0, YUKSEKLIK)) for i in range(10)]
pygame.display.update()