Skip to content

Commit

Permalink
Start from a configurable location
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhenry committed Aug 4, 2017
1 parent 60677f5 commit 5bcc81b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize
def play
Thread.abort_on_exception = true
threads = []
threads << run_thread(0.02) { @render.draw_map(@engine) }
threads << run_thread(0.01) { @render.draw_map(@engine) }
threads << run_thread(1) { @engine.take_turn }
threads << run_thread { @inputs.read }
until @engine.ended?
Expand Down
2 changes: 1 addition & 1 deletion lib/game/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def bind_keys
bind_key(:'2') { skip_to('level6') }
bind_key(:'3') { skip_to('level7_a') }
bind_key(:'4') { skip_to('level8') }
bind_key(:'5') { skip_to('level11') }
bind_key(:'5') { skip_to('level12') }

@editor.bind(:ctrl_x) { puts "Exiting..."; exit }
end
Expand Down
14 changes: 6 additions & 8 deletions lib/game/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def method_missing(method, *args, &blk)
end

def start_tile
at(0, 0)
at(*start_location)
end

def start_location
@map_data['start_location'] || [0, 0]
end

def clear_fog(tile)
Expand All @@ -59,12 +63,6 @@ def clear_fog(tile)
end
end
end
# 0 0 1 0 0
# 0 1 1 1 0
# 1 1 1 1 1
# 0 1 1 1 0
# 0 0 1 0 0

end

private
Expand All @@ -73,7 +71,7 @@ def build_data
Game::Tile.clear
map = []
data = if @map_data['data'] == 'generate'
builder = MapBuilder.new(height, width)
builder = MapBuilder.new(height, width, start_location)
@map_data['objects'] = builder.place_objects(@map_data['objects'])
builder.map
else
Expand Down
13 changes: 7 additions & 6 deletions lib/game/map_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize(height, width)
end
@end_point = [height - 1, width - 1]
@endpoints = []
@start_location = start_location
add_paths
end

Expand Down Expand Up @@ -35,14 +36,14 @@ def next_endpoint
end

def add_paths
location = [0, 2]
@map[0][0] = 0
@map[0][1] = 0
@map[0][2] = 0
location = [@start_location[0], @start_location[1] + 2]
@map[@start_location[0]][@start_location[1]] = 0
@map[@start_location[0]][@start_location[1] + 1] = 0
@map[@start_location[0]][@start_location[1] + 2] = 0

branches = [[[0, 0], 0]]
branches = [[location, 0]]
terminated = []
steps = 0
steps = 2

while true do
action = next_action(branches, location)
Expand Down
1 change: 1 addition & 0 deletions maps/level11
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"name": "LevelExit",
"details": {
"modules": ["Exit"]
"next_map": "level12"
}
}
]
Expand Down
17 changes: 17 additions & 0 deletions maps/level12
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "12: Start inm the center",
"goal": "Navigate to the Exit",
"height": 30,
"width": 30,
"start_location": [15, 14],
"data": "generate",
"fog_of_war": true,
"objects": [
{
"name": "LevelExit",
"details": {
"modules": ["Exit"]
}
}
]
}

0 comments on commit 5bcc81b

Please sign in to comment.