Hello everyone. I ported my level editor for my game "letters" to C++ and DarkGDK, because it has stopped working properly in dbpro after adding a "text" command somewhere.
When such command has been removed, the problem has sticked there and so I ported the entyre code.
By the way, even if the code commands and structure are the same as in dbpro, the executable crashes on startup and I don't know why.
Here is the full source for my level editor, and I attach the needed media files.
#include"DarkGDK.h"
#include <stdio.h>
//Project:level-editor
//Created:15/12/200916.25.06
//*****MainSourceFile*****
int showtiles(void);
void DarkGDK(void) {
dbSetDisplayMode(640,480,32);
dbSetWindowOn();
dbSyncOn();
dbLoadBitmap("letters\\letters-1.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(197,0,0,9*32,3*32);
dbDeleteBitmap(1);
dbLoadBitmap("letters\\letters-2.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(198,0,0,9*32,3*32);
dbDeleteBitmap(1);
dbLoadBitmap("letters\\letters-3.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(199,0,0,9*32,3*32);
dbDeleteBitmap(1);
dbLoadBitmap("letters\\letters-4.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(200,0,0,9*32,3*32);
dbDeleteBitmap(1);
dbLoadBitmap("letters\\letters-5.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(201,0,0,9*32,3*32);
dbDeleteBitmap(1);
dbLoadBitmap("letters\\letters-6.bmp", 1);
dbSetCurrentBitmap(1);
dbGetImage(202,0,0,9*32,3*32);
dbDeleteBitmap(1);
int num, num2, st, a, b, c, x, y, tile, canplace, total, count;
int nero, azzurro, rosso;
typedef struct {
int obstacle, x, y, tn;
} T;
T level[20][14], chrono[280];
for (x = 0; x < 20; x++) {
for (y = 0; y < 14; y++) {
level[x][y].obstacle = 0;
level[x][y].x = 0;
level[x][y].y = 0;
level[x][y].tn = 0;
}
}
for (y = 0; y < 280; y++) {
chrono[y].obstacle = 0;
chrono[y].x = 0;
chrono[y].y = 0;
chrono[y].tn = 0;
}
nero = dbRGB(0,0,0);
azzurro = dbRGB(0,255,255);
rosso = dbRGB(255,0,0);
num = 0;
tile = 0;
num2 = 0;
canplace = 0;
total = 0;
for (a = 0; a < 6; a++) {
dbPasteImage(197 + a, 0, 0);
for (b = 0; b < 3; b++) {
for (c = 0; c < 9; c++) {
dbGetImage(num, (c - 1) * 32, (b - 1) * 32, c * 32, b * 32);
num++;
}
}
}
do {
if (dbReturnKey()) {
st = 1;
}
if (st == 1) {
tile = showtiles();
if (dbMouseClick() == 1) {
st = 0;
canplace = 0;
} else {
count = 1;
}
} else {
for (x = 0; x < 20; x++) {
for (y = 0; y < 14; y++) {
dbBox(x * 32, y * 32, (x + 1) * 32, (y + 1) * 32, azzurro, azzurro, azzurro, azzurro);
if (level[x][y].tn == 0) {
dbBox(x * 32 + 1, y * 32 + 1, (x + 1) * 32 - 1, (y + 1) * 32 - 1, nero, nero, nero, nero);
} else {
dbPasteImage(level[x][y].tn, (level[x][y].x - 1) * 32, (level[x][y].y - 1) * 32);
}
if (x == 1 && y == 8) {
dbBox(x * 32 + 1, y * 32 + 1, (x + 1) * 32 - 1, (y + 1) * 32 - 1, rosso, rosso, rosso, rosso);
}
}
}
}
if (count == 10) {
canplace = 1;
} else {
count++;
}
if (tile != 0 && canplace == 1) {
dbPasteImage(tile, (int)(dbControlDeviceX() / 32) * 32, (int)(dbControlDeviceY() / 32) * 32);
if ((int)(dbControlDeviceY() / 32) <= 13) {
if (level[(int)dbControlDeviceX() / 32][(int)dbControlDeviceY() / 32].tn == 0) {
if ((int)dbControlDeviceX() / 32 == 1 && (int) dbControlDeviceY() / 32 == 7) {
} else {
if (dbMouseClick() == 1 && (int) (dbControlDeviceY() / 32) <= 13) {
level[(int)dbControlDeviceX() / 32][(int)dbControlDeviceY() / 32].obstacle = (tile % 27 == 0);
level[(int)dbControlDeviceX() / 32][(int)dbControlDeviceY() / 32].x = (int) (dbControlDeviceX() / 32);
level[(int)dbControlDeviceX() / 32][(int)dbControlDeviceY() / 32].y = (int) (dbControlDeviceY() / 32);
level[(int)dbControlDeviceX() / 32][(int)dbControlDeviceY() / 32].tn = tile;
}
if (tile % 27 != 0) {
chrono[num2].obstacle = 0;
chrono[num2].x = (int) (dbControlDeviceX() / 32);
chrono[num2].y = (int) (dbControlDeviceY() / 32);
chrono[num2].tn = tile;
num2++;
}
total++;
tile = 0;
}
}
}
}
dbSync();
if (total == 279) {
char * filename;
filename = dbInput();
sprintf(filename, "%s.dat", filename);
dbOpenToWrite(1,filename);
dbWriteFile(1,(total-num2));
for (x = 0; x < 20; x++) {
for (y = 0; y < 14; y++) {
dbWriteFile(1, level[x][y].obstacle);
dbWriteFile(1, level[x][y].x);
dbWriteFile(1, level[x][y].y);
dbWriteFile(1, level[x][y].tn);
}
}
for (x = 0; x < 280; x++) {
if (chrono[x].tn % 27 != 0) {
dbWriteFile(1, chrono[x].tn);
}
}
dbCLS();
if (dbMouseClick() == 2 && num2 >= 1) {
level[chrono[num2].x][chrono[num2].y].obstacle = 0;
level[chrono[num2].x][chrono[num2].y].x = 0;
level[chrono[num2].x][chrono[num2].y].y = 0;
level[chrono[num2].x][chrono[num2].y].tn = 0;
chrono[num2].obstacle = 0;
chrono[num2].x = 0;
chrono[num2].y = 0;
chrono[num2].tn = 0;
if (num2 > 0) {
num2--;
}
if (total > 0) {
total--;
}
}
}
} while (dbEscapeKey() == 0);
}
int showtiles(void) {
int num, choosen;
num = 1;
for (int a = 0; a < 6; a++) {
for (int b = 0; b < 3; b++) {
for (int c = 0; c < 9; c++) {
if (a == 1) {
dbPasteImage(num, c*32, b*32);
}
if (a == 2) {
dbPasteImage(num, c*32, b*32 + 32*3);
}
if (a == 3) {
dbPasteImage(num, c*32, b*32 + 32*3*2);
}
if (a == 4) {
dbPasteImage(num, c*32+32*9, b*32);
}
if (a == 5) {
dbPasteImage(num, c*32+32*9, b*32 + 32*3);
}
if (a == 6) {
dbPasteImage(num, c*32+32*9, b*32 + 32*3*2);
}
num++;
}
}
}
if (dbMouseClick() == 1) {
choosen = (1+(int)(dbControlDeviceX()/32)*(dbControlDeviceX()<=32*9)+9*((int)(dbControlDeviceY()/32)*(dbControlDeviceY()>=32))+72*(dbControlDeviceX()>=32*9)+(dbControlDeviceX()>=32*9)*(int)(dbControlDeviceX()/32))*(dbControlDeviceX()<=32*18)*(dbControlDeviceY()<=32*9);
}
return choosen;
}
Thanks in advance for any help.
Bye, Berserk.
.
Bye, Berserk.
.