samples/99_genre_rpg_roguelike/02_roguelike_line_of_sight/app/main.rb
# Sets default values and initializes variables
Sets default values and initializes variables
Sets default values and initializes variables
def defaults
    outputs.background_color = [0, 0, 0] 
    state.canvas   ||= []
    state.dungeon  ||= []
    state.enemies  ||= []
    if !state.area
      load_area_one
      derive_dungeon_from_area
      state.x = 7
      state.y = 5
      state.enemies << state.new_entity(:enemy) do |e| 
        e.x           = 13 
        e.y           = 5
        e.previous_hp = 3
        e.hp          = 3
        e.max_hp      = 3
        e.is_dead     = false 
      end
      update_line_of_sight 
    end
  end
def defaults outputs . background_color = [ 0 , 0 , 0 ] state . canvas ||= [ ] state . dungeon ||= [ ] state . enemies ||= [ ] if ! state . area load_area_one derive_dungeon_from_area state . x = 7 state . y = 5 state . enemies << state . new_entity ( :enemy ) do | e | e . x = 13 e . y = 5 e . previous_hp = 3 e . hp = 3 e . max_hp = 3 e . is_dead = false end update_line_of_sight end end
Sets default values and initializes variables
Sets default values and initializes variables
# black background # Initializes empty canvas, dungeon, and enemies collections. # If state.area doesn't have value, load_area_one and derive_dungeon_from_area methods are called # Changing these values will change the position of player # Creates new enemies, sets their values, and adds them to the enemies collection. # declares each enemy as new entity # position # the enemy is alive # updates line of sight by adding newly visible cells