Commit 7c7e4bccdd0450aef7242b9edc80e96a50a870ff

Authored by Marius Hanne
1 parent a070906aa7
Exists in master

bma180 accelerometer input (on openmoko gta04)

Showing 2 changed files with 31 additions and 8 deletions Side-by-side Diff

... ... @@ -5,6 +5,7 @@
5 5 require 'rubygame'
6 6 require 'chipmunk'
7 7  
  8 +require 'input_bma180'
8 9 require 'drawable'
9 10 require 'explosion'
10 11 require 'movable'
11 12  
12 13  
13 14  
... ... @@ -94,20 +95,22 @@
94 95  
95 96 @queue.enable_new_style_events
96 97 @queue.each do |event|
97   -
98 98 @keys_pressed << event.key if event.is_a?(Events::KeyPressed)
99 99 @keys_pressed.delete(event.key) if event.is_a?(Events::KeyReleased)
100 100 @keys_pressed << :space if event.is_a?(Events::MousePressed)
101 101 @keys_pressed.delete(:space) if event.is_a?(Events::MouseReleased)
102   - @player.body.p = CP::Vec2.new(*event.pos) if event.is_a?(Events::MouseMoved)
103   -
104   - exit if event.is_a?(Rubygame::Events::QuitRequested) ||
105   - exit if event.is_a?(Events::KeyPressed) && [:escape, :q].include?(event.key)
  102 + if event.is_a?(Events::MouseMoved) && !options[:bma180]
  103 + @player.body.p = CP::Vec2.new(*event.pos)
  104 + end
  105 + exit if event.is_a?(Rubygame::Events::QuitRequested)
  106 + exit if event.is_a?(Events::KeyPressed) &&
  107 + [:escape, :q].include?(event.key)
106 108 end
107 109  
108   - # TODO
  110 + @player.body.v += CP::Vec2.new(*BMA180.read) if options[:bma180]
  111 +
109 112 @player.fire if @keys_pressed.include?(:space) && @state == :running
110   -
  113 +
111 114 Enemy.generate(self) if @enemies.size < @level
112 115  
113 116 [:up, :down, :left, :right].each {|d|
... ... @@ -210,7 +213,13 @@
210 213  
211 214 require 'optparse'
212 215  
213   -@opts = { size: [800, 600], fullscreen: false, mute: false, level: 1, debug: false }
  216 +@opts = { size: [800, 600],
  217 + fullscreen: false,
  218 + mute: false,
  219 + level: 1,
  220 + debug: false,
  221 + bma180: false,
  222 +}
214 223  
215 224 OptionParser.new do |o|
216 225 o.banner = "usage: ruby #{__FILE__} [-l LEVEL] [-d]"
... ... @@ -229,6 +238,10 @@
229 238  
230 239 o.on("-l", "--level LEVEL", "Start at level") do |l|
231 240 @opts[:level] = l.to_i
  241 + end
  242 +
  243 + o.on("--bma180", "Enable bma180 accelerometer input") do
  244 + @opts[:bma180] = true
232 245 end
233 246  
234 247 o.on("-d", "--debug", "Debug mode") do
  1 +class BMA180
  2 +
  3 + FILE = "/sys/bus/i2c/drivers/bma180/2-0041/coord"
  4 +
  5 + def self.read
  6 + d = File.read(FILE).strip.split(",")[0..1].map(&:to_f).map{|v| v / 50}
  7 + [-d[0], d[1]]
  8 + end
  9 +
  10 +end