I've recently changed some of the code in my space simulator game to include a map at the top left corner. Although now when i try to compile it tells me "map is not a type", when it clearly is.
heres my code:
main.cpp
[source lang="cpp]
/* Spax is a 2d space simulator
--------------Includes-----------*/
#include <allegro.h>
#include <stdio.h>
#include <strings.h>
#include <math.h>
//------------gloabl vars---------
#include "global.h"
//------------Functions-----------
#include "functions.h"
//------------Classes------------
#include "spaceship.h"
#include "map.h"
//--------------main Func--------------------------------------------------------------------------
int main(int argc, char *argv[]) {
//start allegro
Start();
//make a map for the default soloar system
map konz;
for (int i = 0; i <=20; i++) {
konz.stuff.set("planet.bmp", rand()%100000, rand()%100000, 0, "thing");
}
konz.bg = load_bitmap("world.bmp", NULL);
spaceship player(1, SHIP_CARGO_SMALL, 100, 100, 3, 0);
world universe(konz, player);
while (!key[KEY_ESC]) {
clear_to_color(buffer, makecol(0, 0, 0));
universe.movePlayer();
universe.drawWorld();
}
return 0;
}
END_OF_MAIN();
map.h
//stars
struct star {
float x;
float y;
};
//a seperate object that can be in a map------------------------------------------------------------------------------------------
class object {
public:
object() {
exist = false;
image = NULL;
}
~object() {}
//x, y and z in world coords (not pixels)
float x;
float y;
float z;
//name
char *name;
bool exist;
//file string so you can reload
char *file;
//init funcs
bool set(char *filename, float _x, float _y, float _z, char *_name);
//pointer to image
BITMAP *image;
};
bool object::set(char *filename, float _x, float _y, float _z, char *_name) {
//set all the members
x = _x;
y = _y;
z = _z;
//name so you can search for it in the world
name = _name;
file = filename;
//load bitmap
if (!(image = load_bitmap(filename, NULL))) {
return false;
}
exist = true;
return true;
}
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------Map Structure-----------------------------------------------------------------
struct map {
BITMAP *bg;
int bgx;
int bgy;
star randomstars[MAX_STARS];
object stuff[MAX_WORLD_OBJECTS];
};
//--------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------World Class-------------------------------------------------------------------
class world {
public:
world(map _place, spaceship _player);
~world();
//drawing functions
bool drawWorld();
int getXPixelCoords(float _zoom, float _x);
int getYPixelCoords(float _zoom, float _y);
//move player
bool movePlayer();
private:
//private funcs
bool withinBoundaryOfPlayer(int _objectnumber);
bool drawHud();
bool drawStars();
bool doStars();
bool drawMap();
//map
map stuff;
//player
spaceship player;
};
world::world(map _place, spaceship _player) {
//make copy of map
stuff = _place;
//make copy of player
player = _player;
}
world::~world() {}
//-=-=-=-=-=-=-=-=-=-=-=-=-drawing=-=-=-=-=-=-=-=-=-=-=-=-=-=-
bool world::drawWorld() {
int x = 0;
int y = 0;
drawStars();
for (int i = 0; i <= MAX_WORLD_OBJECTS; i++) {
if (withinBoundaryOfPlayer(i) == true) {
x = getXPixelCoords(ZOOM, stuff.stuff.x);
y = getYPixelCoords(ZOOM, stuff.stuff.y);
if (x < SCREENW + 1000 && x > -1000 && y < SCREENH + 1000 && y > -1000) {
draw_sprite(buffer, stuff.stuff.image, x, y);
}
}
}
rotate_sprite(buffer, player.image, SCREENW / 2, SCREENH / 2, DEGREES(player.rot));
//draw Hud
drawHud();
acquire_screen();
draw_sprite(screen, buffer, 0, 0);
release_screen();
}
bool world::drawHud() {
//convert player stuff to char *
char fuel[100];
itoa((int)player.fuel, fuel, 10);
strcat(fuel, " - FUEL");
char xpos[100];
itoa((int)player.x, xpos, 10);
strcat(xpos, " - X");
char ypos[100];
itoa((int)player.y, ypos, 10);
strcat(ypos, " - Y");
textout_ex(buffer, font, fuel, 10, 10, makecol(255, 255, 255), -1);
textout_ex(buffer, font, xpos, 10, 30, makecol(255, 255, 255), -1);
textout_ex(buffer, font, ypos, 10, 40, makecol(255, 255, 255), -1);
//drawmap
drawMap();
return true;
}
bool world::drawStars() {
static bool start = true;
if (start == true) {
doStars();
start = false;
}
//now draw the stars
for (int i = 0; i <= MAX_STARS; i++) {
circlefill(buffer, getXPixelCoords(ZOOM, stuff.randomstars.x), getYPixelCoords(ZOOM, stuff.randomstars.y), 2, makecol(255, 255, 255));
}
return true;
}
bool world::doStars() {
for (int i = 0; i <= MAX_STARS; i++) {
if (rand()%2 == 0) {
stuff.randomstars.x = player.x + rand()%100000;
} else {
stuff.randomstars.x = player.x - rand()%100000;
}
if (rand()%2 == 0) {
stuff.randomstars.y = player.y + rand()%100000;
} else {
stuff.randomstars.y = player.y - rand()%100000;
}
}
return true;
}
bool world::drawMap() {
int x;
int y;
for (int i = 0; i <= MAX_WORLD_OBJECTS; i++) {
x = getXPixelCoords(ZOOM / 10, stuff.stuff.x);
y = getYPixelCoords(ZOOM / 10, stuff.stuff.y);
//draw to map bitmap
circlefill(map, x, y, 1, makecol(255, 0, 0));
}
draw_sprite(buffer, map, SCREENW - 200, 10);
return true;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=Collision and stuff=-=-=-=-=-=-=-=-=
bool world::withinBoundaryOfPlayer(int _objectnumber) {
if (stuff.stuff[_objectnumber].exist == false || stuff.stuff[_objectnumber].image == NULL) {
//it doesn't exist
return false;
} else {
return true;
}
}
int world::getXPixelCoords(float _zoom, float _x) {
return (int)(player.x + (x * _zoom));
}
int world::getYPixelCoords(float _zoom, float _y) {
return (int)(player.y + (y * _zoom));
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-keyboard input=-=-=-=-=-=--=-=-=-=-=-=-
bool world::movePlayer() {
clear_keybuf();
if (key[KEY_UP] && player.speed < player.maxspeed) {
player.speed += player.accel;
player.oldrot = player.rot;
player.fuel -= (player.weight / 100) * player.speed;
}
if (key[KEY_DOWN] && player.speed > -player.maxspeed) {
player.speed -= player.accel;
player.oldrot = player.rot;
}
if (key[KEY_RIGHT]) {
player.rot += player.rotspeed;
}
if (key[KEY_LEFT]) {
player.rot -= player.rotspeed;
}
//friction
if (player.speed > 0) {
player.speed -= player.weight / 50;
} else if (player.speed < 0) {
player.speed += player.weight / 50;
}
player.y += player.speed * cos(player.oldrot / 180 * M_PI);
player.x -= player.speed * sin(player.oldrot / 180 * M_PI);
}
//--------------------------------------------------------------------------------------------------------------------------------
I don't see how changing a few functions in a completly different class can make map not appear as a type..