-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile Simulator.py
More file actions
46 lines (36 loc) · 825 Bytes
/
Projectile Simulator.py
File metadata and controls
46 lines (36 loc) · 825 Bytes
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
import pygame
import math
# Initialization
pygame.init()
screen = pygame.display.set_mode((1920, 1080))
clock = pygame.time.Clock()
running = True
# Setup Variables
ivel = 20
angle = math.radians(45)
g = 25
x = 50
y = screen.get_height() - 50
r = 50
xvel = ivel * math.cos(angle)
yvel = ivel * math.sin(angle)
tick = 0
# Run Loop
while running:
# Stops when program exit
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Resets Screen
screen.fill("black")
pygame.draw.circle(screen, "red", (x, y), r)
x += xvel
y -= yvel - (g * tick/60)
if x <= r or x >= screen.get_width() - r:
xvel *= -1
if y <= r or y >= screen.get_height() -r:
tick = 0
pygame.display.flip()
clock.tick(60)
tick += 1
pygame.quit