1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include "DarkGDK.h"
#include "player.h"
int test[5*5]={
0 1 3 5 6
5 2 3 1 5
2 3 2 5 6
3 2 4 5 7
1 2 3 4 5
};
void mapsetup(int map[], int width, int height);
void MenuControl();
//===== GAME CONTROLL ENUM =====
enum cGameState {Menu, Game_Setup, Game1P, Game_End, Exit};
cGameState Game_State = Menu;
void DarkGDK ( void )
{
dbSetDisplayMode (1024,768,32);
dbSyncOn ( );
dbSyncRate ( 60 );
dbMaximizeWindow ();
dbSetImageColorKey ( 255, 0, 255 );
player player(50,220,15,.01,1);
while ( LoopGDK ( ) )
{
switch (Game_State)
{
case Menu:
MenuControl();
break;
case Game_Setup:
dbCLS(dbRGB(0,0,0));
mapsetup(test,5,5);
Game_State = Game1P;
break;
case Game1P:
player.setup();
player.movement();
player.gravity();
break;
case Game_End:
break;
case Exit:
return;
break;
}
if ( dbEscapeKey ( ) )
break;
dbSync ( );
}
for ( int i = 1; i < 30; i++ )
{
dbDeleteSprite ( i );
dbDeleteImage ( i );
}
return;
}
void mapsetup(int map[], int width, int height)
{
dbLoadImage("backgroundtiletest.bmp",11);
int cell = 1;
for(int H = 0; H < height; H++)
for(int W = 0; W < width; W++)
{
dbSprite ( cell, 32 * W, 32 * H, map[cell - 1]);
// All the math is done here:
int cellValue = map[cell - 1] - 1;
int iX = cellValue % 3;
int iY = cellValue / 3;
float fOffset = 1.0f / 3.0f;
float U = iX * fOffset;
float V = iY * fOffset;
// And here the math is used to clip the sprites:
dbSetSpriteTextureCoord (cell, 0, U, V);
dbSetSpriteTextureCoord (cell, 1, U + fOffset, V);
dbSetSpriteTextureCoord (cell, 2, U + fOffset*2, V);
dbSetSpriteTextureCoord (cell, 3, U, V + fOffset);
dbSetSpriteTextureCoord (cell, 4, U + fOffset, V + fOffset);
dbSetSpriteTextureCoord (cell, 5, U + fOffset*2, V + fOffset);
dbSetSpriteTextureCoord (cell, 6, U, V + fOffset*2);
dbSetSpriteTextureCoord (cell, 7, U + fOffset, V + fOffset*2);
dbSetSpriteTextureCoord (cell, 8, U + fOffset*2, V + fOffset*2);
dbSizeSprite (cell, 32, 32);
cell++;
}
}
void MenuControl()
{
static int MENU_STATE = 2;
static bool KeyPressed = false;
dbCLS(dbRGB(0,0,0));
//DRAWING TITLE
dbSetTextFont("Pristina");
dbSetTextToBold ();
dbSetTextSize(100);
dbInk(dbRGB(141,47,155),dbRGB(141,47,155));
dbCenterText(512, 78, "Waffle Warrior!!!");
dbSetTextSize(90);
dbInk(dbRGB(243,248,71),dbRGB(243,248,71));
dbCenterText(512, 75, "Waffle Warrior!!!");
//DRAWING MENU BOXES
dbInk(dbRGB(243, 248, 71),dbRGB(243, 248, 71));
dbBox(362-5, 325-5, 662-5, 400-5); // 200x150 px
dbBox(362-5, 450-5, 662-5, 525-5); // 200x150 px
dbInk(dbRGB(255, 255, 255),dbRGB(255, 255, 255));
dbBox(362, 325, 662, 400); // 200x150 px
dbBox(362, 450, 662, 525); // 200x150 px
//DRAWING CHOSEN MENU BOX
switch(MENU_STATE)
{
case 2:
dbInk(dbRGB(0, 0, 0),dbRGB(0, 0, 0));
dbBox(362, 325, 662, 400); // 200x150 px
break;
case 1:
dbInk(dbRGB(0, 0, 0),dbRGB(0, 0, 0));
dbBox(362, 450, 662, 525); // 200x150 px
break;
}
//INSERT TEXT ON MENU BOXES
dbInk(dbRGB(255, 255, 255),dbRGB(255, 255, 255));
dbSetTextSize(40);
dbCenterText(512, 350, "START GAME");
dbCenterText(512, 475, "EXIT GAME");
//CONTROLING MENU
if( (dbKeyState(200))&&(KeyPressed == false) )
{
MENU_STATE += 1;
KeyPressed = true;
}
if( (dbKeyState(208))&&(KeyPressed == false) )
{
MENU_STATE -= 1;
KeyPressed = true;
}
if(MENU_STATE > 2) {MENU_STATE = 1;}
if(MENU_STATE < 1) {MENU_STATE = 2;}
if( (dbKeyState(200)==0)&&(dbKeyState(208)==0) ) {KeyPressed = false;}
//CHOOSING...
if(dbKeyState(28))
{
if(MENU_STATE == 2){Game_State = Game_Setup;}
if(MENU_STATE == 1){Game_State = Exit;}
}
}
|