Class: GameSpace

Inherits:
Chingu::GameObject
  • Object
show all
Defined in:
lib/prkwars/gamespace.rb

Overview

Class representing the space where the game is being played. Class is essentially an encapsulation for the big rectangle where the game can be played. Also holds possible spawn points for enemy entities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GameSpace

Initialization method sets up the spawn points for enemies and sets up the background image.



21
22
23
24
25
26
# File 'lib/prkwars/gamespace.rb', line 21

def initialize(options = {})
  super(options)

  @image = Image['media/background.png']
  setup_spawn_points
end

Instance Attribute Details

#playerObject

Accessor to the player - used by various enemies to determine the position of the player.



15
16
17
# File 'lib/prkwars/gamespace.rb', line 15

def player
  @player
end

Instance Method Details

#enemy_spawn_point(player_x, player_y) ⇒ Object

Returns a random spawn point from the list of spawn points defined by the setup_spawn_points method.



32
33
34
35
36
# File 'lib/prkwars/gamespace.rb', line 32

def enemy_spawn_point(player_x, player_y)
  sample_points = points_far_enough(player_x, player_y)

  sample_points.sample
end