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
-
#canvas ⇒ Object
Returns the value of attribute canvas.
-
#canvas_context ⇒ Object
Returns the value of attribute canvas_context.
-
#collision_detection ⇒ Object
Returns the value of attribute collision_detection.
-
#scale ⇒ Object
Returns the value of attribute 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, #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 |
# File 'lib/author_engine/game/game.rb', line 17 def initialize(code:) if RUBY_ENGINE == "opal" @scale = 1.0 @canvas = `document.getElementById('canvas')` @canvas_context = `#{@canvas}.getContext('2d')` end if RUBY_ENGINE != "opal" @sprites = SpriteEditor.instance.sprites @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| @levels << level.sort_by {|sprite| sprite.z}.map {|sprite| sprite.dup} end size = 16 @levels.each {|level| level.each {|sprite| sprite.x = sprite.x * size; sprite.y = sprite.y * size}} @collision_detection = CollisionDetection.new(@sprites, @levels, Window.instance.container.savefile.sprites) end @background_color = black self.instance_eval(code) end |
Instance Attribute Details
#canvas ⇒ Object
Returns the value of attribute canvas.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def canvas @canvas end |
#canvas_context ⇒ Object
Returns the value of attribute canvas_context.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def canvas_context @canvas_context end |
#collision_detection ⇒ Object
Returns the value of attribute collision_detection.
16 17 18 |
# File 'lib/author_engine/game/game.rb', line 16 def collision_detection @collision_detection end |
#scale ⇒ Object
Returns the value of attribute scale.
15 16 17 |
# File 'lib/author_engine/game/game.rb', line 15 def scale @scale end |
Instance Method Details
#draw ⇒ Object
49 50 |
# File 'lib/author_engine/game/game.rb', line 49 def draw end |
#draw_background ⇒ Object
42 43 44 |
# File 'lib/author_engine/game/game.rb', line 42 def draw_background rect(0, 0, width, height, @background_color) end |
#init ⇒ Object
46 47 |
# File 'lib/author_engine/game/game.rb', line 46 def init end |
#update ⇒ Object
52 53 |
# File 'lib/author_engine/game/game.rb', line 52 def update end |