From f4e392912a3812b602f787c6db30296cea14962e Mon Sep 17 00:00:00 2001 From: Simponic Date: Fri, 6 Nov 2020 11:48:27 -0700 Subject: [PATCH] Added files --- makefile | 3 ++ sprites/bullet.png | Bin 0 -> 123 bytes sprites/gunRight.png | Bin 0 -> 2834 bytes sprites/player.png | Bin 0 -> 8379 bytes src/acceleration.cpp | 32 ++++++++++++ src/acceleration.h | 18 +++++++ src/bullet.h | 7 +++ src/gun.cpp | 19 +++++++ src/gun.h | 14 +++++ src/main.cpp | 41 +++++++++++++++ src/object.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++ src/object.h | 50 ++++++++++++++++++ src/player.cpp | 88 +++++++++++++++++++++++++++++++ src/player.h | 29 +++++++++++ src/point.cpp | 33 ++++++++++++ src/point.h | 20 ++++++++ src/velocity.cpp | 38 ++++++++++++++ src/velocity.h | 21 ++++++++ 18 files changed, 533 insertions(+) create mode 100644 makefile create mode 100644 sprites/bullet.png create mode 100755 sprites/gunRight.png create mode 100644 sprites/player.png create mode 100644 src/acceleration.cpp create mode 100644 src/acceleration.h create mode 100644 src/bullet.h create mode 100644 src/gun.cpp create mode 100644 src/gun.h create mode 100644 src/main.cpp create mode 100644 src/object.cpp create mode 100644 src/object.h create mode 100644 src/player.cpp create mode 100644 src/player.h create mode 100644 src/point.cpp create mode 100644 src/point.h create mode 100644 src/velocity.cpp create mode 100644 src/velocity.h diff --git a/makefile b/makefile new file mode 100644 index 0000000..3ea6686 --- /dev/null +++ b/makefile @@ -0,0 +1,3 @@ +CXX = g++ +CXXFLAGS = -lsfml-graphics -lsfml-window -lsfml-system + diff --git a/sprites/bullet.png b/sprites/bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..7f144b83734cddf5fc28264764e29fa304053d8b GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^{2f>uN2U!Dy)W1%tPwoiFmc7qMHiM?%+vHr6j`3@)Rqv;&hV(| VkB+y^X?dV&44$rjF6*2UngE^)B`^R0 literal 0 HcmV?d00001 diff --git a/sprites/gunRight.png b/sprites/gunRight.png new file mode 100755 index 0000000000000000000000000000000000000000..ef54df8f921f2b340df57c4bf8ef1ed7214654d9 GIT binary patch literal 2834 zcmZ`*c|6mP8~?ajF=s-eSxDFrv4+yHk!u;z#6p-fbDwR_<~~X{a%TwN9Ob?u$L z7}N#(uxZv)%Zy`=Qhk&qMp0R0L`0%YA1VxK4WykhOO{aKcFN34{IAe3fnbRHTX>QJ+g;4YRXvC*<;_X)RM^9pzH_?Atx!r0Gm?e=3I zK7?9-YT9aF3RZx3zq~HP)))oqSYd+uqM1I9{<83~7afPacyu6!=d^{#*Bb+cDAQ8< z%7UV$eX6!fSjntw0f%kTl^W>LbFI-H__wQSaW-PSVP5 zw^eJ&2J>O8{?sXU8Ve((mSH>1DeYP1}bwe-U zO5)6jiDR}sVm=;(HZc_M8y_f4EG|>wa&*em)X)WB(AMCPp_wHk1yX#3c*9%>rMn%vUpzAe3=GWbohZkb!#Gd}S}$Yfx&mq@)CVC%h0r4JODXH3q{8j(@l(io|joqn1$Z>LTy zMyZOhc%ITXEzyx$ip2i(cDpIYL~leZ%x%{)npAO8?(a^dMPg}Z$bDG5n@2p$U!FLq zv{A8}9`sou!L*Z7_a#+M;RmN7=OUs!K#6MfNdlSm!XvGg}D2c{el zdCxOt@?6#QJj)RQI5{D(UgIQP*X(yHF6WKOt$$EhZ|ISVXT%?InXpQd|4zcl+5XEZ z5D|`;dbf^RDzyUmKF`<;zBVsasQ`AKOtVNGows}+Yt(b}LQE?WRcN8qu;y$5oeQ*c z`W8tYrAbISijWP@{xY;kz{_Rv!szZjInr5K{gUkC1o)|ui?v6VlTOxxh(cY|L#GET zuQkR0K-%Z9SboHMSvyI2nS@=#b!|TH<&#t7isIh_*^E1Z?cWIr#W<7cHp`{zsn>cV z33>Bo#Jl~i$suL-V;(uq!P6?ibX?8_E0o@SZa33nRj2E=(`))`M~IQK?lV>Pm%YMf zN`)sBG1rqMo|yTGmKoV>yE|3%V6ypL=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XmMzcQ|eRjIZ%%e6bKaC6b9MdTk7#?%hDhP85541WDfO4<7V9p|M2xP# zr|4YvXLf-mW&_(XriaxxPr|#z8sX)0XpFmkhRpBi=f)_+M>U2x?P6m#u9N+o54Bj| zX^sF9*uK}Lr!^Dpc2;85KpB8_^eNzS3cUs#&Ir+vnxMgu!uD?jpacNJv+aZvNz)mn zs+4nz-_mJ_>UfpH>nybWe$JGiD9%ygm z&7;}+aSMlq?6sL_HTM5kTUmqJ5uq%DFco)FEN~!3C^BTN0_8j#c~yRCcKk<5`uJei z14?4waL;3!YAffy{ZA`HNn{M*brPH}Jc=2*YC$5?+`tv3pN)Tm?cC%+WB4S4Yixm= zVZHjjsuUkiCUKStTT5_7*kT|ySHS>Gk1YA_Al zzAo#a<-+(r?Z0vD8S*V}G{6%`*?)B41bDRf>BUWJiuRms7Ze|$4hOzl0ku(2_VW`^ z^Xv?>2=Xz*^Jk~I^cKY#^bt~z7|2Dmx@bGuJNct9OzdfEX;*oSf&!(t)iF@zT z^m1AA>7`bZ3qSPlIfSZB*JWj|AY2*p_En^GFIJ3ouf~hN>7ESALD+)mJX!5tas1lj z(j3Qw(vq9U(Cz7RX#Oa1p7YMDX(_@TVg<)%&Dxm#*a?_2~PcTv_qf9VP7%B{hP zQibY%I353<@R9d2x = d2x; +} + +void Acceleration :: setD2y(const float d2y) { + this->d2y = d2y; +} + +float Acceleration :: getD2x() { + return this->d2x; +} + +float Acceleration :: getD2y() { + return this->d2y; +} + +void Acceleration :: addAcceleration(Acceleration &acc) { + this->d2x += acc.getD2x(); + this->d2y += acc.getD2y(); +} diff --git a/src/acceleration.h b/src/acceleration.h new file mode 100644 index 0000000..0186a19 --- /dev/null +++ b/src/acceleration.h @@ -0,0 +1,18 @@ +#ifndef ACCELERATION_H +#define ACCELERATION_H + +class Acceleration { + private: + float d2x; + float d2y; + public: + Acceleration(); + Acceleration(const float d2x, const float d2y); + void setD2x(const float d2x); + void setD2y(const float d2y); + float getD2x(); + float getD2y(); + void addAcceleration(Acceleration &acc); +}; + +#endif diff --git a/src/bullet.h b/src/bullet.h new file mode 100644 index 0000000..6aee4b0 --- /dev/null +++ b/src/bullet.h @@ -0,0 +1,7 @@ +#include "object.h" + +class Bullet : public Object { + public: + Bullet(const Point &point, const Velocity &velocity) : Object(point, velocity) { + } +} diff --git a/src/gun.cpp b/src/gun.cpp new file mode 100644 index 0000000..312e1b1 --- /dev/null +++ b/src/gun.cpp @@ -0,0 +1,19 @@ +#include "point.h" +#include "object.h" +#include "gun.h" +#include +#include + +Gun :: Gun() : Object() {} + +Gun :: Gun(const Point &point, const sf::Texture &texture, const int width, const int height) : Object(point) { + setTexture(texture); + this->sprite.setTexture(texture); + this->sprite.setOrigin(sf::Vector2f(width / 2 - 20, height / 2)); + setWidth(width); + setHeight(height); +} + +void Gun :: draw(sf::RenderWindow &window) { + window.draw(sprite); +} diff --git a/src/gun.h b/src/gun.h new file mode 100644 index 0000000..2642df0 --- /dev/null +++ b/src/gun.h @@ -0,0 +1,14 @@ +#ifndef GUN_H +#define GUN_H + +#include "point.h" +#include "object.h" +#include "SFML/Graphics.hpp" + +class Gun : public Object { + public: + Gun(); + Gun(const Point &point, const sf::Texture &texture, const int width, const int height); + void draw(sf::RenderWindow &window); +}; +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d780ea0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include "player.h" +#include "gun.h" +#include "point.h" +#include "velocity.h" + +float width = 1280; +float height = 720; +std::string window_name = "Toxy"; + +int main() +{ + sf::RenderWindow window(sf::VideoMode(width, height), window_name); + window.setVerticalSyncEnabled(true); // V-Sync enabled + float angle; + int mouseX, mouseY; + sf::Color color(8, 105, 201); + sf::Texture gunTexture; + gunTexture.loadFromFile("sprites/gunRight.png"); + Player player(Point(width / 2, height / 2), Velocity(0,0), color, Gun(player.getPoint(), gunTexture, 150, 45)); + + while (window.isOpen()) + { + sf::Event event; + while (window.pollEvent(event)) + { + if (event.type == sf::Event::Closed) + window.close(); + } + window.clear(sf::Color(184, 184, 184)); + mouseX = sf::Mouse::getPosition(window).x - width / 2; + mouseY = sf::Mouse::getPosition(window).y - height / 2; + player.setAngle(atan2(mouseY,mouseX)); + player.draw(window); + window.display(); + } + + return 0; +} diff --git a/src/object.cpp b/src/object.cpp new file mode 100644 index 0000000..5f1fac7 --- /dev/null +++ b/src/object.cpp @@ -0,0 +1,120 @@ +#include "object.h" +#include "point.h" +#include "velocity.h" +#include "acceleration.h" + +Object :: Object() { + setAngle(0.0f); + setWidth(0); + setHeight(0); + setPoint(Point()); + setVelocity(Velocity()); + setAcceleration(Acceleration()); + setAlive(true); +} + +Object :: Object(const Point &point) { + setAngle(0.0f); + setWidth(0); + setHeight(0); + setPoint(point); + setVelocity(Velocity()); + setAcceleration(Acceleration()); + setAlive(true); +} + +Object :: Object(const Point &point, const Velocity &velocity) { + setAngle(0.0f); + setWidth(0); + setHeight(0); + setPoint(point); + setVelocity(velocity); + setAcceleration(Acceleration()); + setAlive(true); +} +Object :: Object(const Point &point, const Velocity &velocity, const Acceleration &acceleration) { + setAngle(0.0f); + setWidth(0); + setHeight(0); + setPoint(point); + setVelocity(velocity); + setAcceleration(acceleration); + setAlive(true); +} + +void Object :: setAngle(const float angle) { + this->angle = angle; +} + +void Object :: setWidth(const int width) { + this->width = width; +} + +void Object :: setHeight(const int height) { + this->height = height; +} + +void Object :: setPoint(const Point &point) { + this->point = point; +} + +void Object :: setVelocity(const Velocity &velocity) { + this->velocity = velocity; +} + +void Object :: setAcceleration(const Acceleration &acceleration) { + this->acceleration = acceleration; +} + +void Object :: setAlive(const bool alive) { + this->alive = alive; +} + +void Object :: setTexture(const sf::Texture &texture) { + this->texture = texture; +} + +void Object :: setSprite(const sf::Sprite &sprite) { + this->sprite = sprite; +} + +float Object :: getAngle() { + return this->angle; +} + +int Object :: getWidth() { + return this->width; +} + +int Object :: getHeight() { + return this->height; +} + +Point Object :: getPoint() { + return this->point; +} + +Velocity Object :: getVelocity() { + return this->velocity; +} + +Acceleration Object :: getAcceleration() { + return this->acceleration; +} + +bool Object :: getAlive() { + return this->alive; +} + +sf::Texture Object :: getTexture() { + return this->texture; +} + +sf::Sprite Object :: getSprite() { + return this->sprite; +} + +void Object :: kill() { + setAlive(false); +} + diff --git a/src/object.h b/src/object.h new file mode 100644 index 0000000..b29c332 --- /dev/null +++ b/src/object.h @@ -0,0 +1,50 @@ +#ifndef OBJECT_H +#define OBJECT_H + +#include "point.h" +#include "velocity.h" +#include "acceleration.h" +#include + +class Object { + protected: + int width, height; + float angle; + Point point; + Velocity velocity; + Acceleration acceleration; + bool alive; + sf::Texture texture; + sf::Sprite sprite; + public: + Object(); + Object(const Point &point); + Object(const Point &point, const Velocity &velocity); + Object(const Point &point, const Velocity &velocity, const Acceleration &acc); + void setAngle(const float angle); + void setWidth(const int width); + void setHeight(const int height); + void setPoint(const Point &point); + void setVelocity(const Velocity &velocity); + void setAcceleration(const Acceleration &acc); + void setAlive(const bool alive); + void setTexture(const sf::Texture &texture); + void setSprite(const sf::Sprite &sprite); + float getAngle(); + int getWidth(); + int getHeight(); + Point getPoint(); + Velocity getVelocity(); + Acceleration getAcceleration(); + bool getAlive(); + sf::Texture getTexture(); + sf::Sprite getSprite(); + void kill(); + + virtual void update() { + this->velocity.update(this->acceleration); + this->point.update(this->velocity); + } + virtual void draw(sf::RenderWindow &window) = 0; +}; +#endif diff --git a/src/player.cpp b/src/player.cpp new file mode 100644 index 0000000..e99ea43 --- /dev/null +++ b/src/player.cpp @@ -0,0 +1,88 @@ +#include "object.h" +#include "player.h" +#include +#include +#include +#include "gun.h" +#define PI 3.14159265 +using namespace std; + +Player :: Player (const Point &point, const Velocity &velocity, sf::Color &color, const Gun &gun) : Object(point, velocity) { + setWidth(100); + setHeight(150); + setHealth(100); + setColor(color); + setGun(gun); + sf::Texture playerTexture; + playerTexture.loadFromFile("sprites/player.png"); + setTexture(playerTexture); + this->sprite.setTexture(this->texture); + this->sprite.setColor(color); + this->sprite.setTextureRect(sf::IntRect(0,0,100,150)); // 1st frame + this->sprite.setOrigin(sf::Vector2f(50,75)); + setSprite(this->sprite); +} + +void Player :: setGun(const Gun &gun) { + this->gun = gun; +} + +void Player :: setHealth(const float health) { + this->health = health; +} + +void Player :: setColor(const sf::Color &color) { + this->color = color; +} + +sf::Color Player :: getColor() { + return this->color; +} + +float Player :: getHealth() { + return this->health; +} + +Gun Player :: getGun() { + return this->gun; +} + +void Player :: draw(sf::RenderWindow &window) { + // Draw a player to the window + this->sprite.setPosition(sf::Vector2f(this->point.getX(),this->point.getY())); + float ang = -180.0f / PI * this->getAngle(); + int frame; + if (ang > -30 && ang <= 30) { + frame = 4; + } + else if (ang > 30 && ang <= 60) { + frame = 0; + } + else if (ang > 60 && ang <= 120) { + frame = 1; + } + else if (ang > 120 && ang <= 150) { + frame = 2; + } + else if (ang > 150 || ang <= -150) { + frame = 3; + } + else if (ang > -150 && ang <= -120) { + frame = 7; + } + else if (ang > -120 && ang <= -60) { + frame = 6; + } + else if (ang > -60 && ang <= -30) { + frame = 5; + } + window.draw(this->sprite); + sf::Sprite gunSprite = this->gun.getSprite(); + gunSprite.setRotation(-ang); + gunSprite.setPosition(sf::Vector2f(this->point.getX(),this->point.getY() + 40)); + this->gun.setSprite(gunSprite); + + window.draw(this->gun.getSprite()); + this->sprite.setTextureRect(sf::IntRect((frame % 3) * this->getWidth(), + (frame / 3) * this->getHeight(), this->getWidth(), this->getHeight())); +} diff --git a/src/player.h b/src/player.h new file mode 100644 index 0000000..7f7f7ce --- /dev/null +++ b/src/player.h @@ -0,0 +1,29 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include "object.h" +#include "point.h" +#include "velocity.h" +#include "gun.h" +#include +#include + + +class Player : public Object { + private: + float health; + Gun gun; + sf::Color color; + public: + Player (const Point &point, const Velocity &velocity, sf::Color &color, const Gun &gun); + void setGun(const Gun &gun); + void setHealth(const float health); + void setColor(const sf::Color &color); + float getHealth(); + sf::Color getColor(); + Gun getGun(); + + void draw(sf::RenderWindow &window); +}; + +#endif diff --git a/src/point.cpp b/src/point.cpp new file mode 100644 index 0000000..4b89a4a --- /dev/null +++ b/src/point.cpp @@ -0,0 +1,33 @@ +#include "point.h" +#include "velocity.h" + +Point :: Point() { + setX(0.0f); + setY(0.0f); +} + +Point :: Point (const float x, const float y) { + setX(x); + setY(y); +} + +void Point :: setX(const float x) { + this->x = x; +} + +void Point :: setY(const float y) { + this->y = y; +} + +float Point :: getX() { + return this->x; +} + +float Point :: getY() { + return this->y; +} + +void Point :: update(Velocity &vel) { + this->x += vel.getDx(); + this->y += vel.getDy(); +} diff --git a/src/point.h b/src/point.h new file mode 100644 index 0000000..31fdf3e --- /dev/null +++ b/src/point.h @@ -0,0 +1,20 @@ +#ifndef POINT_H +#define POINT_H + +#include "velocity.h" + +class Point { + private: + float x; + float y; + public: + Point(); + Point(const float x, const float y); + void setX(const float x); + void setY(const float y); + float getX(); + float getY(); + void update(Velocity &vel); +}; + +#endif diff --git a/src/velocity.cpp b/src/velocity.cpp new file mode 100644 index 0000000..71bf7cd --- /dev/null +++ b/src/velocity.cpp @@ -0,0 +1,38 @@ +#include "acceleration.h" +#include "velocity.h" + +Velocity :: Velocity() { + setDx(0.0f); + setDy(0.0f); +} + +Velocity :: Velocity(const float dx, const float dy) { + setDx(0.0f); + setDy(0.0f); +} + +void Velocity :: setDx(const float dx) { + this->dx = dx; +} + +void Velocity :: setDy(const float dy) { + this->dy = dy; +} + +float Velocity :: getDx() { + return this->dx; +} + +float Velocity :: getDy() { + return this->dy; +} + +void Velocity :: addVelocity (Velocity &vel) { + this->dx += vel.getDx(); + this->dy += vel.getDy(); +} + +void Velocity :: update(Acceleration &acc) { + this->dx += acc.getD2x(); + this->dy += acc.getD2y(); +} diff --git a/src/velocity.h b/src/velocity.h new file mode 100644 index 0000000..3c48949 --- /dev/null +++ b/src/velocity.h @@ -0,0 +1,21 @@ +#ifndef VELOCITY_H +#define VELOCITY_H + +#include "acceleration.h" + +class Velocity { + private: + float dx; + float dy; + public: + Velocity(); + Velocity(const float dx, const float dy); + void setDx(const float dx); + void setDy(const float dy); + float getDx(); + float getDy(); + void addVelocity(Velocity &vel); + void update(Acceleration &acc); +}; + +#endif