mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-21 19:56:11 +00:00
Added every and after timers to DSL
This commit is contained in:
@@ -3,11 +3,12 @@ module CyberarmEngine
|
|||||||
include Common
|
include Common
|
||||||
|
|
||||||
attr_accessor :options, :global_pause
|
attr_accessor :options, :global_pause
|
||||||
attr_reader :game_objects
|
attr_reader :game_objects, :timers
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
window.text_input = nil unless options[:preserve_text_input]
|
window.text_input = nil unless options[:preserve_text_input]
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@game_objects.each(&:update)
|
@game_objects.each(&:update)
|
||||||
|
@timers.each(&:update)
|
||||||
|
@timers.delete_if(&:dead?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_redraw?
|
def needs_redraw?
|
||||||
@@ -120,5 +123,9 @@ module CyberarmEngine
|
|||||||
def add_game_object(object)
|
def add_game_object(object)
|
||||||
@game_objects << object
|
@game_objects << object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_timer(timer)
|
||||||
|
@timers << timer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,5 +19,9 @@ module CyberarmEngine
|
|||||||
@block.call if @block
|
@block.call if @block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dead?
|
||||||
|
@triggered && !@looping
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
module DSL
|
module DSL
|
||||||
|
def every(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, true, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, false, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def flow(options = {}, &block)
|
def flow(options = {}, &block)
|
||||||
container(CyberarmEngine::Element::Flow, options, &block)
|
container(CyberarmEngine::Element::Flow, options, &block)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module CyberarmEngine
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
|
|
||||||
@down_keys = {}
|
@down_keys = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user