Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Player.cpp
- *
- * Created on: Dec 15, 2017
- * Author: shinobu
- */
- #include "Player.h"
- #include "Graphics.h"
- namespace player_constants {
- const float WALK_SPEED = 0.2f;
- }
- Player::Player() {
- //TODO
- }
- Player::Player(Graphics &graphics, float x, float y) : AnimatedSprite(graphics, globals::IMG_MAIN_CHAR, 0, 0, 16, 16, x, y, 100) {
- graphics.loadImage(globals::IMG_MAIN_CHAR);
- this->dx = 0;
- this->dy = 0;
- this->facing = RIGHT;
- this->setupAnimation();
- this->animate("FaceRight");
- }
- void Player::setupAnimation() {
- this->addAnimation(1, 0, 0, "FaceLeft", 16, 16, Vector2(0, 0));
- this->addAnimation(1, 0, 16, "FaceRight", 16, 16, Vector2(0, 0));
- this->addAnimation(3, 0, 0, "RunLeft", 16, 16, Vector2(0, 0));
- this->addAnimation(3, 0, 16, "RunRight", 16, 16, Vector2(0, 0));
- }
- void Player::animationDone(std::string currentAnimation) {
- //TODO
- }
- void Player::moveLeft() {
- this->dx = -player_constants::WALK_SPEED;
- this->animate("RunLeft");
- this->facing = LEFT;
- }
- void Player::moveRight() {
- this->dx = player_constants::WALK_SPEED;
- this->animate("RunRight");
- this->facing = RIGHT;
- }
- void Player::stopMoving() {
- this->dx = 0.0f;
- //this->animate(this->facing == RIGHT ? "FaceRight" : "FaceLeft");
- if (this->facing == RIGHT) {
- this->animate("FaceRight");
- }
- else {
- this->animate("FaceLeft");
- }
- }
- void Player::update(float elapsedTime) {
- this->x += this->dx * elapsedTime;
- AnimatedSprite::update(elapsedTime);
- }
- void Player::draw(Graphics &graphics) {
- AnimatedSprite::draw(graphics, this->x, this->y);
- }
Advertisement
Add Comment
Please, Sign In to add comment