Last active
February 1, 2019 13:35
-
-
Save Pharaoh00/2d18d5c5c59d868549dcd7e359228714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "../header/player.h" | |
#include <math.h> | |
void Player::init(const char* path, | |
int srcX, int srcY, | |
int w, int h, | |
float initX, float initY) { | |
BaseSprite::init(path, srcX, srcY, w, h, initX, initY); | |
} | |
void Player::update() { | |
// _x += _xvel; | |
// _y += _yvel; | |
if(_angle > 360) { | |
_angle = 0; | |
} | |
else if (_angle < 0) { | |
_angle = 360; | |
} | |
_x = 1 * cos(_tempangle * 3.14/180); | |
_y = 1 * sin(_tempangle * 3.14/180); | |
_x += _xvel; | |
_y += _yvel; | |
_angle += _tempangle; | |
_dstRect.x = _x; | |
_dstRect.y = _y; | |
std::cout << _dstRect.x << std::endl; | |
std::cout << _angle << std::endl; | |
} | |
void Player::keyHandle(SDL_Event event) { | |
if(event.type == SDL_KEYDOWN) { | |
switch(event.key.keysym.sym) { | |
case SDLK_LEFT: | |
_xvel = -10; | |
// West | |
break; | |
case SDLK_RIGHT: | |
_xvel = 10; | |
// East | |
break; | |
case SDLK_UP: | |
_yvel = -10; | |
// North | |
break; | |
case SDLK_DOWN: | |
_yvel = 10; | |
// South | |
break; | |
case SDLK_e: | |
_tempangle = 10; | |
break; | |
case SDLK_q: | |
_tempangle = -10; | |
break; | |
} | |
} | |
else if(event.type == SDL_KEYUP) { | |
switch(event.key.keysym.sym) { | |
case SDLK_LEFT: | |
_xvel = 0; | |
break; | |
case SDLK_RIGHT: | |
_xvel = 0; | |
break; | |
case SDLK_UP: | |
_yvel = 0; | |
break; | |
case SDLK_DOWN: | |
_yvel = 0; | |
break; | |
case SDLK_e: | |
_tempangle = 0; | |
break; | |
case SDLK_q: | |
_tempangle = 0; | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "../header/basesprite.h" | |
class Player : virtual public BaseSprite { | |
public: | |
void init(const char* path, | |
int srcX, int srcY, | |
int w, int h, | |
float initX, float initY); | |
void update(); | |
void keyHandle(SDL_Event event); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment