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
| define_behavior :fades do | |
| requires :director | |
| setup do # |opts| | |
| fade_out_time = 3_000 | |
| actor.has_attributes total_fade_time: fade_out_time, fade_time: fade_out_time | |
| director.when :update do |time_ms, secs| | |
| actor.fade_time -= time_ms | |
| alpha = 255 * actor.fade_time / actor.total_fade_time | |
| actor.remove if actor.fade_time <= 0 |
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
| define_stage :demo do | |
| requires :tween_manager | |
| curtain_up do | |
| @player = spawn :player, x: 10, y:30 | |
| tween = tween_manager.tween_properties @player, {x: 600, y:750}, 6_000, Tween::Sine::InOut | |
| # tweens can be canceled if need be, or they will clean themselves up when finished | |
| timer_manager.add_timer :foo, 3_000, false do | |
| tween.cancel! | |
| 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
| define_behavior :faded do | |
| requires :timer_manager | |
| setup do | |
| actor.has_attributes shadows: [], shadows_to_render: opts[:shadows_to_render] | |
| timer_manager.add_timer timer_name, 100 do | |
| new_shadow = {x: actor.x, y: actor.y} | |
| actor.shadows << new_shadow | |
| actor.shadows.shift if actor.shadows.size > actor.shadows_to_render | |
| 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
| STATS_DIRECTORIES = [ | |
| %w(Source src/), | |
| %w(Config config/), | |
| %w(Maps maps/), | |
| %w(Unit\ tests specs/), | |
| %w(Libraries lib/), | |
| ].collect { |name, dir| [ name, "#{APP_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } | |
| desc "Report code statistics (KLOCs, etc) from the application" | |
| task :stats do |
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 'inflector' | |
| # Actor represent a game object. | |
| # Actors can have behaviors added and removed from them. | |
| class Actor | |
| attr_accessor :behaviors | |
| def initialize | |
| @behaviors = {} | |
| # add our classes behaviors | |
| class_behaviors = self.class.behaviors.dup |
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 'mode' | |
| require 'level' | |
| require 'director' | |
| require 'actor' | |
| class ActorView | |
| attr_accessor :actor, :mode | |
| def initialize(mode,actor) | |
| @mode = mode | |
| @actor = actor |
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
| i = @input_manager | |
| i.reg KeyDownEvent, K_SPACE do | |
| ship.warp vec2(rand(400)-100,rand(400)-100) | |
| end | |
| i.reg KeyDownEvent, K_LEFT do | |
| ship.moving_left = true | |
| end | |
| i.reg KeyDownEvent, K_RIGHT do | |
| ship.moving_right = true | |
| 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
| @input_manager.when :event_received do |event| | |
| case event | |
| when KeyDownEvent | |
| case event.key | |
| when K_SPACE | |
| ship.warp vec2(300,300) | |
| when K_LEFT | |
| ship.moving_left = true | |
| when K_RIGHT | |
| ship.moving_right = true |
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
| class Clock | |
| def tick() | |
| passed = Clock.runtime() - @last_tick # how long since the last tick? | |
| if @target_frametime | |
| wait = @target_frametime - passed | |
| if wait > 0 | |
| return Clock.wait(@target_frametime - passed) + passed | |
| else | |
| return passed | |
| 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
| #!/usr/bin/env ruby | |
| $: << "#{File.dirname(__FILE__)}/../config" | |
| require 'environment' | |
| require 'gamebox' | |
| if $0 == __FILE__ | |
| GameboxApp.run ARGV, ENV | |
| end | |
| require 'actor' |
OlderNewer