Files
fort/chopper_demo.py
Olli Graf 8eed1cd581 background images
movement of chopper
2026-02-14 16:13:18 +01:00

53 lines
1.9 KiB
Python

import pygame
from chopper import Chopper
class Fort:
def __init__(self):
print('init()')
pygame.init()
pygame.display.set_mode((384, 240))
self.background =pygame.image.load('background/fort_02.png')
self.screen = pygame.display.set_mode((384, 240))
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.background,(0,0))
self.screen.blit(self.chopper_front, (self.chopper.xpos, self.chopper.ypos))
# 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:
self.chopper.move(self.chopper.RIGHT)
case pygame.K_LEFT:
self.chopper.move(self.chopper.LEFT)
case pygame.K_UP:
self.chopper.move(self.chopper.UP)
case pygame.K_DOWN:
self.chopper.move(self.chopper.DOWN)
self.screen.blit(self.chopper.current_image(),(self.chopper.xpos,self.chopper.ypos))
pygame.display.flip()
if __name__ == '__main__':
fort = Fort()
fort.mainloop()