Okay so for my beginners c++ class we have to make game for our final project. The game is a simple shooter type game with ascii chars and stuff for the player and the enemy. We covered up to 2d arrays in class and then the teacher gave us the assignment and tasked us with figuring it out ourselves.
So far i have the game board, the player and the enemy. Well the enemy doesn't move around yet still trying to figure out the movement for the player. I'm completely lost on how to code it so you can move around the board. I have it set so that you type w to move up, d for right, a for left and s for down. I can get the first initial movement to work about after that it leaves the original player character in place and moves in a diagonal line.
Any tips would be greatly for the movement would be greatly appreciated. :)
This is my code so far:
#include <cstdlib>
#include <iostream>
using namespace std;
const int SIZE = 23;
const char UP = 30;
const char DOWN = 31;
const char LEFT = 17;
const char RIGHT = 16;
const char ENEMY = 'X';
const char BULLET = 7;
void printmap(char [][SIZE], int);
void loadmap(char [][SIZE], int);
int main(int argc, char *argv[])
{
char move;
char numbers[SIZE][SIZE];
loadmap(numbers, SIZE);
printmap(numbers, SIZE);
system("CLS");
numbers[1][1] = RIGHT;
numbers[21][21] = ENEMY;
printmap(numbers, SIZE);
for(int i = 1; i < 5; i++)
{
cin >> move;
switch(move)
{
case 'w': system("CLS");
numbers[i-1][i] = UP;
printmap(numbers, SIZE);
break;
case 'a': system("CLS");
numbers[i][i-1] = LEFT;
printmap(numbers, SIZE);
break;
case 's': system("CLS");
numbers[i+1][i] = DOWN;
printmap(numbers, SIZE);
break;
case 'd': system("CLS");
numbers[i][i+1] = RIGHT;
numbers[i][i] = 0;
printmap(numbers, SIZE);
break;
case 'r':
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void printmap(char inArray[][SIZE], int S)
{
for(int r = 0; r < S; r++)
{
for(int c = 0; c < S; c++)
{
//total grid
cout << inArray[r][c];
}
cout << endl;
}
}
void loadmap(char inArray[][SIZE], int S)
{
for(int r = 0; r < S; r++)
{
for(int c = 0; c < S; c++)
{
//inside space
inArray[r][c] = 0;
}
}
for(int r = 1; r < S-1; r++)
{
for(int c = 1; c < S-1; c++)
{
//top and bottom
inArray[0][c] = 205;
inArray[S-1][c] = 205;
}
}
for(int r = 1; r < S-1; r++)
{
for(int c = 1; c < S-1; c++)
{
//left and right side
inArray[r][0] = 186;
inArray[r][S-1] = 186;
}
}
//corners
inArray[0][0] = 201;
inArray[S-1][S-1] = 188;
inArray[0][S-1] = 187;
inArray[S-1][0] = 200;
}
The const UP, DOWN, LEFT, AND RIGHT are the facing directions of the player.