Sign in to follow this  

Why this error ?

This topic is 4373 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

Hello, Im trying to learn allegro, so I went to 2dnow.zenzer.net and found a 2d engine written in allegro. So I thought, maybe I could learn something from it. So I wrote down all code in dev-c++ but when I try to compile i get thoose errors: [Linker error] undefined reference to `_imp__key' [Linker error] undefined reference to `_imp__key' [Linker error] undefined reference to `_imp__key' [Linker error] undefined reference to `_imp__key' [Linker error] undefined reference to `_imp__key' [Linker error] undefined reference to `_imp__screen' [Linker error] undefined reference to `_imp__font' [Linker error] undefined reference to `_imp__font' [Linker error] undefined reference to `_imp__font' [Linker error] undefined reference to `_imp__font' [Linker error] undefined reference to `_imp__font' ld returned 1 exit status C:\Dev-Cpp\Makefile.win [Build Error] [2d.exe] Error 1 Thoose errors comes with this code:
/*
main.cpp
Very Basic Tile Engine
- a (what a surprise) very basic tile engine written by DeveloperX.
you may use this code freely, provided you give me credit.
http://ccps.rpgdx.net
This code uses Allegro, don't want to use Allegro?
Replace lines with //ALLEGRO after them with your own code.
*/
#include <allegro.h>
#include <stdio.h>
#define WIDTH           640 // screen width in pixels
#define HEIGHT          480 // screen height in pixels
#define STATE_SHUTDOWN  255 // time to end program?
#define TILEWIDTH       32  // width of tiles in pixels
#define TILEHEIGHT      32  // height of tiles in pixels
#define MAPWIDTH        20  // width of map in tiles
#define MAPHEIGHT       15  // height of map in tiles
#define TILECOUNT       3   // number of tiles in tileset
#define DIR_NORTH       0   // movement directions
#define DIR_EAST        1
#define DIR_SOUTH       2
#define DIR_WEST        3
BITMAP* DoubleBuffer; // ALLEGRO
BITMAP* Tiles[TILECOUNT]; // ALLEGRO
BITMAP* Hero[4]; // ALLEGRO
int Map[MAPHEIGHT][MAPWIDTH] =
{
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2},
{2,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,2},
{2,0,0,0,0,1,0,0,1,1,1,1,1,0,0,0,0,0,0,2},
{2,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,2},
{2,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,2},
{2,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,2},         
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
};
struct NPC // very basic npc, cannot do anything yet.
{
int x, y;
};
NPC HeroNPC; // our little dude

int gamestate = 0;
int HeroFrame = DIR_SOUTH; // direction we are facing
void ShowScreen();
void RenderMap();

void initialize_gameengine()
{
allegro_init(); // ALLEGRO
install_timer(); // ALLEGRO
install_keyboard(); // ALLEGRO
set_color_depth(16); // ALLEGRO
set_gfx_mode(GFX_AUTODETECT_WINDOWED, WIDTH, HEIGHT, 0, 0); // ALLEGRO
DoubleBuffer = create_bitmap(WIDTH, HEIGHT); // ALLEGRO
srand(time(NULL));
text_mode(-1);
//load tiles
for (int index=0; index<TILECOUNT; index++)
{

  char tile_filename[12];
  sprintf(tile_filename, "data\\tile%d.bmp", index);
  Tiles[index] = load_bitmap(tile_filename, NULL);
}
//load hero images north,east,south,west
Hero[DIR_NORTH] = load_bitmap("data\\heronorth.bmp", NULL);
Hero[DIR_SOUTH] = load_bitmap("data\\herosouth.bmp", NULL);
Hero[DIR_EAST]  = load_bitmap("data\\heroeast.bmp", NULL);
Hero[DIR_WEST]  = load_bitmap("data\\herowest.bmp", NULL);
HeroNPC.x = MAPWIDTH/2; // center out little dude
HeroNPC.y = MAPHEIGHT/2; // ..
}

void process_gameengine()
{
RenderMap();
while(gamestate != STATE_SHUTDOWN)
{
  if (key[KEY_ESC])  {gamestate = STATE_SHUTDOWN;} // ALLEGRO
  if (key[KEY_UP])   {HeroFrame = DIR_NORTH;if (HeroNPC.y > 0)         {HeroNPC.y--;}RenderMap();}// ALLEGRO
  if (key[KEY_DOWN]) {HeroFrame = DIR_SOUTH;if (HeroNPC.y < MAPHEIGHT-1) {HeroNPC.y++;}RenderMap();}// ALLEGRO
  if (key[KEY_LEFT]) {HeroFrame = DIR_WEST; if (HeroNPC.x > 0)         {HeroNPC.x--;}RenderMap();}// ALLEGRO
  if (key[KEY_RIGHT]){HeroFrame = DIR_EAST; if (HeroNPC.x <MAPWIDTH-1)   {HeroNPC.x++;}RenderMap();}// ALLEGRO   
  rest(64); // slow game down a bit
}
}

void shutdown_gameengine()
{
int index;
for (index=0; index<3; index++)
  destroy_bitmap(Hero[index]);           // ALLEGRO
for (index=0; index<TILECOUNT; index++)
  destroy_bitmap(Tiles[index]);          // ALLEGRO
destroy_bitmap(DoubleBuffer);           // ALLEGRO
}

void ShowScreen()
{
blit(DoubleBuffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT); // ALLEGRO
}

void RenderMap()
{
int mx,my;
for (my=0; my<MAPHEIGHT; my++)
{
  for (mx=0; mx<MAPWIDTH; mx++)
  {
   int tilenum = Map[my][mx];
   blit(Tiles[tilenum], DoubleBuffer, 0, 0,
   mx * TILEWIDTH, my * TILEHEIGHT, TILEWIDTH, TILEHEIGHT); // ALLEGRO
  }
}
textprintf(DoubleBuffer,font,8,0,makecol(255,255,255),
"Hero Position: X %d Y %d", HeroNPC.x, HeroNPC.y);
  textprintf(DoubleBuffer,font,8,16,makecol(255,255,255), "Hero Dir: %d", HeroFrame);

switch(Map[HeroNPC.y][HeroNPC.x])
{
  case 0: {textout(DoubleBuffer,font,"GRASS",8,32,makecol(255,255,255));}break;
  case 1: {textout(DoubleBuffer,font,"PATH",8,32,makecol(255,255,255));}break; 
  case 2: {textout(DoubleBuffer,font,"WALL",8,32,makecol(255,255,255));}break; 
}
// draw our dude - transparent color is Red(255), Green(0), Blue(255)

draw_sprite(DoubleBuffer,
             Hero[HeroFrame],
             HeroNPC.x * TILEWIDTH,
             HeroNPC.y * TILEHEIGHT);// ALEGRO
ShowScreen();
}


void main (void)
{
initialize_gameengine();
process_gameengine();
shutdown_gameengine();
}
END_OF_MAIN() // ALLEGRO 
Thanks for helping // Jepalano

Share this post


Link to post
Share on other sites
yeah i am familiar with this bit of code .. i am working with the guy who wrote it (hehe) ... make sure you have -lalleg linked. i think i had the same problem when i started out with allegro. if not find me on yahoo IM and i might be able to get the guy who wrote it to help ya.

Share this post


Link to post
Share on other sites

This topic is 4373 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this