Okay so i got another problem now :
PlayerControl.h :
Code: Select all
#pragma once
#include "ChiliWin.h"
#include "Keyboard.h"
#include "PlayerDirection.h"
class PlayerSprite;
class PlayerControls {
public:
PlayerControls(PlayerSprite* player)
:
pPlayer(player)
{}
void CheckControls(Keyboard& kbd);
private:
PlayerSprite* pPlayer;
};
PlayerControl.cpp
Code: Select all
#include "PlayerControls.h"
#include "PlayerSprite.h"
void PlayerControls::CheckControls(Keyboard& kbd)
{
Keyboard::Event kevent = kbd.ReadKey();
switch (kevent.GetCode())
{
case VK_LEFT:
pPlayer->GetDirection()->SetLeft();
pPlayer->GetPlayerState()->KeyLeft(kevent.KeyState());
break;
case VK_RIGHT:
pPlayer->GetDirection()->SetRight();
pPlayer->GetPlayerState()->KeyRight(kevent.KeyState());
break;
case VK_SPACE:
pPlayer->GetPlayerState()->KeySpace(kevent.KeyState());
break;
}
}
PlayerSprite.h
Code: Select all
#pragma once
#include "Keyboard.h"
#include "PlayerControls.h"
#include "LoadPlayerRes.h"
class PlayerState;
class PlayerSprite{
public:
PlayerSprite(float x, float y, float speed);
~PlayerSprite() {
delete pCurrentState;
}
void Draw(Graphics& gfx) const;
void Update(Keyboard& kbd);
float GetX() const { return x; }
float GetY() const { return y; }
float GetSpeed() const { return speed; }
void SetX(float newx) { x = newx; }
void SetY(float newy) { y = newy; }
void SetSpeed(float newspd) { speed = newspd; }
void SetState(PlayerState* state) { pCurrentState = state; }
SurfaceAnimation* GetSurface(std::string name) {
return res.GetSurface(name);
}
PlayerState* GetPlayerState();
PlayerDirection* GetDirection();
private:
float x, y, speed;
LoadPlayerRes res;
PlayerDirection PlayerDirection;
PlayerControls* PlayerControl;
PlayerState* pCurrentState;
};
So not problem is that PlayerControl.cpp gives me errors on those lines
Code: Select all
pPlayer->GetPlayerState()->KeyLeft(kevent.KeyState());
pPlayer->GetPlayerState()->KeyRight(kevent.KeyState());
pPlayer->GetPlayerState()->KeySpace(kevent.KeyState());
its because of incomplete class of PlayerState , any way around ?
i mean if i do as i did before i would have to include PlayerSprite in each State class and then include PlayerState inside a PlayerSprite , and now i only do include to main class