Vinn nätagg från Seasonic

Hjälp med mapeditor C++, unresolved external symbol

Permalänk

Hjälp med mapeditor C++, unresolved external symbol

Hej, jag har försökt kodat en map editor i C++. Men jag får ett fel som jag inte har en aning vad det är för någo. Koden ser felfri ut enligt mig. Hoppas ni kan hjälpa mig!

#include "SDL.h"
#include <string>
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"
#include <fstream>
#include <vector>

using namespace std;

const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int EDITOR_SIZE = 560;
const int SCREEN_BPP = 32;

const int LEVEL_WIDTH = 16*16;
const int LEVEL_HEIGHT = 16*36;

const int TILE_WIDTH = 16;
const int TILE_HEIGHT = 16;
const int TOTAL_TILES = LEVEL_WIDTH/16 * LEVEL_HEIGHT/16;
const int TILE_SPRITES = 11;

int currentTile = 0;
int edbutstat = 0, edbutstat2 = 2;

SDL_Surface *screen;
SDL_Surface *editorbuttons;
SDL_Surface *tilesheet;
SDL_Surface *menu;

SDL_Rect camera = { 0, 0, SCREEN_WIDTH, EDITOR_SIZE };
SDL_Rect clips[ TILE_SPRITES ];
SDL_Rect mclips[4];
SDL_Rect edbut[4];

Mix_Music *music = NULL;

SDL_Event event;

bool quit = false;
bool inmenu = true;
bool ineditor = false;

class Tile
{
private:
SDL_Rect box;

int type;

public:
Tile( int x, int y, int tileType );

void show();

int get_type();

SDL_Rect get_box();
};

SDL_Surface *load_image( std::string filename )
{
SDL_Surface* loadedImage = NULL;

SDL_Surface* optimizedImage = NULL;

loadedImage = IMG_Load( filename.c_str() );

if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );

SDL_FreeSurface( loadedImage );

if( optimizedImage != NULL )
{
Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );

SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
}

}
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
SDL_Rect offset;

offset.x = x;
offset.y = y;

SDL_BlitSurface( source, clip, destination, &offset );
}
bool init()
{
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}

if( TTF_Init() == -1 )
{
return false;
}

if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
{
return false;
}

screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

if( screen == NULL )
{
return false;
}

SDL_WM_SetCaption( "Map Editor", NULL );

return true;
}
bool load_files()
{
editorbuttons = load_image( "editorbuttons.png" );
tilesheet = load_image("tiles.png");
menu = load_image("menu.png");

music = Mix_LoadMUS( "music.wav" );

if( music == NULL )
{
return false;
}

if( editorbuttons == NULL || tilesheet == NULL || menu == NULL)
{
return false;
}

return true;

}
void clean_up()
{
SDL_FreeSurface( editorbuttons );
SDL_FreeSurface( tilesheet );
SDL_FreeSurface( menu );
Mix_FreeMusic( music );

SDL_Quit();
}

void load_map(Tile *tiles[]){

ifstream map;
map.open("mappnamn.map");

int t, x =0, y = 0, i=0;

while(!map.eof())
{
map >> t;
tiles[ i ] = new Tile( x, y, t );
x += 16;
if(x >= LEVEL_WIDTH)
{
y += 16;
x = 0;
}
i++;
}

}
void save_map(Tile *tiles[]){

ofstream map;
map.open("pkmn.map");

int x=0;

for(int i=0; i< TOTAL_TILES; i++)
{
if(x < LEVEL_WIDTH/16-1){
map << tiles[i]->get_type() << '\t';
}
else{
map << tiles[i]->get_type() << '\n';
x = -1;
}

x++;
}

}

void set_menu(){

int y=0, x=0;
for(int i=0; i<4; i++)
{
mclips[i].x=0;
mclips[i].y=y;
mclips[i].w=417;
mclips[i].h=45;
y+=45;
}
x=0;
y=0;
for(int i=0; i<4; i++)
{
edbut[i].x = x;
edbut[i].y = y;
edbut[i].w = 90;
edbut[i].h = 40;
x += 90;
}

}
void handle_menu_events(Tile *tiles[]){

int x = 0, y = 0;

if( event.type == SDL_MOUSEBUTTONDOWN )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
x = event.button.x;
y = event.button.y;

if( ( x > 190 ) && ( x < 190 + mclips[1].w ) && ( y > 200 ) && ( y < 200 + mclips[1].h ) )
{
inmenu = false;
ineditor = true;
}
if( ( x > 190 ) && ( x < 190 + mclips[1].w ) && ( y > 200+(85) ) && ( y < 200+(85) + mclips[1].h ) )
{
load_map(tiles);
}
if( ( x > 190 ) && ( x < 190 + mclips[1].w ) && ( y > 200+(2*85) ) && ( y < 200+(2*85) + mclips[1].h ) )
{
quit = true;
}
}
}

if(event.key.keysym.sym == SDLK_s)
{
inmenu = false;
ineditor = true;
}

}

void tile_button(Tile *tiles[]){
SDL_Rect b;
SDL_Rect b2;

b.y = 16;
b.w = 16;

if(event.button.button == SDL_BUTTON_LEFT){
if( event.type == SDL_MOUSEMOTION )
{
b.x = event.button.x + camera.x;
b.y = event.button.y + camera.y;

for(int i=0; i<TOTAL_TILES; i++){
b2 = tiles[ i ]->get_box();
if( ( b.x > b2.x ) && ( b.x < b2.x + b2.w ) && ( b.y > b2.y ) && ( b.y < b2.y + b2.h ) )
{
tiles[ i ] = new Tile( b2.x, b2.y, currentTile );
}
}
}
}

if( event.type == SDL_MOUSEBUTTONDOWN )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
b.x = event.button.x + camera.x;
b.y = event.button.y + camera.y;

for(int i=0; i<TOTAL_TILES; i++){
b2 = tiles[ i ]->get_box();
if( ( b.x > b2.x ) && ( b.x < b2.x + b2.w ) && ( b.y > b2.y ) && ( b.y < b2.y + b2.h ) )
{
tiles[ i ] = new Tile( b2.x, b2.y, currentTile );
}
}
}
}

}
void set_tiles(Tile *tiles[]){

int a=0;

for(int i=0; i<TILE_SPRITES; i++)
{

clips[i].x=a;
clips[i].y=0;
clips[i].w=TILE_WIDTH;
clips[i].h=TILE_HEIGHT;

a += 16;
}

int x=0, y=0, tileType=5;

for(int i=0; i<TOTAL_TILES; i++){

tiles[ i ] = new Tile( x, y, tileType );
x += 16;
if(x >= LEVEL_WIDTH)
{
y += 16;
x = 0;
}
}

}
void handle_tile_input(){

if(event.key.keysym.sym == SDLK_0)
{
currentTile = 9;
}
else if(event.key.keysym.sym == SDLK_1)
{
currentTile = 0;
}
else if(event.key.keysym.sym == SDLK_2)
{
currentTile = 1;
}
else if(event.key.keysym.sym == SDLK_3)
{
currentTile = 2;
}
else if(event.key.keysym.sym == SDLK_4)
{
currentTile = 3;
}
else if(event.key.keysym.sym == SDLK_5)
{
currentTile = 4;
}
else if(event.key.keysym.sym == SDLK_6)
{
currentTile = 5;
}
else if(event.key.keysym.sym == SDLK_7)
{
currentTile = 6;
}
else if(event.key.keysym.sym == SDLK_8)
{
currentTile = 7;
}
else if(event.key.keysym.sym == SDLK_9)
{
currentTile = 8;
}
else if(event.key.keysym.sym == SDLK_p)
{
currentTile = 10;
}

}
void editor_buttons(Tile *tiles[]){

int x = 0, y = 0;

if( event.type == SDL_MOUSEBUTTONDOWN )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
x = event.button.x;
y = event.button.y;

if( ( x > 0 ) && ( x < 0 + 90 ) && ( y > 560 ) && ( y < 560 + 40 ) )
{
edbutstat = 1;
}
}
}
if( event.type == SDL_MOUSEBUTTONUP )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
x = event.button.x;
y = event.button.y;

if( ( x > 0 ) && ( x < 0 + 90 ) && ( y > 560 ) && ( y < 560 + 40 ) )
{
edbutstat = 0;
quit = true;
}
else {
edbutstat = 0;
}

}
}

if( event.type == SDL_MOUSEBUTTONDOWN )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
x = event.button.x;
y = event.button.y;

if( ( x > 90 ) && ( x < 90 + 90 ) && ( y > 560 ) && ( y < 560 + 40 ) )
{
edbutstat2 = 3;
}
}
}

if( event.type == SDL_MOUSEBUTTONUP )
{
if( event.button.button == SDL_BUTTON_LEFT )
{
x = event.button.x;
y = event.button.y;

if( ( x > 90 ) && ( x < 90 + 90 ) && ( y > 560 ) && ( y < 560 + 40 ) )
{
edbutstat2 = 2;
save_map(tiles);
}
else {
edbutstat2 = 2;
}

}
}

if(event.key.keysym.sym == SDLK_m)
{
ineditor = false;
inmenu = true;
}

if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_DOWN)
{
camera.y += 16;
if(camera.y+camera.h > LEVEL_HEIGHT)
{
camera.y -= 16;
}
}
if(event.key.keysym.sym == SDLK_UP)
{
camera.y -= 16;
if(camera.y < 0)
{
camera.y += 16;
}
}
if(event.key.keysym.sym == SDLK_LEFT)
{
camera.x -= 16;
if(camera.x < 0)
{
camera.x += 16;
}
}
if(event.key.keysym.sym == SDLK_RIGHT)
{
camera.x += 16;
if(camera.x+camera.w > LEVEL_WIDTH)
{
camera.x -= 16;
}
}
}

}
void editor_interface(){

apply_surface(320, 584, tilesheet, screen);
apply_surface(0, 560, editorbuttons, screen, &edbut[edbutstat]);
apply_surface(90, 560, editorbuttons, screen, &edbut[edbutstat2]);
apply_surface(784, 584, tilesheet, screen, &clips[currentTile]);

}

Tile::Tile( int x, int y, int tileType )
{
box.x = x;
box.y = y;

box.w = TILE_WIDTH;
box.h = TILE_HEIGHT;

type = tileType;
}
void Tile::show()
{
{
if(box.y < camera.y+ EDITOR_SIZE){
apply_surface( box.x - camera.x, box.y - camera.y, tilesheet, screen, &clips[ type ] );
}
}
}
int Tile::get_type()
{
return type;
}
SDL_Rect Tile::get_box()
{
return box;
}

int main( int argc, char* args[] )
{
Tile *tiles[ TOTAL_TILES ];

if( !init() || !load_files() )
{
return 1;
}

set_tiles(tiles);
set_menu();

if( Mix_PlayMusic( music, -1 ) == -1 )
{
return 1;
}

while(!quit)
{
while(SDL_PollEvent(&event))
{
if(inmenu){
handle_menu_events(tiles);
}
if(ineditor){
handle_tile_input();
editor_buttons(tiles);
}

if( event.key.keysym.sym == SDLK_q )
{
quit = true;
}
}

if(inmenu){
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
apply_surface(190, 30, menu, screen, &mclips[0]);
int y = 200;
for(int i=1; i<4; i++)
{
apply_surface(190, y, menu, screen, &mclips[i]);
y += 85;
}
}
if(ineditor){

SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
editor_buttons(tiles);
tile_button(tiles);
for( int t = 0; t < TOTAL_TILES; t++ )
{
tiles[ t ]->show();
}
editor_interface();
}

if(SDL_Flip(screen) == -1)
{
return 1;
}
}

clean_up();
return 0;
}

Fel beskrivningen är:

1>------ Build started: Project: MapEditor, Configuration: Debug Win32 ------
1>Build started 2010-09-07 18:59:16.
1>InitializeBuildStatus:
1> Touching "Debug\MapEditor.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ)
1>C:\Users\gb\Documents\Visual Studio 2010\Projects\MapEditor\Debug\MapEditor.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.65
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Vad ska jag göra?

Permalänk
Vila i frid
Permalänk
Medlem

använd code taggar så indenteringen blir rätt så underlättar det massa för folk som ska hjälpa dig

Visa signatur

i7 14700k, 32gb ram, massa lagring, Windows 11, Fractal Design North
Citera så jag hittar tillbaka :)

Permalänk
Medlem
Skrivet av E_maN:

använd code taggar så indenteringen blir rätt så underlättar det massa för folk som ska hjälpa dig

Och när det är så här mycket kod är det bättre att använda pastebin.ca