-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2d9a63
commit 9706b25
Showing
60 changed files
with
1,291 additions
and
1,023 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
*.d | ||
/Gameplay.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
#include "Global.h" | ||
|
||
|
||
float random(float begin, float end){return ((float)rand()) / RAND_MAX * (end - begin) + begin;} | ||
|
||
Bot::Bot(){ | ||
setSpeed(speed_default); | ||
srand((unsigned)time(NULL)); | ||
shape = Bot::shape_default; | ||
setDamage(damage_default); | ||
setHealth(health_default); | ||
}; | ||
|
||
void Bot::setUp() { | ||
static float perimeter_y = screenHeight - boundary_y; | ||
static float perimeter = perimeter_y * 2 + screenWidth; | ||
float random_loc = random(0, perimeter); | ||
|
||
if (random_loc <= perimeter_y) { | ||
Figure::setUp(0,screenHeight - random_loc); | ||
} | ||
else if (random_loc < perimeter - perimeter_y) { | ||
Figure::setUp(random_loc - perimeter_y, boundary_y); | ||
} | ||
else { | ||
Figure::setUp(screenWidth,random_loc - screenWidth - perimeter_y + boundary_y); | ||
} | ||
|
||
setVel(0, 0); | ||
frame_count = dumbness; | ||
|
||
setActive(true); | ||
setHealth(health_default); | ||
} | ||
|
||
void Bot::move(float rect_x, float rect_y) { | ||
if (!getActive()) return; | ||
|
||
if (frame_count >= dumbness/delay) { | ||
float norm = sqrt((rect_x - getX()) *(rect_x - getX()) + (rect_y - getY()) *(rect_y - getY())); | ||
if (norm == 0) setVel(0, 0); | ||
else setVel((rect_x - getX()) / norm, (rect_y - getY()) / norm); | ||
frame_count = 0; | ||
} | ||
frame_count++; | ||
|
||
Figure::move(); | ||
|
||
#include "Global.h" | ||
|
||
|
||
float random(float begin, float end){return ((float)rand()) / RAND_MAX * (end - begin) + begin;} | ||
|
||
Bot::Bot(){ | ||
setSpeed(speed_default); | ||
srand((unsigned)time(NULL)); | ||
shape = Bot::shape_default; | ||
setDamage(damage_default); | ||
setHealth(health_default); | ||
}; | ||
|
||
void Bot::setUp() { | ||
static float perimeter_y = screenHeight - boundary_y; | ||
static float perimeter = perimeter_y * 2 + screenWidth; | ||
float random_loc = random(0, perimeter); | ||
|
||
if (random_loc <= perimeter_y) { | ||
Figure::setUp(0,screenHeight - random_loc); | ||
} | ||
else if (random_loc < perimeter - perimeter_y) { | ||
Figure::setUp(random_loc - perimeter_y, boundary_y); | ||
} | ||
else { | ||
Figure::setUp(screenWidth,random_loc - screenWidth - perimeter_y + boundary_y); | ||
} | ||
|
||
setVel(0, 0); | ||
frame_count = dumbness; | ||
|
||
setActive(true); | ||
setHealth(health_default); | ||
} | ||
|
||
void Bot::move(float rect_x, float rect_y) { | ||
if (!getActive()) return; | ||
|
||
if (frame_count >= dumbness/delay) { | ||
float norm = sqrt((rect_x - getX()) *(rect_x - getX()) + (rect_y - getY()) *(rect_y - getY())); | ||
if (norm == 0) setVel(0, 0); | ||
else setVel((rect_x - getX()) / norm, (rect_y - getY()) / norm); | ||
frame_count = 0; | ||
} | ||
frame_count++; | ||
|
||
Figure::move(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
#pragma once | ||
|
||
//temporary | ||
#include <iostream> | ||
|
||
#include "Figure.h" | ||
#include "MyShape.h" | ||
|
||
#include <time.h> | ||
|
||
class Bot :public Figure | ||
{ | ||
public: | ||
Bot(); | ||
|
||
void setUp(); | ||
|
||
sf::Vector2f getSize() { return shape.getSize(); } | ||
|
||
static void setHealthD(float h) { health_default = h; } | ||
static float getHealthD() { return health_default; } | ||
|
||
static void setPeriodD(float p) { period_default = p; } | ||
static float getPeriodD() { return period_default; } | ||
|
||
static void setDamageD(float d) { damage_default = d; } | ||
static float getDamageD() { return damage_default; } | ||
|
||
static float getHealth0() { return health_0; } | ||
static float getDamage0() { return damage_0; } | ||
static float getPeriod0() { return period_0; } | ||
|
||
void move(float rect_x, float rect_y); | ||
|
||
private: | ||
float frame_count; | ||
|
||
static const float health_0; | ||
static const float damage_0; | ||
static const float period_0; | ||
|
||
static float health_default; | ||
static float damage_default; | ||
static float period_default; | ||
static const float speed_default; | ||
|
||
static const float dumbness; | ||
|
||
static const MyShape shape_default; | ||
}; | ||
|
||
#pragma once | ||
|
||
//temporary | ||
#include <iostream> | ||
|
||
#include "Figure.h" | ||
#include "MyShape.h" | ||
|
||
#include <time.h> | ||
|
||
class Bot :public Figure | ||
{ | ||
public: | ||
Bot(); | ||
|
||
void setUp(); | ||
|
||
sf::Vector2f getSize() { return shape.getSize(); } | ||
|
||
static void setHealthD(float h) { health_default = h; } | ||
static float getHealthD() { return health_default; } | ||
|
||
static void setPeriodD(float p) { period_default = p; } | ||
static float getPeriodD() { return period_default; } | ||
|
||
static void setDamageD(float d) { damage_default = d; } | ||
static float getDamageD() { return damage_default; } | ||
|
||
static float getHealth0() { return health_0; } | ||
static float getDamage0() { return damage_0; } | ||
static float getPeriod0() { return period_0; } | ||
|
||
void move(float rect_x, float rect_y); | ||
|
||
private: | ||
float frame_count; | ||
|
||
static const float health_0; | ||
static const float damage_0; | ||
static const float period_0; | ||
|
||
static float health_default; | ||
static float damage_default; | ||
static float period_default; | ||
static const float speed_default; | ||
|
||
static const float dumbness; | ||
|
||
static const MyShape shape_default; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
#include "Global.h" | ||
|
||
const float Button::up = 1.f / 3.f; | ||
const float Button::down = 1.f / 4.f; | ||
|
||
void Button::setUp(float size_xx, float size_yy, sf::Color colorr, float pos_x, float pos_y) { | ||
setColor(colorr, size_xx, size_yy); | ||
|
||
MyShape::setPosition(pos_x, pos_y); | ||
}; | ||
|
||
|
||
void Button::draw(sf::RenderWindow &window) { | ||
MyShape::draw(window); | ||
if (!text.getString().isEmpty()) window.draw(text); | ||
if (!subtext.getString().isEmpty()) window.draw(subtext); | ||
} | ||
|
||
void Button::setText(std::string ttext, sf::Color color, unsigned char_size, std::string ffont) { | ||
|
||
setFont(ffont); | ||
setUpText(text, ttext, color, char_size, font); | ||
setTextPosition(); | ||
} | ||
|
||
void Button::setSubText(int pprice, sf::Color color, unsigned char_size, std::string ffont) { | ||
price = pprice; | ||
|
||
bool flag = false; | ||
if (subtext.getString().isEmpty()) flag = true; | ||
|
||
if (ffont != "") setFont(ffont); | ||
else if (text.getString().isEmpty()) { | ||
std::cout << "WARNING: NO FONT DEFINED - NOTHINH DONE" << std::endl; | ||
return; | ||
} | ||
|
||
setUpText(subtext, std::to_string(price), color, char_size, font); | ||
setSubTextPosition(); | ||
if (flag) setTextPosition(); | ||
} | ||
|
||
void Button::setPosition(float x, float y) { | ||
MyShape::setPosition(x, y); | ||
setTextPosition(); | ||
setSubTextPosition(); | ||
} | ||
|
||
|
||
bool Button::isClicked(float x, float y) { | ||
|
||
if ((abs(x - getPosition().x) <= getSize().x / 2) && (abs(y - getPosition().y) <= getSize().y / 2)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void Button::Upgrade(Player &player) { | ||
if (price > player.getMoney()) return; | ||
if (func != NULL) setSubText(func(player, price), subtext.getFillColor(), subtext.getCharacterSize()); | ||
|
||
} | ||
|
||
void Button::setUpText(sf::Text &ttext, std::string str, sf::Color color, unsigned char_size, sf::Font &ffont) { | ||
ttext.setFont(ffont); | ||
ttext.setString(str); | ||
ttext.setCharacterSize(char_size); | ||
ttext.setOrigin(ttext.getGlobalBounds().width / 2, ttext.getGlobalBounds().height / 2); | ||
ttext.setFillColor(color); | ||
} | ||
|
||
void Button::setTextPosition() { | ||
if (text.getString().isEmpty()) return; | ||
if (subtext.getString().isEmpty()) | ||
text.setPosition(sf::Vector2f(getPosition().x, getPosition().y)); | ||
else | ||
text.setPosition(sf::Vector2f((float)getPosition().x, (float)(getPosition().y - (1. / 2. - up) * getSize().y))); | ||
} | ||
|
||
void Button::setSubTextPosition() { | ||
if (subtext.getString().isEmpty()) return; | ||
subtext.setPosition(sf::Vector2f((float)getPosition().x, (float)(getPosition().y + (1. / 2. - down) * getSize().y))); | ||
} | ||
|
||
|
||
int isClicked(Button *button, int number, sf::Vector2i mouse) { | ||
for (int i = 0; i < number; i++) | ||
if (button[i].isClicked((float)mouse.x, (float)mouse.y)) | ||
return i; | ||
|
||
return -1; | ||
#include "Global.h" | ||
|
||
const float Button::up = 1.f / 3.f; | ||
const float Button::down = 1.f / 4.f; | ||
|
||
void Button::setUp(float size_xx, float size_yy, sf::Color colorr, float pos_x, float pos_y) { | ||
setColor(colorr, size_xx, size_yy); | ||
|
||
MyShape::setPosition(pos_x, pos_y); | ||
}; | ||
|
||
|
||
void Button::draw(sf::RenderWindow &window) { | ||
MyShape::draw(window); | ||
if (!text.getString().isEmpty()) window.draw(text); | ||
if (!subtext.getString().isEmpty()) window.draw(subtext); | ||
} | ||
|
||
void Button::setText(std::string ttext, sf::Color color, unsigned char_size, std::string ffont) { | ||
|
||
setFont(ffont); | ||
setUpText(text, ttext, color, char_size, font); | ||
setTextPosition(); | ||
} | ||
|
||
void Button::setSubText(int pprice, sf::Color color, unsigned char_size, std::string ffont) { | ||
price = pprice; | ||
|
||
bool flag = false; | ||
if (subtext.getString().isEmpty()) flag = true; | ||
|
||
if (ffont != "") setFont(ffont); | ||
else if (text.getString().isEmpty()) { | ||
std::cout << "WARNING: NO FONT DEFINED - NOTHINH DONE" << std::endl; | ||
return; | ||
} | ||
|
||
setUpText(subtext, std::to_string(price), color, char_size, font); | ||
setSubTextPosition(); | ||
if (flag) setTextPosition(); | ||
} | ||
|
||
void Button::setPosition(float x, float y) { | ||
MyShape::setPosition(x, y); | ||
setTextPosition(); | ||
setSubTextPosition(); | ||
} | ||
|
||
|
||
bool Button::isClicked(float x, float y) { | ||
|
||
if ((abs(x - getPosition().x) <= getSize().x / 2) && (abs(y - getPosition().y) <= getSize().y / 2)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void Button::Upgrade(Player &player) { | ||
if (price > player.getMoney()) return; | ||
if (func != NULL) setSubText(func(player, price), subtext.getFillColor(), subtext.getCharacterSize()); | ||
|
||
} | ||
|
||
void Button::setUpText(sf::Text &ttext, std::string str, sf::Color color, unsigned char_size, sf::Font &ffont) { | ||
ttext.setFont(ffont); | ||
ttext.setString(str); | ||
ttext.setCharacterSize(char_size); | ||
ttext.setOrigin(ttext.getGlobalBounds().width / 2, ttext.getGlobalBounds().height / 2); | ||
ttext.setFillColor(color); | ||
} | ||
|
||
void Button::setTextPosition() { | ||
if (text.getString().isEmpty()) return; | ||
if (subtext.getString().isEmpty()) | ||
text.setPosition(sf::Vector2f(getPosition().x, getPosition().y)); | ||
else | ||
text.setPosition(sf::Vector2f((float)getPosition().x, (float)(getPosition().y - (1. / 2. - up) * getSize().y))); | ||
} | ||
|
||
void Button::setSubTextPosition() { | ||
if (subtext.getString().isEmpty()) return; | ||
subtext.setPosition(sf::Vector2f((float)getPosition().x, (float)(getPosition().y + (1. / 2. - down) * getSize().y))); | ||
} | ||
|
||
|
||
int isClicked(Button *button, int number, sf::Vector2i mouse) { | ||
for (int i = 0; i < number; i++) | ||
if (button[i].isClicked((float)mouse.x, (float)mouse.y)) | ||
return i; | ||
|
||
return -1; | ||
} |
Oops, something went wrong.