Snippets

Stephen Mark Smith C++ Tank Object Files

Created by Stephen Mark Smith

File Bullet.cpp Added

  • Ignore whitespace
  • Hide word diff
+#include "Bullet.h"
+
+Bullet::Bullet()
+{
+	Fired = false;
+	xPosition = 100.00f;
+	yPosition = 100.00f;
+	rotation = 0.0f;
+	speed = 0.0f;
+}
+
+//Setter/Getter for Bullet's X position
+void Bullet::setBulletX(float x)
+{
+	xPosition = x;
+}
+float Bullet::getBulletX(void)
+{
+	return xPosition;
+}
+
+//Setter/Getter for Bullet's Y position
+void Bullet::setBulletY(float y)
+{
+	yPosition = y;
+}
+float Bullet::getBulletY(void)
+{
+	return yPosition;
+}
+
+//Setter/Getter for Bullet's Rotation
+void Bullet::setBulletRotation(float rot)
+{
+	rotation = rot;
+}
+float Bullet::getBulletRotation(void)
+{
+	return rotation;
+}
+
+//Setter/Getter for Bullet's Speed
+void Bullet::setBulletSpeed(float s)
+{
+	speed = s;
+}
+float Bullet::getBulletSpeed(void)
+{
+	return speed;
+}
+
+

File Bullet.h Added

  • Ignore whitespace
  • Hide word diff
+using namespace std;
+
+class Bullet
+{
+public:
+	Bullet();
+	void setBulletX(float);
+	float getBulletX(void);
+	void setBulletY(float);
+	float getBulletY(void);
+	void setBulletRotation(float);
+	float getBulletRotation(void);
+	void setBulletSpeed(float);
+	float getBulletSpeed(void);
+	void setFired(bool);
+	bool getFired();
+
+
+private:
+	bool Fired;
+	float xPosition;
+	float yPosition;
+	float rotation;
+	float speed;
+};

File tankPlayer.cpp Added

  • Ignore whitespace
  • Hide word diff
+#include "tankPlayer.h"
+
+tankPlayer::tankPlayer()
+{
+	xPosition = 0.0f;
+	yPosition = 0.0f;
+	rotation = 0.0f;
+	rotationRads = 0.0f;
+	tankSpeed = 0.0f;
+	topSpeed = 0.015f;
+	goForward = false;
+	goBackward = false;
+	goLeft = false;
+	goRight = false;
+	fireGun = false;
+	turrRot = 0.0f;
+	turrLeft = false;
+	turrRight = false;
+	bulletPointer = new Bullet[2];
+	bulletPointer[0].setBulletRotation(0.0f);
+	bulletPointer[0].setBulletSpeed(0.0f);
+	bulletPointer[1].setBulletX(0.0f);
+	bulletPointer[1].setBulletY(0.0f);
+	bulletPointer[1].setBulletRotation(0.0f);
+	bulletPointer[1].setBulletSpeed(0.0f);
+}
+
+//Initial X Position
+void tankPlayer::setXPosition(float xPos1)
+{
+	xPosition = xPos1;
+}
+// Float is the parameter for Setter
+float tankPlayer::getXPosition()
+{
+	return xPosition;
+}
+// Float is the function type for Getter
+
+//Initial Y Position
+void tankPlayer::setYPosition(float yPos1)
+{
+	yPosition = yPos1;
+}
+float tankPlayer::getYPosition(void)
+{
+	return yPosition;
+}
+
+//Initial Rotation
+void tankPlayer::setRotation(float rot1)
+{
+	rotation = rot1;
+}
+float tankPlayer::getRotation(void)
+{
+	return rotation;
+}
+
+//Updated Rotation
+void tankPlayer::setRotRads(float rot2)
+{
+	rotationRads = rot2;
+}
+float tankPlayer::getRotRads(void)
+{
+	return rotationRads;
+}
+
+//Speed
+void tankPlayer::setSpeed(float speed)
+{
+	tankSpeed = speed;
+}
+float tankPlayer::getSpeed(void)
+{
+	return tankSpeed;
+}
+
+//Moving Forward
+void tankPlayer::setForward(bool forward)
+{
+	goForward = forward;
+}
+bool tankPlayer::getForward(void)
+{
+	return goForward;
+}
+
+//Moving Backward
+void tankPlayer::setBackward(bool backward)
+{
+	goBackward = backward;
+}
+bool tankPlayer::getBackward(void)
+{
+	return goBackward;
+}
+
+//Turning Left
+void tankPlayer::setLeft(bool left)
+{
+	goLeft = left;
+}
+bool tankPlayer::getLeft(void)
+{
+	return goLeft;
+}
+
+//Turning Right
+void tankPlayer::setRight(bool right)
+{
+	goRight = right;
+}
+bool tankPlayer::getRight(void)
+{
+	return goRight;
+}
+
+//Firing the Gun
+void tankPlayer::setGun(bool gun)
+{
+	fireGun = gun;
+}
+bool tankPlayer::getGun(void)
+{
+	return fireGun;
+}
+
+//Tank Turret
+void tankPlayer::setTurrRot(float turret)
+{
+	turrRot = turret;
+}
+float tankPlayer::getTurrRot(void)
+{
+	return turrRot;
+}
+
+//Turning Turret Left
+void tankPlayer::setTurrLeft(bool turrleft)
+{
+	turrLeft = turrleft;
+}
+bool tankPlayer::getTurrLeft(void)
+{
+	return turrLeft;
+}
+
+//Turning Turret Right
+void tankPlayer::setTurrRight(bool turrright)
+{
+	turrRight = turrright;
+}
+bool tankPlayer::getTurrRight(void)
+{
+	return turrRight;
+}
+
+//Top Speed
+void tankPlayer::setTopSpeed(float TopSpeed)
+{
+	topSpeed = TopSpeed;
+}
+float tankPlayer::getTopSpeed(void)
+{
+	return topSpeed;
+}
+
+tankPlayer::~tankPlayer()
+{
+	delete[] bulletPointer;
+	bulletPointer = NULL;
+}

File tankPlayer.h Added

  • Ignore whitespace
  • Hide word diff
+#include <string>
+#include "Bullet.h"
+using namespace std;
+
+class tankPlayer
+{
+public:
+	tankPlayer();
+	~tankPlayer();
+	void setXPosition(float);	//Set X Position
+	float getXPosition(void);	//Get X Position
+	void setYPosition(float);	//Set Y Position
+	float getYPosition(void);	//Get Y Position
+	void setRotation(float);	//Set Rotation
+	float getRotation(void);	//Get Rotation
+	void setRotRads(float);		//Set Radians
+	float getRotRads(void);		//Get Radians
+	void setSpeed(float);		//Set Speed
+	float getSpeed(void);		//Get Speed
+	void setForward(bool);		//Moving Forward true or false
+	bool getForward(void);
+	void setBackward(bool);		//Moving Backward true or false
+	bool getBackward(void);
+	void setLeft(bool);			//Turning Left true or false
+	bool getLeft();
+	void setRight(bool);		//Turning Right true or false
+	bool getRight();
+	void setGun(bool);			//Gun firing true or false
+	bool getGun();
+	void setTurrRot(float);
+	float getTurrRot();
+	void setTurrLeft(bool);
+	bool getTurrLeft();
+	void setTurrRight(bool);
+	bool getTurrRight();
+	void setTopSpeed(float);
+	float getTopSpeed();
+	Bullet * bulletPointer;
+	//~tankPlayer();
+
+private: 
+	float xPosition;
+	float yPosition;
+	float rotation;
+	float rotationRads;
+	float tankSpeed;
+	float topSpeed;
+	bool goForward;
+	bool goBackward;
+	bool goLeft;
+	bool goRight;
+	bool fireGun;
+	float turrRot;
+	bool turrLeft;
+	bool turrRight;
+};
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.