samples/05_mouse/02_mouse_move/app/main.rb
# Decreases the zombie spawn countdown by 1 if it has a value greater than 0.
Decreases the zombie spawn countdown by 1 if it has a value greater than 0.
Decreases the zombie spawn countdown by 1 if it has a value greater than 0 .
def calc_spawn_zombie
    if state.zombie_spawn_countdown > 0
      state.zombie_spawn_countdown -= 1
      return
    end
    state.zombies << state.new_entity(:zombie) do |z| 
      if rand > 0.5
        z.x = grid.rect.w.randomize(:ratio) 
        z.y = [-10, 730].sample 
      else
        z.x = [-10, 1290].sample 
        z.y = grid.rect.w.randomize(:ratio) 
      end
    end
    state.zombie_spawn_countdown = random_spawn_countdown state.zombie_min_spawn_rate
    state.zombie_min_spawn_rate -= 1
    state.zombie_min_spawn_rate  = state.zombie_min_spawn_rate.greater(0)
  end
def calc_spawn_zombie if state . zombie_spawn_countdown > 0 state . zombie_spawn_countdown -= 1 return end state . zombies << state . new_entity ( :zombie ) do | z | if rand > 0.5 z . x = grid . rect . w . randomize ( :ratio ) z . y = [ - 10 , 730 ] . sample else z . x = [ - 10 , 1290 ] . sample z . y = grid . rect . w . randomize ( :ratio ) end end state . zombie_spawn_countdown = random_spawn_countdown state . zombie_min_spawn_rate state . zombie_min_spawn_rate -= 1 state . zombie_min_spawn_rate = state . zombie_min_spawn_rate . greater ( 0 ) end
Decreases the zombie spawn countdown by 1 if it has a value greater than 0.
Decreases the zombie spawn countdown by 1 if it has a value greater than 0 .
# New zombies are created, positioned on the screen, and added to the zombies collection. # each zombie is declared a new entity # random x position on screen (within grid scope) # y position is set to either -10 or 730 (randomly chosen) # the possible values exceed the screen's scope so zombies appear to be coming from far away # x position is set to either -10 or 1290 (randomly chosen) # random y position on screen # Calls random_spawn_countdown method (determines how fast new zombies appear) # set to either the current zombie_min_spawn_rate or 0, depending on which value is greater