class Game(object): """main gameworld object""" def __init__(self): super(Game, self).__init__() pygame.init() self.screen = pygame.display.set_mode((640, 448)) self.screen_rect = self.screen.get_rect() self.clock = pygame.time.Clock() self.player = MotionTrailGenerator( 640, 448, 20, 20, 255, 255, 0, 5 ) self.effect = EffectAnimation( 200, 200, "arrow.png", 50, 50, 4, 4, True ) self.lineBurst = LineBurst( 100, 300, 0, 60, 20, 40, (255, 255, 255), 0.2, True ) def process_events(self): """process all game events""" for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: sys.exit(0) if event.key == pygame.K_w: self.player.moving[0] = True if event.key == pygame.K_s: self.player.moving[1] = True if event.key == pygame.K_a: self.player.moving[2] = True if event.key == pygame.K_d: self.player.moving[3] = True self.lineBurst = LineBurst( 100, 300, 0, 360, 30, 30, (255, 255, 255), 0.1, True ) if event.type == pygame.KEYUP: if event.key == pygame.K_w: self.player.moving[0] = False if event.key == pygame.K_s: self.player.moving[1] = False if event.key == pygame.K_a: self.player.moving[2] = False if event.key == pygame.K_d: self.player.moving[3] = False def update(self): """updates the game""" self.player.update() self.effect.update() def draw(self): """draw the gameworld""" self.screen.fill((0,0,0)) self.player.draw(self.screen) self.effect.draw(self.screen) self.lineBurst.draw( self.screen )
def __init__(self): super(Game, self).__init__() pygame.init() self.screen = pygame.display.set_mode((640, 448)) self.screen_rect = self.screen.get_rect() self.clock = pygame.time.Clock() self.player = MotionTrailGenerator( 640, 448, 20, 20, 255, 255, 0, 5 ) self.effect = EffectAnimation( 200, 200, "arrow.png", 50, 50, 4, 4, True ) self.lineBurst = LineBurst( 100, 300, 0, 60, 20, 40, (255, 255, 255), 0.2, True )