I've ended up deviating from the tutorials somewhat, and attempted to use (wnd.kbd.KeyIsPressed) in a new Class and function (not in the constructor) but I'm getting a red line under "kbd" telling me Keyboard has no member "kbd"
Code: Select all
void Control::KeyPresses(MainWindow&kbd, Keyboard &wnd)
{
if (CoPlayerNum = 1)
{
if (wnd.kbd.KeyIsPressed(VK_UP)) {
CoPlayerY = CoPlayerY - 1;
My header file looks like
Code: Select all
#pragma once
#include "Keyboard.h"
#include "MainWindow.h"
class Control
{
public:
Control(int GetControlX,int GetControlY,int PlayerNum);
void KeyPresses(MainWindow&kbd, Keyboard &wnd);
int SetBoundaryX(int PosX);
int SetBoundaryY(int PosY);
private:
int CoPlayerX;
int CoPlayerY;
int CoPlayerNum;
};
Code: Select all
#include "Control.h"
#include "Keyboard.h"
#include "MainWindow.h"
#include "Graphics.h"
Control::Control(int PlayerLocX, int PlayerLocY, int GrabPlayerNumber)
{
int CoPlayerX;
int CoPlayerY;
int CoPlayerNum;
KeyPresses();
}
void Control::KeyPresses(MainWindow&kbd, Keyboard &wnd)
{
if (CoPlayerNum = 1)
{
if (wnd.kbd.KeyIsPressed(VK_UP)) {
CoPlayerY = CoPlayerY - 1;
}
if (wnd.kbd.KeyIsPressed(VK_DOWN)) {
CoPlayerY = CoPlayerY + 1;
}
if (wnd.kbd.KeyIsPressed(VK_LEFT)) {
CoPlayerX = CoPlayerX - 1;
}
if (wnd.kbd.KeyIsPressed(VK_RIGHT)) {
CoPlayerX = CoPlayerX + 1;
}
CoPlayerX = SetBoundaryX(CoPlayerX);
CoPlayerX = SetBoundaryY(CoPlayerX);
if (wnd.kbd.KeyIsPressed('I')) {
Fire::Fire(CoPlayerX, CoPlayerY, 1);
}
}
if (CoPlayerNum = 2) {
if (wnd.kbd.KeyIsPressed(0x57)) {
CoPlayerY = CoPlayerY - 1;
}
if (wnd.kbd.KeyIsPressed(0x53)) {
CoPlayerY = CoPlayerY + 1;
}
if (wnd.kbd.KeyIsPressed(0x41)) {
CoPlayerX = CoPlayerX - 1;
}
if (wnd.kbd.KeyIsPressed(0x44)) {
CoPlayerX = CoPlayerX + 1;
}
CoPlayerX = SetBoundaryX(CoPlayerX);
CoPlayerY = SetBoundaryY(CoPlayerY);
if (wnd.kbd.KeyIsPressed('T')) {
Fire::Fire(CoPlayerX, CoPlayerY, 2);
}
}
}
int Control::SetBoundaryX(int GetLocX)
{
int right = GetLocX + 5;
int left = GetLocX - 5;
if (right >= Graphics::ScreenWidth)
{
return Graphics::ScreenWidth - 6;
}
else if (left < 0)
{
return 5;
}
else {
return GetLocX;
}
}
int Control::SetBoundaryY(int GetLocY)
{
int Up = GetLocY - 5;
int down = GetLocY + 5;
if (Up <= 0) {
return 5;
}
else if (down >= Graphics::ScreenHeight)
{
return Graphics::ScreenHeight - 6;
}
else {
return GetLocY;
}
}
Im sure some of it doesn't make sence atm and I've no idea if it will run because I'm not able to solve this kbd problem, any help is much appreciated!
I'm not sure if you have later explained this in the tutorals but I'm reluctant to bindge watch the next few to find out and risk flooding my brain and losing interest in this current problem and thus not learning the answer to what has taken me hours