background images
movement of chopper
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
@@ -8,9 +8,37 @@ class Chopper:
|
||||
self.STATE_FRONT=0
|
||||
self.STATE_RIGHT=1
|
||||
self.STATE_LEFT = 2
|
||||
|
||||
# directions of movement
|
||||
self.UP = 0
|
||||
self.DOWN = 1
|
||||
self.LEFT = 2
|
||||
self.RIGHT = 3
|
||||
|
||||
self.images = {}
|
||||
|
||||
|
||||
def add_sprite(self,state,sprite):
|
||||
self.images[state] = sprite
|
||||
|
||||
def move(self,direction):
|
||||
match direction:
|
||||
case self.UP:
|
||||
self.state = self.STATE_FRONT
|
||||
if self.ypos > 2:
|
||||
self.ypos -= 2
|
||||
case self.DOWN:
|
||||
self.state = self.STATE_FRONT
|
||||
self.ypos +=2
|
||||
case self.LEFT:
|
||||
self.state = self.STATE_LEFT
|
||||
if self.xpos > 2:
|
||||
self.xpos -=2
|
||||
case self.RIGHT:
|
||||
self.state = self.STATE_RIGHT
|
||||
self.xpos += 2
|
||||
|
||||
def current_image(self):
|
||||
return self.images[self.state]
|
||||
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ 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))
|
||||
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()
|
||||
@@ -22,7 +21,8 @@ class Fort:
|
||||
|
||||
def mainloop(self):
|
||||
running = True
|
||||
self.screen.blit(self.chopper_front, (self.chopper_x, self.chopper_y))
|
||||
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()
|
||||
@@ -36,16 +36,15 @@ class Fort:
|
||||
case pygame.QUIT:
|
||||
running = False
|
||||
case pygame.K_RIGHT:
|
||||
print('right')
|
||||
self.screen.blit(self.chopper_side_right,(self.chopper_x,self.chopper_y))
|
||||
self.chopper.move(self.chopper.RIGHT)
|
||||
case pygame.K_LEFT:
|
||||
print('left')
|
||||
self.screen.blit(self.chopper_moving_left,(self.chopper_x,self.chopper_y))
|
||||
|
||||
self.chopper.move(self.chopper.LEFT)
|
||||
case pygame.K_UP:
|
||||
self.chopper.move(self.chopper.UP)
|
||||
case pygame.K_DOWN:
|
||||
print('down')
|
||||
self.screen.blit(self.chopper_front,(self.chopper_x,self.chopper_y))
|
||||
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()
|
||||
|
||||