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
- #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 |
# File 'lib/author_engine/game/game.rb', line 17 def initialize(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)) end @background_color = black self.instance_eval(code) 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
#draw ⇒ Object
50 51 |
# File 'lib/author_engine/game/game.rb', line 50 def draw end |
#draw_background ⇒ Object
43 44 45 |
# File 'lib/author_engine/game/game.rb', line 43 def draw_background rect(0, 0, width, height, @background_color) end |
#init ⇒ Object
47 48 |
# File 'lib/author_engine/game/game.rb', line 47 def init end |
#update ⇒ Object
53 54 |
# File 'lib/author_engine/game/game.rb', line 53 def update end |