Hello everyone,
I am trying to use classes to display my 2d-background use a tiling technique. However, I tried the most simplest ways to produce my background but it all ended in failure. Can provide me with some assistance with this? I don't care if the whole code has to be rewritten I just it to get it up and running.
Here are the codes down below.
details: I created an single array of sprite-loaded objects with the "Sprite.h" class, then I created a 2d-array sprites and where they are going to be positioned. Next I created an object from the "Coordinate.h" class where it takes the width and height of each new sprite. The "Coordinate.h" then takes the width and height variables and uses a nested for-loop to produce the row and column numbers for the tileMap address which it should retrieve the sprite object withn the array tileMap. It should also produce the x and y position of each sprite.
However when I try it i get this error code:
1>------ Build started: Project: slide show3c, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>Linking...
1>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>Debug\slide show3c.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Chris Walker\Documents\Game Programming\+Fist Full of ANIMA+\slide show3c\slide show3c\Debug\BuildLog.htm"
1>slide show3c - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Main.cpp
//Main.cpp
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <conio.h>
#include <cstdlib>
#include "DarkGDK.h"
#include "Sprite.h"
#include "MapReader.h"
#include "Coordinate.h"
using namespace std;
const int REFRESH_RATE = 60;
const int FRUITS = 100;
const int VEGGIE = 200;
const int GRASS = 1;
const int PATH = 2;
const int PATHNE = 3;
const int PATHNW = 4;
const int PATHSE = 5;
const int PATHSW = 6;
const int NONE = 0;
const int TREENW = 7;
const int TREENE = 8;
const int TREESW = 9;
const int TREESE = 10;
const int ROCK = 11;
// Constants for the tile image sizes
const int TILE_WIDTH = 64;
const int TILE_HEIGHT = 48;
const int TILE_NUM = 11;
// Constants for the tile map sizes
const int TILE_ROWS = 10;
const int TILE_COLS = 10;
//bool TRIGGER = false;
void DarkGDK()
{
Sprite tile[TILE_NUM] = {
Sprite(GRASS, GRASS, "Grass.bmp"),
Sprite(PATH, PATH, "Path.bmp"),
Sprite(PATHNE, PATHNE, "PathNE.bmp"),
Sprite(PATHNW, PATHNW, "PathNW.bmp"),
Sprite(PATHSE, PATHSE, "PathSE.bmp"),
Sprite(PATHSW, PATHSW, "PathSW.bmp"),
Sprite(TREENE, TREENE, "TreeNE.bmp"),
Sprite(TREENW, TREENW, "TreeNW.bmp"),
Sprite(TREESE, TREESE, "TreeSE.bmp"),
Sprite(TREESW, TREESW, "TreeSW.bmp"),
Sprite(ROCK, ROCK, "Rock.bmp")};
int tileMap[TILE_ROWS][TILE_COLS] =
{
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, PATHNW, PATH, PATH },
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, PATH, GRASS, GRASS},
{PATH, PATH, PATH, PATH, PATHNE, GRASS, GRASS, PATH, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, PATH, GRASS, GRASS, PATH, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, PATHSW, PATH, PATH, PATHSE, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS}
};
Coordinate setting(TILE_WIDTH, TILE_HEIGHT);
//MapReader m(tileMap);
dbSetImageColorKey(255, 0, 255);
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn();
dbSyncRate(REFRESH_RATE);
// our main loop
while (LoopGDK())
{ int map = tileMap[setting.getRow()][setting.getCol()];
int x = setting.getXCoord();
int y = setting.getYCoord();
tile[map].pasteIm(x, y);
///*Trying to uconvert the nested for-loop as a class
// Display all the tiles specified in the map.
//
//for (int r = 0; r < TILE_ROWS; r++)
//{
// x = 0;
//
// // Display all the tiles in this row.
// for (int c = 0; c < TILE_COLS; c++)
// {
// int map = tileMap[r][c] - 1;
//
// tile[map].pasteIm(x, y);
// x += TILE_WIDTH;
// }
//
// // Increase y for the next row.
// y += TILE_HEIGHT;
//}*/
// update the screen
dbSync();
}
}
Sprite.h
// Sprite.h
#ifndef SPRITE_H
#define SPRITE_H
class Sprite
{
private:
int imageNum;
int spriteNum;
int colsNum;
int rowsNum;
public:
//Used to load images to computer
Sprite(int image, int sprite, char filename[])
{
imageNum = image;
spriteNum = sprite;
dbLoadImage(filename, imageNum);
}
//Overwritten for loading animated sprites
Sprite(int image, int sprite, char filename[], int cols, int rows)
{
imageNum = image;
spriteNum = sprite;
colsNum = cols;
rowsNum = rows;
dbCreateAnimatedSprite(spriteNum, filename, colsNum, rowsNum, imageNum);
}
~Sprite()
{
if( dbSpriteExist(spriteNum) )
{
dbDeleteSprite(spriteNum);
}
}
//This is used to display sprites
void display(int x, int y) const
{
dbSprite(spriteNum, x, y, imageNum);
}
void display() const
{
int x = dbSpriteX(spriteNum);
int y = dbSpriteY(spriteNum);
dbSprite(spriteNum, x, y, imageNum);
}
void pasteIm(int x, int y) const
{
dbPasteImage(imageNum, x, y);
}
void show() const
{
dbShowSprite(spriteNum);
}
void hide() const
{
dbHideSprite(spriteNum);
}
int getImageNumber() const
{
return imageNum;
}
int getSpriteNumber() const
{
return spriteNum;
}
int getX() const
{
return dbSpriteX(spriteNum);
}
int getY() const
{
return dbSpriteY(spriteNum);
}
};
#endif
Coordinate.h
// Coordinate.h
#ifndef COORDINATE_H
#define COORDINATE_H
class Coordinate
{
int r, c, x, y;
private:
int heightNum;
int widthNum;
public:
Coordinate(int width, int height)
{
widthNum = width;
heightNum = height;
}
void CreateXY()
{
for (r = 0; r < 10; r++)
{
x = 0;
// Display all the tiles in this row.
for (c = 0; c < 10; c++)
{
x += widthNum;
}
// Increase y for the next row.
y += heightNum;
}
}
int getXCoord()
{
return x;
}
int getYCoord()
{
return y;
}
int getRow()
{
return r;
}
int getCol()
{
return c;
}
};
#endif
I can do all things through Christ which strengthens me!