-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_projectile.py
More file actions
108 lines (79 loc) · 2.28 KB
/
testing_projectile.py
File metadata and controls
108 lines (79 loc) · 2.28 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
'''
So. This is going to be a Game.
'''
# imports
import pygame
pygame.init()
# pygame init
WIN_SIZE = WIDTH, HEIGHT = 1000, 600
win = pygame.display.set_mode(WIN_SIZE)
pygame.display.set_caption("First Game")
# vars
red = (255, 0, 0)
x = WIDTH/6
y = HEIGHT/1.5
player_size = player_width, player_height = (40,64)
vel = 5
isJump = False
jumpCount = 10
shot = False
# mainloop
def main():
#global playerpos
global x
global y
global jumpCount
global isJump
global shot
running = True
while running:
pygame.time.delay(20)
# quitting the game
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# general movement
keys = pygame.key.get_pressed()
if keys[pygame.K_a] and x > 0:
print("a pressed...")
x -= vel
if keys[pygame.K_d] and x < WIDTH - player_width:
print("d pressed...")
x += vel
if not(isJump):
if keys[pygame.K_w] and y > 0:
print("w pressed...")
y -= vel
if keys[pygame.K_s] and y < HEIGHT - player_height:
print("s pressed...")
y += vel
# jumping key
if keys[pygame.K_SPACE]:
print("space pressed...")
isJump = True
# jumping mechanic
else:
print("jumping...")
if jumpCount >= -10:
neg = 1
if jumpCount < 0:
neg = -1
y -= (jumpCount ** 2) * 0.38 * neg
jumpCount -= 1
else:
isJump = False
jumpCount = 10
print("Jumped..")
# shooting mechanic
if keys[pygame.K_q]:
shot = True
print("q pressed")
# updating the screen
win.fill((0,0,0))
pygame.draw.rect(win, red, ((x,y), player_size))
if shot == True:
(ballX, ballY) = (int(x), int(y))
pygame.draw.circle(win, red, (ballX, ballY), 8)
pygame.display.update()
main()
pygame.quit()