├── .gitpod.yml ├── README.md ├── projectile_motion.py └── requirements.txt /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-full-vnc 2 | ports: 3 | - port: 5900 4 | onOpen: ignore 5 | - port: 6080 6 | onOpen: open-preview 7 | tasks: 8 | - init: pip3 install -r requirements.txt 9 | command: python3 projectile_motion.py 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Projectile Motion Physics Engine 2 | 3 | This program simulates projectile motion using a small pygame window that allows you to shoot a ball around the screen. 4 | 5 | You can watch my video tutorials on how to create this here: https://www.youtube.com/watch?v=_gDOz7E6HVM 6 | 7 | # Requirements 8 | - Python 3.x 9 | - Pygame 10 | 11 | # Run Instructions 12 | Run the file *projectile_motion.py* to start the program. 13 | 14 | # 💻 Launch Your Software Development Career Today! 15 | 16 | 🎓 **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. 17 | 18 | 🚀 **Why Join?** 19 | - 💼 **$70k+ starting salary potential** 20 | - 🕐 **Self-paced:** Complete on your own time 21 | - 🤑 **Affordable:** Low risk compared to expensive bootcamps or degrees 22 | - 🎯 **45,000+ job openings** in the market 23 | 24 | 👉 **[Start your journey today!](https://techwithtim.net/dev)** 25 | No experience needed—just your determination. Future-proof your career and unlock six-figure potential like many of our students have! 26 | -------------------------------------------------------------------------------- /projectile_motion.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import math 3 | 4 | wScreen = 1200 5 | hScreen = 500 6 | 7 | win = pygame.display.set_mode((wScreen,hScreen)) 8 | pygame.display.set_caption('Projectile Motion') 9 | 10 | 11 | class ball(object): 12 | def __init__(self,x,y,radius,color): 13 | self.x = x 14 | self.y = y 15 | self.radius = radius 16 | self.color = color 17 | 18 | def draw(self, win): 19 | pygame.draw.circle(win, (0,0,0), (self.x,self.y), self.radius) 20 | pygame.draw.circle(win, self.color, (self.x,self.y), self.radius-1) 21 | 22 | 23 | @staticmethod 24 | def ballPath(startx, starty, power, ang, time): 25 | angle = ang 26 | velx = math.cos(angle) * power 27 | vely = math.sin(angle) * power 28 | 29 | distX = velx * time 30 | distY = (vely * time) + ((-4.9 * (time ** 2)) / 2) 31 | 32 | newx = round(distX + startx) 33 | newy = round(starty - distY) 34 | 35 | 36 | return (newx, newy) 37 | 38 | 39 | def redrawWindow(): 40 | win.fill((64,64,64)) 41 | golfBall.draw(win) 42 | pygame.draw.line(win, (0,0,0),line[0], line[1]) 43 | pygame.display.update() 44 | 45 | def findAngle(pos): 46 | sX = golfBall.x 47 | sY = golfBall.y 48 | try: 49 | angle = math.atan((sY - pos[1]) / (sX - pos[0])) 50 | except: 51 | angle = math.pi / 2 52 | 53 | if pos[1] < sY and pos[0] > sX: 54 | angle = abs(angle) 55 | elif pos[1] < sY and pos[0] < sX: 56 | angle = math.pi - angle 57 | elif pos[1] > sY and pos[0] < sX: 58 | angle = math.pi + abs(angle) 59 | elif pos[1] > sY and pos[0] > sX: 60 | angle = (math.pi * 2) - angle 61 | 62 | return angle 63 | 64 | 65 | golfBall = ball(300,494,5,(255,255,255)) 66 | 67 | run = True 68 | time = 0 69 | power = 0 70 | angle = 0 71 | shoot = False 72 | clock = pygame.time.Clock() 73 | while run: 74 | clock.tick(200) 75 | if shoot: 76 | if golfBall.y < 500 - golfBall.radius: 77 | time += 0.05 78 | po = ball.ballPath(x, y, power, angle, time) 79 | golfBall.x = po[0] 80 | golfBall.y = po[1] 81 | else: 82 | shoot = False 83 | time = 0 84 | golfBall.y = 494 85 | 86 | line = [(golfBall.x, golfBall.y), pygame.mouse.get_pos()] 87 | redrawWindow() 88 | 89 | for event in pygame.event.get(): 90 | if event.type == pygame.QUIT: 91 | run = False 92 | 93 | if event.type == pygame.MOUSEBUTTONDOWN: 94 | if not shoot: 95 | x = golfBall.x 96 | y = golfBall.y 97 | pos =pygame.mouse.get_pos() 98 | shoot = True 99 | power = math.sqrt((line[1][1]-line[0][1])**2 +(line[1][0]-line[0][1])**2)/8 100 | angle = findAngle(pos) 101 | 102 | 103 | 104 | pygame.quit() 105 | quit() 106 | 107 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pygame 2 | --------------------------------------------------------------------------------