I'm pretty new to writting c++ and i made this file to create a random x and y coordinate and place a bitmap image upon it, i made the program save the coordinates to .dat files *or txt i dont really care at this point* now i want a way of reading these coordinates one line at a time (or any way to write a valid x == x_taken function) and applying them to a string called x/y_taken so i can make sure i dont place a bitmap in the same spot twice, heres my code (keep in mind its a sloppy rough draft, and any help would be greatly appreciated):
#include <allegro>
#include <fstream>
#include <iostream>
using namespce std;
//--------------------------------------variables-------------------------------------------
BITMAP *human_upSprite;
BITMAP *human_downSprite; // human bitmaps.
BITMAP *human_leftSprite;
BITMAP *human_rightSprite;
BITMAP *zombie_downSprite;
BITMAP *zombie_upSprite; // zombie bitmaps.
BITMAP *zombie_rightSprite;
BITMAP *zombie_leftSprite;
BITMAP *hero_downSprite;
BITMAP *hero_upSprite; //hero bitmaps.
BITMAP *hero_leftSprite;
BITMAP *hero_rightSprite;
//-----------------------------random coor functions-----------------------------------------
int random_x_unit(x)
{
rand() % 640 + 1 = x;
ofstream a_file ("x_coor.dat");
a_file( x, ios::app );
a_file.close();
return(x)'
};
int random_y_unit(y)
{
rand() % 420 + 1 = y;
ofstream a_file ("y_coor.dat");
a_file( y, ios::app );
a_file.close();
return(y);
};
//------------------------------------------------------------------------------------
void spawn_human() //try to find a way to make a parameter that calls the function
{ //x amount of times so you dont have to spam spawn_human().
int x;
int y;
string x_taken; // calls a string that will be used to apply the file to.
string y_taken;
//------------------------------X------------------------------------------------
random_x_unit(x);
ifstream b_file("x_coor.dat");
b_file>> x_taken;
if(x_taken == x)
spawn_human();
else
ofstream a_file("\n", ios::ate); //hopefully creats a newline and sets to end for
// reading next coor
a_file.close(); //without deleting anything.
random_y_unit(y);
//--------------------------------y--------------------------------------------------
ifstream b_file("y_coor.dat");
bfile>> y_taken;
if(y_taken == y)
spawn_human();
else
ofstream a_file("\n", ios::ate);
a_file.close();
//-----------------------------ENDING----------------------------------------------
{
humandSprite = load_bitmap( "human_downSprite.bmp", NULL );
draw_sprite( buffer, humandSprite, x, y);
};
};