Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

maze is generated dynamically at start. created static maze for testing

  • Loading branch information...
commit 63dcd63d03c5c02adec33ee7ef92a57c1992d2ac 1 parent c224e62
@jwoertink authored
Showing with 255 additions and 10 deletions.
  1. +1 −0  Gemfile
  2. +254 −10 lib/maze.rb
View
1  Gemfile
@@ -1,5 +1,6 @@
source "http://rubygems.org"
+gem 'theseus', :git => "git://github.com/jwoertink/theseus.git"
group :development do
gem "shoulda", ">= 0"
View
264 lib/maze.rb
@@ -1,3 +1,6 @@
+require 'rubygems'
+require 'bundler'
+Bundler.require
require 'java'
PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
require File.join(PROJECT_ROOT, 'vendor', 'jme3_2011-08-29.jar')
@@ -32,6 +35,8 @@ class Maze < SimpleApplication
def initialize
[:up, :down, :left, :right].each { |direction| self.instance_variable_set("@#{direction}", false) }
@walk_direction = Vector3f.new
+ @floor = {:width => 200, :height => 100}
+ @wall = {:width => 10, :height => 20}
end
def simpleInitApp
@@ -39,33 +44,267 @@ def simpleInitApp
state_manager.attach(bullet_app_state)
view_port.background_color = ColorRGBA.new(ColorRGBA.random_color)
-
capsule_shape = CapsuleCollisionShape.new(1.5, 6.0, 1)
self.player = CharacterControl.new(capsule_shape, 0.05)
player.jump_speed = 20
player.fall_speed = 30
player.gravity = 30
- player.physics_location = Vector3f.new(0, 10, 0)
+ player.physics_location = Vector3f.new(-185, 15, -95)
bullet_app_state.physics_space.add(player)
- bullet_app_state.physics_space.enable_debug(asset_manager)
setup_camera!
setup_floor!
- create_wall(0, 0, 100, 100, 10, 0)
- create_wall(0, 0, -100, 100, 10, 0)
- create_wall(100, 0, 0, 0, 10, 100)
- create_wall(-100, 0, 0, 0, 10, 100)
-
setup_keys!
setup_light!
+
+ generate_dynamic_maze
+ #generate_static_maze
end
+ def generate_static_maze
+ # Row 1
+ create_wall(-190, 20, -100, 10, 20, 0) # _
+ create_wall(-170, 20, -100, 10, 20, 0) # _
+ create_wall(-150, 20, -100, 10, 20, 0) # _
+ create_wall(-130, 20, -100, 10, 20, 0) # _
+ create_wall(-110, 20, -100, 10, 20, 0) # _
+ create_wall(-90, 20, -100, 10, 20, 0) # _
+ create_wall(-70, 20, -100, 10, 20, 0) # _
+ create_wall(-50, 20, -100, 10, 20, 0) # _
+ create_wall(-30, 20, -100, 10, 20, 0) # _
+ create_wall(-10, 20, -100, 10, 20, 0) # _
+ create_wall( 10, 20, -100, 10, 20, 0) # _
+ create_wall( 30, 20, -100, 10, 20, 0) # _
+ create_wall( 50, 20, -100, 10, 20, 0) # _
+ create_wall( 70, 20, -100, 10, 20, 0) # _
+ create_wall( 90, 20, -100, 10, 20, 0) # _
+ create_wall(110, 20, -100, 10, 20, 0) # _
+ create_wall(130, 20, -100, 10, 20, 0) # _
+ create_wall(150, 20, -100, 10, 20, 0) # _
+ create_wall(170, 20, -100, 10, 20, 0) # _
+ create_wall(190, 20, -100, 10, 20, 0) # _
+ create_wall(210, 20, -100, 10, 20, 0) # _
+
+ # Row 2
+ ' '
+ ' '
+ create_wall(-150, 20, -90, 10, 20, 10) # |
+ ' '
+ ' '
+ create_wall(-90, 20, -80, 10, 20, 0) # _
+ create_wall(-70, 20, -80, 10, 20, 0) # _
+ create_wall(-50, 20, -80, 10, 20, 0) # _
+ create_wall(-30, 20, -80, 10, 20, 0) # _
+ create_wall(-10, 20, -80, 10, 20, 0) # _
+ ' '
+ ' '
+ ' '
+ create_wall(70, 20, -80, 10, 20, 0) # _
+ create_wall(90, 20, -80, 10, 20, 0) # _
+ create_wall(110, 20, -80, 10, 20, 0) # _
+ create_wall(130, 20, -80, 10, 20, 0) # _
+ create_wall(150, 20, -80, 10, 20, 0) # _
+ ' '
+ ' '
+ create_wall(210, 20, -90, 10, 20, 10) # |
+
+ # Row 3
+ create_wall(-190, 20, -70, 10, 20, 10) # |
+ ' '
+ create_wall(-150, 20, -70, 10, 20, 10) # |
+ create_wall(-130, 20, -60, 10, 20, 0) # _
+ ' '
+ ' '
+ create_wall(-70, 20, -70, 10, 20, 10) # |
+ create_wall(-50, 20, -60, 10, 20, 0) # _
+ ' '
+ ' '
+ create_wall(10, 20, -70, 10, 20, 10) # |
+ ' '
+ create_wall(50, 20, -70, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(130, 20, -70, 10, 20, 10) # |
+ ' '
+ create_wall(170, 20, -70, 10, 20, 10) # |
+ ' '
+ create_wall(210, 20, -70, 10, 20, 10) # |
+
+ # Row 4
+ create_wall(-190, 20, -50, 10, 20, 10) # |
+ ' '
+ ' '
+ create_wall(-130, 20, -40, 10, 20, 0) # _
+ create_wall(-110, 20, -50, 10, 20, 10) # |
+ ' '
+ create_wall(-70, 20, -50, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(10, 20, -50, 10, 20, 10) # |
+ create_wall(30, 20, -40, 10, 20, 0) # _
+ create_wall(50, 20, -40, 10, 20, 0) # _
+ create_wall(70, 20, -40, 10, 20, 0) # _
+ create_wall(90, 20, -50, 10, 20, 10) # |
+ ' '
+ create_wall(130, 20, -50, 10, 20, 10) # |
+ create_wall(150, 20, -40, 10, 20, 0) # _
+ create_wall(170, 20, -40, 10, 20, 0) # _
+ create_wall(190, 20, -40, 10, 20, 0) # _
+ create_wall(210, 20, -50, 10, 20, 10) # |
+
+ # Row 5
+ create_wall(-190, 20, -30, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(-110, 20, -30, 10, 20, 10) # |
+ create_wall(-90, 20, -20, 10, 20, 0) # _
+ create_wall(-70, 20, -20, 10, 20, 0) # _
+ create_wall(-50, 20, -20, 10, 20, 0) # _
+ create_wall(-30, 20, -30, 10, 20, 10) # |
+ ' '
+ create_wall(10, 20, -30, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(90, 20, -30, 10, 20, 10) # |
+ create_wall(110, 20, -20, 10, 20, 0) # _
+ create_wall(130, 20, -20, 10, 20, 0) # _
+ create_wall(150, 20, -20, 10, 20, 0) # _
+ ' '
+ ' '
+ create_wall(210, 20, -30, 10, 20, 10) # |
+
+ # Row 6
+ create_wall(-190, 20, -10, 10, 20, 10) # |
+ create_wall(-170, 20, 0, 10, 20, 0) # _
+ create_wall(-150, 20, -10, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(-70, 20, -10, 10, 20, 10) # |
+ ' '
+ ' '
+ create_wall(-10, 20, 0, 10, 20, 0) # _
+ create_wall(10, 20, -10, 10, 20, 10) # |
+ create_wall(30, 20, 0, 10, 20, 0) # _
+ create_wall(50, 20, -10, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ ' '
+ ' '
+ create_wall(170, 20, -10, 10, 20, 10) # |
+ ' '
+ create_wall(210, 20, -10, 10, 20, 10) # |
+
+ # Row 7
+ create_wall(-190, 20, 10, 10, 20, 10) # |
+ ' '
+ ' '
+ create_wall(-130, 20, 20, 10, 20, 0) # _
+ create_wall(-110, 20, 10, 10, 20, 10) # |
+ create_wall(-90, 20, 20, 10, 20, 0) # _
+ create_wall(-70, 20, 10, 10, 20, 10) # |
+ create_wall(-50, 20, 20, 10, 20, 0) # _
+ create_wall(-30, 20, 20, 10, 20, 0) # _
+ create_wall(-10, 20, 20, 10, 20, 0) # _
+ ' '
+ ' '
+ create_wall(50, 20, 10, 10, 20, 10) # |
+ ' '
+ create_wall(90, 20, 10, 10, 20, 10) # |
+ ' '
+ create_wall(130, 20, 10, 10, 20, 10) # |
+ create_wall(150, 20, 20, 10, 20, 0) # _
+ create_wall(170, 20, 10, 10, 20, 10) # |
+ create_wall(190, 20, 20, 10, 20, 0) # _
+ create_wall(210, 20, 10, 10, 20, 10) # |
+
+ # Row 8
+ create_wall(-190, 20, 30, 10, 20, 10) # |
+ ' '
+ create_wall(-150, 20, 30, 10, 20, 10) # |
+ ' '
+ ' '
+ ' '
+ create_wall(-70, 20, 30, 10, 20, 10) # |
+ ' '
+ ' '
+ create_wall(-10, 20, 40, 10, 20, 0) # _
+ create_wall(10, 20, 40, 10, 20, 0) # _
+ create_wall(30, 20, 40, 10, 20, 0) # _
+ create_wall(50, 20, 30, 10, 20, 10) # |
+ create_wall(70, 20, 40, 10, 20, 0) # _
+ create_wall(90, 20, 30, 10, 20, 10) # |
+ create_wall(110, 20, 40, 10, 20, 0) # _
+ ' '
+ ' '
+ ' '
+ ' '
+ create_wall(210, 20, 30, 10, 20, 10) # |
+
+ # Row 9
+ create_wall(-190, 20, 50, 10, 20, 10) # |
+ ' '
+
+
+ # Row 10
+ create_wall(-190, 20, 70, 10, 20, 10) # |
+
+ # Row 11
+ create_wall(-190, 20, 90, 10, 20, 10) # |
+ maze =
+ <<-MAZE
+ _____________________
+ | _____ _____ |
+ | |_ |_ | | | | |
+ | _| | |___| |___|
+ | |___| | |___ |
+ |_| | _|_| | |
+ | _|_|___ | | |_|_|
+ | | | ___|_|_ |
+ | | |___| ___ |_| |
+ | | | ___| _| | |
+ |_____|___________|__
+ MAZE
+ end
+
+ def generate_dynamic_maze
+ maze = Theseus::OrthogonalMaze.generate(:width => 10)
+ rows = maze.to_s.split("\n")
+ starting_left = -(@floor[:width] - @wall[:width])
+ us_start = -@floor[:height]
+ pipe_start = us_start - @wall[:width]
+ rows.each_with_index do |step, row|
+ puts "Row #{row + 1}"
+ step.split(//).each_with_index do |type, col|
+ move_right = starting_left + (col * 20) # May need that 20 to be dynamic....
+ pipe_move_down = pipe_start + (row * 20)
+ us_move_down = us_start + (row * 20)
+ case type
+ when "_"
+ create_wall(move_right, @wall[:height], us_move_down, @wall[:width], @wall[:height], 0)
+ when "|"
+ create_wall(move_right, @wall[:height], pipe_move_down, @wall[:width], @wall[:height], 10)
+ when " "
+ # This is a space
+ end
+ end
+ end
+
+ puts "\n\n#{maze}\n\n"
+ end
+
+
def setup_camera!
flyCam.move_speed = 100
end
def setup_floor!
- box = Box.new(Vector3f.new(0, 0, 0), 100, 0.2, 100)
+ box = Box.new(Vector3f.new(0, 0, 0), @floor[:width], 0.2, @floor[:height])
floor = Geometry.new("the Floor", box)
matl = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
matl.set_texture("ColorMap", asset_manager.load_texture(File.join('assets', 'Textures', 'hardwood.jpg')))
@@ -78,10 +317,15 @@ def setup_floor!
end
# vx = x position
+ # '_' => -(floor_width - wall_width)
+ # '|' => -floor_height
# vy = elevation
+ # vy == by
# vz = y position
+ # '_' = -floor_height
+ # '|' = -(floor_height - wall_width)
# bx = x width
- # by = thickness (height)
+ # by = height
# bz = y width
def create_wall(vx, vy, vz, bx, by, bz)
box = Box.new(Vector3f.new(vx, vy, vz), bx, by, bz)
Please sign in to comment.
Something went wrong with that request. Please try again.