Adding Player, movement, and drawing/updating functionality
This commit is contained in:
24
main.py
24
main.py
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user