Re: Cannot Find The Problem
Posted: Thu Oct 29, 2009 8:34 pm
davidthefat wrote:The error is that ifstream is undeclared, it should work but no, the compiler is choosing to be gay...
Code: Select all
using namespace std;
The Next Generation of 2D Roleplaying Games
http://elysianshadows.com/phpBB3/
davidthefat wrote:The error is that ifstream is undeclared, it should work but no, the compiler is choosing to be gay...
Code: Select all
using namespace std;
I feel so stupid...andrew wrote:davidthefat wrote:The error is that ifstream is undeclared, it should work but no, the compiler is choosing to be gay...ifstream lives in the std namespace.Code: Select all
using namespace std;
Code: Select all
//Main.cpp
#include "Player.h"
#include "Collision.h"
#include "Map.h"
#include "Draw.h"
void init();
void deinit();
int main()
{
init();
Map m;
Draw D;
D.SetBuffer();
m.GetMap();
while (!key[KEY_ESC])
{
clear_keybuf();
clear_bitmap(D.bBuffer());
acquire_screen();
for (int c = 0; c < 12; c++)
{
for( int r = 0; r < 16; r++)
{
D.DrawMap(m.MapCoor(c, r), c, r);
}
}
D.DrawBitmap(D.bBuffer());
release_screen();
rest(50);
}
deinit();
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
}
void deinit() {
clear_keybuf();
}
Code: Select all
//Player.h
#ifndef PLAYER_H
#define PLAYER_H
class Player
{
};
#endif
Code: Select all
//Player.cpp
#include "Player.h"
Code: Select all
//Collision.cpp
#include "Collision.h"
Code: Select all
//Collision.h
#ifndef COLLISION_H
#define COLLISION_H
class Collision
{
};
#endif
Code: Select all
//Map.h
#ifndef MAP_H
#define MAP_H
#include <iostream>
#include <fstream>
class Map
{
private:
int map[12][16];
public:
void GetMap();
int MapCoor(int c, int r);
};
#endif
Code: Select all
//Map.cpp
#include "Map.h"
void Map::GetMap()
{
std::ifstream infile("Default.map");
for (int j=0; j < 12; j++)
{
for (int i=0; i < 16; i++)
{
int temp;
infile >> temp;
map[i][j] = temp;
}
}
infile.close();
}
int Map::MapCoor(int c, int r)
{
return map[c][r];
}
Code: Select all
//Draw.h
#include <allegro.h>
#ifndef DRAW_H
#define DRAW_H
class Draw
{
private:
BITMAP* Buffer;
public:
int DrawMap(int flag, int t, int i);
void SetBuffer();
BITMAP* bBuffer();
void DrawBitmap(BITMAP* draw);
};
#endif
Code: Select all
//Draw.cpp
#include "Draw.h"
int Draw::DrawMap(int flag, int t, int i)
{
if( flag == 1)
{
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 440, makecol( 128, 255, 255));
}
else if( flag == 2)
{
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 255, 128, 0));
}
else if( flag == 3)
{
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 255, 0, 0));
}
else if( flag == 4)
{
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 0, 0, 0));
}
}
void Draw::SetBuffer()
{
Buffer = create_bitmap( 640, 480);
}
BITMAP* Draw::bBuffer()
{
return Buffer;
}
void Draw::DrawBitmap(BITMAP* draw)
{
draw_sprite( screen, Buffer, 0, 0);
}
Code: Select all
int Draw::DrawMap(int flag, int t, int i)
{
if( flag == 1)
{
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 440, makecol( 128, 255, 255)); //I think this is the problem is y2?
}
Code: Select all
int Draw::DrawMap(int flag, int t, int i) {
Color mColor; //not sure about color types in allegro...
mColor = getColor(flag);
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, mColor);
}
Code: Select all
enum {
kCyan,
kOrange,
kRed,
kBlack
};
Can you not just use cout?BTW anyone know how to open a console window and print stuff out while running an allegro window for debugging usage? I dont think the map is getting read corectly or the draw function is wrong
Nope, I doubt it. He just has an application window.Innerscope wrote:Can you not just use cout?BTW anyone know how to open a console window and print stuff out while running an allegro window for debugging usage? I dont think the map is getting read corectly or the draw function is wrong
edit: Yea, my fault, I misread his question. Your 1st method.GyroVorbis wrote:Nope, I doubt it. He just has an application window.Innerscope wrote:Can you not just use cout?BTW anyone know how to open a console window and print stuff out while running an allegro window for debugging usage? I dont think the map is getting read corectly or the draw function is wrong
See all the repetition? This means you're doing something wrong :)Code: Select all
int Draw::DrawMap(int flag, int t, int i) { if( flag == 1) { rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 440, makecol( 128, 255, 255)); } else if( flag == 2) { rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 255, 128, 0)); } else if( flag == 3) { rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 255, 0, 0)); } else if( flag == 4) { rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, makecol( 0, 0, 0)); } }
Code: Select all
drawMap(...) {
Color color;
switch (flag) {
case 1:
color = makecol(128, 255, 255);
break;
case 2:
....
}
rectfill( Buffer, t * 40, i * 40, (t + 1) * 40, (i + 1) * 40, color);
}
Wouldnt that be a problem in the long run? Like that namespace might interfere with another?ibly31 wrote:Didnt look at the code for more than 10 seconds, but
using namespace std;
??? after the includes
Just did that, easy as just going to project option and clicking window consoleGyroVorbis wrote:
1) Make a command-line project so that you have one window for Allegro+graphics, and one console in the background for printing things.
Not really, no. Unless you plan on naming your functions cout and your classes fstream.davidthefat wrote:Wouldnt that be a problem in the long run? Like that namespace might interfere with another?ibly31 wrote:Didnt look at the code for more than 10 seconds, but
using namespace std;
??? after the includes
Elaborate on the pointers please, from the books I read, it only taught me HOW to use it, not WHY or WHERE to use it...MarauderIIC wrote:
I agree with innerscope's solution of using another function, but at that point you'll want to use a pointer, so that you don't make a copy of the object... and now we're into dynamically allocated memory territory.
You could do a switch in the function itself as long as you don't need to reuse your "get color" code...
http://elysianshadows.com/phpBB3/viewto ... t=pointersdavidthefat wrote:Elaborate on the pointers please, from the books I read, it only taught me HOW to use it, not WHY or WHERE to use it...MarauderIIC wrote:
I agree with innerscope's solution of using another function, but at that point you'll want to use a pointer, so that you don't make a copy of the object... and now we're into dynamically allocated memory territory.
You could do a switch in the function itself as long as you don't need to reuse your "get color" code...