I'm currently in the process of learning C/C++ and I was just messing around with some projects I had in my head. This problem might be easy to fix but I have no idea about how C++ Works underneath So thats why i'm here now.
I have a header file with a Namespace, and inside of the namespace is a Struct with a few methods:
Code:
#pragma once
#include <iostream>
#include <Windows.h>
namespace IM {
// Movement Controls ------------//
const int MoveUp = VK_UP; //-//
const int MoveDown = VK_DOWN; //
const int MoveLeft = VK_LEFT; //
const int MoveRight = VK_RIGHT; //
//-------------------------------//
// Tekken Styled Action Buttons -//
const int LeftPunch = 0x41; //--//
const int RightPunch = 0x53; //--//
const int LeftKick = 0x5A; //--//
const int RightKick = 0x58; //--//
//-------------------------------//
// Start and Select. --------//
const int Start = 0x44; //
const int Select = 0x43; //
//---------------------------//
struct Instance {
bool KeyHeld(int keyCode);
bool KeyDown(int keyCode);
bool KeyUp(int keyCode);
};
}
Alongside this there is a .cpp file with the same name, Here's the code inside of it:
Code:
#include "InputManager.hpp"
using namespace IM;
bool Instance::KeyHeld(int KeyCode)
{
if (GetKeyState(KeyCode) & 0x8000) {
return true;
}
}
bool Instance::KeyDown(int KeyCode)
{
return true;
}
bool Instance::KeyUp(int KeyCode)
{
return true;
}
And My main.cpp file looks as such:
Code:
#include "InputManager.hpp"
int main()
{
IM::Instance InputManager;
while (1) {
if (InputManager.KeyHeld(IM::Start)) {
std::cout << "Key Down." << std::endl;
}
}
}
This is the Output produced by Microsoft Compiler:
I'm using Visual Studio Code with C++ Extensions. Heres how the build.bat file looks like:
Code:
@echo off
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86
) else (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
)
set compilerflags=/Od /Zi /EHsc /std:c++latest /I include
set linkerflags=/OUT:bin\main.exe
cl.exe %compilerflags% src\*.cpp /link %linkerflags%
del bin\*.ilk *.obj *.pdb