Class: AuthorEngine::Game

Inherits:
Object
  • Object
show all
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

Part::GosuInput::BUTTONS

Constants included from Part::OpalInput

Part::OpalInput::BUTTONS, Part::OpalInput::KEY_STATES

Constants included from Part::Colors

Part::Colors::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Part::GosuInput

#button?

Methods included from Part::GosuGraphics

#level, #rect, #rotate, #sprite, #swap, #text, #translate

Methods included from Part::OpalInput

#button?

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_canvasObject

Returns the value of attribute authorengine_canvas.



15
16
17
# File 'lib/author_engine/game/game.rb', line 15

def authorengine_canvas
  @authorengine_canvas
end

#authorengine_canvas_contextObject

Returns the value of attribute authorengine_canvas_context.



15
16
17
# File 'lib/author_engine/game/game.rb', line 15

def authorengine_canvas_context
  @authorengine_canvas_context
end

#authorengine_collision_detectionObject

Returns the value of attribute authorengine_collision_detection.



16
17
18
# File 'lib/author_engine/game/game.rb', line 16

def authorengine_collision_detection
  @authorengine_collision_detection
end

#authorengine_scaleObject

Returns the value of attribute authorengine_scale.



15
16
17
# File 'lib/author_engine/game/game.rb', line 15

def authorengine_scale
  @authorengine_scale
end

Instance Method Details

#drawObject



50
51
# File 'lib/author_engine/game/game.rb', line 50

def draw
end

#draw_backgroundObject



43
44
45
# File 'lib/author_engine/game/game.rb', line 43

def draw_background
  rect(0, 0, width, height, @background_color)
end

#initObject



47
48
# File 'lib/author_engine/game/game.rb', line 47

def init
end

#updateObject



53
54
# File 'lib/author_engine/game/game.rb', line 53

def update
end