File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,21 @@ bool Monster::init() {
2424 return true ;
2525}
2626int Monster::get_new_direction () {
27- int new_direction = floor (CCRANDOM_0_1 () * 4 );
27+ int new_direction = ( int ) floor (CCRANDOM_0_1 () * 4 );
2828 return new_direction;
2929}
3030// void Monster::move_forward(int new_direction) {
31- // step = CCRANDOM_0_1() * 100;
3231// switch (new_direction) {
3332// case MOVE_UP:
3433//
34+ //
3535// }
36- // }
36+ // }
37+ bool Monster::collided_with (Player * player) {
38+ /* Get the bounding box of the player */
39+ Rect player_bounding_box = player->getBoundingBox ();
40+ Vec2 monster_position = this ->getPosition ();
41+ /* Check whether the player and the monster has intersection */
42+ bool is_collided = player_bounding_box.containsPoint (monster_position);
43+ return is_collided;
44+ }
Original file line number Diff line number Diff line change @@ -28,11 +28,15 @@ class Monster : public Player {
2828 /* Initiate Method */
2929 virtual bool init ();
3030
31+ bool collided_with (Player * player);
32+
3133 /* Method: get_new_direction */
3234 int get_new_direction ();
35+
3336 /* Method: move_forward */
3437// void move_forward(int new_direction);
3538
39+
3640private:
3741 enum direction { MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT };
3842
You can’t perform that action at this time.
0 commit comments