-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathFish.cpp
More file actions
53 lines (42 loc) · 1.07 KB
/
Fish.cpp
File metadata and controls
53 lines (42 loc) · 1.07 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
#include "Fish.h"
#include "Forest.h"
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
sf::Texture *Fish::texture = NULL;
Fish::Fish() : vx(1), vy(1) {
}
Fish::Fish(double m, double b) : Animal(m, b), vx(1), vy(1) {
}
Fish::Fish(double m, double b, int _x, int _y) : Animal(m, b, _x, _y), vx(1), vy(1) {
}
Fish::~Fish() {
if (texture) {
delete texture;
texture = NULL;
}
}
void Fish::talk() {
cout << "*Bubbles*" << endl; //Fish's underwater, what else can it say...
}
void Fish::setSprite() {
if (!texture) {
texture = new sf::Texture;
if (!texture->loadFromFile("res/fish.png"))
cout << "Fish went wrong" << endl;
}
s = new sf::Sprite;
s->setTexture(*texture);
}
void Fish::walk(Forest *f) {
if (!(f->check(x + vx, y))) { //Fish move in a specific way, not randomly. It swims from corner to corner, changing its direction if there's an obstacle
vx *= -1;
} else {
x += vx;
return;
}
if (!(f->check(x, y + vy))) {
vy *= -1;
}
y += vy;
}