In your GameWorld.cpp file on line 67 you define a function void player(Player*player) inside void GameWorld::Move() and this is not allowed. Try adding and } on line 65 should solve this problem.
Thanks for your feedback, I did as you said. I now have the errors that my x and y have a undeclared identifier, along with my getMonsterx (and y) and all my moveUp, moveDown etc are undefined. I tried to define them myself but i cant seem to get it to work. Would i have to put the definitions in my .h files? if so please help me get them in the right place. Thanks.
Trouble with Identifier not Found 'moveUp' and Intellisense expected ';' errors.
Hi all,
I'm currently working on a project and i have found myself stuck. I am aware that I need to make an identifier to fix one of those errors but I can seem to make it in the right place (or make it right at all. Also i have checked my ';'s and i cant seem to find where they need to be. I'm sorry if you find my code confusing as i'm still a beginner. I hope you are able to guide me in the right direction.
#include <iostream>
#include "GameWorld.h"
#include <windows.h>
#include "Vector2.h"
#include "Monster.h"
usingnamespace std;
int option; //allowing the user to exit the menu and begin the game
//-----GAME MENU-------
void GameWorld::menu(){
Vector2 vec; //calling the Vector2 func
vec.SetX(1); // Setting the X Values of the player
vec.SetY(1); // Setting the Y Values of the player
system("cls");
cout << "Computer Games Development AS1" << endl; //Title
cout << "" << endl;
cout << "Your Starting X,Y Coordinates Are:" << endl; //Starting Coordinates Displayed To Player
cout << "" << endl;
cout << "X = " << vec.GetX() << endl; //vector get function to display the X,Y coordanites
cout << "" << endl;
cout << "Y = " << vec.GetY() << endl;
cout << "" << endl;
cout << "Press 1 and Enter to Start The Game" << endl; //Option funtion to exit the menu and begin the game
cout << "" << endl;
cin >> option;
system("PAUSE");
}
void GameWorld::Move(){
///----------------------------ADD IF OPTION -------------------------
cout << "Your current X and Y Coordinates are:" << endl;
cout << "" << endl;
cout << "" << endl;
char map[10][11] = {
"##########",
"# #",
"#--- #",
"# #",
"# ---#",
"# #",
"#--- #",
"# #",
"# #",
"##########"
};
void player(Player*player){
char direction; //Stores user input
cin >> direction; //Get's user input
switch (direction) {
case'a': moveLeft(player);
case'A':
break;
case'd': moveRight(player);
case'D':
break;
case'w': moveUp(player);
case'W':
break;
case's': moveDown(player);
case'S':
break;
}
}
}
//----MONSTER-------
void Monster::monster(){
if (x == 0) { x++; } //Monster will spawned within x - 0 to 11
if (x == 11){ x--; }
int getMonsterX(){ return x; }
if (x == 0) { y++; } //Monster will spawned within y - 0 to 11
if (x == 11){ y--; }
int getMonsterX(){ return y; }
//Monster(int playX, int playY){ x = playX; y = playY; } --------FIX
};
//----CLEAN UP-------
void GameWorld::cleanup(){
std::cout << "Game Is Now Closing" << std::endl; //cout statement for game closing
}
#pragma once
class GameWorld{
private:
public:
GameWorld(int x, int y);
~GameWorld();
bool active = true;
int x = 1;
int y = 1;
void Move();
void init();
void menu();
void gameLoop();
void cleanup();
};
You have defined the functions as member functions of the Player class so you need to specify which Player object you want to call the function on.
player->moveUp(player);
You probably should decide if you want it to be a member function or if you want to pass the player as argument. Doing both seems a bit redundant.
member function
1 2 3 4 5 6 7 8
// Inside the Player class.
void moveUp()
{
setX(getPlayerX() - 1);
}
// When calling the function.
player->moveUp();
non-member function
1 2 3 4 5 6 7 8
// Outside the Player class.
void moveUp(Player* player)
{
player->setX(player->getPlayerX() - 1);
}
// When calling the function.
moveUp(player);
By the way, haven't you mixed up X and Y? Normally the Y-coordinate is the one that should be changed when moving up and down.