Hey Guys!
So im trying to finish my game here, but now a bug appeared..
The spritecollision is not working ...
Here's the code:
#include "DarkGDK.h"
#include "dinput.h"
char XPos[30];
char YPos[30];
char lol[5];
bool debug = false;
int level = 1;
int maxen = level * 2;
int speed = 1;
int score = 0;
int lvl1 = 10;
int lvl2 = 15;
int lvl3 = 20;
int lvl4 = 25;
int lvl5 = 34;
int lvl6 = 45;
int lvl7 = 68;
bool shooting = false;
char score1[10];
char highscore[100];
void GameOver()
{
if (dbFileExist("hg//highscore.txt"))
{
sprintf_s ( highscore, 20, "||Score: %d", score);
dbOpenToWrite ( 1, "hg//highscore.txt" ) ;
dbWriteString ( 1, highscore );
}
else
{
dbMakeFile("hg//highscore.txt");
sprintf_s ( highscore, 20, "||Score: %d", score);
dbOpenToWrite ( 1, "hg//highscore.txt" ) ;
dbWriteString ( 1, highscore );
}
return;
}
void load()
{
dbLoadImage("res//p1.png", 1);
dbLoadImage("res//water.png", 2);
dbLoadImage("res//mouse.png", 3);
dbLoadImage("res//bomb.png", 5);
// barcos
dbLoadImage("res//barco1.png", 4);
dbLoadImage("res//barco1.png", 6);
dbMakeFile("hg//highscore.txt");
dbMakeFile("cfg//cfg.dat");
dbMakeFile("cfg//island.idc");
}
void Movement()
{
if(!dbSpriteExist(4))
{
int speed2 = speed;
if(dbSpriteCollision(4, 1))
{
GameOver();
}
}
}
void collision()
{
if(dbSpriteCollision(5, 4)) // bomba ao barco
{
dbDeleteSprite(5);
dbDeleteSprite(4);
score = score + 4 * level;
}
if(dbSpriteCollision(6, 4)) // bomba ao barco
{
dbDeleteSprite(5);
dbDeleteSprite(4);
score = score + 4 * level;
}
if(dbSpriteCollision(7, 4)) // bomba ao barco
{
dbDeleteSprite(5);
dbDeleteSprite(4);
score = score + 4 * level;
}
if(dbSpriteCollision(8, 4)) // bomba ao barco
{
dbDeleteSprite(5);
dbDeleteSprite(4);
score = score + 4 * level;
}
if(dbSpriteCollision(5, 2))dbDeleteSprite(5);
if(dbSpriteCollision(5, 1))GameOver();
}
void Spawn1()
{
dbSprite(4, 600, 434, 4);
if (level > 1)dbSprite(5, 600, 434, 6);
else if (level > 2)dbSprite(6, 600, 434, 6);
else if (level > 3)dbSprite(7, 600, 434, 6);
else if (level > 4)dbSprite(8, 600, 434, 6);
Movement();
if(dbSpriteCollision(4, 1))
{
GameOver();
}
}
void generate()
{
if (!dbSpriteExist(4))
{
Spawn1();
}
}
void display()
{
dbHideMouse();
dbSprite(3, dbMouseX() - 13, dbMouseY() - 13, 3); //change Mouse
sprintf_s ( score1, 20, "Score: %d", score);
dbText (10,50, score1);
if (debug == true)
{
sprintf_s ( XPos, 20, "X: %d", dbSpriteX(3));
sprintf_s ( YPos, 20, "Y: %d", dbSpriteY(3));
dbText (10,10, XPos);
dbText (10,30, YPos);
}
}
void bomb()
{
dbMoveSprite(5, -6); //speed da bomba
dbRotateSprite(4, 90);
dbMoveSprite(4, -0.6 - score * 0.1 / 2);
dbRotateSprite(4, 0);
if(dbSpriteCollision(4, 1))
{
return;
}
}
void input()
{
if(dbMouseClick() == 1 && shooting == false)
{
shooting = true;
int x = dbSpriteX(3);
int y = dbSpriteY(3);
int subir = 5;
dbSprite(5, x, -20, 5);
}
if(dbKeyState(66) == 1) //F8
{
debug = true;
}
if(dbKeyState(67) == 1) // F9
{
debug = false;
}
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
load();
dbSprite(1, 10, 240, 1);
dbSprite(2, 0, 460, 2); //water
Spawn1();
while ( LoopGDK ( ) )
{
if(dbSpriteCollision(1, 4))
{
GameOver();
}
input();
display();
Movement();
generate();
bomb();
collision();
dbSetWindowTitle("Island Defender | ");
if(!dbSpriteExist(5)) shooting = false;
if(dbEscapeKey() == 1)break;
dbSync ( );
}
return;
}
what is wrong?
Learning C++
VB6 Advanced: 4/5
VB.NET Advanced: 4/5