If anyone wants to start dabbling with c++ and Dark GDK here is a intro project. This is just the barebones basics to learn how to use Dark GDK. It contains 8 directional movement with a rmxp sprite. A map with a ground, mask, fringe and item layer. That is it. This can be programmed in under a hour if you know what your doing.
I know a lot of people have had trouble with tiling maps when creating there own mapping systems. It also contains some simple pointer operations to learn from.
www.freemmorpgmaker.com/Game-2.rar
I hardly claim this is perfect code. But it gets the job done and you can see how one person has managed to get it working.
Wont work without the files included in the zip but if you just want a quick look at the source.
#include "DarkGDK.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
// File Numbers
int groundTile = 1;
int maskTile = 2;
int itemTile = 3;
int playerSprite = 4;
int fringeTile = 5;
// Variables
bool debugEnabled = true;
byte playerSpeed = 2;
byte walkAnimationSpeed = 150;
int playerX = 0;
int playerY = 0;
byte currentDirection = 0;
bool newMap = true;
void playerMovement(int *playerX, int *playerY)
{
// Standard Movement
if(dbLeftKey() && dbDownKey() == 0 && dbUpKey() == 0)
{
if( currentDirection != 1) { dbSetSpriteFrame(playerSprite,5); }
currentDirection = 1;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
(*playerX) -= playerSpeed;
}
if(dbRightKey() && dbDownKey() == 0 && dbUpKey() == 0)
{
if( currentDirection != 2) { dbSetSpriteFrame(playerSprite,9); }
currentDirection = 2;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
(*playerX) += playerSpeed;
}
if(dbUpKey() && dbLeftKey() == 0 && dbRightKey() == 0)
{
if( currentDirection != 3) { dbSetSpriteFrame(playerSprite,13); }
currentDirection = 3;
dbPlaySprite(playerSprite,13,16,walkAnimationSpeed);
(*playerY) -= playerSpeed;
}
if(dbDownKey() && dbLeftKey() == 0 && dbRightKey() == 0)
{
if( currentDirection != 4) { dbSetSpriteFrame(playerSprite,1); }
currentDirection = 4;
dbPlaySprite(playerSprite,1,4,walkAnimationSpeed);
(*playerY) += playerSpeed;
}
// Diagonal Movement
if(dbLeftKey() && dbUpKey())
{
if( currentDirection != 5) { dbSetSpriteFrame(playerSprite,5); }
currentDirection = 5;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
(*playerX) -= playerSpeed;
(*playerY) -= playerSpeed;
}
if(dbRightKey() && dbUpKey())
{
if( currentDirection != 6) { dbSetSpriteFrame(playerSprite,9); }
currentDirection = 6;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
(*playerX) += playerSpeed;
(*playerY) -= playerSpeed;
}
if(dbLeftKey() && dbDownKey())
{
if( currentDirection != 7) { dbSetSpriteFrame(playerSprite,5); }
currentDirection = 7;
dbPlaySprite(playerSprite,5,8,walkAnimationSpeed);
(*playerX) -= playerSpeed;
(*playerY) += playerSpeed;
}
if(dbRightKey() && dbDownKey())
{
if( currentDirection != 8) { dbSetSpriteFrame(playerSprite,9); }
currentDirection = 8;
dbPlaySprite(playerSprite,9,12,walkAnimationSpeed);
(*playerX) += playerSpeed;
(*playerY) += playerSpeed;
}
// Check to prevent players leaving screen
if ((*playerX) > 768)
{
dbPasteSprite(playerSprite,768,(*playerY));
(*playerX) = 768;
}
if ((*playerX) < 0)
{
dbPasteSprite(playerSprite,0,(*playerY));
(*playerX) = 0;
}
if ((*playerY) < 0)
{
dbPasteSprite(playerSprite,(*playerX),0);
(*playerY) = 0;
}
if ((*playerY) > 554)
{
dbPasteSprite(playerSprite,(*playerX),554);
(*playerY) = 554;
}
// Teleport helps to debug
if(dbShiftKey() && dbMouseClick() == 1 && debugEnabled == true)
{
(*playerX) = dbMouseX();
(*playerY) = dbMouseY();
}
// Update screen position.
dbPasteSprite(playerSprite,*playerX,*playerY);
}
void loadFiles(int *groundTile, int *maskTile, int *fringeTile, int *itemTile)
{
// Set Transparency
dbSetImageColorKey ( 0, 0, 0 );
// Load Player Sprite
dbCreateAnimatedSprite(playerSprite,"Player.png",4,4,playerSprite);
dbSprite(playerSprite,playerX,playerY,playerSprite);
// Get Tile size.
// Load Tilesets
dbCreateAnimatedSprite((*groundTile),"Tiles.bmp",8,568,(*groundTile)); // Ground
dbCreateAnimatedSprite((*maskTile),"Tiles.bmp",8,568,(*maskTile)); // Mask
dbCreateAnimatedSprite((*itemTile),"Items.bmp",6,467,(*itemTile)); // Items
dbCreateAnimatedSprite((*fringeTile),"Tiles.bmp",8,568,(*fringeTile)); // Fringe
// Using DbPasteSprite so hide original Sprite
dbHideSprite((*groundTile));
dbHideSprite((*maskTile));
dbHideSprite((*itemTile));
dbHideSprite(playerSprite);
dbHideSprite((*fringeTile));
}
void loadMap()
{
// Variables
int a = 0; int b = 0;
string FileContents[500];
int MapData[1500];
int value = 0;
char comma;
int XTile = 0;
int YTile = 0;
byte mapLayer = 1;
// Read File
string line;
ifstream myfile ("Maps/Map1.map");
if (myfile.is_open())
{
while ( myfile.good() )
{
++a;
getline (myfile,line);
FileContents[a] = line;
// Split By Commas
stringstream ss(FileContents[a]);
while (ss >> value)
{
++b;
MapData[b] = value;
ss >> comma;
}
}
myfile.close();
a = 0;
b = 0;
}
else
{
MessageBox(NULL,"Map File Missing","Error",NULL);
}
while(mapLayer <= 5)
{
while(YTile < 600)
{
a++;
if (MapData[a] > 0)
{
dbSetSpriteFrame(mapLayer,MapData[a]);
dbPasteSprite(mapLayer,XTile,YTile);
}
XTile = XTile + 32;
if (XTile == 800)
{
YTile = YTile + 32;
XTile = 0;
}
}
mapLayer++;
if (mapLayer == playerSprite)
{
mapLayer = fringeTile;
// Control player movement. Do it here to be behind fringe.
playerMovement(&playerX,&playerY);
}
// Reset Values
YTile = 0;
XTile = 0;
}
}
void debug()
{
if (debugEnabled == true)
{
// Debug Display
dbInk(dbRGB(255,0,0),1);
dbText(770,0,dbStr(dbScreenFPS()));
dbText(770,15,dbStr(dbScanCode()));
dbText(770,30,dbStr(playerX));
dbText(770,45,dbStr(playerY));
dbText(770,60,dbStr(dbMouseX()));
dbText(770,75,dbStr(dbMouseY()));
}
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 604 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
// Set up Game Screen
dbSetDisplayMode(800,600,32);
dbSetWindowTitle("7 Sins");
// Load the Sprites
loadFiles(&groundTile, &maskTile, &fringeTile, &itemTile);
while ( LoopGDK ( ) )
{
// Load Map
loadMap();
// Debug
debug();
if ( dbEscapeKey ( ) )
break;
// Sync Screen
dbSync ( );
}
return;
}
Also if anyone has suggestions on how it can be improved i would love to hear them.
Your signature has been erased by a mod - Please reduce it to 600x120 maximum size