samples/05_mouse/02_mouse_move/app/main.rb
def calc_kill_zombie

    # Find all zombies that intersect with the player. They are considered killed.
    killed_this_frame = state.zombies.find_all { |z| z.sprite && (z.sprite.intersect_rect? state.player_sprite) }
    state.zombies = state.zombies - killed_this_frame # remove newly killed zombies from zombies collection
    state.killed_zombies += killed_this_frame # add newly killed zombies to killed zombies

    if killed_this_frame.length > 0 # if atleast one zombie was killed in the frame
      state.flash_at = state.tick_count # flash_at set to the frame when the zombie was killed
    # Don't forget, the rendered flash lasts for 10 frames after the zombie is killed (look at render_flash method)
    end

    # Sets the tick_count (passage of time) as the value of the death_at variable for each killed zombie.
    # Death_at stores the frame a zombie was killed.
    killed_this_frame.each do |z|
      z.death_at = state.tick_count
    end

    # Zombies are rejected from the killed_zombies collection depending on when they were killed.
    # They are rejected if more than 30 frames have passed since their death.
    state.killed_zombies = state.killed_zombies.reject { |z| state.tick_count - z.death_at > 30 }
  end
# Finds all zombies that intersect with the player's sprite. These zombies are removed from the zombies collection
# and added to the killed_zombies collection since any zombie that intersects with the player is killed.
Finds all zombies that intersect with the player's sprite. These zombies are removed from the zombies collection
and added to the killed_zombies collection since any zombie that intersects with the player is killed.
Finds all zombies that intersect with the player ' s sprite . These zombies are removed from the zombies collection and added to the killed_zombies collection since any zombie that intersects with the player is killed .
def calc_kill_zombie
    killed_this_frame = state.zombies.find_all { |z| z.sprite && (z.sprite.intersect_rect? state.player_sprite) }
    state.zombies = state.zombies - killed_this_frame 
    state.killed_zombies += killed_this_frame 
    if killed_this_frame.length > 0 
      state.flash_at = state.tick_count 
    end
    killed_this_frame.each do |z|
      z.death_at = state.tick_count
    end
    state.killed_zombies = state.killed_zombies.reject { |z| state.tick_count - z.death_at > 30 }
  end
def calc_kill_zombie killed_this_frame = state . zombies . find_all { | z | z . sprite && ( z . sprite . intersect_rect? state . player_sprite ) } state . zombies = state . zombies - killed_this_frame state . killed_zombies += killed_this_frame if killed_this_frame . length > 0 state . flash_at = state . tick_count end killed_this_frame . each do | z | z . death_at = state . tick_count end state . killed_zombies = state . killed_zombies . reject { | z | state . tick_count - z . death_at > 30 } end
Finds all zombies that intersect with the player's sprite.
Finds all zombies that intersect with the player ' s sprite .
# Find all zombies that intersect with the player. They are considered killed. # remove newly killed zombies from zombies collection # add newly killed zombies to killed zombies # if atleast one zombie was killed in the frame # flash_at set to the frame when the zombie was killed # Don't forget, the rendered flash lasts for 10 frames after the zombie is killed (look at render_flash method) # Sets the tick_count (passage of time) as the value of the death_at variable for each killed zombie. # Death_at stores the frame a zombie was killed. # Zombies are rejected from the killed_zombies collection depending on when they were killed. # They are rejected if more than 30 frames have passed since their death.