first demo for displaying chopper sprites.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
||||||
16
chopper.py
Normal file
16
chopper.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
class Chopper:
|
||||||
|
|
||||||
|
def __init__(self,xpos,ypos,state):
|
||||||
|
self.xpos = xpos
|
||||||
|
self.ypos = ypos
|
||||||
|
self.state = state
|
||||||
|
self.STATE_FRONT=0
|
||||||
|
self.STATE_RIGHT=1
|
||||||
|
self.STATE_LEFT = 2
|
||||||
|
self.images = {}
|
||||||
|
|
||||||
|
|
||||||
|
def add_sprite(self,state,sprite):
|
||||||
|
self.images[state] = sprite
|
||||||
|
|
||||||
53
chopper_demo.py
Normal file
53
chopper_demo.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
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()
|
||||||
|
|
||||||
6
hello.py
6
hello.py
@@ -1,6 +0,0 @@
|
|||||||
def main():
|
|
||||||
print("Hello from fort!")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
BIN
sprites/chopper_front.png
Normal file
BIN
sprites/chopper_front.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
BIN
sprites/chopper_moving_left.png
Normal file
BIN
sprites/chopper_moving_left.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
BIN
sprites/chopper_side_right.png
Normal file
BIN
sprites/chopper_side_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
xcf/chopper_front.xcf
Normal file
BIN
xcf/chopper_front.xcf
Normal file
Binary file not shown.
BIN
xcf/chopper_moving_left.xcf
Normal file
BIN
xcf/chopper_moving_left.xcf
Normal file
Binary file not shown.
BIN
xcf/chopper_side_right.xcf
Normal file
BIN
xcf/chopper_side_right.xcf
Normal file
Binary file not shown.
BIN
xcf/shifted.png
Normal file
BIN
xcf/shifted.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
xcf/shifted.xcf
Normal file
BIN
xcf/shifted.xcf
Normal file
Binary file not shown.
Reference in New Issue
Block a user