Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moved maze_craze to its own repo. few small sample updates

  • Loading branch information...
commit 410916de3a429bb47b8ce7d541c856cb2257e8fc 1 parent 50982d4
Jeremy Woertink authored October 24, 2012
6  Gemfile
... ...
@@ -1,9 +1,5 @@
1  
-source "http://rubygems.org"
2  
-
3  
-gem 'theseus', :git => "git://github.com/jwoertink/theseus.git"
4  
-
  1
+source :rubygems
5 2
 
6 3
 group :development do
7  
-  gem "rawr"
8 4
   gem "rspec"
9 5
 end
12  README.rdoc
Source Rendered
@@ -18,10 +18,7 @@ The main application can be run by
18 18
 You can view other samples by passing the sample number as an argument
19 19
   jruby bin/waves 8
20 20
   
21  
-Normal camera operations use W A S D to move. To exit just hit esc.
22  
-
23  
-== Running Maze Craze
24  
-  jruby lib/maze_craze
  21
+Normal camera operations use W A S D to move. To exit just hit esc. Some examples use space bar, or J and K keys. Read sample file in lib/samples for more info.
25 22
   
26 23
 == Requirements
27 24
   OSX (Because I haven't tried this on anything else)
@@ -37,16 +34,13 @@ The Nifty-gui must be implemented in Java (for now) to work. This requires takin
37 34
   mv lib/samples/nifty/StartScreenController.class package/classes/java
38 35
 
39 36
 == Current (known) Issues
40  
-* MazeCraze runs smooth for the first 15 seconds, then gets really "jumpy"
41 37
 * Not tested in any other OS
42  
-* MazeCraze maze is limited to size 10. Floor isn't dynamic enough to change sizes of maze
43 38
 * Nifty/JRuby example (sample 13a) throws nasty exception
44 39
 * Rag-doll sample loads, but isn't useable
45  
-* Sample 8 renders green in JRuby, but normal in Java
46  
-
  40
+* Sample 9 isn't working
  41
+* Sample 16 isn't working
47 42
 
48 43
 == Contributing to waves
49  
- 
50 44
 * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
51 45
 * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
52 46
 * Fork the project
14  Rakefile
@@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e
11 11
 end
12 12
 require 'rake'
13 13
 require 'rawr'
14  
-require 'jeweler'
15  
-Jeweler::Tasks.new do |gem|
16  
-  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17  
-  gem.name = "waves"
18  
-  gem.homepage = "http://github.com/jwoertink/waves"
19  
-  gem.license = "MIT"
20  
-  gem.summary = %Q{TODO: one-line summary of your gem}
21  
-  gem.description = %Q{TODO: longer description of your gem}
22  
-  gem.email = "jeremywoertink@gmail.com"
23  
-  gem.authors = ["Jeremy Woertink"]
24  
-  # dependencies defined in Gemfile
25  
-end
26  
-Jeweler::RubygemsDotOrgTasks.new
27  
-
28 14
 # require 'rake/testtask'
29 15
 # Rake::TestTask.new(:test) do |test|
30 16
 #   test.libs << 'lib' << 'test'
BIN  assets/Sound/Environment/lost.ogg
Binary file not shown
BIN  assets/Textures/brickwall.jpg
BIN  assets/Textures/hardwood.jpg
BIN  assets/Textures/start.jpg
BIN  assets/Textures/stop.jpg
BIN  assets/Textures/target.png
BIN  assets/town.zip 100755 → 100644
Binary file not shown
10  bin/maze_craze
... ...
@@ -1,10 +0,0 @@
1  
-#!/usr/bin/ruby
2  
-# -*- coding: utf-8 -*-
3  
-
4  
-require 'rubygems'
5  
-$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6  
-require 'waves'
7  
-require 'maze_craze/maze'
8  
-
9  
-Waves.echo("Booting Maze Craze", :green)
10  
-Maze.new.start
59  lib/maze_craze/controllers/StartScreenController.java
... ...
@@ -1,59 +0,0 @@
1  
-import com.jme3.app.Application;
2  
-import com.jme3.app.SimpleApplication;
3  
-import com.jme3.app.state.AbstractAppState;
4  
-import com.jme3.app.state.AppStateManager;
5  
-import de.lessvoid.nifty.Nifty;
6  
-import de.lessvoid.nifty.screen.Screen;
7  
-import de.lessvoid.nifty.screen.ScreenController;
8  
- 
9  
-public class StartScreenController extends AbstractAppState implements ScreenController {
10  
- 
11  
-  private Nifty nifty;
12  
-  private Screen screen;
13  
-  private SimpleApplication app;
14  
- 
15  
-  /** custom methods */ 
16  
- 
17  
-  public StartScreenController(Application app) { 
18  
-    /** You custom constructor, can accept arguments */
19  
-    this.app = (SimpleApplication) app;
20  
-  } 
21  
- 
22  
-  /** Nifty GUI ScreenControl methods */ 
23  
- 
24  
-  public void bind(Nifty nifty, Screen screen) {
25  
-    this.nifty = nifty;
26  
-    this.screen = screen;
27  
-  }
28  
- 
29  
-  public void onStartScreen() { }
30  
- 
31  
-  public void onEndScreen() { }
32  
- 
33  
-  /** jME3 AppState methods */ 
34  
- 
35  
-  @Override
36  
-  public void initialize(AppStateManager stateManager, Application app) {
37  
-    super.initialize(stateManager, app);
38  
-  }
39  
- 
40  
-  @Override
41  
-  public void update(float tpf) { 
42  
-    /** jME update loop! */ 
43  
-  }
44  
-  
45  
-  public void startGame(String nextScreen) {
46  
-    nifty.gotoScreen(nextScreen);  // switch to another screen
47  
-    // start the game and do some more stuff...
48  
-    // app.setupgame(); // Need to run this method, but it doesn't exist here.
49  
-    System.out.println("\n\n setting up game\n\n");
50  
-  }
51  
-
52  
-  public void quitGame() {
53  
-    System.out.println("\n\n quitGame called\n\n");
54  
-    app.stop();
55  
-    // TODO:
56  
-    // find app instance variable @controller_path and delete that file.
57  
-  }
58  
- 
59  
-}
62  lib/maze_craze/imports.rb
... ...
@@ -1,62 +0,0 @@
1  
-# require 'rubygems'
2  
-# require 'java'
3  
-# require 'jruby/core_ext'
4  
-require 'bundler'
5  
-Bundler.require
6  
-
7  
-# GAME_ROOT_PATH = File.expand_path(File.dirname(__FILE__))
8  
-# $CLASSPATH << File.join(GAME_ROOT_PATH, "java", "classes")
9  
-# 
10  
-# $: << File.join(GAME_ROOT_PATH)
11  
-
12  
-#require File.join(GAME_ROOT_PATH, '..', '..', 'vendor', 'jme3_2012-12-20.jar')
13  
-
14  
-java_import "com.jme3.app.SimpleApplication"
15  
-java_import "com.jme3.system.AppSettings"
16  
-java_import "com.jme3.system.NanoTimer"
17  
-java_import "com.jme3.asset.TextureKey"
18  
-java_import "com.jme3.font.BitmapText"
19  
-java_import "com.jme3.audio.AudioNode"
20  
-java_import "com.jme3.bullet.BulletAppState"
21  
-java_import "com.jme3.bullet.control.CharacterControl"
22  
-java_import "com.jme3.bullet.control.RigidBodyControl"
23  
-java_import "com.jme3.bullet.util.CollisionShapeFactory"
24  
-java_import "com.jme3.bullet.collision.shapes.CapsuleCollisionShape"
25  
-java_import "com.jme3.bullet.collision.shapes.CollisionShape"
26  
-java_import "com.jme3.collision.CollisionResult"
27  
-java_import "com.jme3.collision.CollisionResults"
28  
-java_import "com.jme3.input.KeyInput"
29  
-java_import "com.jme3.input.controls.ActionListener"
30  
-java_import "com.jme3.input.controls.KeyTrigger"
31  
-java_import "com.jme3.input.MouseInput"
32  
-java_import "com.jme3.input.controls.MouseButtonTrigger"
33  
-java_import "com.jme3.light.AmbientLight"
34  
-java_import "com.jme3.light.DirectionalLight"
35  
-java_import "com.jme3.math.ColorRGBA"
36  
-java_import "com.jme3.math.Vector2f"
37  
-java_import "com.jme3.math.Vector3f"
38  
-java_import "com.jme3.math.Ray"
39  
-java_import "com.jme3.scene.Node"
40  
-java_import "com.jme3.scene.Spatial"
41  
-java_import "com.jme3.scene.shape.Box"
42  
-java_import "com.jme3.scene.shape.Sphere"
43  
-java_import "com.jme3.scene.Geometry"
44  
-java_import "com.jme3.material.Material"
45  
-java_import "com.jme3.util.SkyFactory"
46  
-java_import "com.jme3.texture.Texture"
47  
-java_import "com.jme3.material.RenderState"
48  
-java_import "com.jme3.niftygui.NiftyJmeDisplay"
49  
-# java_import "de.lessvoid.nifty.Nifty"
50  
-# java_import "de.lessvoid.nifty.screen.Screen"
51  
-# java_import "de.lessvoid.nifty.screen.ScreenController"
52  
-java_import "java.util.logging.Level"
53  
-java_import "java.util.logging.Logger"
54  
-
55  
-# java_import "java.awt.DisplayMode"
56  
-# java_import "java.awt.GraphicsDevice"
57  
-# java_import "java.awt.GraphicsEnvironment"
58  
-
59  
-java_import "StartScreenController"
60  
-# java_import "HudScreenController"
61  
-# java_import "PauseScreenController"
62  
-# java_import "EndScreenController"
328  lib/maze_craze/maze.rb
... ...
@@ -1,328 +0,0 @@
1  
-require 'maze_craze/imports'
2  
-
3  
-class Maze < SimpleApplication
4  
-  include ActionListener
5  
-  VERSION = "1.0"
6  
-  
7  
-  field_accessor :flyCam, :paused
8  
-  field_reader :cam, :settings
9  
-  attr_accessor :playtime, :playing, :bullet_app_state, :player, :mark, :shootables, :gun_sound, :ambient_noise
10  
-  
11  
-  def initialize
12  
-    super
13  
-    [:up, :down, :left, :right].each { |direction| self.instance_variable_set("@#{direction}", false) }
14  
-    @walk_direction = Vector3f.new
15  
-    @floor = {:width => 200, :height => 100}
16  
-    @wall = {:width => 10, :height => 20}
17  
-    self.playing = false
18  
-    config = AppSettings.new(true)
19  
-    config.settings_dialog_image = File.join("assets", "Interface", "maze_craze_logo.png")
20  
-    config.set_resolution(800, 600)
21  
-    config.title = "Maze Craze #{VERSION}"
22  
-    self.settings = config
23  
-    self.show_settings = false
24  
-    @time_text = nil
25  
-    @counter = 0
26  
-    @targets = []
27  
-    @targets_generated = 0
28  
-    @game_state = 0
29  
-    Logger.get_logger("").level = Level::WARNING
30  
-  end
31  
-  
32  
-  def simpleInitApp
33  
-    self.timer = NanoTimer.new
34  
-    display_start_screen
35  
-    setupgame
36  
-  end
37  
-  
38  
-  def display_start_screen
39  
-    nifty_display = NiftyJmeDisplay.new(asset_manager, input_manager, audio_renderer, gui_view_port)
40  
-    nifty = nifty_display.nifty
41  
-    controller = StartScreenController.new(self)
42  
-    nifty.from_xml(File.join('lib', 'maze_craze', 'views', 'screen.xml'), 'start', controller)
43  
-    gui_view_port.add_processor(nifty_display)
44  
-    flyCam.enabled = false
45  
-    flyCam.drag_to_rotate = true
46  
-    input_manager.cursor_visible = true
47  
-    
48  
-    # device = GraphicsEnvironment.local_graphics_environment.default_screen_device
49  
-    # modes = device.display_modes
50  
-    # modes.each do |mode|
51  
-    #   puts "#{mode.width}x#{mode.height} #{mode.bit_depth}bit"
52  
-    # end
53  
-    # self.stop
54  
-  end
55  
-  
56  
-  def setupgame
57  
-    @game_state = 1
58  
-    self.bullet_app_state = BulletAppState.new
59  
-    state_manager.attach(bullet_app_state)
60  
-  
61  
-    capsule_shape = CapsuleCollisionShape.new(1.5, 15.0, 1)
62  
-    self.player = CharacterControl.new(capsule_shape, 0.05)
63  
-    player.jump_speed = 20
64  
-    player.fall_speed = 30
65  
-    player.gravity = 30
66  
-    player.physics_location = Vector3f.new(-185, 15, -95)
67  
-    # This isn't being used yet.
68  
-    player_model = asset_manager.load_model(File.join("Models", "Oto", "Oto.mesh.xml"))
69  
-    player_model.local_scale = 0.5
70  
-    player_model.local_translation = Vector3f.new(-185, 15, -95)
71  
-    player_model.add_control(player)
72  
-    bullet_app_state.physics_space.add(player_model)
73  
-  
74  
-  
75  
-    sphere = Sphere.new(30, 30, 0.2)
76  
-    self.mark = Geometry.new("BOOM!", sphere)
77  
-    mark_mat = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
78  
-    mark_mat.set_color("Color", ColorRGBA::Red)
79  
-    mark.material = mark_mat
80  
-  
81  
-    setup_text!
82  
-    setup_camera!
83  
-    setup_floor!
84  
-    setup_sky!
85  
-    setup_keys!
86  
-    setup_light!
87  
-    setup_audio!
88  
-  
89  
-    generate_maze(:width => 5) #(static_maze)
90  
-
91  
-    self.playing = true
92  
-    self.playtime = Time.now
93  
-  end
94  
-  
95  
-  def static_maze
96  
-    maze = 
97  
-<<-MAZE
98  
-_____________________
99  
-  |  _____   _____  |
100  
-| |_  |_  | |   | | |
101  
-|  _| |   |___| |___|
102  
-|   |___| |   |___  |
103  
-|_|   |  _|_|     | |
104  
-|  _|_|___  | | |_|_|
105  
-| |   |  ___|_|_    |
106  
-| | |___|  ___  |_| |
107  
-| | |  ___|  _| |   |
108  
-|_____|___________|__
109  
-MAZE
110  
-  end
111  
-  
112  
-  def generate_maze(opts = {})
113  
-    maze_width = opts[:width] || 10
114  
-    maze = opts[:maze] || Theseus::OrthogonalMaze.generate(:width => maze_width)
115  
-    rows = maze.to_s.split("\n")
116  
-    starting_left = -(@floor[:width] - @wall[:width])
117  
-    us_start = -@floor[:height]
118  
-    pipe_start = us_start - @wall[:width]
119  
-    create_wall(starting_left, 10, pipe_start + 20, 0, 10, 10, {:image => "start.jpg"}) #Start wall
120  
-    create_wall(@floor[:width] + 10, 0, @floor[:height] - 10, 10, 0, 10, {:image => "stop.jpg"}) #End wall
121  
-    rows.each_with_index do |step, row|
122  
-      step.split(//).each_with_index do |type, col|
123  
-        move_right = starting_left + (col * 20) # May need that 20 to be dynamic....
124  
-        pipe_move_down = pipe_start + (row * 20)
125  
-        us_move_down = us_start + (row * 20)
126  
-        case type
127  
-        when "_"
128  
-          create_wall(move_right, @wall[:height], us_move_down, @wall[:width], @wall[:height], 0)
129  
-        when "|"
130  
-          create_wall(move_right, @wall[:height], pipe_move_down, @wall[:width], @wall[:height], 10)
131  
-        when " "
132  
-          # This is a space
133  
-          # Randomly generate a target
134  
-          if row > 0 && col > 11 && rand(100) > 90
135  
-            create_wall(move_right, @wall[:height], us_move_down, @wall[:width], @wall[:height], 0, {:image => "target.png", :name => "Target"})
136  
-            @targets_generated += 1
137  
-          end
138  
-        end
139  
-      end
140  
-    end
141  
-    
142  
-    #puts "\n\n#{maze}\n\n"
143  
-  end
144  
-  
145  
-  
146  
-  def setup_camera!
147  
-    flyCam.enabled = true
148  
-    flyCam.move_speed = 100
149  
-    cam.look_at_direction(Vector3f.new(10, 0, 0).normalize_local, Vector3f::UNIT_Y)
150  
-  end
151  
-  
152  
-  def setup_floor!
153  
-    floor = Box.new(Vector3f::ZERO, @floor[:width], 0.2, @floor[:height])
154  
-    floor.scale_texture_coordinates(Vector2f.new(3, 6))
155  
-    floor_mat = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
156  
-    key = TextureKey.new(File.join('assets', 'Textures', 'hardwood.jpg'))
157  
-    key.generate_mips = true
158  
-    texture = asset_manager.load_texture(key)
159  
-    texture.wrap = Texture::WrapMode::Repeat
160  
-    floor_mat.set_texture("ColorMap", texture)
161  
-    floor_geo = Geometry.new("Floor", floor)
162  
-    floor_geo.material = floor_mat
163  
-    floor_geo.set_local_translation(0, -0.1, 0)
164  
-    root_node.attach_child(floor_geo)
165  
-    floor_phy = RigidBodyControl.new(0.0)
166  
-    floor_geo.add_control(floor_phy)
167  
-    bullet_app_state.physics_space.add(floor_phy)
168  
-  end
169  
-  
170  
-  def setup_sky!
171  
-    root_node.attach_child(SkyFactory.create_sky(asset_manager, File.join("Textures", "Sky", "Bright", "BrightSky.dds"), false))
172  
-    #view_port.background_color = ColorRGBA.new(ColorRGBA.random_color)
173  
-  end
174  
-  
175  
-  #  vx = x position
176  
-  #   '_' => -(floor_width - wall_width)
177  
-  #   '|' => -floor_height
178  
-  #  vy = elevation
179  
-  #   vy == by  
180  
-  #  vz = y position
181  
-  #   '_' = -floor_height
182  
-  #   '|' = -(floor_height - wall_width)
183  
-  #  bx = x width
184  
-  #  by = height
185  
-  #  bz = y width
186  
-  def create_wall(vx, vy, vz, bx, by, bz, options = {})
187  
-    image = options[:image] || 'brickwall.jpg'
188  
-    name = options[:name] || "a Wall"
189  
-    box = Box.new(Vector3f.new(vx, vy, vz), bx, by, bz)
190  
-    wall = Geometry.new(name, box)
191  
-    matl = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
192  
-    matl.set_texture("ColorMap", asset_manager.load_texture(File.join('assets', 'Textures', image)))
193  
-    matl.additional_render_state.blend_mode = RenderState::BlendMode::Alpha if image.include?(".png")
194  
-    wall.material = matl
195  
-    scene_shape = CollisionShapeFactory.create_mesh_shape(wall)
196  
-    landscape = RigidBodyControl.new(scene_shape, 0)
197  
-    wall.add_control(landscape)
198  
-    bullet_app_state.physics_space.add(landscape)
199  
-    root_node.attach_child(wall)
200  
-  end
201  
-  
202  
-  def setup_light!
203  
-    al = AmbientLight.new
204  
-    al.color = ColorRGBA::White.mult(1.3)
205  
-    root_node.add_light(al)
206  
-    dl = DirectionalLight.new
207  
-    dl.color = ColorRGBA::White
208  
-    dl.direction = Vector3f.new(2.8, -2.8, -2.8).normalize_local
209  
-    root_node.add_light(dl)
210  
-  end
211  
-  
212  
-  def setup_keys!
213  
-    input_manager.add_mapping("Left",  KeyTrigger.new(KeyInput::KEY_A))
214  
-    input_manager.add_mapping("Right", KeyTrigger.new(KeyInput::KEY_D))
215  
-    input_manager.add_mapping("Up",    KeyTrigger.new(KeyInput::KEY_W))
216  
-    input_manager.add_mapping("Down",  KeyTrigger.new(KeyInput::KEY_S))
217  
-    input_manager.add_mapping("Shoot", KeyTrigger.new(KeyInput::KEY_SPACE))
218  
-    input_manager.add_listener(ControllerAction.new(self), ["Left", "Right", "Up", "Down", "Shoot"].to_java(:string))
219  
-  end
220  
-  
221  
-  def setup_text!
222  
-    gui_node.detach_all_children
223  
-    gui_font = asset_manager.load_font(File.join("Interface", "Fonts", "Default.fnt"))
224  
-    ch = BitmapText.new(gui_font, false)
225  
-    ch.size = gui_font.char_set.rendered_size * 2
226  
-    ch.text = "+"
227  
-    ch.set_local_translation(settings.width / 2 - gui_font.char_set.rendered_size / 3 * 2, settings.height / 2 + ch.line_height / 2, 0)
228  
-    gui_node.attach_child(ch)
229  
-    
230  
-    @time_text = BitmapText.new(gui_font, false)
231  
-    @time_text.size = 20
232  
-    @time_text.color = ColorRGBA::Blue
233  
-    @time_text.text = "PLAY TIME:"
234  
-    @time_text.set_local_translation(50, 50, 0)
235  
-    gui_node.attach_child(@time_text)
236  
-  end
237  
-  
238  
-  def setup_audio!
239  
-    self.gun_sound = AudioNode.new(asset_manager, File.join("Sound", "Effects", "Gun.wav"), false)
240  
-    gun_sound.looping = false
241  
-    gun_sound.volume = 3
242  
-    root_node.attach_child(gun_sound)
243  
-    
244  
-    self.ambient_noise = AudioNode.new(asset_manager, File.join("assets", "Sound", "Environment", "lost.ogg"), false)
245  
-    ambient_noise.looping = true
246  
-    ambient_noise.positional = true
247  
-    ambient_noise.local_translation = Vector3f::ZERO.clone
248  
-    ambient_noise.volume = 2
249  
-    root_node.attach_child(ambient_noise)
250  
-    ambient_noise.play
251  
-  end
252  
-  
253  
-  def simpleUpdate(tpf)
254  
-    unless @game_state.zero?
255  
-      #@time_text.text = "PLAY TIME: #{(@counter += 1) / 1000}" if playing?
256  
-      cam_dir = cam.direction.clone.mult_local(0.6)
257  
-      cam_left = cam.left.clone.mult_local(0.4)
258  
-      @walk_direction.set(0, 0, 0)
259  
-      @walk_direction.add_local(cam_left) if @left
260  
-      @walk_direction.add_local(cam_left.negate) if @right
261  
-      @walk_direction.add_local(cam_dir) if @up
262  
-      @walk_direction.add_local(cam_dir.negate) if @down
263  
-      player.walk_direction = @walk_direction
264  
-      cam.location = player.physics_location
265  
-      if cam.location.x > (@floor[:width]) && cam.location.z > (@floor[:height] - 20) && playing?
266  
-        if @targets.empty? && @targets_generated > 0
267  
-          @time_text.text = "YOU MUST SHOOT A TARGET FIRST!"
268  
-        else
269  
-          puts "finish"
270  
-          self.playing = false
271  
-          finish_time = Time.now - playtime
272  
-          # finish_time != (@counter / 1000)
273  
-          # @targets.size == actual targets shot * 2 ....
274  
-          @time_text.text = "FINISH TIME: #{finish_time.ceil} seconds. You shot #{@targets.size}/#{@targets_generated} targets"
275  
-          self.paused = true
276  
-          input_manager.cursor_visible = true
277  
-          flyCam.enabled = false
278  
-          # use nifty
279  
-        end
280  
-      
281  
-      end
282  
-    end
283  
-  end
284  
-  
285  
-  def playing?
286  
-    playing
287  
-  end
288  
-  
289  
-  class ControllerAction
290  
-    include ActionListener
291  
-    
292  
-    def initialize(obj)
293  
-      @parent = obj
294  
-    end
295  
-    
296  
-    def on_action(binding, value, tpf)
297  
-      @parent.instance_variable_set("@#{binding.downcase}", value)
298  
-      if binding.eql?("Shoot") && !value
299  
-        @parent.gun_sound.play_instance
300  
-        results = CollisionResults.new
301  
-        ray = Ray.new(@parent.cam.location, @parent.cam.direction)
302  
-        @parent.root_node.collide_with(ray, results)
303  
-        if results.size > 0
304  
-          closest = results.closest_collision
305  
-          @parent.mark.local_translation = closest.contact_point
306  
-          @parent.root_node.attach_child(@parent.mark)
307  
-        else
308  
-          @parent.root_node.detach_child(@parent.mark)
309  
-        end
310  
-        results.each_with_index do |result, index|
311  
-          collision = results.get_collision(index)
312  
-          dist = collision.distance
313  
-          pt = collision.contact_point
314  
-          spacial = collision.geometry
315  
-          hit = spacial.name
316  
-          if hit.eql?("Target")
317  
-            @parent.instance_variable_get("@targets") << spacial
318  
-            @parent.root_node.detach_child(@parent.mark)
319  
-            spacial.remove_from_parent
320  
-            @parent.bullet_app_state.physics_space.remove(spacial.get_control(RigidBodyControl.java_class))
321  
-          end
322  
-        end
323  
-      end
324  
-    end
325  
-    
326  
-  end
327  
-  
328  
-end
58  lib/maze_craze/views/screen.xml
... ...
@@ -1,58 +0,0 @@
1  
-<?xml version="1.0" encoding="UTF-8"?>
2  
-<nifty xmlns="http://nifty-gui.sourceforge.net/nifty.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
3  
-       xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty.xsd http://nifty-gui.sourceforge.net/nifty.xsd">
4  
-  <useControls filename="nifty-default-controls.xml" />
5  
-  <useStyles filename="nifty-default-styles.xml" />
6  
-  <screen id="start" controller="StartScreenController">
7  
-    <layer id="background" childLayout="center">
8  
-      <image filename="assets/Interface/start-background.png"></image>
9  
-    </layer>
10  
-    <layer id="foreground" backgroundColor="#0000" childLayout="vertical">
11  
-      <panel id="panel_top" height="25%" width="75%" align="center" childLayout="center">
12  
-        <text text="Maze Craze 1.0" font="Interface/Fonts/Default.fnt" width="100%" height="100%" />
13  
-      </panel>
14  
-      <panel id="panel_mid" height="50%" width="75%" align="center" childLayout="center">       
15  
-        <text text="Here goes some text describing the game and the rules and stuff. Incidentally, the text is quite long and needs to wrap at the end of lines. ..." 
16  
-        font="Interface/Fonts/Default.fnt" width="100%" height="100%" wrap="true" />
17  
-      </panel>
18  
-      <panel id="panel_bottom" height="25%" width="75%" align="center" childLayout="horizontal" backgroundColor="#00f8">  
19  
-        <panel id="panel_bottom_left" height="50%" width="50%" valign="center" childLayout="center">  
20  
-          <control name="button" label="Start" id="StartButton" align="center" valign="center" visibleToMouse="true">
21  
-            <interact onClick="startGame(hud)"/>
22  
-          </control>
23  
-        </panel>
24  
-        <panel id="panel_bottom_right" height="50%" width="50%" valign="center" childLayout="center">  
25  
-          <control name="button" label="Quit" id="QuitButton" align="center" valign="center" visibleToMouse="true">
26  
-            <interact onClick="quitGame()" />
27  
-          </control>
28  
-        </panel>
29  
-      </panel>
30  
-    </layer>
31  
-  </screen>
32  
-  <screen id="hud" controller="HudScreenController">
33  
-    <layer id="background" childLayout="center">
34  
-    </layer>
35  
-    <layer id="foreground" backgroundColor="#0000" childLayout="vertical">
36  
-      <panel id="panel_bottom_left" height="75%" width="20%" valign="center" childLayout="center">  
37  
-        
38  
-      </panel>
39  
-      <panel id="panel_right" width="20%" height="100%" childLayout="vertical" backgroundColor="#00f8" >  
40  
-        <panel id="panel_top_right" height="100%" width="15%" childLayout="center">  
41  
-          <control name="label" color="#000" text="123" width="100%" height="100%" />
42  
-        </panel>
43  
-        <panel id="panel_top_right1" width="100%" height="15%" childLayout="center" backgroundColor="#00f8">  
44  
-        </panel>
45  
-        <panel id="panel_top_right2" width="100%" height="15%" childLayout="center" backgroundColor="#44f8">  
46  
-        </panel>
47  
-        <panel id="panel_bot_right" width="100%" height="70%" valign="center" backgroundColor="#88f8">  
48  
-        </panel>
49  
-      </panel>
50  
-    </layer>
51  
-  </screen>
52  
-  <screen id="pause" controller="PauseScreenController">
53  
-    <!-- To be implemented -->
54  
-  </screen>
55  
-  <screen id="end" controller="EndScreenController">
56  
-    <!-- To be implemented -->
57  
-  </screen>
58  
-</nifty>
1  lib/samples/nifty/StartScreenController.java
@@ -44,6 +44,7 @@ public void update(float tpf) {
44 44
   
45 45
   public void startGame(String nextScreen) {
46 46
     System.out.println("\n\n startGame called\n\n");
  47
+    System.out.println("\n\n " + app + "\n\n");
47 48
     nifty.gotoScreen(nextScreen);  // switch to another screen
48 49
     // start the game and do some more stuff...
49 50
   }
226  lib/samples/sample16.rb
... ...
@@ -0,0 +1,226 @@
  1
+=begin
  2
+  This is an example of how to create a vehicle.
  3
+  TODO: currently not working.
  4
+=end
  5
+
  6
+java_import "com.jme3.app.SimpleApplication"
  7
+java_import "com.jme3.bounding.BoundingBox"
  8
+java_import "com.jme3.bullet.BulletAppState"
  9
+java_import "com.jme3.bullet.PhysicsSpace"
  10
+java_import "com.jme3.bullet.collision.shapes.CollisionShape"
  11
+java_import "com.jme3.bullet.control.VehicleControl"
  12
+java_import "com.jme3.bullet.objects.VehicleWheel"
  13
+java_import "com.jme3.bullet.util.CollisionShapeFactory"
  14
+java_import "com.jme3.bullet.collision.shapes.MeshCollisionShape"
  15
+java_import "com.jme3.bullet.control.PhysicsControl"
  16
+java_import "com.jme3.input.KeyInput"
  17
+java_import "com.jme3.input.controls.ActionListener"
  18
+java_import "com.jme3.input.controls.KeyTrigger"
  19
+java_import "com.jme3.light.DirectionalLight"
  20
+java_import "com.jme3.math.FastMath"
  21
+java_import "com.jme3.math.Matrix3f"
  22
+java_import "com.jme3.math.Vector2f"
  23
+java_import "com.jme3.math.Vector3f"
  24
+java_import "com.jme3.renderer.queue.RenderQueue$ShadowMode"
  25
+java_import "com.jme3.texture.Texture"
  26
+java_import "com.jme3.scene.shape.Box"
  27
+java_import "com.jme3.scene.Geometry"
  28
+java_import "com.jme3.scene.Node"
  29
+java_import "com.jme3.scene.Spatial"
  30
+java_import "com.jme3.shadow.BasicShadowRenderer"
  31
+
  32
+
  33
+class Sample16 < SimpleApplication
  34
+  include ActionListener
  35
+  field_reader :settings, :cam
  36
+  field_accessor :flyCam
  37
+  attr_accessor :bullet_app_state, :steering_value, :acceleration_value, :player, :car_node
  38
+  
  39
+  def initialize
  40
+    self.steering_value = 0
  41
+    self.acceleration_value = 0
  42
+  end
  43
+  
  44
+  def simpleInitApp
  45
+    self.bullet_app_state = BulletAppState.new
  46
+    state_manager.attach(bullet_app_state)
  47
+    bullet_app_state.physics_space.enable_debug(asset_manager)
  48
+    if settings.renderer.include?('LWJGL')
  49
+      bsr = BasicShadowRenderer.new(asset_manager, 512)
  50
+      bsr.direction = Vector3f.new(-0.5, -0.3, -0.3).normalize_local
  51
+      view_port.add_processor(bsr)
  52
+    end
  53
+    cam.frustum_far = 150.0
  54
+    flyCam.move_speed = 10
  55
+    setup_keys!
  56
+    setup_floor!
  57
+    build_player
  58
+    dl = DirectionalLight.new
  59
+    dl.direction = Vector3f.new(-0.5, -1.0, -0.3).normalize_local
  60
+    root_node.add_light(dl)
  61
+    dl = DirectionalLight.new
  62
+    dl.direction = Vector3f.new(0.5, -0.1, 0.3).normalize_local
  63
+    root_node.add_light(dl)
  64
+  end
  65
+  
  66
+  def simpleUpdate(tpf)
  67
+    cam.look_at(car_node.world_translation, Vector3f::UNIT_Y)
  68
+  end
  69
+  
  70
+  def setup_keys!
  71
+    input_manager.add_mapping("Lefts", KeyTrigger.new(KeyInput::KEY_H))
  72
+    input_manager.add_mapping("Rights", KeyTrigger.new(KeyInput::KEY_K))
  73
+    input_manager.add_mapping("Ups", KeyTrigger.new(KeyInput::KEY_U))
  74
+    input_manager.add_mapping("Downs", KeyTrigger.new(KeyInput::KEY_J))
  75
+    input_manager.add_mapping("Space", KeyTrigger.new(KeyInput::KEY_SPACE))
  76
+    input_manager.add_mapping("Reset", KeyTrigger.new(KeyInput::KEY_RETURN))
  77
+    input_manager.add_listener(ControllerAction.new(self), "Lefts");
  78
+    input_manager.add_listener(ControllerAction.new(self), "Rights");
  79
+    input_manager.add_listener(ControllerAction.new(self), "Ups");
  80
+    input_manager.add_listener(ControllerAction.new(self), "Downs");
  81
+    input_manager.add_listener(ControllerAction.new(self), "Space");
  82
+    input_manager.add_listener(ControllerAction.new(self), "Reset");
  83
+  end
  84
+  
  85
+  def setup_floor!
  86
+    mat = asset_manager.load_material(File.join("Textures", "Terrain", "BrickWall", "BrickWall.j3m"))
  87
+    mat.get_texture_param("DiffuseMap").texture_value.wrap = Texture::WrapMode::Repeat
  88
+    mat.get_texture_param("NormalMap").texture_value.wrap = Texture::WrapMode::Repeat
  89
+    mat.get_texture_param("ParallaxMap").texture_value.wrap = Texture::WrapMode::Repeat
  90
+    
  91
+    floor = Box.new(Vector3f::ZERO, 140, 1.0, 140)
  92
+    floor.scale_texture_coordinates(Vector2f.new(112.0, 112.0))
  93
+    floor_geom = Geometry.new("Floor", floor)
  94
+    floor_geom.shadow_mode = ShadowMode::Receive
  95
+    floor_geom.material = mat
  96
+    
  97
+    # This API has changed
  98
+    #tb = PhysicsControl.new(floor_geom, MeshCollisionShape.new(floor_geom.mesh), 0)
  99
+    #tb.local_translation = Vector3f.new(0.0, -6, 0.0)
  100
+    #tb.attach_debug_shape(asset_manager)
  101
+    #root_node.attach_child(tb)
  102
+    #bullet_app_state.physics_space.add(tb)
  103
+  end
  104
+  
  105
+  def build_player
  106
+    stiffness = 120.0
  107
+    comp_value = 0.2
  108
+    damp_value = 0.3
  109
+    mass = 400
  110
+    
  111
+    self.car_node = asset_manager.load_model(File.join('Models', 'Ferrari', 'Car.scene'))
  112
+    car_node.shadow_mode = ShadowMode::Cast
  113
+    chasis = find_geom(car_node, "Car")
  114
+    box = chasis.model_bound
  115
+    
  116
+    car_hull = CollisionShapeFactory.create_dynamic_mesh(chasis)
  117
+    
  118
+    self.player = VehicleControl.new(car_hull, mass)
  119
+    car_node.add_control(player)
  120
+    
  121
+    player.suspension_compression = comp_value * 2.0 * FastMath.sqrt(stiffness)
  122
+    player.suspension_damping = damp_value * 2.0 * FastMath.sqrt(stiffness)
  123
+    player.suspension_stiffness = stiffness
  124
+    player.max_suspension_force = 10000
  125
+
  126
+    wheel_direction = Vector3f.new(0, -1, 0)
  127
+    wheel_axle = Vector3f.new(-1, 0, 0)
  128
+
  129
+    wheel_fr = find_geom(carNode, "WheelFrontRight")
  130
+    wheel_fr.center
  131
+    box = wheel_fr.model_bound
  132
+    wheel_radius = box.y_extent
  133
+    back_wheel_h = (wheel_radius * 1.7) - 1.0
  134
+    front_wheel_h = (wheelRadius * 1.9) - 1.0
  135
+    player.add_wheel(wheel_fr.parent, box.center.add(0, -front_wheel_h, 0), wheel_direction, wheel_axle, 0.2, wheel_radius, true)
  136
+
  137
+    wheel_fl = find_geom(car_node, "WheelFrontLeft")
  138
+    wheel_fl.center
  139
+    box = wheel_fl.model_bound
  140
+    player.add_wheel(wheel_fl.parent, box.center.add(0, -front_wheel_h, 0), wheel_direction, wheel_axle, 0.2, wheel_radius, true)
  141
+
  142
+    wheel_br = find_geom(car_node, "WheelBackRight")
  143
+    wheel_br.center
  144
+    box = wheel_br.model_bound
  145
+    player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheel_direction, wheel_axle, 0.2, wheel_radius, false)
  146
+
  147
+    wheel_bl = find_geom(car_node, "WheelBackLeft")
  148
+    wheel_bl.center
  149
+    box = wheel_bl.model_bound
  150
+    player.add_wheel(wheel_bl.parent, box.center.add(0, -back_wheel_h, 0), wheel_direction, wheel_axle, 0.2, wheel_radius, false)
  151
+
  152
+    player.get_wheel(2).friction_slip = 4
  153
+    player.get_wheel(3).friction_slip = 4
  154
+
  155
+    root_node.attach_child(car_node)
  156
+    bullet_app_state.physics_space.add(player)
  157
+  end
  158
+  
  159
+  class ControllerAction
  160
+    include ActionListener
  161
+    
  162
+    def initialize(obj)
  163
+      @parent = obj
  164
+    end
  165
+    
  166
+    def on_action(name, key_pressed, time_per_frame)
  167
+      if name.eql?("Lefts")
  168
+        if key_pressed
  169
+          @parent.steering_value += 0.5
  170
+        else
  171
+          @parent.steering_value -= 0.5
  172
+        end
  173
+        @parent.player.steer(@parent.steering_value);
  174
+      elsif name.eql?("Rights")
  175
+        if key_pressed
  176
+          @parent.steering_value -= 0.5
  177
+        else
  178
+          @parent.steering_value += 0.5
  179
+        end
  180
+        player.steer(@parent.steering_value)
  181
+      elsif name.eql?("Ups")
  182
+        if key_pressed
  183
+          @parent.acceleration_value -= 800
  184
+        else
  185
+          @parent.acceleration_value += 800;
  186
+        end
  187
+        @parent.player.accelerate(@parent.acceleration_value)
  188
+        @parent.player.collision_shape = CollisionShapeFactory.create_dynamic_mesh_shape(@parent.find_geom(carNode, "Car"))
  189
+      elsif name.eql?("Downs")
  190
+        if key_pressed
  191
+          @parent.player.brake(40.0)
  192
+        else
  193
+          @parent.player.brake(0.0)
  194
+        end
  195
+      elsif name.eql?("Reset")
  196
+        if key_pressed
  197
+          puts "Reset"
  198
+          @parent.player.physics_location = Vector3f::ZERO
  199
+          @parent.player.physics_rotation = Matrix3f.new
  200
+          @parent.player.linear_velocity = Vector3f::ZERO
  201
+          @parent.player.angular_velocity = Vector3f::ZERO
  202
+          @parent.player.reset_suspension
  203
+        end
  204
+      end    
  205
+    end
  206
+    
  207
+  end
  208
+  
  209
+  #private (kinda, but not really)
  210
+    
  211
+    def find_geom(spatial, name)
  212
+      if spatial.is_a? Node
  213
+        node = spatial
  214
+        0.upto(node.quantity) do |i|
  215
+          child = node.child(i)
  216
+          result = find_geom(child, name)
  217
+          return result unless result.nil?
  218
+        end
  219
+      elsif spatial.is_a? Geometry
  220
+        return spatial if spatial.name.include?(name)
  221
+      end
  222
+      
  223
+      nil
  224
+    end
  225
+  
  226
+end
2  lib/samples/sample8.rb
@@ -80,7 +80,7 @@ def setup_light!
80 80
     al.color = ColorRGBA::White.mult(1.3)
81 81
     root_node.add_light(al)
82 82
     dl = DirectionalLight.new
83  
-    dl.color = ColorRGBA.new(0.75, 1.0, 0.0, 1.0)
  83
+    dl.color = ColorRGBA::White
84 84
     dl.direction = Vector3f.new(2.8, -2.8, -2.8).normalize_local
85 85
     root_node.add_light(dl)
86 86
   end
1  lib/samples/sample9.rb
... ...
@@ -1,5 +1,6 @@
1 1
 =begin
2 2
   This sample creates a full landscape with hills, dirt trails, and rocks from 3 jpg images.
  3
+  TODO: this isn't loading for some reason.
3 4
 =end
4 5
 
5 6
 java_import "com.jme3.app.SimpleApplication"
0  maze_craze/controllers/EndScreenController.java b/lib/maze_craze/controllers/EndScreenController.java
No changes.
0  maze_craze/controllers/HudScreenController.java b/lib/maze_craze/controllers/HudScreenController.java
No changes.
0  maze_craze/controllers/PauseScreenController.java b/lib/maze_craze/controllers/PauseScreenController.java
No changes.
BIN  package/classes/java/StartScreenController.class 100755 → 100644
Binary file not shown

0 notes on commit 410916d

Please sign in to comment.
Something went wrong with that request. Please try again.