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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
//Dark GDK - The Game Creators - www.thegamecreators.com
//the wizard has created a very simple project that uses Dark GDK
//it contains the basic code for a GDK application
//whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
//Global
int Block_Size=20;
int grid[20][10];
//colors
const DWORD Red = dbRGB(255,0,0);
const DWORD Green = dbRGB(0,255,0);
const DWORD Blue = dbRGB(0,0,255);
const DWORD Magenta = dbRGB(255,0,255);
const DWORD Black = dbRGB(0,0,0);
const DWORD White = dbRGB(255,255,255);
const DWORD Yellow = dbRGB(255,255,0);
const DWORD Cyan = dbRGB(0,255,255);
const DWORD Orange = dbRGB(255,165,0);
const DWORD Grey = dbRGB(177,177,177);
//end colors
//end global
//Classes
class Block {
private:
DWORD color;
//int blocks[4];
public:
int x,y;
Block();
Block(int, int, DWORD);
void draw();
void move(int, int);
void clear();
//bool col();
};
Block::Block(){
x = 0;
y =0;
color = White;
}
//Methods (Block)
Block::Block(int X, int Y, DWORD COLOR)
{
x=X;
y=Y;
color=COLOR;
}
void Block::draw()
{
int x1, y1, x2, y2;
x1=x*Block_Size;
y1=y*Block_Size;
x2=x1+Block_Size;
y2=y1+Block_Size;
// dbInk(color, Black);
dbBox(x1,y1,x2,y2);
}
void Block::clear()
{
dbInk(Black, Black);
//dbBox(x1,y1,x2,y2);
draw();
}
void Block::move(int dx, int dy)
{
x=x+dx;
y=y+dy;
dbInk(color, Black);
draw();
}
//End Method (Block)
class Shape {
private:
Block blocks[4];
//int pos[8];
public:
int pos[8];
DWORD color;
Shape();
void make_ishape();
void move_shape(int,int);
void draw_shape();
bool col();
};
//Methods (Shape)
Shape::Shape() {
blocks[0] = Block(0,0, Red);
blocks[1] = Block(0,0, Red);
blocks[2] = Block(0,0, Red);
blocks[3] = Block(0,0, Red);
}
bool Shape::col()
{
for (int i=0; i<=4; i++)
{
if (blocks[i].y >= 19)
{
return false;
}
/*/else if (blocks[i].x >= 0 && blocks[i].x <= 9)
{
return false;
}/*/
}
return true;
}
void Shape::make_ishape()
{
blocks[0] = Block(pos[0],pos[1],Blue);
blocks[1] = Block(pos[2],pos[3],Blue);
blocks[2] = Block(pos[4],pos[5],Blue);
blocks[3] = Block(pos[6],pos[7],Blue);
}
void Shape::draw_shape()
{
for (int i=0; i<4; i++)
{
blocks[i].draw();
}
}
void Shape::move_shape(int dx, int dy)
{
for (int i=0; i<4; i++)
{
blocks[i].clear();
}
for (int i=0; i<4; i++)
{
blocks[i].move(dx,dy);
}
}
class I_Shape: public Shape{
public:
I_Shape(int,int);
private:
DWORD color;
//int pos[8];
};
//Methods (I_Shape)
I_Shape::I_Shape(int x, int y):Shape()
{
//make_shape(pos[8],color);
color=Blue;
pos[0]=x-1;
pos[1]=y;
pos[2]=x;
pos[3]=y;
pos[4]=x+1;
pos[5]=y;
pos[6]=x+2;
pos[7]=y;
//Shape(); //makes one block
make_ishape(); //makes I_Shape
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
I_Shape First(5,0);
// turn on sync rate and set maximum rate to 1 fps
dbSyncOn ( );
dbSyncRate (1);
First.draw_shape();
//First.move_shape(5,4);
// our main loop
while ( LoopGDK ( ) )
{
if (First.col())
{
if (dbLeftKey())
{
First.move_shape(-1,0);
}
else if (dbRightKey())
{
First.move_shape(1,0);
}
else if (First.col())
{
First.move_shape(0,1);
}
}
// update the screen
dbSync ( );
//dbWaitKey();
}
// return back to windows
return;
}
|