Player.h
#pragma once
#include "Game.h"
#include "AnimatedSprite.h"
class Player
{
public:
Player();
~Player();
void OnKeyDown();
void Draw(sf::RenderWindow &window);
private:
sf::Texture playerTexture;
sf::Sprite playerImage;
};
Player.cpp
#include "Player.h"
Player::Player()
{
if (!playerTexture.loadFromFile("images/wizardT.png"))
{
std::cout << "Can't load the player image";
}
playerImage.setTexture(playerTexture);
playerImage.setPosition(200, 200);
playerImage.setTextureRect(sf::IntRect(48, 14, 73, 73));
}
Player::~Player()
{
}
void Player::OnKeyDown(){
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
playerImage.move(0, -5.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
playerImage.move(0, 5.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
playerImage.move(-5.0, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
playerImage.move(5.0, 0);
}
}
void Player::Draw(sf::RenderWindow &window){
window.draw(playerImage);
}
Game.cpp
#include "Game.h"
#include "AnimatedSprite.h"
Game::Game()
{
}
Game::~Game()
{
}
void Game::Setup(){
}
void Game::OnKeyDown(){
Player player;
player.OnKeyDown();
}
void Game::Update(sf::RenderWindow &window){
Setup();
OnKeyDown();
}
void Game::Draw(sf::RenderWindow &window){
Player player;
player.Draw(window);
}
Main.cpp
#include <SFML/Graphics.hpp>
#include "Game.h"
int main()
{
sf::RenderWindow window(sf::VideoMode(800,600), "SFML works!");
Game game;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
game.Update(window);
window.clear();
game.Draw(window);
window.display();
}
return 0;
}
I cant spot anything wrong with it, any help would be great