Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL/SDL.h>
- #include <SDL/SDL_thread.h>
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- using namespace std;
- class Monster{
- public:
- Monster(const char* typeOfMob,bool boss,int x, int y);
- int calcDamage();
- void update(int delta,int playerX, int playerY, int chanx,int chany);
- bool hitPlayer;
- private:
- float mobSpeed;
- double posX,posY;
- int damageMax;
- int damageMin;
- bool isBoss;
- int deltaTime;
- SDL_Surface* mobImage;
- };
- Monster::Monster(const char* typeOfMob, bool boss, int x, int y)
- {
- isBoss = boss;
- posX = x;
- posY = y;
- hitPlayer = false;
- if(typeOfMob == "goblin")
- {
- damageMin = 5;
- damageMax = 10;
- mobSpeed = 1.f;
- mobImage = SDL_LoadBMP("Content/Images/Player/up.bmp");
- }else
- {
- damageMin = 5;
- damageMax = 10;
- mobSpeed = 1.f; //I increase the speed
- mobImage = SDL_LoadBMP("Content/Images/Mobs/goblin.bmp");
- }
- }
- void Monster::update(int delta,int playerX, int playerY, int chanx,int chany)
- {
- //pointing to the player
- double x=SDL_GetVideoSurface()->w/2-(playerX+posX);
- double y=SDL_GetVideoSurface()->h/2-(playerY+posY);
- //normalize
- double length=sqrt(x*x+y*y);
- x/=length;
- y/=length;
- //move on the vector
- posX+=x*mobSpeed;
- posY+=y*mobSpeed;
- SDL_Rect tmprect = {posX+playerX,posY+playerY}; //make sure the monster is static on the screen, by adding the camera coordinate to it's position
- SDL_BlitSurface(mobImage,NULL,SDL_GetVideoSurface(),&tmprect);
- }
- int Monster::calcDamage()
- {
- return rand()%damageMax+damageMin;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement