Class: AuthorEngine::Game
- Inherits:
-
Object
- Object
- AuthorEngine::Game
- Includes:
- Part::CollisionDetection, Part::Colors, Part::Common, Part::GosuGraphics, Part::GosuInput, Part::OpalGraphics, Part::OpalInput
- Defined in:
- lib/author_engine/game/game.rb
Constant Summary
Constants included from Part::GosuInput
Constants included from Part::OpalInput
Part::OpalInput::BUTTONS, Part::OpalInput::KEY_STATES
Constants included from Part::Colors
Instance Attribute Summary collapse
-
#authorengine_canvas ⇒ Object
Returns the value of attribute authorengine_canvas.
-
#authorengine_canvas_context ⇒ Object
Returns the value of attribute authorengine_canvas_context.
-
#authorengine_collision_detection ⇒ Object
Returns the value of attribute authorengine_collision_detection.
-
#authorengine_scale ⇒ Object
Returns the value of attribute authorengine_scale.
Instance Method Summary collapse
- #authorengine_eval_code ⇒ Object
- #draw ⇒ Object
- #draw_background ⇒ Object
- #init ⇒ Object
-
#initialize(code:) ⇒ Game
constructor
A new instance of Game.
- #update ⇒ Object
Methods included from Part::GosuInput
Methods included from Part::GosuGraphics
#level, #rect, #rotate, #sprite, #swap, #text, #translate
Methods included from Part::OpalInput
Methods included from Part::OpalGraphics
#level, #rect, #rotate, #sprite, #swap, #text, #translate
Methods included from Part::Colors
#black, #blue, #brown, #dark_blue, #dark_gray, #dark_green, #dark_purple, #green, #indigo, #light_gray, #orange, #peach, #pink, #red, #rgb, #white, #xml_color, #yellow
Methods included from Part::CollisionDetection
#bounding_box, #colliding_edge, #draw_level_boxes, #draw_sprite_box, #render_bounding_box, #sprite_vs_level, #sprite_vs_sprite
Methods included from Part::Common
#distance, #fps, #height, #levels, #milliseconds, #width
Constructor Details
#initialize(code:) ⇒ Game
Returns a new instance of Game.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/author_engine/game/game.rb', line 17 def initialize(code:) @authorengine_code = code if RUBY_ENGINE == "opal" @authorengine_scale = 1.0 @authorengine_canvas = `document.getElementById('canvas')` @authorengine_canvas_context = `#{@authorengine_canvas}.getContext('2d')` end if RUBY_ENGINE != "opal" @authorengine_sprites = SpriteEditor.instance.sprites @authorengine_levels = [] # Create a "Deep Copy" to allow for swapping of a level's sprites without corrupting LevelEditor's version LevelEditor.instance.levels.each do |level| @authorengine_levels << level.sort_by {|sprite| sprite.z}.map {|sprite| sprite.dup} end size = 16 @authorengine_levels.each {|level| level.each {|sprite| sprite.x = sprite.x * size; sprite.y = sprite.y * size}} spritesheet = SpriteEditor.instance.spritesheet @authorengine_collision_detection = CollisionDetection.new(@authorengine_sprites, @authorengine_levels, SaveFile::SpriteSheetData.new(spritesheet.width, spritesheet.height, spritesheet.to_blob)) self.instance_eval(code) end @background_color = black end |
Instance Attribute Details
#authorengine_canvas ⇒ Object
Returns the value of attribute authorengine_canvas.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def @authorengine_canvas end |
#authorengine_canvas_context ⇒ Object
Returns the value of attribute authorengine_canvas_context.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def @authorengine_canvas_context end |
#authorengine_collision_detection ⇒ Object
Returns the value of attribute authorengine_collision_detection.
16 17 18 |
# File 'lib/author_engine/game/game.rb', line 16 def @authorengine_collision_detection end |
#authorengine_scale ⇒ Object
Returns the value of attribute authorengine_scale.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def @authorengine_scale end |
Instance Method Details
#authorengine_eval_code ⇒ Object
46 47 48 |
# File 'lib/author_engine/game/game.rb', line 46 def self.instance_eval(@authorengine_code) end |
#draw ⇒ Object
57 58 |
# File 'lib/author_engine/game/game.rb', line 57 def draw end |
#draw_background ⇒ Object
50 51 52 |
# File 'lib/author_engine/game/game.rb', line 50 def draw_background rect(0, 0, width, height, @background_color) end |
#init ⇒ Object
54 55 |
# File 'lib/author_engine/game/game.rb', line 54 def init end |
#update ⇒ Object
60 61 |
# File 'lib/author_engine/game/game.rb', line 60 def update end |