Module: AuthorEngine::Part::GosuGraphics

Included in:
Game
Defined in:
lib/author_engine/game/gosu/parts/graphics.rb

Instance Method Summary collapse

Instance Method Details

#level(index, z = 0) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 28

def level(index, z = 0)
  _level = @authorengine_levels[index]
  raise "No level at '#{index}'!" unless _level

  _level.each do |sprite|
    sprite(sprite.sprite, sprite.x, sprite.y, z)
  end
end

#rect(x = 0, y = 0, width = 1, height = 1, color = Gosu::Color::WHITE, z = 0) ⇒ Object



4
5
6
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 4

def rect(x = 0, y = 0, width = 1, height = 1, color = Gosu::Color::WHITE, z = 0)
  Gosu.draw_rect(x, y, width, height, color, z)
end

#rotate(angle, around_x = 0, around_y = 0, &block) ⇒ Object



52
53
54
55
56
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 52

def rotate(angle, around_x = 0, around_y = 0, &block)
  Gosu.rotate(angle, around_x, around_y) do
    block.call if block
  end
end

#sprite(index, x = 0, y = 0, z = 0, alpha = 255) ⇒ Object



22
23
24
25
26
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 22

def sprite(index, x = 0, y = 0, z = 0, alpha = 255)
  image = @authorengine_sprites[index]
  raise "No sprite at '#{index}'!" unless image
  image.draw(x, y, z, 1,1, Gosu::Color.rgba(255,255,255, alpha))
end

#swap(level, current_sprite, replacement_sprite) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 37

def swap(level, current_sprite, replacement_sprite)
  _level = @authorengine_levels[level]
  raise "No level at '#{index}'!" unless _level
  raise "No sprite at '#{current_sprite}'!" unless @authorengine_sprites[current_sprite]
  raise "No sprite at '#{current_sprite}'!" unless @authorengine_sprites[replacement_sprite]

  _level.each {|sprite| sprite.sprite = replacement_sprite if sprite.sprite == current_sprite}
end

#text(text, x = 0, y = 0, size = 4, z = 0, color = white) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 8

def text(text, x = 0, y = 0, size = 4, z = 0, color = white)
  @authorengine_fonts ||= {}

  font = nil

  if @authorengine_fonts.dig(size)
    font = @authorengine_fonts.dig(size)
  else
    font = (@authorengine_fonts[size] = Gosu::Font.new(size, name: Text::FONT_DEFAULT))
  end

  font.draw_markup(text, x, y, z, 1, 1, color)
end

#translate(x, y, &block) ⇒ Object



46
47
48
49
50
# File 'lib/author_engine/game/gosu/parts/graphics.rb', line 46

def translate(x, y, &block)
  Gosu.translate(x, y) do
    block.call if block
  end
end