def move_to_target(self, x, y): """ Add new target for the sprite to move towards. Starts movement towards target if stationary, otherwise appends the target to a queue. """ # Set new direction new_target = vec2(x, y) if self.state == State.STATIONARY and new_target != self.target and not self.need_to_move(): self.facing_direction = self.get_facing(x, y) self.state = State.MOVING self.target = vec2(x, y) else: self.targets.append(vec2(x, y))
def Update(self): # update metal position self.metals[0].update(self.left_right_pressed) self.left_right_pressed = 0 if self.num_of_player == 2: self.metals[1].update(self.a_d_pressed) self.a_d_pressed = 0 # update photon position for sub_photons in self.photons: for photon in sub_photons: photon.update_pos() # generate next_photons if self.photons[-1][0].pos.centery >= photon_distance: self.photons.append(self.new_photons()) # update electron position for electron in self.electrons: electron.update_pos() if not electron.inside(self.electron_valid_rect): self.electrons.remove(electron) # photon collision handle for photon in self.photons[0]: remove_this = False if photon.inside(self.horizon_rect2): remove_this = True for i in range(self.num_of_player): if photon.collide_with(self.metals[i].collision_rect): remove_this = True increment = 0 if (not self.charge_enabled ) and photon.color_n >= self.level: increment = photon.color_n elif self.charge_enabled and photon.color_n >= self.level: increment = photon.color_n * ( 1 - self.metal_statuss[i].charge / 200) if increment != 0: self.metals[i].set_highlight() self.scores[i].update(int(6 * 5 * increment)) self.metal_statuss[i].update(3 * photon.color_n) self.generate_electron(photon.pos.center, vec2(0, -increment)) if remove_this: self.photons[0].remove(photon) if not self.photons[0]: del self.photons[0] # ground (recharge) for i in range(self.num_of_player): if self.metals[i].pos_rect.collidelist( [self.ground.pos_rect_l, self.ground.pos_rect_r]) != -1: self.metal_statuss[i].update(-5) self.metals[i].set_ground() # update timer self.countdown.update()
def __init__(self, x, y, width, height): super(MovingSprite, self).__init__(x, y, width, height) # Center the sprite to initial coords center_coords = (self.rect.centerx - self.rect.width, self.rect.centery - self.rect.height) self.rect = Rect(center_coords, self.rect.size) # Set current movement target equal to initial position self.target = vec2(self.rect.centerx, self.rect.centery) self.targets = deque() # Target queue self.facing_direction = Direction.DOWN self.state = State.STATIONARY
def calculate_movement(self): if self.state != State.STATIONARY: current_position = vec2(self.rect.centerx, self.rect.centery) velocity = DIRECTIONS[self.facing_direction] * self.speed new_position = current_position + velocity target_position = self.target # Calculate velocity to just reach the target, not go over if (current_position.x < target_position.x < new_position.x or new_position.x < target_position.x < current_position.x): velocity.x = target_position.x - current_position.x elif (current_position.y < target_position.y < new_position.y or new_position.y < target_position.y < current_position.y): velocity.y = target_position.y - current_position.y return velocity else: return vec2(0, 0)
data_path = os.path.join('..', 'data') default_font = os.path.join(data_path, 'VT323-Regular.ttf') # time default_flashing_period = 1 game_time = 31 game_bridge_time = 1.99 * 1000 end_bridge_time = 2.9 * 1000 metal_highlight_time = 0.3 # objects line_of_horizon2 = 600 - 30 photon_distance = 80 photons_per_line = 7 # should be odd number velocity_of_photon = vec2(0, 2) velocity_of_metal = 100 # font size title_font_size = 150 options_font_size = 55 mode_font_size = 40 help_font_size = 35 score_font_size = 57 countdown_font_size = 70 motto_font_size = 20 masks = [ (255, 65280, 16711680, 4278190080), (255, 65280, 0, 4278190080), (100, 65280, 16711680, 4278190080),