-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOctorok.cpp
More file actions
69 lines (58 loc) · 2.23 KB
/
Copy pathOctorok.cpp
File metadata and controls
69 lines (58 loc) · 2.23 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
#include "Octorok.hpp"
#include "ScenePlayable.hpp"
#include "Prop.hpp"
Octorok::Octorok(ScenePlayable* scene, Map* map, sf::Vector2f pos) : Enemy(scene, map,pos) {
_sprite.setTexture(Resources::overEnemies);
_description = Resources::descriptions[octorokDescriptions];
_dir = directions(std::rand()%4);
_action = linkActions::move;
_elapsedWalking = 0.5;
_speed = sf::Vector2f(7,7);
_walkBounds = sf::IntRect(2,2,12,12);
_bounds = _walkBounds;
_time = 0;
_damage = 0.5;
_sprite.setTextureRect(_description[_action*4+_dir][_currentAnimation%_description[_action*4+_dir].size()]);
}
Octorok::~Octorok() {}
void Octorok::update(float deltaTime) {
_time -= deltaTime;
if (_time < 0) {
_time += 2;
directions dirAux = directions(pointsToDirection4(getPosition(),_scene->getPlayer()->getPosition()));
if (dirAux == _dir && _blocked) dirAux = directions(rand()%4);
_dir = dirAux;
}
if (std::rand()%(FRAMERATE*3) == 0) shot();
_moving = true;
Enemy::update(deltaTime);
_blocked = false;
}
sf::Vector2f Octorok::getBotPosition() {
return sf::Vector2f(_sprite.getPosition().x+_bounds.left+_bounds.width/2, _sprite.getPosition().y);
}
void Octorok::resetMove() {
_blocked = true;
Collisionable::resetMove();
}
void Octorok::shot() {
SoundManager::playSound("shootBigBall");
sf::Vector2f offset;
offset.x = getHorizontal(_dir) * (getBounds().left+getBounds().width /2);
offset.y = getVertical (_dir) * (getBounds().top +getBounds().height/2);
_scene->addEnemyWeapon(new RockProjectile(_map, getRelativeCenter(_sprite.getPosition(), getBounds(), RockProjectile::bounds()) + offset, _dir));
}
void Octorok::drop() {
int r = std::rand()%10;
objectType dropType;
bool droping = true;
if (r == 0) dropType = objectType::rupee;
else if (r <= 1) dropType = objectType::fullHeal;
else if (r <= 3) dropType = objectType::rupee;
else if (r <= 6) dropType = objectType::halfHeal;
else droping = false;
if (droping) _scene->addObject(new Object(dropType,
sf::Vector2f(_sprite.getPosition().x+_bounds.left+_bounds.width/2,
_sprite.getPosition().y+_bounds.top+_bounds.height/2),
_scene));
}