def __init__(self, pos, image, size, clock, player=None, room=None, direction=0): # position self.position = position_class.Position(pos) # center of panzer self.speed = 0 self.acceleration = 0 self.direction = 0 # image self.original_image = image self.image = pygame.transform.scale(image, size) self.size = size self.clock = clock # collision self.collision_obj = collision_tools.CollisionCircle(self.position, 20, self, solid=True) # fire self.flag_ready_fire = True self.timer = timer_obj.Timer(1) # reload timer self.room = room self.bullet_type = fire_load.BouncyFireLoad self.Gun = None self.player = player self.set_direction(direction) self.Ragbar_timer = timer_obj.Timer(2)
def __init__(self, pos, direction=0, speed=0, image=None, size=None, collision_object=None, t=10, room=None, player=None): self.size = size self.image_original = image # todo it is a good idea to create a class able to handle animation and use it instead self.image = pygame.transform.scale(self.image_original, self.size) self.image = pygame.transform.rotozoom(self.image, -direction, 1) self.position = position_class.Position(pos) # current position of obj self.speed = speed self.direction = direction self.collision_obj = collision_object # todo Do I really need to give the room to object ?? self.room = room # room which this object is in self.timer = timer_obj.Timer(t) # t sec to self destruction self.timer.set_timer() # start of timer is creation time self.player = player FireLoadObjectsList.append(self) # add self to object list
def __init__(self, img, frame_size, frame_count, frame_rate=0.0625, offset=(0, 0), dist=0, start=True): self.frame_count = frame_count # number of frames self.frame_index = 0 # current frame number self.images = [] self.timer = timer_obj.Timer(frame_rate) # frame rate per second self.play = False for i in range(self.frame_count): rect = pygame.Rect((offset[0] + i * (frame_size[0] + dist), offset[1], frame_size[0], frame_size[1])) image = pygame.Surface(frame_size) # current frame image # image = img.subsurface(rect) image.blit(img, (0, 0), rect) image.set_colorkey((0, 0, 0)) self.images.append(image) if start: self.start_animation() object_list.append(self)
def __init__(self, pos, direction, speed=2, room=None, player=None): size = (20, 20) collision_obj = collision_tools.CollisionPoint(pos, self) BulletBase.__init__(self, pos, direction, speed, img_Amoo, size, collision_obj, 30, room, player) self.chosen_player = None self.chosen_point = None self.choose_timer = timer_obj.Timer(2) self.choose_timer.set_timer() self.flag_lock = False self.player.get_panzer().set_bullet_type(BouncyFireLoad)
def __init__(self, screen, clock, map): room_obj.Room.__init__( self, screen, 'Test', clock=clock, caption="Panzer Game") # create room with name Test # walls/ collectable objects/ ... map_obj.load(map) # ready_players_tank tank_start_point = map_obj.get_start_points(map) for player in player_class.player_list: idx = randrange(len(tank_start_point)) pos = tank_start_point[idx][0] dire = tank_start_point[idx][1] del tank_start_point[idx] player.ready_panzer(pos, dire, self.clock, self) self.mouse = tools.Mouse() self.timer = timer_obj.Timer(3) # 3 sec
def __init__(self, screen, clock): room_obj.Room.__init__(self, screen, 'MultiRoom', clock=clock, caption="PanzerGame") # key_set = key_map_sets.KeySetOne() # p = player_class.Player('KeySetOne', key_set.control, key_set.key_map, "p1", None) key_set = key_map_sets.KeySetTwo() p = player_class.Player('KeySetTwo', key_set.control, key_set.key_map, "p2", None) message2 = '("' + p.name + '",' + '"' + p.key_set + '")' s.sendto(message2.encode(), server) data = [] player_num = 1 while True: try: message = s.recv(1024).decode() player_num = int(message[8:9]) data = eval(message[9:]) break except: pass print(data) # "maps/map{0}.txt".format(data[0][1]) # data = [['name', 'key_set_name', 'full_map_add', (pos, dire), img_number], [...], ...] map_address = data[0][2] print(map_address) map_obj.load(map_address) for i in range(0, player_num): img = pygame.image.load('images/panzer{0}.png'.format( data[i][-1])).convert_alpha() if i != player_num - 1: key_set = key_map_sets.control_map[data[i][1]]() player = player_class.Player(data[i][1], key_set.control, key_set.key_map, data[i][0], img) else: player = player_class.player_list[0] player.panzer_img = img pos = data[i][3][0] dire = data[i][3][1] player.ready_panzer(pos, dire, self.clock, self) self.mouse = tools.Mouse() self.timer = timer_obj.Timer(3) # 3 sec self.keys = [False for i in range(400)]