Simple starter skeleton for asteroids video game.

Dependencies:   PinDetect

Committer:
jhurley31
Date:
Thu Apr 01 20:09:47 2021 +0000
Revision:
5:454ff3197a74
Parent:
3:98aa3db6a48f
Updating OS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhurley31 3:98aa3db6a48f 1 #include <iterator>
jhurley31 3:98aa3db6a48f 2 #include <list>
jhurley31 3:98aa3db6a48f 3
jhurley31 3:98aa3db6a48f 4 #include "./Sounds/Speaker.h"
jhurley31 3:98aa3db6a48f 5 #include "CommandShip.h"
jhurley31 3:98aa3db6a48f 6 #include "graphic.h"
jhurley31 3:98aa3db6a48f 7 #include "uLCD_4DGL.h"
jhurley31 3:98aa3db6a48f 8 #include "Projectile.h"
jhurley31 3:98aa3db6a48f 9
jhurley31 3:98aa3db6a48f 10 const double DEFAULT_ROTATION_SPEED = 2.0;
jhurley31 3:98aa3db6a48f 11
jhurley31 3:98aa3db6a48f 12 extern Speaker gSpeakerOut;
jhurley31 3:98aa3db6a48f 13 extern uLCD_4DGL guLCD;
jhurley31 3:98aa3db6a48f 14
jhurley31 3:98aa3db6a48f 15 extern double gOriginX;
jhurley31 3:98aa3db6a48f 16 extern double gOriginY;
jhurley31 3:98aa3db6a48f 17
jhurley31 3:98aa3db6a48f 18 CommandShip::CommandShip()
jhurley31 3:98aa3db6a48f 19 {
jhurley31 3:98aa3db6a48f 20 m_xCenter = gOriginX;
jhurley31 3:98aa3db6a48f 21 m_yCenter = gOriginY;
jhurley31 3:98aa3db6a48f 22 // Top of CommandShip
jhurley31 3:98aa3db6a48f 23 m_xPoints[0] = gOriginX;
jhurley31 3:98aa3db6a48f 24 m_yPoints[0] = (8 + gOriginY);
jhurley31 3:98aa3db6a48f 25 //Bottom left of CommandShip
jhurley31 3:98aa3db6a48f 26 m_xPoints[1] = (4 + gOriginX);
jhurley31 3:98aa3db6a48f 27 m_yPoints[1] = (-8 + gOriginY);
jhurley31 3:98aa3db6a48f 28 //Bottom left of CommandShip
jhurley31 3:98aa3db6a48f 29 m_xPoints[2] = (-4 + gOriginX);
jhurley31 3:98aa3db6a48f 30 m_yPoints[2] = (-8 + gOriginY);
jhurley31 3:98aa3db6a48f 31
jhurley31 3:98aa3db6a48f 32 // Set color to red
jhurley31 3:98aa3db6a48f 33 m_color = _RED_;
jhurley31 3:98aa3db6a48f 34
jhurley31 3:98aa3db6a48f 35 m_numPoints = 3;
jhurley31 3:98aa3db6a48f 36
jhurley31 3:98aa3db6a48f 37 m_Velocity = 0.0f; // Command ship has no linear velocity
jhurley31 3:98aa3db6a48f 38 m_RotationVelocity = 0.0f; // degrees/sec
jhurley31 3:98aa3db6a48f 39 m_RotationDirection = NONE;
jhurley31 3:98aa3db6a48f 40 }
jhurley31 3:98aa3db6a48f 41
jhurley31 3:98aa3db6a48f 42 void CommandShip::fire()
jhurley31 3:98aa3db6a48f 43 {
jhurley31 3:98aa3db6a48f 44 // Enable a projectile
jhurley31 3:98aa3db6a48f 45 for (int ii = 0 ; ii < NUM_LASERS ; ++ii)
jhurley31 3:98aa3db6a48f 46 {
jhurley31 3:98aa3db6a48f 47 if (!m_lasers[ii].isValid())
jhurley31 3:98aa3db6a48f 48 {
jhurley31 3:98aa3db6a48f 49 m_lasers[ii].reset();
jhurley31 3:98aa3db6a48f 50 break;
jhurley31 3:98aa3db6a48f 51 }
jhurley31 3:98aa3db6a48f 52 }
jhurley31 3:98aa3db6a48f 53
jhurley31 3:98aa3db6a48f 54 gSpeakerOut.SwitchSound(Speaker::FIRE);
jhurley31 3:98aa3db6a48f 55
jhurley31 3:98aa3db6a48f 56 }
jhurley31 3:98aa3db6a48f 57
jhurley31 3:98aa3db6a48f 58 void CommandShip::move()
jhurley31 3:98aa3db6a48f 59 {
jhurley31 3:98aa3db6a48f 60
jhurley31 3:98aa3db6a48f 61 Sprite::move();
jhurley31 3:98aa3db6a48f 62
jhurley31 3:98aa3db6a48f 63 for (int ii = 0 ; ii < NUM_LASERS ; ii++)
jhurley31 3:98aa3db6a48f 64 {
jhurley31 3:98aa3db6a48f 65 if (m_lasers[ii].isValid())
jhurley31 3:98aa3db6a48f 66 {
jhurley31 3:98aa3db6a48f 67 m_lasers[ii].move();
jhurley31 3:98aa3db6a48f 68 }
jhurley31 3:98aa3db6a48f 69 }
jhurley31 3:98aa3db6a48f 70 }
jhurley31 3:98aa3db6a48f 71 // Rotate left and right maybe swapped. Make sure you check it out
jhurley31 3:98aa3db6a48f 72 void CommandShip::rotateLeft()
jhurley31 3:98aa3db6a48f 73 {
jhurley31 3:98aa3db6a48f 74
jhurley31 3:98aa3db6a48f 75 // if rotating right just stop in place
jhurley31 3:98aa3db6a48f 76 if (m_RotationDirection == RIGHT)
jhurley31 3:98aa3db6a48f 77 {
jhurley31 3:98aa3db6a48f 78 m_RotationDirection = NONE;
jhurley31 3:98aa3db6a48f 79 m_RotationVelocity = 0.0;
jhurley31 3:98aa3db6a48f 80 }
jhurley31 3:98aa3db6a48f 81 else
jhurley31 3:98aa3db6a48f 82 {
jhurley31 3:98aa3db6a48f 83 m_RotationDirection = LEFT;
jhurley31 3:98aa3db6a48f 84 m_RotationVelocity = DEFAULT_ROTATION_SPEED;
jhurley31 3:98aa3db6a48f 85 }
jhurley31 3:98aa3db6a48f 86
jhurley31 3:98aa3db6a48f 87
jhurley31 3:98aa3db6a48f 88 }
jhurley31 3:98aa3db6a48f 89 void CommandShip::rotateRight()
jhurley31 3:98aa3db6a48f 90 {
jhurley31 3:98aa3db6a48f 91 // if rotating right just stop in place
jhurley31 3:98aa3db6a48f 92 if (m_RotationDirection == LEFT)
jhurley31 3:98aa3db6a48f 93 {
jhurley31 3:98aa3db6a48f 94 m_RotationDirection = NONE;
jhurley31 3:98aa3db6a48f 95 m_RotationVelocity = 0.0;
jhurley31 3:98aa3db6a48f 96 }
jhurley31 3:98aa3db6a48f 97 else
jhurley31 3:98aa3db6a48f 98 {
jhurley31 3:98aa3db6a48f 99 m_RotationDirection = RIGHT;
jhurley31 3:98aa3db6a48f 100 m_RotationVelocity = -DEFAULT_ROTATION_SPEED;
jhurley31 3:98aa3db6a48f 101 }
jhurley31 3:98aa3db6a48f 102 }