From d598c7dc377ab86fd29e6e39c7096bf220e2aa8d Mon Sep 17 00:00:00 2001 From: zombidust Date: Tue, 15 Apr 2014 20:26:01 +0300 Subject: [PATCH] Adding template code for enemy! --- source/enemy.cpp | 14 ++++++++++++++ source/entities.h | 30 +++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 source/enemy.cpp diff --git a/source/enemy.cpp b/source/enemy.cpp new file mode 100644 index 0000000..490e0ac --- /dev/null +++ b/source/enemy.cpp @@ -0,0 +1,14 @@ +#include "entities.h" + +int Enemy::findPlayer(int *xVel, int *yVel) { +//Nedko svurshi si rabotata +//pip +} + +void Enemy::move() { + int xVel; + int yVel; + direction_ = findPlayer(&xVel, &yVel); + origin_.setX(origin_.getX() + xVel); + origin_.setY(origin_.getY() + yVel); +} diff --git a/source/entities.h b/source/entities.h index ceb7608..2cb95c2 100644 --- a/source/entities.h +++ b/source/entities.h @@ -7,17 +7,18 @@ #include class Player { +protected: Point origin_; Point map_; int direction_; int size_; int speed_; std::vector *obstacles_; - + +private: void checkDirection(int dir, int *xVel, int *yVel) const; - -public: - + +public: Player() : origin_(1,1), map_(640,480), @@ -27,10 +28,29 @@ public: obstacles_(NULL) {} + Player(Point origin, Point map, int dir, int size, int speed, std::vector *obstacles) + : origin_(origin.getX(),origin.getY()), + map_(map.getX(),map.getY()), + direction_(dir), + size_(size), + speed_(speed), + obstacles_(obstacles) + {} + Point getPosition() const; int getDirection() const; - void movePlayer(int dir); + void move(int dir); void init(Point origin, int size, int dir, Point map, std::vector *obstacles, int speed); }; +class Enemy::public Player { + Player player_; + int findPlayer(int *xVel, int *yVel); +public: + Enemy(Point origin, Point map, int dir, int size, int speed, std::vector *obstacles, Player player) + : Player(origin, map, dir, size, speed, obstacles), + player_(player) + {} + void move(); +}; #endif