Class: RedBird::RelativeEntity

Inherits:
Entity
  • Object
show all
Defined in:
lib/red_bird/relative_entity.rb

Overview

The Entity has an absolute position on the screen. Use this class if you want an entity that has a position relative to a scenario (TileMap).

Author:

  • Frederico Linhares

Instance Attribute Summary collapse

Attributes inherited from Entity

#priority

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#cursor_down, #cursor_hover, #cursor_up, #render, #tick

Constructor Details

#initialize(relative_pos_x, relative_pos_y, width, height) ⇒ RelativeEntity

Returns a new instance of RelativeEntity.

Parameters:

  • relative_pos_x (Integer)

    position in the scenario

  • relative_pos_y (Integer)

    position in the scenario

  • width (Integer)
  • height (Integer)

Author:

  • Frederico Linhares



19
20
21
22
23
24
25
26
# File 'lib/red_bird/relative_entity.rb', line 19

def initialize(relative_pos_x, relative_pos_y, width, height)
  super()

  @priority = 1

  @collision_box = RedBird::Rect.new(
    relative_pos_x, relative_pos_y, width, height)
end

Instance Attribute Details

#collision_boxRedBird::Rect (readonly)

Returns:



12
13
14
# File 'lib/red_bird/relative_entity.rb', line 12

def collision_box
  @collision_box
end

Class Method Details

.scenarioRedBird::TileMap

Returns:

Author:

  • Frederico Linhares



39
40
41
# File 'lib/red_bird/relative_entity.rb', line 39

def self.scenario
  return @@scenario
end

.scenario=(scenario) ⇒ Object

Define which scenario to use as a reference for every RedBird::RelativeEntity.

Parameters:

Author:

  • Frederico Linhares



33
34
35
# File 'lib/red_bird/relative_entity.rb', line 33

def self.scenario=(scenario)
  @@scenario = scenario
end

Instance Method Details

#heightInteger

Returns:

  • (Integer)

Author:

  • Frederico Linhares



91
92
93
# File 'lib/red_bird/relative_entity.rb', line 91

def height
  @collision_box.height
end

#pos_xFloat

Gets absolute position (position in the screen).

Returns:

  • (Float)

    position in the screen

Author:

  • Frederico Linhares



71
72
73
# File 'lib/red_bird/relative_entity.rb', line 71

def pos_x
  @collision_box.x - @@scenario.hor_offset + @@scenario.pos_x
end

#pos_yFloat

Gets absolute position (position in the screen).

Returns:

  • (Float)

    position in the screen

Author:

  • Frederico Linhares



79
80
81
# File 'lib/red_bird/relative_entity.rb', line 79

def pos_y
  @collision_box.y - @@scenario.ver_offset + @@scenario.pos_y
end

#relative_pos_xInteger

Returns position in the scenario.

Returns:

  • (Integer)

    position in the scenario

Author:

  • Frederico Linhares



45
46
47
# File 'lib/red_bird/relative_entity.rb', line 45

def relative_pos_x
  return @collision_box.x
end

#relative_pos_x=(x) ⇒ Object

Parameters:

  • x (Integer)

    position in the scenario

Author:

  • Frederico Linhares



57
58
59
# File 'lib/red_bird/relative_entity.rb', line 57

def relative_pos_x=(x)
  @collision_box.x = x
end

#relative_pos_yInteger

Returns position in the scenario.

Returns:

  • (Integer)

    position in the scenario

Author:

  • Frederico Linhares



51
52
53
# File 'lib/red_bird/relative_entity.rb', line 51

def relative_pos_y
  return @collision_box.y
end

#relative_pos_y=(y) ⇒ Object

Parameters:

  • y (Integer)

    position in the scenario

Author:

  • Frederico Linhares



63
64
65
# File 'lib/red_bird/relative_entity.rb', line 63

def relative_pos_y=(y)
  @collision_box.y = y
end

#widthInteger

Returns:

  • (Integer)

Author:

  • Frederico Linhares



85
86
87
# File 'lib/red_bird/relative_entity.rb', line 85

def width
  @collision_box.width
end