Files
fort/chopper_demo.py
2026-02-14 12:16:57 +01:00

54 lines
1.8 KiB
Python

import pygame
from chopper import Chopper
class Fort:
def __init__(self):
print('init()')
pygame.init()
pygame.display.set_mode((640, 480))
self.chopper_x = 100
self.chopper_y = 100
self.screen = pygame.display.set_mode((800, 600))
self.chopper_front = pygame.image.load("sprites/chopper_front.png").convert()
self.chopper_side_right = pygame.image.load("sprites/chopper_side_right.png").convert()
self.chopper_moving_left = pygame.image.load("sprites/chopper_moving_left.png").convert()
self.chopper = Chopper(100,100,0)
self.chopper.add_sprite(self.chopper.STATE_FRONT, self.chopper_front)
self.chopper.add_sprite(self.chopper.STATE_RIGHT, self.chopper_side_right)
self.chopper.add_sprite(self.chopper.STATE_LEFT, self.chopper_moving_left)
def mainloop(self):
running = True
self.screen.blit(self.chopper_front, (self.chopper_x, self.chopper_y))
# self.screen.blit(self.chopper_side_right, (100, 100))
# self.screen.blit(self.chopper_moving_left, (150, 150))
pygame.display.flip()
while running:
# print (f'running={running}')
for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False
if event.type == pygame.KEYDOWN:
match event.key:
case pygame.QUIT:
running = False
case pygame.K_RIGHT:
print('right')
self.screen.blit(self.chopper_side_right,(self.chopper_x,self.chopper_y))
case pygame.K_LEFT:
print('left')
self.screen.blit(self.chopper_moving_left,(self.chopper_x,self.chopper_y))
case pygame.K_DOWN:
print('down')
self.screen.blit(self.chopper_front,(self.chopper_x,self.chopper_y))
pygame.display.flip()
if __name__ == '__main__':
fort = Fort()
fort.mainloop()