Class: Play
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- Play
- Includes:
- GamespacePersistence
- Defined in:
- lib/prkwars/play.rb
Overview
A class representing the game state of playing the game itself.
Constant Summary collapse
- PLAYER_START_X =
800- PLAYER_START_Y =
640
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Play
constructor
Initialization method of Play maps input to the exit function, creates a
gamespaceto play in and spawns theplayer. -
#update ⇒ Object
Update loop does three major things each frame: * Collides enemies with player’s bullets and reduces their HP if possible.
Methods included from GamespacePersistence
Constructor Details
#initialize(options = {}) ⇒ Play
Initialization method of Play maps input to the exit function, creates a gamespace to play in and spawns the player. Together with that, sets up variables for enemy generation, score calculation and message displays.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/prkwars/play.rb', line 20 def initialize( = {}) super() self.input = { esc: :exit } @gamespace = GameSpace.create(x: 1280 / 2, y: 720 / 2) @player = Player.create(@gamespace, zorder: ZOrder::GAMEOBJECT, x: PLAYER_START_X, y: PLAYER_START_Y) @gamespace.player = @player setup_enemy_generation setup_score_calculation end |
Instance Method Details
#update ⇒ Object
Update loop does three major things each frame:
-
Collides enemies with player’s bullets and reduces their HP if possible.
-
Collides enemies with player’s ship and removes the player’s life if so.
-
Performs another step in the enemy unit generation.
42 43 44 45 46 47 48 |
# File 'lib/prkwars/play.rb', line 42 def update super collide_enemies_bullets collide_enemies_player generate_random_enemy end |