Adding Player, movement, and drawing/updating functionality

This commit is contained in:
franky212
2024-10-28 16:00:40 -06:00
parent 90d55e89b7
commit 0412b21bb0
5 changed files with 84 additions and 5 deletions

24
main.py
View File

@@ -2,20 +2,34 @@
# the open-source pygame library
# throughout this file
import pygame
from constants import *
from constants import SCREEN_HEIGHT, SCREEN_WIDTH
from player import Player
def main():
pygame.init()
print("Starting asteroids!")
print(f"Screen width: {SCREEN_WIDTH}")
print(f"Screen height: {SCREEN_HEIGHT}")
clock = pygame.time.Clock()
dt = 0
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
updatable = []
drawable = []
updatable.append(player)
drawable.append(player)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
pygame.Surface.fill(screen, (0, 0, 0))
screen.fill("black")
# limit the framerate to 60 FPS
dt = clock.tick(60) / 1000
for object in drawable:
object.draw(screen)
for object in updatable:
object.update(dt)
pygame.display.flip()
if __name__ == "__main__":