-
Notifications
You must be signed in to change notification settings - Fork 0
/
ironman.py
36 lines (32 loc) · 1.27 KB
/
ironman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pygame
from pygame.sprite import Sprite
class Ironman(Sprite):
def __init__(self,screen,setting):
#inheriting from sprite
super().__init__()
#choose where ironman appears
self.screen=screen
self.setting=setting
#choose ironmans photo
self.image=pygame.image.load('data/images.bmp')
#get a rectangle for the ship
self.rect=self.image.get_rect()
self.scr_rect=screen.get_rect()
self.move_right=False
self.move_left=False
#start each new ship at the bottom centerof the screen
self.rect.centerx=self.scr_rect.centerx
self.rect.bottom=self.scr_rect.bottom
self.center=float(self.rect.centerx)
def blitme(self):
#draw the ship at its current location
self.screen.blit(self.image,self.rect)
def update(self):
if self.move_right and self.rect.right<=self.scr_rect.right:
self.center+=self.setting.speed_fact
if self.move_left and self.rect.left>=self.scr_rect.left:
self.center-=self.setting.speed_fact
self.rect.centerx=self.center
def center_iron(self):
'''centralise ironman'''
self.center=self.scr_rect.centerx