-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlant.cpp
More file actions
34 lines (31 loc) · 705 Bytes
/
Plant.cpp
File metadata and controls
34 lines (31 loc) · 705 Bytes
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
#include "Plant.h"
#include"config.h"
#include"World.h"
Plant::Plant(int power, World *world, int x, int y)
{
this->power = power;
this->world = world;
this->x = x;
this->y = y;
activity = 0;
}
void Plant::action(int move_dx, int move_dy)
{
if (world->randInt(0, 100) <= PLANT_RATIO*10)
{
int new_x = x;
int new_y = y;
if (world->findFreeSpace(&new_x, &new_y, PLANT_RANGE))
{
world->addOrganism(image, new_x, new_y);
world->addComment(string(1, image), "spread");
}
}
}
void Plant::collision(Organism *attacker)
{
int a = x, b = y;
world->moveOrganism(attacker, a, b);
world->addComment(string(1, attacker->getImage()), "ate", string(1, image));
world->delOrganism(this);
}