This repository was archived by the owner on Feb 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimal.cpp
More file actions
128 lines (98 loc) · 2.82 KB
/
animal.cpp
File metadata and controls
128 lines (98 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "game_objects.h"
#include <SFML/Graphics.hpp>
#include <Box2D/Box2D.h>
#include "service.h"
//////////////////////////////////////////////////////////////////////////////////////////////
//////////// HUMAN ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Human::Human(b2World* World, sf::Vector2f initCord, std::string textr, int health) :Alive(World, initCord, textr, figureType::rect_T, 10, health) {
setDrag(3, 2);
}
Human::~Human() {
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////// PERSON ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Person::Person(b2World* World, sf::Vector2f initCord, std::string textr, int health) :Human(World, initCord, textr, health) {
body_ph->SetActive(true);
}
void Person::blit() {
this->update();
Human::blit();
}
void Person::update() {
PAIForce();
}
void Person::PAIForce() {
if (PAIdelta < PAIiter) {
PAIdelta++;
body_ph->ApplyForceToCenter(PAIvec, true);
}
else {
PAIiter = spl::Rand::intRand(60, 240);
PAIdelta = 0;
b2Vec2 temp(0, 0);
float x = spl::Rand::intRand(0, 10), y = spl::Rand::intRand(0, 10);
temp.Set(x, y);
temp.Normalize();
if (spl::Rand::intRand(0, 1))
PAIvec = -speed*temp;
else
PAIvec = speed*temp;
}
}
Person::~Person() {
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////// PLAYER ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Player::Player(b2World* World, sf::Vector2f initCord, int health, std::string textr, std::string textrCur) :Human(World, initCord, textr, health) {
if (textrCur != "None")
cursor = new Cursor(World, textrCur);
speed = 2;
}
void Player::freezeObject()
{
DynamicObject::freezeObject();
speed = 0;
}
void Player::blit() {
if (cursor != nullptr)
cursor->blit();
update();
Human::blit();
}
void Player::update() {
currForceVec.Normalize();
currForceVec *= speed;
body_ph->ApplyForceToCenter(currForceVec, true);
currForceVec.SetZero();
if (speed > 2)
speed -= 0.05;
}
inline void Player::moveTop() {
b2Vec2 curr(0, -1);
currForceVec += curr;
}
inline void Player::moveBottom() {
b2Vec2 curr(0, 1);
currForceVec += curr;
}
inline void Player::moveLeft() {
b2Vec2 curr(-1, 0);
currForceVec += curr;
}
inline void Player::moveRight() {
b2Vec2 curr(1, 0);
currForceVec += curr;
}
inline void Player::haste() {
if (speed < 5)
speed += 0.1;
}
Player::~Player() {
if (cursor != nullptr) {
delete cursor;
cursor = nullptr;
}
}