line-em-up/models/player.rb in line-em-up-0.3.6 vs line-em-up/models/player.rb in line-em-up-0.4.0

- old
+ new

@@ -1,45 +1,118 @@ require_relative 'general_object.rb' +require_relative 'rocket_launcher_pickup.rb' class Player < GeneralObject SPEED = 7 MAX_ATTACK_SPEED = 3.0 - attr_accessor :cooldown_wait, :secondary_cooldown_wait, :attack_speed, :health, :armor, :x, :y, :rockets, :score, :time_alive, :bombs, :secondary_weapon, :grapple_hook_cooldown_wait + attr_accessor :cooldown_wait, :secondary_cooldown_wait, :attack_speed, :health, :armor, :x, :y, :rockets, :score, :time_alive + + attr_accessor :bombs, :secondary_weapon, :grapple_hook_cooldown_wait, :damage_reduction, :boost_increase, :damage_increase, :kill_count + attr_accessor :special_attack MAX_HEALTH = 200 - SECONDARY_WEAPONS = %w[missile bomb] + SECONDARY_WEAPONS = [RocketLauncherPickup::NAME] + %w[bomb] # Range goes clockwise around the 0-360 angle MISSILE_LAUNCHER_MIN_ANGLE = 75 MISSILE_LAUNCHER_MAX_ANGLE = 105 MISSILE_LAUNCHER_INIT_ANGLE = 90 + SPECIAL_POWER = 'laser' + SPECIAL_POWER_KILL_MAX = 50 + + def get_kill_count_max + self.class::SPECIAL_POWER_KILL_MAX + end + + def ready_for_special? + @kill_count >= get_kill_count_max + end + + def special_attack + # Fire special attack. + @kill_count = 0 + end + + # Rocket Launcher, Rocket launcher, Cannon, Cannon, Bomb Launcher + HARD_POINTS = 12 + + def add_kill_count kill_count + if @kill_count + kill_count > get_kill_count_max + @kill_count = get_kill_count_max + else + @kill_count += kill_count + end + end + + def add_hard_point hard_point + @hard_point_items << hard_point + trigger_hard_point_load + end + + def trigger_hard_point_load + @rocket_launchers, @bomb_launchers, @cannon_launchers = [0, 0, 0] + count = 0 + # puts "RUNNING ON: #{@hard_point_items}" + @hard_point_items.each do |hard_point| + break if count == HARD_POINTS + case hard_point + when 'bomb_launcher' + @bomb_launchers += 1 + when RocketLauncherPickup::NAME + # puts "INCREASTING ROCKET LAUNCHER: #{RocketLauncherPickup::NAME}" + @rocket_launchers += 1 + when 'cannon_launcher' + @cannon_launchers += 1 + else + "Raise should never get here. hard_point: #{hard_point}" + end + count += 1 + end + end + def get_image Gosu::Image.new("#{MEDIA_DIRECTORY}/spaceship.png") end def initialize(scale, x, y, screen_width, screen_height, options = {}) super(scale, x, y, screen_width, screen_height, options) + # Top of screen + @min_moveable_height = options[:min_moveable_height] || 0 + # Bottom of the screen + @max_movable_height = options[:max_movable_height] || screen_height @right_image = Gosu::Image.new("#{MEDIA_DIRECTORY}/spaceship_right.png") @left_image = Gosu::Image.new("#{MEDIA_DIRECTORY}/spaceship_left.png") @score = 0 @cooldown_wait = 0 @secondary_cooldown_wait = 0 @grapple_hook_cooldown_wait = 0 @attack_speed = 1 - @health = 100 + # @attack_speed = 3 + @health = 100.0 @armor = 0 - @rockets = 25 + @rockets = 50 # @rockets = 250 @bombs = 3 - @secondary_weapon = "missile" + @secondary_weapon = RocketLauncherPickup::NAME @turn_right = false @turn_left = false + + @hard_point_items = [RocketLauncherPickup::NAME, 'cannon_launcher', 'cannon_launcher', 'bomb_launcher'] + @rocket_launchers = 0 + @bomb_launchers = 0 + @cannon_launchers = 0 + trigger_hard_point_load + @damage_reduction = options[:handicap] ? options[:handicap] : 1 + invert_handicap = 1 - options[:handicap] + @boost_increase = invert_handicap > 0 ? 1 + (invert_handicap * 1.25) : 1 + @damage_increase = invert_handicap > 0 ? 1 + (invert_handicap) : 1 + @kill_count = 0 end def take_damage damage - @health -= damage + @health -= damage * @damage_reduction end def toggle_secondary current_index = SECONDARY_WEAPONS.index(@secondary_weapon) if current_index == SECONDARY_WEAPONS.count - 1 @@ -57,16 +130,16 @@ self.rockets end end - def decrement_secondary_ammo_count + def decrement_secondary_ammo_count count = 1 return case @secondary_weapon when 'bomb' - self.bombs -= 1 + self.bombs -= count else - self.rockets -= 1 + self.rockets -= count end end def get_secondary_name return case @secondary_weapon @@ -101,23 +174,28 @@ @turn_right = true @x = [@x + get_speed, (@screen_width - (get_width/3))].min end def accelerate - @y = [@y - get_speed, (get_height/2)].max + # # Top of screen + # @min_moveable_height = options[:min_moveable_height] || 0 + # # Bottom of the screen + # @max_movable_height = options[:max_movable_height] || screen_height + + @y = [@y - get_speed, @min_moveable_height + (get_height/2)].max end def brake - @y = [@y + get_speed, @screen_height].min + @y = [@y + get_speed, @max_movable_height - (get_height/2)].min end def attack pointer return { projectiles: [ - Bullet.new(@scale, @screen_width, @screen_height, self, {side: 'left', relative_object: self}), - Bullet.new(@scale, @screen_width, @screen_height, self, {side: 'right', relative_object: self}) + Bullet.new(@scale, @screen_width, @screen_height, self, {side: 'left', damage_increase: @damage_increase}), + Bullet.new(@scale, @screen_width, @screen_height, self, {side: 'right', damage_increase: @damage_increase}) ], cooldown: Bullet::COOLDOWN_DELAY } end @@ -128,11 +206,10 @@ projectiles = results[:projectiles] cooldown = results[:cooldown] self.secondary_cooldown_wait = cooldown.to_f.fdiv(self.attack_speed) projectiles.each do |projectile| - self.decrement_secondary_ammo_count return_projectiles.push(projectile) end end return return_projectiles end @@ -144,38 +221,47 @@ # end # return second_weapon # end def secondary_attack pointer - second_weapon = case @secondary_weapon + projectiles = [] + cooldown = 0 + case @secondary_weapon when 'bomb' - { - projectiles: [Bomb.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y)], - cooldown: Bomb::COOLDOWN_DELAY - } - else - if get_secondary_ammo_count > 1 - { - projectiles: [ - Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', relative_object: self}), - Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', relative_object: self}) - ], - cooldown: Missile::COOLDOWN_DELAY - } - # { - # projectiles: [ - # Missile.new(@scale, @screen_width, @screen_height, self, mouse_x, mouse_y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE) - # ], - # cooldown: Missile::COOLDOWN_DELAY - # } - else get_secondary_ammo_count == 1 - { - projectiles: [Missile.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, {relative_object: self})], - cooldown: Missile::COOLDOWN_DELAY - } + projectiles << Bomb.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, nil, nil, nil, {damage_increase: @damage_increase}) + cooldown = Bomb::COOLDOWN_DELAY + when RocketLauncherPickup::NAME + # NEEED TO DECRETMENT AMMO BASED OFF OF LAUNCHERS!!!!!!!!!!! + # puts "ROCKET LAUNCHERS: #{@rocket_launchers}" + cooldown = Missile::COOLDOWN_DELAY + if get_secondary_ammo_count == 1 && @rocket_launchers > 0 || @rocket_launchers == 1 + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {damage_increase: @damage_increase}) + elsif get_secondary_ammo_count == 2 && @rocket_launchers >= 2 || @rocket_launchers == 2 + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase}) + elsif get_secondary_ammo_count == 3 && @rocket_launchers >= 3 || @rocket_launchers == 3 + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase}) + elsif get_secondary_ammo_count == 4 && @rocket_launchers >= 4 || @rocket_launchers == 4 + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE + 15, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE - 15, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase}) + + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half / 2, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE + 5, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase, relative_x_padding: (@image_width_half / 2) }) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half / 2, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE - 5, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase, relative_x_padding: -(@image_width_half / 2) }) + elsif get_secondary_ammo_count == 5 && @rocket_launchers >= 5 || @rocket_launchers >= 5 + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE + 15, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase}) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE - 15, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase}) + + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x - @image_width_half / 2, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE + 5, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'left', damage_increase: @damage_increase, relative_x_padding: (@image_width_half / 2) }) + projectiles << Missile.new(@scale, @screen_width, @screen_height, self, pointer.x + @image_width_half / 2, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE - 5, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {side: 'right', damage_increase: @damage_increase, relative_x_padding: -(@image_width_half / 2) }) + else + raise "Should never get here: @secondary_weapon: #{@secondary_weapon} for @rocket_launchers: #{@rocket_launchers} and get_secondary_ammo_count: #{get_secondary_ammo_count}" end end - return second_weapon + decrement_secondary_ammo_count projectiles.count + return {projectiles: projectiles, cooldown: cooldown} end def get_draw_ordering ZOrder::Player end \ No newline at end of file