Aloha all. I'm quite new to C++ programming.
I've been asked to make a demo app - a dungeon RPG with characters for graphics.
I decided to draw the map in notepad and use fstream in C++ to read from the file and draw the map. I will then draw the player into the world (as the letter 'x' to start with) and set the controls to the arrow keys to move the character around. The collision detection will work on detecting what type of character occupies the space you are trying to move to, | and _ for doors, # for walls and a space for open floor etc.
I've run into the problem of placing the player in the map:
dungeonseeker.cpp
Code:
#include <iostream>
#include <string> //This allows creation and manipulation of strings.
#include <fstream> //This allows opening and reading of files.
#include <process> //This allows the use of system("cls");
using namespace std;
//This is the function that will open the map file
//and draw it into the console
void drawMap()
{
//Open the map file for reading
ifstream mapfile("map.ds");
//Store each line of the file in a string to be displayed
string line;
if (mapfile.is_open())
{
//Read from the file until the end is reached
while (! mapfile.eof())
{
//Read each line and output it to the screen.
//This will loop through each line until there
//are no lines left to read.
getline(mapfile, line);
cout << line << endl;
}
mapfile.close();
}
}
//Set the starting location of the player
void initPlayer()
{
//0,0 is at the top left of the map file.
//Positive X values move horizontally right,
//Positive Y values move vertically down.
int x = 15;
int y = 5;
}
int main()
{
//Location variables (link with initPlayer and controlPlayer)?
//int x, y;
//Clear the screen ready for the game
system("cls");
//Draw the map
drawMap();
//Position the player
initPlayer();
return 0;
}
I can't seem to attach the map file
As you can see, I've initialised two integers (x and y) to hold the co-ords of the start position but I cannot think of how to place a character at a position on the screen relating to these values. Any suggestions?