Created
November 26, 2009 14:27
-
-
Save shawn42/243485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'actor' | |
class Bacteria < Actor | |
has_behaviors :graphical, :updatable, :physical => { | |
:shape => :circle, | |
:mass => 10, | |
:radius => 45, | |
:friction => 1.7, | |
:moment => 150 | |
} | |
attr_accessor :move_left, :move_right, :move_forward, :move_back | |
def setup | |
super | |
@speed = 200 | |
@turn_speed = 100 | |
i = input_manager | |
i.while_key_pressed(:left,self,:move_left) | |
i.while_key_pressed(:right,self,:move_right) | |
i.while_key_pressed(:up,self,:move_forward) | |
i.while_key_pressed(:down,self,:move_back) | |
end | |
def update(time) | |
physical.body.reset_forces | |
if move_left | |
physical.body.t -= @turn_speed * time | |
end | |
if move_right | |
physical.body.t += @turn_speed * time | |
end | |
if move_back | |
val = physical.body.a | |
move_vec = CP::Vec2.new(Math::cos(val), Math::sin(val)) * time * @speed * 0.5 | |
physical.body.apply_force(-move_vec, ZERO_VEC_2) | |
end | |
if move_forward | |
val = physical.body.a | |
move_vec = CP::Vec2.new(Math::cos(val), Math::sin(val)) * time * @speed | |
physical.body.apply_force(move_vec, ZERO_VEC_2) | |
end | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'physical_stage' | |
class DemoStage < PhysicalStage | |
GRAVITY = 9 | |
DAMPING = 0.7 | |
def setup | |
super | |
space.iterations = 5 | |
space.damping = DAMPING | |
space.gravity = vec2(0,GRAVITY) | |
@svg_doc = resource_manager.load_svg @opts[:file] | |
@score = create_actor :score, :x => 10, :y => 10 | |
create_actor :logo, :x => 10, :y => 660 | |
create_actor :background | |
dynamic_actors = create_actors_from_svg @svg_doc | |
create_actor :svg_actor, :name => :ground, :svg_doc => @svg_doc | |
@bacteria = dynamic_actors[:bacteria] | |
create_actor :red_bloodcell, :x => 220, :y => 500 | |
create_actor :white_bloodcell, :x => 220, :y => 400 | |
viewport.follow @bacteria | |
space.add_collision_func(:bacteria, :white_bloodcell) do |b, wc| | |
shippy = director.find_physical_obj b | |
puts "DEAD" | |
sleep 2 | |
fire :restart_stage | |
end | |
space.add_collision_func(:bacteria, :red_bloodcell) do |b, rc| | |
cell = director.find_physical_obj rc | |
if cell.alive? | |
puts "got one!" | |
sound_manager.play_sound :splat | |
cell.remove_self | |
end | |
end | |
end | |
def curtain_up | |
sound_manager.play_music :current_rider | |
end | |
def draw(target) | |
target.fill [25,25,25,255] | |
super | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'actor' | |
class RedBloodcell < Actor | |
has_behaviors :graphical, :updatable, :layered => {:layer => 2}, | |
:physical => { | |
:shape => :circle, | |
:mass => 10, | |
:radius => 45, | |
:friction => 1.7, | |
:moment => 150 | |
} | |
def setup | |
# register for events here | |
# or pull stuff out of @opts | |
end | |
def update(time) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:stages: | |
- :demo: | |
:file: nose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment