pointers will eat video memory? well i can put up the source code but its in rough shape ATM cause im trying to figure out the game. Never programmed a graphic game. My experience is 6 years old in ANSII C for linux in MUDS.
#include "DarkGDK.h"
void Load( int location);
void Menu();
void ClearSprites();
void GetName();
void MoveChar();
int Menu_Loop = 0;
CONST int INTRO = 1;
//Loaction Consts
CONST int MENU = 1;
CONST int LOADHOME = 2;
CONST int HOME = 3;
// Player Sprite States
CONST int MAINDOWN = 20;
CONST int MAINUP = 21;
CONST int MAINLEFT = 22;
CONST int MAINRIGHT = 23;
//Level Tiles/Frames
CONST int GRASS = 60;
//Keys Pressed
CONST int KEYUP = 200;
CONST int KEYDOWN = 208;
CONST int KEYLEFT = 203;
CONST int KEYRIGHT = 205;
//Player Structure Set
class Player_Data
{
public:
char Name[50];
int Level;
int State;
int HP;
int HP_MAX;
int Mana;
int Mana_Max;
int Attack;
int Defence;
int Luck;
int Dodge;
int Accuracy;
int Gender;
int Alignment;
int Location;
};
Player_Data Player1;
int BACKX = -1248;
int BACKY = -2212;
void DarkGDK ( void )
{
dbFlushVideoMemory();
dbSetWindowLayout( 0,0,0);
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode(1024, 768, 32);
dbSetWindowPosition(0,0);
dbMaximizeWindow();
dbDrawSpritesFirst();
//dbHideMouse();
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
Player1.Location = MENU;
while ( LoopGDK ( ) )
{
if (Player1.Location== MENU)
Menu();
if (Player1.Location == LOADHOME)
Load(Player1.Location);
MoveChar();
dbText(0, 0, dbStr(BACKX));
dbText(0, 20, dbStr(BACKY));
if ( dbEscapeKey ( ) )
ClearSprites();
dbSync ( );
}
return;
}
void Load(int location)
{
if (location == LOADHOME)
{
dbCLS();
dbText(490, 370, "Loading....");
dbSync();
dbSync();
for (int a = 1; a < 100; a++)
{
dbHideSprite(a);
dbDeleteSprite(a);
}
dbLoadImage("Main1.bmp", MAINDOWN);
dbLoadImage("Mainup.bmp", MAINUP);
dbLoadImage("Mainright.bmp", MAINRIGHT);
dbLoadImage("Mainleft.bmp", MAINLEFT);
dbLoadImage("testgrass.png", GRASS);
dbSprite(GRASS, BACKX, BACKY, GRASS);
dbSprite(MAINDOWN, 500, 500, MAINDOWN);
Player1.Location = HOME;
}
return;
}
void Menu()
{
int BannerY = -200;
int MenuX = -500;
int CreationY = 1400;
strcpy(Player1.Name, "FARNIR");
char buffer[255];
dbSetImageColorKey ( 0, 0, 0 );
dbLoadImage("Menu_Back.bmp", 3);
dbLoadImage("Creation_Back.bmp", 10);
//Load New Game Button
dbLoadImage("Button_Up.bmp", 4);
dbLoadImage("Button_Down.bmp", 5);
//Load Quit Game Button
dbLoadImage("Button_Up.bmp", 6);
dbLoadImage("Button_Down.bmp", 7);
//Load Continue Game Button
dbLoadImage("Button_Up.bmp", 8);
dbLoadImage("Button_Down.bmp", 9);
dbSetImageColorKey ( 255, 0, 255 );
dbLoadImage("input.bmp", 11);
dbLoadImage("Intro.bmp", INTRO);
dbLoadImage("select.bmp", 12);
dbLoadImage("select.bmp", 13);
dbSprite(INTRO,0,0,INTRO);
dbCreateAnimatedSprite(2, "darksword.bmp", 1, 4, 2);
dbSetTextFont("Arial");
dbSetTextSize(24);
int Menu_State = 0;
while ( LoopGDK ( ) )
{
if (Menu_State == 0)
{
if (BannerY < 50)
BannerY += 3;
if (BannerY >= 50 && MenuX < 312)
MenuX +=20;
dbPlaySprite(2, 1, 4, 75);
dbSprite(2, 112, BannerY, 2);
dbSprite(3, MenuX, 300, 3);
if ( dbMouseClick() == 1 && dbMouseX() > 415 && dbMouseX() < 610 && dbMouseY() > 320 && dbMouseY() < 370)
{
dbHideSprite(4);
dbSprite(5, MenuX + 100, 320, 5);
dbShowSprite(5);
dbText(MenuX +140, 335, "New Game");
Menu_State = 1;
dbShowSprite(10);
}
else
{
dbHideSprite(5);
dbSprite(4, MenuX + 100, 320, 4);
dbShowSprite(4);
dbText(MenuX +135, 330, "New Game");
}
if ( dbMouseClick() == 1 && dbMouseX() > 415 && dbMouseX() < 610 && dbMouseY() > 380 && dbMouseY() < 430)
{
dbHideSprite(8);
dbSprite(9, MenuX + 100, 380, 9);
dbShowSprite(9);
dbText(MenuX +155, 395, "Continue");
}
else
{
dbHideSprite(9);
dbSprite(8, MenuX + 100, 380, 8);
dbShowSprite(8);
dbText(MenuX +150, 390, "Continue");
}
if ( dbMouseClick() == 1 && dbMouseX() > 415 && dbMouseX() < 610 && dbMouseY() > 530 && dbMouseY() < 570)
{
dbHideSprite(6);
dbSprite(7, MenuX + 100, 530, 7);
dbShowSprite(7);
dbText(MenuX +180, 545, "Quit");
dbSync ( );
dbSync ( );
ClearSprites();
}
else
{
dbHideSprite(7);
dbSprite(6, MenuX + 100, 530, 6);
dbShowSprite(6);
dbText(MenuX +175, 540, "Quit");
}
}
if (Menu_State == 1)
{
if ( MenuX > -500 )
MenuX -=40;
dbPlaySprite(2, 1, 4, 75);
dbSprite(2, 112, BannerY, 2);
dbSprite(3, MenuX, 300, 3);
dbSprite(5, MenuX + 100, 320, 5);
dbShowSprite(5);
dbText(MenuX +140, 335, "New Game");
dbSprite(8, MenuX + 100, 380, 8);
dbShowSprite(8);
dbText(MenuX +150, 390, "Continue");
dbSprite(6, MenuX + 100, 530, 6);
dbShowSprite(6);
dbText(MenuX +180, 540, "Quit");
if ( MenuX <= -500 )
{
dbHideSprite(3);
dbHideSprite(4);
dbHideSprite(5);
dbHideSprite(6);
dbHideSprite(7);
dbHideSprite(8);
dbHideSprite(9);
dbShowSprite(10);
dbShowSprite(11);
if (CreationY > 220)
CreationY -= 20;
else
{
dbShowSprite(12);
dbShowSprite(13);
}
dbInk(dbRGB(255,255,255),0);
dbSprite( 10, 120, CreationY, 10 );
dbText(170, CreationY + 20, "Welcome to 'Dark Sword', adventurer. Before we can unleash\n you on the world we need your name.");
dbText(330, CreationY + 80, "Name:");
dbSprite( 11, 410, CreationY + 75, 11);
dbText(420, CreationY + 80, Player1.Name);
dbText(330, CreationY + 120, "Gender:");
if (Player1.Gender == 1)
dbSprite(12, 420, 335, 12);
dbText(450, CreationY + 120, "Male");
if (Player1.Gender == 2)
dbSprite(12, 535, 335, 12);
dbText(550, CreationY + 120, "Female");
dbText(298, CreationY + 160, "Alignment:");
if (Player1.Alignment == 1000)
dbSprite(13, 420, 375, 13);
dbText(450, CreationY + 160, "Pure");
if (Player1.Alignment == -1000)
dbSprite(13, 535, 375, 13);
dbText(550, CreationY + 160, "Evil");
dbText(450, CreationY + 450, "Back");
dbText(530, CreationY + 450, "Quit");
if ( dbMouseClick() == 1 && dbMouseX() > 450 && dbMouseX() < 505 && dbMouseY() < 695 && dbMouseY() > 670)
{
Menu_State = 0;
dbHideSprite(12);
dbHideSprite(13);
for (int i = 0; i < 30; i++)
{
dbSprite( 10, 120, CreationY, 10 );
dbText(170, CreationY + 20, "Welcome to 'Dark Sword', adventurer. Before we can unleash\n you on the world we need your name.");
dbText(330, CreationY + 80, "Name:");
dbSprite( 11, 410, CreationY + 75, 11);
dbText(330, CreationY + 120, "Gender:");
if (Player1.Gender == 1)
dbSprite(12, 420, 335, 12);
dbText(450, CreationY + 120, "Male");
if (Player1.Gender == 2)
dbSprite(12, 535, 335, 12);
dbText(550, CreationY + 120, "Female");
dbText(298, CreationY + 160, "Alignment:");
if (Player1.Alignment == 1000)
dbSprite(13, 420, 375, 13);
dbText(450, CreationY + 160, "Pure");
if (Player1.Alignment == -1000)
dbSprite(13, 535, 375, 13);
dbText(550, CreationY + 160, "Evil");
dbText(450, CreationY + 450, "Back");
dbText(530, CreationY + 450, "Quit");
dbPlaySprite(2, 1, 4, 75);
dbSprite(2, 112, BannerY, 2);
if (CreationY < 1400)
CreationY += 50;
dbSync ( );
dbSync ( );
}
sprintf(Player1.Name, "FARNIR");
Player1.Gender = 0;
Player1.Alignment = 0;
dbHideSprite(10);
dbHideSprite(11);
dbHideSprite(12);
dbSprite(12, -300, -300, 12);
dbSprite(13, -300, -300, 13);
dbHideSprite(13);
CreationY = 1400;
dbShowSprite(3);
}
if ( dbMouseClick() == 1 && dbMouseX() > 530 && dbMouseX() < 575 && dbMouseY() < 695 && dbMouseY() > 670)
{
ClearSprites();
}
if ( dbMouseClick() == 1 && dbMouseX() > 420 && dbMouseX() < 720 && dbMouseY() < 340 && dbMouseY() > 300)
{
while (!dbReturnKey())
{
dbSprite( 10, 120, CreationY, 10 );
dbText(170, CreationY + 20, "Welcome to 'Dark Sword', adventurer. Before we can unleash\n you on the world we need your name.");
dbText(330, CreationY + 80, "Name:");
dbSprite( 11, 410, CreationY + 75, 11);
dbText(330, CreationY + 120, "Gender:");
if (Player1.Gender == 1)
dbSprite(12, 420, 335, 12);
dbText(450, CreationY + 120, "Male");
if (Player1.Gender == 2)
dbSprite(12, 535, 335, 12);
dbText(550, CreationY + 120, "Female");
dbText(298, CreationY + 160, "Alignment:");
if (Player1.Alignment == 1000)
dbSprite(13, 420, 375, 13);
dbText(450, CreationY + 160, "Pure");
if (Player1.Alignment == -1000)
dbSprite(13, 535, 375, 13);
dbText(550, CreationY + 160, "Evil");
dbText(450, CreationY + 450, "Back");
dbText(530, CreationY + 450, "Quit");
//get name input
GetName();
dbSync ( );
dbWaitKey();
}
}
//male
if ( dbMouseClick() == 1 && dbMouseX() > 450 && dbMouseX() < 505 && dbMouseY() < 365 && dbMouseY() > 340)
{
dbSprite(12, 420, 335, 12);
Player1.Gender = 1;
}
//female
if ( dbMouseClick() == 1 && dbMouseX() > 550 && dbMouseX() < 635 && dbMouseY() < 365 && dbMouseY() > 340)
{
dbSprite(12, 535, 335, 12);
Player1.Gender = 2;
}
//pure
if ( dbMouseClick() == 1 && dbMouseX() > 420 && dbMouseX() < 505 && dbMouseY() < 405 && dbMouseY() > 375)
{
dbSprite(13, 420, 375, 13);
Player1.Alignment = 1000;
}
//evil
if ( dbMouseClick() == 1 && dbMouseX() > 535 && dbMouseX() < 645 && dbMouseY() < 405 && dbMouseY() > 375)
{
dbSprite(13, 535, 375, 13);
Player1.Alignment = -1000;
}
//all selections finished
if (Player1.Gender != 0 && Player1.Alignment != 0)
{
sprintf(buffer, "Thank You, %s, You may now enter the land of Dark Sword!\n", Player1.Name);
dbText(165, 475, buffer);
dbText(485, 525, "Enter");
}
// click the enter game function
if ( dbMouseClick() == 1 && dbMouseX() > 485 && dbMouseX() < 545 && dbMouseY() < 545 && dbMouseY() > 525)
{
Player1.Location = LOADHOME;
break;
}
}
}
dbText(10,10, dbStr( dbMouseX() ) );
dbText(10,30, dbStr( dbMouseY() ) );
dbSync ( );
}
//Clean up Menu Sprites
dbDeleteSprite(1);
dbDeleteSprite(2);
dbDeleteSprite(3);
dbDeleteSprite(4);
dbDeleteSprite(5);
dbDeleteSprite(6);
dbDeleteSprite(7);
dbDeleteSprite(8);
dbDeleteSprite(9);
dbDeleteSprite(10);
dbDeleteSprite(11);
dbDeleteSprite(12);
dbDeleteSprite(13);
return;
}
void ClearSprites()
{
//Clean up Menu Sprites
dbCLS();
for (int a = 1; a < 100; a++)
{
dbHideSprite(a);
dbDeleteSprite(a);
}
dbText(0,0,"All sprites cleared");
dbSync();
dbSync();
dbWait(1000);
dbFlushVideoMemory();
exit(0);
return;
}
void GetName()
{
if (dbLen(Player1.Name) < 15)
{
switch (dbScanCode())
{
case 2 :
strcat(Player1.Name, "1");
break;
case 3 :
strcat(Player1.Name, "2");
break;
case 4 :
strcat(Player1.Name, "3");
break;
case 5 :
strcat(Player1.Name, "4");
break;
case 6 :
strcat(Player1.Name, "5");
break;
case 7 :
strcat(Player1.Name, "6");
break;
case 8 :
strcat(Player1.Name, "7");
break;
case 9 :
strcat(Player1.Name, "8");
break;
case 10 :
strcat(Player1.Name, "9");
break;
case 11 :
strcat(Player1.Name, "0");
break;
case 16 :
strcat(Player1.Name, "Q");
break;
case 17 :
strcat(Player1.Name, "W");
break;
case 18 :
strcat(Player1.Name, "E");
break;
case 19 :
strcat(Player1.Name, "R");
break;
case 20 :
strcat(Player1.Name, "T");
break;
case 21 :
strcat(Player1.Name, "Y");
break;
case 22 :
strcat(Player1.Name, "U");
break;
case 23 :
strcat(Player1.Name, "I");
break;
case 24 :
strcat(Player1.Name, "O");
break;
case 25 :
strcat(Player1.Name, "P");
break;
case 30 :
strcat(Player1.Name, "A");
break;
case 31 :
strcat(Player1.Name, "S");
break;
case 32 :
strcat(Player1.Name, "D");
break;
case 33 :
strcat(Player1.Name, "F");
break;
case 34 :
strcat(Player1.Name, "G");
break;
case 35 :
strcat(Player1.Name, "H");
break;
case 36 :
strcat(Player1.Name, "J");
break;
case 37 :
strcat(Player1.Name, "K");
break;
case 38 :
strcat(Player1.Name, "L");
break;
case 44 :
strcat(Player1.Name, "Z");
break;
case 45 :
strcat(Player1.Name, "X");
break;
case 46 :
strcat(Player1.Name, "C");
break;
case 47 :
strcat(Player1.Name, "V");
break;
case 48 :
strcat(Player1.Name, "B");
break;
case 49 :
strcat(Player1.Name, "N");
break;
case 50 :
strcat(Player1.Name, "M");
break;
case 57 :
strcat(Player1.Name, " ");
break;
case 14 :
Player1.Name[dbLen(Player1.Name) - 1] = '\0';
break;
}
}
else
{
switch(dbScanCode())
{
case 14 :
Player1.Name[dbLen(Player1.Name) - 1] = '\0';
break;
}
}
dbText(420, 300, Player1.Name);
return;
}
void MoveChar()
{
switch (dbScanCode())
{
case KEYDOWN:
dbShowSprite(MAINDOWN);
dbHideSprite(MAINUP);
dbHideSprite(MAINLEFT);
dbHideSprite(MAINRIGHT);
if (BACKY > -2228 )
BACKY -= 4;
dbSprite(GRASS, BACKX, BACKY, GRASS);
dbSprite(MAINDOWN, 500, 500, MAINDOWN);
break;
case KEYUP:
dbHideSprite(MAINDOWN);
dbShowSprite(MAINUP);
dbHideSprite(MAINLEFT);
dbHideSprite(MAINRIGHT);
if (BACKY < -4 )
BACKY += 4;
dbSprite(MAINUP, 500, 500, MAINUP);
dbSprite(GRASS, BACKX, BACKY, GRASS);
break;
case KEYRIGHT:
dbHideSprite(MAINDOWN);
dbHideSprite(MAINUP);
dbHideSprite(MAINLEFT);
dbShowSprite(MAINRIGHT);
if (BACKX > -2972 )
BACKX -= 4;
dbSprite(MAINRIGHT, 500, 500, MAINRIGHT);
dbSprite(GRASS, BACKX, BACKY, GRASS);
break;
case KEYLEFT:
dbHideSprite(MAINDOWN);
dbHideSprite(MAINUP);
dbShowSprite(MAINLEFT);
dbHideSprite(MAINRIGHT);
if (BACKX < -4 )
BACKX += 4;
dbSprite(MAINLEFT, 500, 500, MAINLEFT);
dbSprite(GRASS, BACKX, BACKY, GRASS);
break;
}
}
void DisplayMap()
{
int Map[5][5];
if (Player1.Location == HOME)
{
//Map{1, 1, 1, 1, 1}
}
//dbGetImage(
}
Saving the world, one bit at a time.... Wait it's not worth saving. Get your own bits!