Jump to content
  • Advertisement
Sign in to follow this  
BennettSteele

C++ std::ifstream cant open files that are there

This topic is 2642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i moved some of my game code into a new project, so i can use OpenGL instead of SDL, and now when im using std::ifstream's, they cant find the files that i know 100% are there and spelled right. i might have not linked the librarys right or something, im using code::blocks so... i dont know... here is the active code:

LoadImage.h:



#ifndef LOADIMAGE_H_INCLUDED
#define LOADIMAGE_H_INCLUDED

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/SOIL.h>
GLuint GetTexture(std::string Filename)
{
GLuint tex_ID =0;
tex_ID= SOIL_load_OGL_texture
(
Filename.c_str(),
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
return tex_ID;
}

#endif // LOADIMAGE_H_INCLUDED


File.h:

#ifndef FILE_H_INCLUDED
#define FILE_H_INCLUDED

class File
{
public:
bool Opened;
std::ofstream OutFile;
std::ifstream InFile;
void Close();
void Write(const char* Write);
std::string Read();
void Flush();
void Open(const char* Dest);
};

void File::Open(const char* Dest)
{
File::Opened=true;
File::OutFile.open(Dest);
File::InFile.open(Dest);
}

void File::Write(const char* stuff)
{
if(File::Opened)
{
File::OutFile<<stuff;
}
}

std::string File::Read()
{
std::stringstream Buf;
if(File::Opened)
{
Buf<<File::InFile.rdbuf();
}
if(File::Opened==false){Buf<<"FAIL";}
std::string Ret(Buf.str());
return Ret;
}

void File::Close()
{
File::Opened=false;
File::OutFile.close();
File::InFile.close();
}

void File::Flush()
{
File::OutFile.flush();
}
#endif // FILE_H_INCLUDED


App.h:

#ifndef APP_H_INCLUDED
#define APP_H_INCLUDED

class myApp
{
public:
bool isRunning,inGame,Playing,MusicOn;

long GlobalTime;
int Seconds,Minutes,Hours;

bool Focus,Fullscreen;
int Screenw,Screenh;
int ScreenwMAX,ScreenhMAX;

bool ConsoleOpen;

bool Connected;

std::string whatTyping;
bool Typing;
void FinnishedTyping();
std::string TypingFor;

// TextToDraw Version;

bool left,right,up,down;

int MouseX,MouseY;
int LMouseXPressed,LMouseYPressed,RMouseXPressed,RMouseYPressed;
bool LMouseDown,RMouseDown;
int Scroll;
bool Shift;
// TextToDraw ShowWhatTyping;
File Log;
File KeyLog;
File ServerLog;
File ChatLog;
File WorldLog;

std::string MAPNAME;
std::string PROFILENAME;//_mkdir("stuff/test");
bool ALLOWEDIT,ALLOWCOMMANDS;
int NUMBEROFTILES;
std::string Texturepack;
unsigned int FPS;
int FRAME_TIME;
int HOLD;
int MAXSIGHT;
int BPP;
float PLAYERSPEED;
int NUMAI,BULLETS;

bool keycheck;
void Logic();

void Init(std::string Test);
};

void myApp::Init(std::string Test)
{
myApp::isRunning=true;
myApp::Playing=true;
myApp::GlobalTime=0;
myApp::Seconds=0;
myApp::Minutes=0;
myApp::Hours=0;
myApp::Fullscreen=false;
myApp::Connected=false;
//myApp::Screenw=640;
//myApp::Screenh=480;
myApp::Focus=true;
myApp::ConsoleOpen=false;
myApp::whatTyping="";
myApp::TypingFor="";
// myApp::ShowWhatTyping.Write(myApp::whatTyping);
// myApp::ShowWhatTyping.SetPos(5,8);
myApp::Typing=false;
myApp::MouseX=0;
myApp::MouseY=0;
myApp::LMouseDown=false;
myApp::RMouseDown=false;
myApp::LMouseXPressed=-1;
myApp::LMouseYPressed=-1;
myApp::RMouseXPressed=-1;
myApp::RMouseYPressed=-1;
myApp::Scroll=0;
myApp::Shift=false;


myApp::Log.Open("stuff/data/log.txt");
myApp::KeyLog.Open("stuff/data/keylog.txt");
myApp::ServerLog.Open("stuff/data/serverlog.txt");
myApp::ChatLog.Open("stuff/data/chatlog.txt");
myApp::WorldLog.Open("stuff/data/worldlog.txt");

std::string OpsReport="LOADED OPS: ";
bool OpsFailed=false;

if(std::ifstream("stuff/data/ops.txt"))
{
std::ifstream GetOps;GetOps.open("stuff/data/ops.txt");
std::stringstream NewOps;NewOps<<GetOps.rdbuf();
std::string Ops=NewOps.str();
unsigned int At=-1;

for(int WhatIsIt=0;WhatIsIt<5;WhatIsIt++)
{
std::stringstream Buffer;
bool Searching=true;
while(Searching)
{
At++;
if(At>=Ops.length()){Searching=false;WhatIsIt=4;OpsReport+="NO MORE OPS CHARS AVAILABLE TO LOAD\n";OpsFailed=true;}
else if(Ops[At]=='|')
{
std::string FoundInfo=Buffer.str();
switch(WhatIsIt)
{
case 0:
OpsReport+="EDIT= ";
if(FoundInfo=="passwordforallowingediting"){myApp::ALLOWEDIT=true;OpsReport+="TRUE, DEV COMMANDS= ";}
else{myApp::ALLOWEDIT=false;OpsReport+="FALSE, TEXTURE PACK= ";}
break;
case 1:
if(FoundInfo=="passwordforallowingcommands"){myApp::ALLOWCOMMANDS=true;OpsReport+="TRUE, TEXTURE PACK= ";}
else{myApp::ALLOWCOMMANDS=false;OpsReport+="FALSE, TEXTURE PACK= ";}
break;
case 2:
if(std::ifstream(("stuff/tiles/"+FoundInfo+".bmp").c_str())){myApp::Texturepack=FoundInfo;OpsReport+=FoundInfo+", FPS= ";}
else{myApp::Texturepack="normalTP";OpsReport+="DEFAULT, FPS= ";}
break;
case 3:
myApp::FPS=atoi(FoundInfo.c_str());OpsReport+=FoundInfo+", MUSIC ON= ";
break;//should be 60
case 4:
if(atoi(FoundInfo.c_str())==0){myApp::MusicOn=false;OpsReport+="FALSE";}
else{myApp::MusicOn=true;OpsReport+="TRUE";}
OpsReport+="\n";
break;
default:break;
}
Searching=false;
}
else{Buffer<<Ops[At];}
}
}
}
if(OpsFailed || !std::ifstream("stuff/data/ops.txt"))
{
OpsReport+="OPS COULD NOT BE LOADED\n";
myApp::ALLOWEDIT=false;
myApp::ALLOWCOMMANDS=false;
myApp::Texturepack="normalTP";
myApp::FPS=60;
myApp::MusicOn=true;
}
myApp::Log.Write(OpsReport.c_str());

if(!std::ifstream("stuff/data/version.txt")){myApp::Log.Write("NO VERSION FILE FOUND\n");}//exit(EXIT_FAILURE);}
std::ifstream GetVersion;GetVersion.open("stuff/data/version.txt");
std::stringstream NewVersion;NewVersion<<"Version: ";NewVersion<<GetVersion.rdbuf();NewVersion<<"/";
// myApp::Version.Write(NewVersion.str());

myApp::MAPNAME="TestMap";
myApp::NUMBEROFTILES=255;
myApp::MAXSIGHT=30;
myApp::BPP=32;
myApp::FRAME_TIME=1000/myApp::FPS;
myApp::PLAYERSPEED=0.1;
myApp::HOLD=1200;
myApp::NUMAI=20;
myApp::BULLETS=10;

std::ifstream Lol;Lol.open("stuff/lol.bmp",std::fstream::binary);
std::stringstream Lolol;Lolol<<Lol.rdbuf()<<Test;

std::ofstream loling;loling.open("stuff/data/Log.txt");loling<<std::endl;
if(!loling.is_open()){exit(1);}//<------------------------------------------------------------------This is how i found out it couldnt open files
loling.close();
}

void myApp::FinnishedTyping()
{
myApp::Typing=false;
myApp::whatTyping="";
// myApp::ShowWhatTyping.Write("/");
}
#endif // APP_H_INCLUDED


GameLogic.h:

#ifndef GAMELOGIC_H_INCLUDED
#define GAMELOGIC_H_INCLUDED

void GameLogic()
{
APP.Log.Flush();
APP.KeyLog.Flush();
// if(APP.Screenw!=screen->w){APP.Screenw=screen->w;}
// if(APP.Screenh!=screen->h){APP.Screenh=screen->h;Game.Sheet=BodyTan;}
Game.Second++;
Game.AnimElasped++;
Game.InfoTimer++;
Game.UseTimer++;
// GlobalMusic.DoNow();
if(Game.InfoTimer>=500){Game.NewInfo();}
//if(Game.AllowEdit==true)
//{
Game.SpawnZombieTimer++;
Game.ChatBump++;
// if(Game.AnimElasped>burn.MyAnim.Speed){burn.MyAnim.Next();Game.AnimElasped=0;}//UPDATE ANIMATIONS
if(Game.Second>=60){Game.Minute++;Game.Second=0;}
if(Game.Minute>=60){Game.Hour++;Game.Minute=0;}
if(Game.Hour>=24){Game.Hour=0;}
// if(Game.ChatBump>=7){Chatty.Bump();Game.ChatBump=0;APP.Log.Write("CHAT LOG BUMPED\n");}
// if(Game.SpawnZombieTimer==100){SpawnZombies();}
// for(int n=0;n<ZOMBIES;n++){Zombies[n].DoNow();}
// for(int n=0;n<TOWNFOLK;n++){TownFolk[n].DoNow();}
/* for(int b=0;b<APP.BULLETS;b++)
{
Game.ActiveBullets.inx+=Game.ActiveBullets.velox;
Game.ActiveBullets.iny+=Game.ActiveBullets.veloy;
if(Game.ActiveBullets.inx>=1)
{
while(Game.ActiveBullets.inx>=1){Game.ActiveBullets.inx-=1;Game.ActiveBullets.x++;}
}
else if(Game.ActiveBullets.inx<0)
{
while(Game.ActiveBullets.inx<0){Game.ActiveBullets.inx+=0.9;Game.ActiveBullets.x--;}
}

if(Game.ActiveBullets.iny>=1)
{
while(Game.ActiveBullets.iny>=1){Game.ActiveBullets.iny-=1;Game.ActiveBullets.y++;}
}
else if(Game.ActiveBullets.iny<0)
{
while(Game.ActiveBullets.iny<0){Game.ActiveBullets.iny+=0.9;Game.ActiveBullets.y--;}
}
if(Game.ActiveBullets.x>300 || Game.ActiveBullets.x<0 || Game.ActiveBullets.y>300 || Game.ActiveBullets.y<0)
{
Game.ActiveBullets.active=false;
}
}*/

// if(Game.Myinx<0){Game.myX--;Game.Myinx=1;}else if(Game.Myinx>1){Game.myX++;Game.Myinx=0;}
// if(Game.Myiny<0){Game.myY--;Game.Myiny=1;}else if(Game.Myiny>1){Game.myY++;Game.Myiny=0;}
bool PlayWalk=false;
int Goingx=0,Goingy=0;
if(APP.left==true){Game.Move_Camera(0.01);}//.myX++;Goingx-=1;}
if(APP.right==true){Game.Move_Camera(-0.01);}//Game.myX--;Goingx+=1;}
if(APP.up==true){Game.Move_Camera(0.01);}//Game.myZ++;Goingy-=1;}
if(APP.down==true){Game.Move_Camera(-0.01);}//Game.myZ--;Goingy+=1;}

// POINT Where=MoveHere(Game.myX,Game.myY,Game.Myinx,Game.Myiny,Goingx,Goingy);

// if(Where.x!=0){Game.Myinx+=Goingx*Game.Speed;PlayWalk=true;Game.Looking.x=Goingx;}
// if(Where.y!=0){Game.Myiny+=Goingy*Game.Speed;PlayWalk=true;Game.Looking.y=Goingy;}

/*if ( APP.left == true && MoveHors(Game.myX,-1,Game.Myinx,Game.myY) && Game.myX>0){Game.Myinx-=Game.Speed;PlayWalk=true;Game.Looking.x=-1;} //Move left
else if ( APP.right == true && MoveHors(Game.myX,1,Game.Myinx,Game.myY) && Game.myX<SIZEOFMAP){Game.Myinx+=Game.Speed;PlayWalk=true;Game.Looking.x=1;} //Move right
if ( APP.up == true && MoveVert(Game.myY,-1,Game.Myiny,Game.myX) && Game.myY>0){Game.Myiny-=Game.Speed;PlayWalk=true;Game.Looking.y=-1;} //Move up
else if ( APP.down == true && MoveVert(Game.myY,1,Game.Myiny,Game.myX) && Game.myY<SIZEOFMAP){Game.Myiny+=Game.Speed;PlayWalk=true;Game.Looking.y=1;} //Move down
*/

/* if(APP.Scroll>0 && Game.ItemHotSel>0){APP.Scroll=0;Game.ItemHotSel--;APP.Log.Write("HIGHER ITEM\n");Mix_PlayChannel(HUDChannel,change_tile,0);}
if(APP.Scroll<0 && Game.ItemHotSel<2){APP.Scroll=0;Game.ItemHotSel++;APP.Log.Write("LOWER ITEM\n");Mix_PlayChannel(HUDChannel,change_tile,0);}
if(APP.LMouseDown && Game.UseTimer>30){Game.UseItem();}

for(int c=0;c<Game.NumcheckpToShow;c++)
{
if(Game.myX==Game.Checkpoints[c].x && Game.myY==Game.Checkpoints[c].y){Game.HitCheckpoint(c);}
}

Game.WalkTimer++;
unsigned int NextWalk=10+rand()%10;
if(PlayWalk && Game.WalkTimer>=NextWalk){Mix_PlayChannel(HUDChannel,TileToWalkSound(myMap.Environment[Game.myY][Game.myX]),0);Game.WalkTimer=0;}

for(int c=0;c<Game.NumcheckpToShow;c++)
{
if(Game.Checkpoints[c].x==Game.myX && Game.Checkpoints[c].y==Game.myY)
{
Game.HitCheckpoint(c);
}
}
if(Game.Looking.x!=0 || Game.Looking.y!=0){Game.Apperance=LookToBody(Game.Looking.x,Game.Looking.y,Game.Sheet);}
}



if(Game.AllowEdit)
{
if ( APP.left == true && Game.myX>0){Game.myX--;} //Move left
if ( APP.right == true && Game.myX<SIZEOFMAP){Game.myX++;} //Move right
if ( APP.up == true && Game.myY>0){Game.myY--;} //Move up
if ( APP.down == true && Game.myY<SIZEOFMAP){Game.myY++;} //Move down
if(APP.Scroll<0 && Game.TileUsing>-29 && Game.HoldingTile==false){APP.Scroll=0;Game.TileUsing--;APP.Log.Write("LOWER TILE\n");Mix_PlayChannel(HUDChannel,change_tile,0);}
if(APP.Scroll>0 && Game.TileUsing<APP.NUMBEROFTILES && Game.HoldingTile==false){APP.Scroll=0;Game.TileUsing++;APP.Log.Write("HIGHER TILE\n");Mix_PlayChannel(HUDChannel,change_tile,0);}
Game.EditTileAt.x=(APP.MouseX-APP.Screenw/2)/16+Game.myX;
Game.EditTileAt.y=(APP.MouseY-APP.Screenh/2)/16+Game.myY;
if(APP.LMouseDown)
{
std::stringstream Report;
int newx=(APP.LMouseXPressed-APP.Screenw/2)/16+Game.myX,newy=(APP.LMouseYPressed-APP.Screenh/2)/16+Game.myY;
if(newx<SIZEOFMAP && newx>=0 && newy<SIZEOFMAP && newy>=0 && Game.HoldingTile==false)
{
myMap.Point(newx,newy,Game.TileUsing);
Report<<"PLACED TILE AT:X="<<newx<<",Y="<<newy<<"\n";
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
else if(Game.HoldingTile==false)
{
Report<<"CANNOT PLACE TILE AT:X="<<newx<<",Y="<<newy<<"\n";
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
else if(Game.HoldingTile)
{
Game.HoldingTile=false;
APP.RMouseDown=false;
APP.LMouseDown=false;
}
}
if(APP.RMouseDown)
{
std::stringstream Report;
int newx=(APP.RMouseXPressed-APP.Screenw/2)/16+Game.myX,newy=(APP.RMouseYPressed-APP.Screenh/2)/16+Game.myY;
if(newx<SIZEOFMAP && newx>=0 && newy<SIZEOFMAP && newy>=0 && Game.HoldingTile==false)
{
Game.HoldingTile=true;
Game.EditHoldx=newx;
Game.EditHoldy=newy;
Report<<"STARTING BOX AT:X="<<newx<<",Y="<<newy<<"\n";
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
else
{
Report<<"CANNOT PLACE TILE AT:X="<<newx<<",Y="<<newy<<"\n";
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
}
if(APP.RMouseDown==false && Game.HoldingTile)
{
std::stringstream Report;
int newx=(APP.RMouseXPressed-APP.Screenw/2)/16+Game.myX,newy=(APP.RMouseYPressed-APP.Screenh/2)/16+Game.myY;
if(newx<SIZEOFMAP && newx>=0 && newy<SIZEOFMAP && newy>=0)
{
Game.HoldingTile=false;
myMap.Box(Game.EditHoldx,Game.EditHoldy,newx-Game.EditHoldx,newy-Game.EditHoldy,Game.TileUsing);
Report<<"ENDED BOX AT:X="<<newx<<",Y="<<newy<<"\n";
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
else
{
Game.HoldingTile=false;
Report<<"COULDNT END BOX AT:X="<<newx<<",Y="<<newy<<", SO IT ENDED AT: X=";
if(newx<0){newx=0;}else if(newx>=SIZEOFMAP){newx=SIZEOFMAP;}
if(newy<0){newy=0;}else if(newy>=SIZEOFMAP){newy=SIZEOFMAP;}
Report<<newx<<", Y="<<newy<<"\n";
myMap.Box(Game.EditHoldx,Game.EditHoldy,newx-Game.EditHoldx,newy-Game.EditHoldy,Game.TileUsing);
std::string NewLog=Report.str();
APP.Log.Write(NewLog.c_str());
}
}
}
APP.Scroll=0;*/

}

#endif // GAMELOGIC_H_INCLUDED



GameDraw.h:

#ifndef GAMEDRAW_H_INCLUDED
#define GAMEDRAW_H_INCLUDED

void GameDraw(void)
{
Mouse_Move(640,480);
GameLogic();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0.7,0.7,0.9,0);
gluLookAt(Game.mPos.x,Game.mPos.y,Game.mPos.z,Game.mView.x,Game.mView.y,Game.mView.z,Game.mUp.x,Game.mUp.y,Game.mUp.z);
for(int n=0;n<5;n++)
{
DrawCube(10+n+n*0.2+Game.myX*0.01,Game.myY,Game.myZ*0.01,n*0.2,n*0.2,n*0.2,n*0.2);
}


/*for(int x=0;x<SIZEOFMAP/50;x++){for(int y=0;y<SIZEOFMAP/50;y++){for(int z=0;z<SIZEOFMAP/50;z++){
int newBlock=myMap.Environment[x][y][z];
if(newBlock){DrawCube(x+Game.myX*0.01,y+Game.myY*0.01,z+Game.myZ*0.01,rand()*0.00003,rand()*0.00003,rand()*0.00003,0);}
}}}*/

glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D,tex_t);

glBegin(GL_QUADS);
glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f( 1.0f, 1.0f,-1.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f,-1.0f);
glEnd();
//for(int o=0;0<1;o++)
//{
// Obs[o].Draw(o+o*0.2,0,10);
//}

glFlush();
// const int ScreenW=screen->w,ScreenH=screen->h;
// SDL_FillRect(SDL_GetVideoSurface(),NULL,SDL_MapRGB(SDL_GetVideoSurface()->format,0,0,0));

/* int MAXx=(ScreenW/16)+2,MAXy=(ScreenH/16)+2;
for (int y=0;y<MAXy;y++){for(int x=0;x<MAXx;x++)
{
if(Game.myX+x-MAXx/2>=0 && Game.myX+x-MAXx/2<SIZEOFMAP && Game.myY+y-MAXy/2>=0 && Game.myY+y-MAXy/2<SIZEOFMAP)
{
int newblock=myMap.Environment[Game.myY+y-MAXy/2][Game.myX+x-MAXx/2];
ApplySurface(-8+Game.Myinx*-16+x*16,-8+Game.Myiny*-16+y*16,IntToTile(newblock),screen);
if(TileToCollision(newblock)!=0 && Game.AllowEdit){ApplySurface(-8+Game.Myinx*-16+x*16,-8+Game.Myiny*-16+y*16,Hitbox,screen);}
if(TileToCollision(newblock)!=0 && newblock!=1 && Game.AllowEdit==false){ApplySurface(-8+Game.Myinx*-16+x*16,Game.Myiny*-16+y*16,IntToObj(newblock),screen);}
}
}}


for(int b=0;b<APP.BULLETS;b++)
{
if(Game.ActiveBullets.active){ApplySurface(ScreenW/2+Game.ActiveBullets.x*16+Game.ActiveBullets.inx*16-Game.myX*16-Game.Myinx*16,ScreenH/2+Game.ActiveBullets.y*16+Game.ActiveBullets.iny*16-Game.myY*16-Game.Myiny*16,BulletShow,screen);}
}


for(int n=0;n<ZOMBIES;n++)
{
ApplySurface(ScreenW/2-8-Game.myX*16-Game.Myinx*16+Zombies[n].myX*16+Zombies[n].inx*16,ScreenH/2-8-Game.myY*16-Game.Myiny*16+Zombies[n].myY*16+Zombies[n].iny*16,Zombies[n].Apperance,screen);
if(Zombies[n].isBurning){ApplySurface(ScreenW/2-8-Zombies[n].myX*-16-Game.myX*16-Game.Myinx*16,ScreenH/2-8-Zombies[n].myY*-16-Game.myY*16-Game.Myiny*16,burn.MyAnim.Reel[burn.MyAnim.At],screen);}
}
for(int n=0;n<TOWNFOLK;n++)
{
ApplySurface(ScreenW/2-8-TownFolk[n].myX+TownFolk[n].inx*-16-Game.myX*16-Game.Myinx*16,ScreenH/2-8-TownFolk[n].myY+TownFolk[n].iny*-16-Game.myY*16-Game.Myiny*16,TownFolk[n].Apperance,screen);
if(TownFolk[n].isBurning){ApplySurface(ScreenW/2-8-TownFolk[n].myX*-16-Game.myX*16-Game.Myinx*16,ScreenH/2-8-TownFolk[n].myY*-16-Game.myY*16-Game.Myiny*16,burn.MyAnim.Reel[burn.MyAnim.At],screen);}
}


if(Game.AllowEdit==false)
{
ApplySurface(ScreenW-640,ScreenH/2-240,RSidebar,screen);
ApplySurface(0,ScreenH-480,screenchatbar,screen);
ApplySurface(ScreenW-640,ScreenH-480,screentoolboxbar,screen);
ApplySurface(ScreenW-80+(Game.ItemHotSel*28),ScreenH-44,Pointer,screen);
for(int i=0;i<3;i++)
{
ApplySurface(ScreenW-80+(i*28),ScreenH-22,ItemIDToImage(Game.myStuff.Hotbar.ID,2,Game.myStuff.Hotbar.Type),screen);
}
for(int n=0;n<APP.Version.Size;n++)
{
ApplySurface(ScreenW-340+n*APP.Version.Spacing,ScreenH-20,CharToText(APP.Version.Text[n]),screen);
}
ApplySurface(ScreenW-28,ScreenH/2-209,Healthbar,screen);
ApplySurface(ScreenW-25,ScreenH/2-36-IntToBarPos(Game.Health),BarTick,screen);//+206/Game.Health//-36-206
ApplySurface(ScreenW-28,ScreenH/2+17,Energybar,screen);
ApplySurface(ScreenW-25,ScreenH/2+20+IntToBarPos(Game.Energy),BarTick,screen);//-206/Game.Energy//+20+190
for(int n=0;n<Game.NumcheckpToShow;n++)
{
float Chkx=Game.Checkpoints[n].x*16+ScreenW/2-8-Game.myX*16-Game.Myinx*16;
float Chky=Game.Checkpoints[n].y*16+ScreenH/2-8-Game.myY*16-Game.Myiny*16;
if(Chkx<0){Chkx=0;}else if(Chkx>ScreenW-22){Chkx=ScreenW-22;}
if(Chky<0){Chky=0;}else if(Chky>ScreenH-22){Chky=ScreenH-22;}
ApplySurface(Chkx,Chky,BarTick,screen);
}

}
else if(Game.AllowEdit==true)
{
if(APP.RMouseDown)
{
int newx=(APP.RMouseXPressed-APP.Screenw/2)/16+Game.myX,newy=(APP.RMouseYPressed-APP.Screenh/2)/16+Game.myY;
int newSizex=abs(newx-Game.EditHoldx),newSizey=abs(newy-Game.EditHoldy);
int Dirx,Diry;
if(newx-Game.EditHoldx>0){Dirx=1;}else{Dirx=-1;}
if(newy-Game.EditHoldy>0){Diry=1;}else{Diry=-1;}
for (int sizey=0;sizey<newSizey+1;sizey++){for(int sizex=0;sizex<newSizex+1;sizex++)
{
if(Game.EditHoldx+(sizex*Dirx)>=0 && Game.EditHoldx+(sizex*Dirx)<SIZEOFMAP && Game.EditHoldy+(sizey*Diry)>=0 && Game.EditHoldy+(sizey*Diry)<SIZEOFMAP)
{
ApplySurface(ScreenW/2+Game.EditHoldx*16+(sizex*16*Dirx)-Game.myX*16-3,ScreenH/2+Game.EditHoldy*16+(sizey*16*Diry)-Game.myY*16+3,IntToTile(Game.TileUsing),screen);
if(TileToCollision(Game.TileUsing)!=0){ApplySurface(ScreenW/2+Game.EditHoldx*16+(sizex*16*Dirx)-Game.myX*16-3,ScreenH/2+Game.EditHoldy*16+(sizey*16*Diry)-Game.myY*16+3,Hitbox,screen);}
}
}}
}
ApplySurface(ScreenW-640,ScreenH/2-240,RSidebar,screen);
for(int tile=1;tile<=6;tile++)
{
if(Game.TileUsing-tile>=-29)
{
ApplySurface(ScreenW-24,ScreenH/2-tile*-30,IntToTile(Game.TileUsing-tile),screen);
if(TileToCollision(Game.TileUsing-tile)!=0){ApplySurface(ScreenW-24,ScreenH/2-tile*-30,Hitbox,screen);}
}
if(Game.TileUsing+tile<=APP.NUMBEROFTILES)
{
ApplySurface(ScreenW-24,ScreenH/2-16-tile*30,IntToTile(Game.TileUsing+tile),screen);
if(TileToCollision(Game.TileUsing+tile)!=0){ApplySurface(ScreenW-24,ScreenH/2-16-tile*30,Hitbox,screen);}
}
}
ApplySurface(ScreenW-24,ScreenH/2-8,IntToTile(Game.TileUsing),screen);
if(TileToCollision(Game.TileUsing)!=0){ApplySurface(ScreenW-24,ScreenH/2-8,Hitbox,screen);}
}


if(Game.ChatOpen)
{
ApplySurface(0,ScreenH-480,screenchatlog,screen);
for(int s=0;s<5;s++){for(int l=0;l<Chatty.Chat[s].Size;l++)//s=sentence, l=letter
{
ApplySurface(5+Chatty.Chat[s].x+l*Chatty.Chat[s].Spacing,ScreenH-50-Chatty.Chat[s].y*20-16*s,CharToText(Chatty.Chat[s].Text[l]),screen);
}}
}
ApplySurface(ScreenW/2-320,0,screentop,screen);
if(APP.Typing)
{
for(int a=0;a<APP.ShowWhatTyping.Size;a++)//s=sentence, l=letter
{
ApplySurface(ScreenW/2-(APP.ShowWhatTyping.Size/2)*10.5+APP.ShowWhatTyping.x+a*APP.ShowWhatTyping.Spacing,APP.ShowWhatTyping.y,CharToText(APP.ShowWhatTyping.Text[a]),screen);
}
}
else
{
for(int a=0;a<Game.InfoToDraw.Size;a++)//s=sentence, l=letter
{
ApplySurface(ScreenW/2-(Game.InfoToDraw.Size/2)*10.5+Game.InfoToDraw.x+a*Game.InfoToDraw.Spacing,Game.InfoToDraw.y,CharToText(Game.InfoToDraw.Text[a]),screen);
}
}

if(Game.AllowEdit==false)
{
ApplySurface(ScreenW/2,ScreenH/2,Game.Apperance,screen);
ApplySurface(APP.MouseX-8,APP.MouseY-8,cursor,screen);
}
else
{
ApplySurface(-8+(Game.EditTileAt.x-Game.myX)*16+ScreenW/2+5,-8+(Game.EditTileAt.y-Game.myY)*16+ScreenH/2+11,IntToTile(Game.TileUsing),screen);
if(TileToCollision(Game.TileUsing)!=0){ApplySurface(-8+(Game.EditTileAt.x-Game.myX)*16+ScreenW/2+5,-8+(Game.EditTileAt.y-Game.myY)*16+ScreenH/2+11,Hitbox,screen);}
ApplySurface(-8+ScreenW/2-8,-8+ScreenH/2-8,cursor,screen);
ApplySurface(-8+(Game.EditTileAt.x-Game.myX)*16+ScreenW/2+15,-8+(Game.EditTileAt.y-Game.myY)*16+ScreenH/2+18,editcursor,screen);
}
lastscreen=screen;
SDL_Flip(screen);*/
}

#endif // GAMEDRAW_H_INCLUDED


main.cpp:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <dir.h>
#include <time.h>
#include <math.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <windows.h>
#include <process.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/SOIL.h>
//#include "source/Bitmap.h"
#include "source/LoadImage.h"
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ CONSTANTS
const int SIZEOFMAP=300;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#include "source/Math.h"
#include "source/File.h"
#include "source/DrawCube.h"
//#include "source/Part.h"
//#include "source/Object.h"
//Object Obs[2];
#include "source/App.h"
myApp APP;
//#include "source/Map.h"
//Map myMap("lol");
#include "source/GameStats.h"
GameStats Game;
#include "source/KeyPresses.h"
#include "source/GameLogic.h"

GLuint tex_t;
#include "source/GameDraw.h"
const int IMAGE_ROWS=64,IMAGE_COLS=64;
GLubyte imageData[IMAGE_ROWS][IMAGE_COLS][3]; // Texture image data

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST | GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
Game.Position_Camera(0,2.5f,5,0, 2.5f,0,0,1,0);
glGenTextures( 1, &tex_t );
tex_t=GetTexture("stuff/trv.png");
glBindTexture(GL_TEXTURE_2D, tex_t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, IMAGE_ROWS, IMAGE_COLS, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)tex_t);


int value;
for (int row = 0; row < IMAGE_ROWS; row++) {
for (int col = 0; col < IMAGE_COLS; col++) {
// Each cell is 8x8, value is 0 or 255 (black or white)
value = (((row & 0x1) == 0) ^ ((col & 0x1) == 0)) * rand();
imageData[row][col][0] = (GLubyte)rand();
imageData[row][col][1] = (GLubyte)rand();
imageData[row][col][2] = (GLubyte)rand();
}
}

glTexImage2D(GL_TEXTURE_2D, 0, 3, IMAGE_COLS, IMAGE_ROWS, 0, GL_RGB,
GL_UNSIGNED_BYTE, imageData); // Create texture from image data
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// Obs[0].assignID(1);
// Obs[1].assignID(0);
APP.Init("lol");
}

void reshape(int w, int h)
{
glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();


gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutInitWindowPosition(0, 0);
glutCreateWindow("Survivor");
init();
glutDisplayFunc(GameDraw);
glutIdleFunc(GameDraw);
glutReshapeFunc(reshape);
glutKeyboardFunc(KeyPresses);
glutKeyboardUpFunc(KeyReleases);
glutMainLoop();

while(APP.isRunning)
{

}
exit(EXIT_SUCCESS);
return 0;
}


this is how the files are setup:
+<Survivor>
+++++<bin>
+++++++++<Debug>
++++++++++++Survivor.exe
+++++++++<Release>
++++++++++++Survivor.exe
+++++<source>// My .h files
+++++<stuff>
+++++++++<data>
++++++++++++Log.txt
++++++++++++//other .txts
++++++++//pictures
++++main.cpp
++++Survivor.cbp
++++Survivor.depend
++++Survivor.layout


I have no clue why its not working, any troubleshooting/tips would help. thanks! :D

Share this post


Link to post
Share on other sites
Advertisement
[font=arial, verdana, tahoma, sans-serif][size=2]From the forum's FAQ and Rules:

If you are asking for help with a piece of code, especially for debugging or troubleshooting purposes, please reduce the code as far as you can to a minimum sample that reproduces your problem. For instance, if you have a syntax error, post the smallest piece of code you can that triggers the syntax error, and no more. If you have commented out code for testing or experimentation purposes, please either omit it when posting, or clearly explain the purpose of the commented-out sections. This helps reduce ambiguity and makes it faster and easier for others to assist you.[/quote]


Please follow this rule. This is the second time I've had to explicitly ask you about this; please don't make me do it thrice.[/font]

Share this post


Link to post
Share on other sites
DX there is no way to simplify it; im asking if anyone who would want to read through all the code and see if i made any mistakes. i honestly dont care if you dont help me because you dont feel like reading all that code.

Share this post


Link to post
Share on other sites
What does the project file look like ?

double check the line containing:
<Option working_dir=.........

(It is entierly possible that your project is configured to run the built executable from the debug or release folder which doesn't contain the files you try to open)

Also, if you run this under a *nix system your filenames will be case sensitive which might also be worth double checking.

Share this post


Link to post
Share on other sites
There is most definitely a way to simplify this.

Delete stuff until it works.

Or, try the opposite approach: do nothing in your program but use an ifstream. Does that work? If so, start adding stuff back in until in breaks.


This isn't just about people being too lazy to read your code. This is to help you. By reducing the problem, you learn three critical things:

  • How to focus on relevant details and ignore irrelevant ones
  • How to separate what really affects your program from what doesn't
  • What actually is involved in your bug and what just looks like it might be involved

    This is about making you a better programmer so you can solve this kind of thing on your own in the future.

Share this post


Link to post
Share on other sites

DX there is no way to simplify it; im asking if anyone who would want to read through all the code and see if i made any mistakes. i honestly dont care if you dont help me because you dont feel like reading all that code.


Can you post the contents of your hard drive(s) too? Just to make sure we don't miss any details.

Share this post


Link to post
Share on other sites
Your project is misconfigured, it has the working directories set to the compilers directory:
<Option working_dir="C:\Program Files (x86)\CodeBlocks\MinGW\bin" />

(Thus when you try to open stuff/data/whatever it will try to open C:\Program Files (x86)\CodeBlocks\MinGW\bin\stuff\data\whatever which doesn't exist)


It should be: <Option working_dir="."/>
(For both release and debug targets)

You can change it using the GUI by going into Project -> Properties -> Build targets -> Debug/Release -> Execution working dir

Share this post


Link to post
Share on other sites
GOD I FEEL SO DUMB, like the rest of everything i code... DX
THANK YOU, btw. i wish i did this a week ago, ive literally spent (no lie) at least 24+hours trying to figure this out. you deserve a award! :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!