def __init__(self, angle, power, player, type): pygame.sprite.Sprite.__init__(self, self.containers) folder = 'dan' self.frame_rate = 1 image_source = Utils.my_load_image(folder, type) self.images = [] if type=='simple.png': self.images = Utils.load_frame(image_source, 0, 0, 30, 30, 0, 4) else: self.images = Utils.load_frame(image_source, 0, 0, 30, 28, 0, 4) self.frame_length = len(self.images) self.frame = 0 self.image = self.images[int(round(self.frame))] self.rect = self.image.get_rect() self.speed_x = math.cos(math.radians(angle)) * power * 2 + 20 self.speed_y = -math.sin(math.radians(angle)) * power * 2 + 50 self.acceleration = Constant.GRAVITY self.t = 0 self.start_x = player.pos[0]#centerx self.start_y = player.pos[1]#.centery - 70 self.rect.move_ip(self.start_x, self.start_y) self.x = self.start_x self.y = self.start_y self.energy_cost = 10 self.pos_creep_screen = -100
def __init__(self, x, y, left, right, direction, speed_x): """ Constructor :param x: position x in screen :param y: position y in screen :param direction: direction to move, 0 or 1 :return: """ BasicCreep.__init__(self, x, y, left, right) # Coefficients self.frame = 0 self.move_speed_x = speed_x self.frame_rate = 0.8 * 0.25 * speed_x self.move_speed_y = 1 self.direction = direction # TODO Define enum if self.direction == 1: self.move_speed_x = -self.move_speed_x self.dis = 0 self.left = left self.right = self.right # Status self.down_able = True image_source = Utils.my_load_image('creep', 'creep3.png') self.images_forward = Utils.load_frame(image_source, 0, 0, 131.5, 66, 0, 4) images_forward_ex1 = Utils.load_frame(image_source, 0, 69, 129.3, 47, 0, 3) images_forward_ex2 = Utils.load_frame(image_source, 0, 143, 131.5, 66, 0, 4) images_forward_ex3 = Utils.load_frame(image_source, 0, 214, 129.3, 47, 0, 3) for image in images_forward_ex1: self.images_forward.append(image) for image in images_forward_ex2: self.images_forward.append(image) for image in images_forward_ex3: self.images_forward.append(image) for i in range(len(self.images_forward) - 1, -1, -1): self.images_forward.append(self.images_forward[i]) self.images_back = [] for image in self.images_forward: self.images_back.append(pygame.transform.flip(image, 1, 0)) self.frame_length = len(self.images_forward) self.image = self.images_forward[0] self.rect = self.image.get_rect() # Default position at (0,0) self.rect.move_ip(x, y)
def __init__(self,x,y,item_name): pygame.sprite.Sprite.__init__(self,self.containers) self.item_name = item_name self.x = x self.y = y self.state = Constant.ITEM_STATE_LIVE self.frame_index = 0 self.frame_count = 0 self.timer_die = 0 self.timer_live = 0 self.fall = True if self.item_name == Constant.MONEY_ITEM : self.style = Constant.ADD self.feature = Constant.MONEY self.num_frame = 7 image = Utils.my_load_image("vatpham","money.png") self.image_frame = Utils.load_frame(image,0,0,40,40,0,self.num_frame) elif self.item_name == Constant.BUMERANGE_TREE_ITEM : print 28 self.style = Constant.ADD self.feature = Constant.BUMERANGE self.num_frame = 1 image = Utils.my_load_image("vatpham","bumerange.png") self.image_frame = Utils.load_frame(image,0,0,89,70,0,self.num_frame) print len(self.image_frame) elif self.item_name == Constant.MAGIC_BOX_ITEM : self.style = Constant.ADD self.feature = Constant.LIFE self.num_frame = 1 image = Utils.my_load_image("vatpham","magic_box.png") self.image_frame = Utils.load_frame(image,0,0,69,69,0,self.num_frame) elif self.item_name == Constant.MONSTER_ITEM : self.style = Constant.SUBTRACT self.feature = Constant.LIFE self.num_frame = 1 image = Utils.my_load_image("vatpham","monster.png") self.image_frame = Utils.load_frame(image,0,0,89,89,0,self.num_frame) elif self.item_name == Constant.BERRY_ITEM : self.style = Constant.ADD self.feature = Constant.ENERGY self.num_frame = 1 image = Utils.my_load_image("vatpham","berry.png") self.image_frame = Utils.load_frame(image,0,0,59,59,0,self.num_frame) print len(self.image_frame) self.image = self.image_frame[self.frame_index] self.rect = self.image.get_rect() self.rect.move_ip(x,y) self.max_right = x + self.move_length self.max_left = x - self.move_length self.sound = Utils.load_sound('Ding.ogg') self.pos_creep_screen = 0
def __init__(self, x, y, left, right, direction, speed_x): """ Constructor :param x: position x in world :param y: position y in world :param direction: direction to move, 0 or 1 :param left, right: limit position for moving of creep :return: None """ CreepA.__init__(self, x, y, left, right, direction, speed_x) # Coefficients self.frame = 0 self.move_speed_x = speed_x self.frame_rate = self.move_speed_x * 0.3 self.move_speed_y = 1 self.direction = direction # TODO Define enum if self.direction == 1: self.move_speed_x = -self.move_speed_x self.x = x self.y = y self.pos_creep_screen = 0 self.left = left self.right = right # Status self.down_able = True image_source = Utils.my_load_image("creep", "creep1.png") self.images_forward = Utils.load_frame(image_source, 803, 215, 41, 55, 12, 4) self.images_back = [] for image in self.images_forward: self.images_back.append(pygame.transform.flip(image, 1, 0)) self.frame_length = len(self.images_forward) self.image = self.images_forward[0] self.rect = self.image.get_rect() # Default position at (0,0) self.rect.move_ip(self.pos_creep_screen, self.y) self.base_line = self.y