Skip to content

Commit 40dd218

Browse files
committed
fix
1 parent bfdac90 commit 40dd218

File tree

10 files changed

+218
-0
lines changed

10 files changed

+218
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea\

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/Pygame-dash.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PUSAB_.ttf

35.8 KB
Binary file not shown.

dash.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
from random import randint
2+
3+
import pygame
4+
from pygame.draw import *
5+
6+
pygame.init()
7+
8+
score = 0
9+
total = 0
10+
11+
myfont = pygame.font.Font(
12+
"PUSAB_.ttf", 50)
13+
14+
# Jumping Variables
15+
yVel = 0
16+
Jumping = 0
17+
Dead = False
18+
clock = pygame.time.Clock()
19+
display = {
20+
"width": 800,
21+
"height": 700
22+
}
23+
24+
platform = {
25+
'y': 600,
26+
"x": 700,
27+
"pass": 0,
28+
"length": 20,
29+
"ammount": 2,
30+
"distanceApart": 40
31+
}
32+
33+
character = {
34+
"width": 20,
35+
"height": 20,
36+
"x": 200,
37+
"y": 560,
38+
"velocity": 10
39+
}
40+
spike = {
41+
"height": -15,
42+
"y": 600,
43+
"x": 700,
44+
"pass": 0,
45+
"length": 20,
46+
"ammount": 2,
47+
"distanceApart": 30
48+
}
49+
test = 0
50+
51+
52+
def nextSection(a):
53+
spike["x"] = 700
54+
spike['pass'] += spike['ammount']
55+
spike['ammount'] = randint(1, 5)
56+
spike['distanceApart'] = randint(2, 8) * 10
57+
return a + 1
58+
59+
60+
def triangleDraw(i): # Draws the triangles
61+
polygon(win, (0, 0, 0), ((spike["x"] + spike['distanceApart'] * i, spike["y"]),
62+
(spike['x'] + spike['distanceApart'] * i + spike["length"], spike['y']), (
63+
spike['x'] + int(spike['length'] / 2) +
64+
spike['distanceApart'] * i,
65+
spike['y'] + spike['height'])))
66+
67+
68+
def jump(): # Start Jumping
69+
global yVel
70+
global Jumping
71+
if Jumping == 0:
72+
Jumping = 1
73+
yVel = 15
74+
character['y'] = character['y'] - yVel
75+
if character['y'] > platform['y']:
76+
Jumping = 0
77+
yVel -= 1
78+
79+
80+
def cJump(): # Contine Jump
81+
global yVel
82+
global Jumping
83+
if Jumping == 0:
84+
if character['y'] > platform['y']:
85+
pass
86+
else:
87+
Jumping = 1
88+
if Jumping == 1:
89+
character['y'] = character['y'] - yVel
90+
if character['y'] > platform['y']:
91+
Jumping = 2
92+
yVel -= 1
93+
elif Jumping == 2:
94+
Jumping = 3
95+
elif Jumping == 3:
96+
Jumping = 4
97+
elif Jumping == 4:
98+
Jumping = 5
99+
elif Jumping == 5:
100+
Jumping = 0
101+
102+
103+
def next():
104+
cJump()
105+
rect(
106+
win, (255, 0, 0), (character["x"], character["y"], character["width"], character["height"]))
107+
pygame.display.update()
108+
spike['x'] -= 5
109+
110+
111+
# Launching the window, setting it to the dimensions of the `display` dictionary.
112+
win = pygame.display.set_mode((display["width"], display["height"]))
113+
pygame.display.toggle_fullscreen()
114+
115+
while not Dead: # Main Game Loop
116+
117+
win.blit(myfont.render("[SPACE]/[UP] TO JUMP, [ESC] TO QUIT, [BACKSPACE] to return to this screen", False,
118+
(255, 0, 0)), (300, 10))
119+
win.fill((255, 255, 255))
120+
line(win, (0, 0, 0), (0, platform["y"]),
121+
(display["width"], platform["y"]),
122+
2)
123+
for i in range(spike['ammount']): # Spike Drawing
124+
triangleDraw(i)
125+
keys = pygame.key.get_pressed()
126+
127+
if keys[pygame.K_UP] or keys[pygame.K_w] or keys[pygame.K_SPACE]: # Checks if need to Jump
128+
jump()
129+
if keys[pygame.K_ESCAPE]:
130+
break
131+
for event in pygame.event.get(): # Quit statement
132+
if event.type == pygame.QUIT:
133+
break
134+
# checks to start next section
135+
if spike['x'] + spike['distanceApart'] * spike['ammount'] < character['x']:
136+
i = nextSection(i)
137+
if spike['pass'] < 100: # Win Statement
138+
textsurface2 = myfont.render(
139+
"Percentage {0}%".format(spike['pass']), False, (0, 0, 0))
140+
win.blit(textsurface2, (300, 10))
141+
else:
142+
textsurface2 = myfont.render("YOU WIN", False, (255, 0, 0))
143+
win.blit(textsurface2, (300, 10))
144+
break
145+
for i in range(spike['ammount']): # Checks if death occurs
146+
if spike['x'] + spike['distanceApart'] * i <= character['x'] <= spike['x'] + spike['distanceApart'] * i + \
147+
spike['length']:
148+
posOnSpike = abs(character['x'] -
149+
(spike['x'] + spike['length'] / 2))
150+
test = 1
151+
if posOnSpike * 2 + spike['y'] > character['y'] and spike['y'] < character['y'] or posOnSpike * 2 + \
152+
spike[
153+
'y'] > character['y'] + character['height'] and spike['y'] < character['y'] + character[
154+
'height']:
155+
Dead = True
156+
else:
157+
None
158+
# Drawing Stuff
159+
next()
160+
pygame.display.flip()
161+
clock.tick(30)
162+
163+
quit()
164+
165+
# g = 3
166+
#
167+
# print(f"the number g is {g}")

0 commit comments

Comments
 (0)