def __init__(self, x, y, input_manager): self.x = x self.y = y self.vel = 8 self.width = 25 self.height = 32 self.renderer = ImageRenderer("assets/images/sprite/player.png") self.box_collider = BoxCollider(25, 32) self.is_active = True self.input_manager = input_manager self.isJump = False self.jumpCount = 5 self.count = 0 self.move = True
def __init__(self, x, y): GameObject.__init__(self,x ,y) self.overlap = False # 1 load image self.renderer = ImageRenderer("assets/images/sprite/gift/gift_close.png") self.width = 25 self.height = 25 self.box_collider = BoxCollider(self.width, self.height)
def __init__(self, x, y, dx, dy): GameObject.__init__(self, x, y) self.overlap = False # 1 load image self.width = 10 self.height = 10 self.box_collider = BoxCollider(self.width, self.height) self.dx = dx self.dy = dy self.dam = 5 if self.dy > 0: self.renderer = ImageRenderer( "assets/images/sprite/bullet_player/bullet_down.png") elif self.dy < 0: self.renderer = ImageRenderer( "assets/images/sprite/bullet_player/bullet_up.png") elif self.dx > 0: self.renderer = ImageRenderer( "assets/images/sprite/bullet_player/bullet_right.png") elif self.dx < 0: self.renderer = ImageRenderer( "assets/images/sprite/bullet_player/bullet_left.png")
def update(self): GameObject.update(self) if not self.overlap: for game_object in game_objects: if type(game_object) == Player: overlap = BoxCollider.overlap(self.box_collider, game_object.box_collider) if overlap and game_object.count_coin == 7: self.overlap = True game_object.can_shoot = True if self.overlap: image_urls = ["assets/images/sprite/gift/gift_close.png", "assets/images/sprite/gift/gift_opening.png", "assets/images/sprite/gift/gift_open.png"] self.renderer = Animation(image_urls,False) self.renderer = ImageRenderer("assets/images/sprite/gift/gift_open.png") enemy_tower = EnemyTower(10*16+8, 15*16) add(enemy_tower)
def __init__(self,x ,y, x_player, y_player): GameObject.__init__(self,x ,y) self.dam = 30 self.x = x self.y = y self.overlap = False self.x_player = x_player self.y_player = y_player # 1 load image self.renderer = ImageRenderer("assets/images/sprite/enemy/tower/tower_bullet.png") self.width = 20 self.height = 20 self.box_collider = BoxCollider(self.width, self.height) self.vectorX = self.x_player - self.x self.vectorY = self.y_player - self.y self.velocityX = self.vectorX/((self.vectorX**2 + self.vectorY**2)**(1/2))*10 self.velocityY = self.vectorY/((self.vectorX**2 + self.vectorY**2)**(1/2))*10
def __init__(self, x, y, input_manager): GameObject.__init__(self, x, y) self.overlap = False # 1 load image self.renderer = ImageRenderer("assets/images/sprite/player_left.png") self.width = 15 self.height = 15 self.box_collider = BoxCollider(self.width, self.height) self.speed = 4 self.dx = 0 self.dy = 0 self.shootX = -6 self.shootY = 0 self.frame_counter = FrameCounter(10) self.shoot_lock = True self.can_shoot = False self.hp = 100 self.count_coin = 0 self.count_enemy = 0 self.input_manager = input_manager
def __init__(self, x, y): GameObject.__init__(self, x, y) self.renderer = ImageRenderer('assets/images/sprite/grass0000.png') self.box_collider = BoxCollider(28, 8)
def update(self): if self.box_collider is not None: self.box_collider.x = self.x self.box_collider.y = self.y if self.input_manager.right_pressed: self.x += 2 elif self.input_manager.left_pressed: self.x -= 2 if not self.isJump: if self.input_manager.x_pressed: self.isJump = True else: if self.jumpCount >= -5: neg = 1 if self.jumpCount < 0: neg = -1 self.y -= self.jumpCount**2 * 0.8 * neg if neg == 1: if len(game_object.collide_with(self.box_collider, Grass)) != 0: self.jumpCount *= -1 elif neg == -1: if len(game_object.collide_with(self.box_collider, Grass)) != 0: list_collide = game_object.collide_with( self.box_collider, Grass) for object in list_collide: dy = object.y - 32 if object.y < self.y: continue if dy <= self.y: self.y = dy self.jumpCount = -5 self.jumpCount -= 1 else: self.isJump = False self.jumpCount = 5 if not self.isJump: if len(game_object.collide_with(self.box_collider, Grass)) != 0: list_collide = game_object.collide_with( self.box_collider, Grass) for object in list_collide: if self.box_collider.y == object.y: if self.x >= object.x: self.x += 1 elif self.x < object.x: self.x -= 1 pass else: self.move = True dy = object.y - 32 if dy <= self.y: self.y = dy elif len(game_object.collide_with(self.box_collider, Spike)) != 0: self.is_active = False elif len(game_object.collide_with(self.box_collider, SpikeFake)) != 0: list_object = game_object.collide_with(self.box_collider, SpikeFake) for obj in list_object: obj.renderer = ImageRenderer( 'assets/images/sprite/spike0000.png') self.count += 1 if self.count >= 30: self.is_active = False self.count = 0 else: for object in game_object.game_objects: if (object.x <= self.x <= object.x + 32 or object.x <= self.x + self.width <= object.x + 32 ) and self.y < object.y: if self.x + 32 == object.x: continue else: self.y = object.y - 32 break
class Player(): def __init__(self, x, y, input_manager): self.x = x self.y = y self.vel = 8 self.width = 25 self.height = 32 self.renderer = ImageRenderer("assets/images/sprite/player.png") self.box_collider = BoxCollider(25, 32) self.is_active = True self.input_manager = input_manager self.isJump = False self.jumpCount = 5 self.count = 0 self.move = True def update(self): if self.box_collider is not None: self.box_collider.x = self.x self.box_collider.y = self.y if self.input_manager.right_pressed: self.x += 2 elif self.input_manager.left_pressed: self.x -= 2 if not self.isJump: if self.input_manager.x_pressed: self.isJump = True else: if self.jumpCount >= -5: neg = 1 if self.jumpCount < 0: neg = -1 self.y -= self.jumpCount**2 * 0.8 * neg if neg == 1: if len(game_object.collide_with(self.box_collider, Grass)) != 0: self.jumpCount *= -1 elif neg == -1: if len(game_object.collide_with(self.box_collider, Grass)) != 0: list_collide = game_object.collide_with( self.box_collider, Grass) for object in list_collide: dy = object.y - 32 if object.y < self.y: continue if dy <= self.y: self.y = dy self.jumpCount = -5 self.jumpCount -= 1 else: self.isJump = False self.jumpCount = 5 if not self.isJump: if len(game_object.collide_with(self.box_collider, Grass)) != 0: list_collide = game_object.collide_with( self.box_collider, Grass) for object in list_collide: if self.box_collider.y == object.y: if self.x >= object.x: self.x += 1 elif self.x < object.x: self.x -= 1 pass else: self.move = True dy = object.y - 32 if dy <= self.y: self.y = dy elif len(game_object.collide_with(self.box_collider, Spike)) != 0: self.is_active = False elif len(game_object.collide_with(self.box_collider, SpikeFake)) != 0: list_object = game_object.collide_with(self.box_collider, SpikeFake) for obj in list_object: obj.renderer = ImageRenderer( 'assets/images/sprite/spike0000.png') self.count += 1 if self.count >= 30: self.is_active = False self.count = 0 else: for object in game_object.game_objects: if (object.x <= self.x <= object.x + 32 or object.x <= self.x + self.width <= object.x + 32 ) and self.y < object.y: if self.x + 32 == object.x: continue else: self.y = object.y - 32 break def render(self, canvas): if self.renderer is not None: self.renderer.render(canvas, self.x, self.y) # if self.box_collider is not None: # self.box_collider.render(canvas) def deactivate(self): self.is_active = False
def __init__(self): t = choice(pData) GameObject.__init__(self, t.x, t.y) self.box_collider = BoxCollider(20, 20) self.renderer = ImageRenderer("/Users/apple/Desktop/ai:mlPr/carDrive/assets/images/point.png")
def __init__(self, x, y): GameObject.__init__(self, x, y) self.renderer = ImageRenderer('assets/images/sprite/platform0000.png') self.box_collider = BoxCollider(32, 32)
def __init__(self, x, y): GameObject.__init__(self, x, y) self.box_collider = BoxCollider(12, 48) self.renderer = ImageRenderer('images/player/player_bullet1.png')
def move(self): self.dx = 0 self.dy = 0 GameObject.update(self) if self.input_manager.up_pressed: pygame.mixer.Channel(0).play( pygame.mixer.Sound("music/player/player_move.wav")) self.shootX = 0 self.shootY = -6 self.renderer = ImageRenderer("assets/images/sprite/player_up.png") self.box_collider.y = self.y - self.speed self.check_overlap() if self.overlap: self.dy += 0 else: self.dy += -self.speed elif self.input_manager.down_pressed: pygame.mixer.Channel(1).play( pygame.mixer.Sound("music/player/player_move.wav")) self.shootX = 0 self.shootY = 6 self.renderer = ImageRenderer( "assets/images/sprite/player_down.png") self.box_collider.y = self.y + self.speed self.check_overlap() if self.overlap: self.dy += 0 else: self.dy += self.speed elif self.input_manager.left_pressed: pygame.mixer.Channel(1).play( pygame.mixer.Sound("music/player/player_move.wav")) self.shootX = -6 self.shootY = 0 self.renderer = ImageRenderer( "assets/images/sprite/player_left.png") self.box_collider.x = self.x - self.speed self.check_overlap() if self.overlap: self.dx += 0 else: self.dx += -self.speed elif self.input_manager.right_pressed: pygame.mixer.Channel(1).play( pygame.mixer.Sound("music/player/player_move.wav")) self.shootX = 6 self.shootY = 0 self.renderer = ImageRenderer( "assets/images/sprite/player_right.png") self.box_collider.x = self.x + self.speed self.check_overlap() if self.overlap: self.dx += 0 else: self.dx += self.speed self.x += self.dx self.y += self.dy self.box_collider.x = self.x self.box_collider.y = self.y self.overlap = False if len(gamelevel) == 3: enemy = Enemy1(6 * 16, 13.5 * 16, 5, 0, 5, "tank") enemy.hp = 50 enemy1 = Enemy1(10 * 16, 3 * 16, -2, 0, 2, "tank") enemy1.hp = 50 game_object.add(enemy) game_object.add(enemy1) gamelevel.append("*")
def __init__(self, x, y, path): GameObject.__init__(self, x, y) self.renderer = ImageRenderer(path) self.box_collider = BoxCollider(16,16)
def __init__(self): GameObject.__init__(self, 320, 240) self.renderer = ImageRenderer( "assets/images/36987938_870119473192633_6676325747356860416_n.png")
def __init__(self, x, y): GameObject.__init__(self, x, y) self.builded = False self.box_collider = BoxCollider(70, 70) self.renderer = ImageRenderer("images/hole.png")
def __init__(self): GameObject.__init__(self, 400, 320) self.renderer = ImageRenderer( "/Users/apple/Desktop/ai:mlPr/carDrive/mapImages/map.png")
def __init__(self, x, y): GameObject.__init__(self, x, y) self.renderer = ImageRenderer("images/castle.png") self.box_collider = BoxCollider(70, 70) self.HP = 5
def __init__(self, x, y): GameObject.__init__(self, x, y) self.renderer = ImageRenderer("assets/images/sprite/tải xuống.png")