Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
BioEnemyShip.cpp
Go to the documentation of this file.
1
2#include "BioEnemyShip.h"
3#include "Level.h"
4
5
12
13
14void BioEnemyShip::Update(const GameTime& gameTime)
15{
16 if (IsActive())
17 {
18 float x = sin(gameTime.GetTotalTime() * Math::PI + GetIndex());
19 x *= GetSpeed() * gameTime.GetElapsedTime() * 1.4f;
20 TranslatePosition(x, GetSpeed() * gameTime.GetElapsedTime());
21
22 if (!IsOnScreen()) Deactivate();
23 }
24
25 EnemyShip::Update(gameTime);
26}
27
28
30{
31 if (IsActive())
32 {
33 const float alpha = GetCurrentLevel()->GetAlpha();
34 spriteBatch.Draw(m_pTexture, GetPosition(), Color::White * alpha, m_pTexture->GetCenter(), Vector2::ONE, Math::PI, 1);
35 }
36}
BioEnemyShip()
Creates a new instance of BioEnemyShip.
virtual void Update(const GameTime &gameTime)
Updates the enemy ship.
virtual void Draw(SpriteBatch &spriteBatch)
Draws the enemy ship.
virtual void Update(const GameTime &gameTime)
Loads the content for the enemy ship.
Definition EnemyShip.cpp:12
virtual uint32_t GetIndex() const
Get the index of the object. Each object is assigned a unique ID when created, starting at 0.
Definition GameObject.h:72
virtual void TranslatePosition(const float x, const float y)
virtual void SetCollisionRadius(const int radius)
Definition GameObject.h:98
virtual bool IsOnScreen() const
virtual bool IsActive() const
Flag to determine if the object is active.
Definition GameObject.h:42
virtual void Deactivate()
Deactivate the object.
Definition GameObject.h:48
static Level * GetCurrentLevel()
Get the current level.
Definition GameObject.h:30
virtual Vector2 & GetPosition()
Get the position of the object.
Definition GameObject.h:52
static const Color White
White.
Definition Color.h:201
Contains timing values for game updates and rendering.
Definition GameTime.h:21
double GetElapsedTime() const
Gets the time in seconds since last frame.
Definition GameTime.h:30
double GetTotalTime() const
Gets the time in seconds since the game started.
Definition GameTime.h:34
static const float PI
Represents the value of pi.
Definition MathUtil.h:25
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
void Draw(const Texture *pTexture, const Vector2 position, const Region region, const Color color=Color::White, const Vector2 origin=Vector2::ZERO, const Vector2 scale=Vector2::ONE, const float rotation=0, const float drawDepth=0)
Adds a sprite to a batch of sprites to be rendered.
Vector2 GetCenter() const
Gets the center position of the texture.
Definition Texture.h:48
static const Vector2 ONE
A vector with both of its components set to one.
Definition Vector2.h:32
virtual float GetAlpha() const
Get the alpha value of the screen.
Definition Level.cpp:212
virtual void SetSpeed(const float speed)
Sets the speed of the ship.
Definition Ship.h:59
virtual void SetMaxHitPoints(const float hitPoints)
Sets the max hit points of the ship.
Definition Ship.h:63
virtual float GetSpeed() const
Gets the speed of the ship.
Definition Ship.h:55