#include "DarkGDK.h"
int g;
int n;
int i = 0;
int x = 0;
int y = 974;
int BulletX;
int BulletY;
int Fire = 0;
int boost = 1;
int jumped;
void Prepare();
void Jump();
void MapLimits();
void SpawnObject(int SpriteID, int ObjPosX,int ObjPosY,int ImageID);
void Player();
void Bullet();
void Crosshair();
void DarkGDK(void)
{
Prepare();
while(LoopGDK()){
Player();
dbSync();
MapLimits();
}
}
void Jump()
{
i++;
if (i < 95)
y = y - 7 * boost;
g = 2;
if (i>= 95)
y = y + 7 * boost;
if (i>= 190){
i = 0;
y = 974;
jumped = 0;
g = 1;
}
}
void MapLimits()
{
if (x>=1255)
x = 1255;
if (x<=0)
x = 0;
}
void SpawnObject(int SpriteID,int ObjPosX,int ObjPosY,int ImageID)
{
dbSprite(SpriteID,ObjPosX,ObjPosY,ImageID);
}
void Shoot()
{
dbSprite(3,x+dbSpriteWidth(1)-25+dbSpriteWidth(2),y+dbSpriteHeight(1)/2-10,3);
dbPlaySound(1);
Fire = 1;
}
void Bullet()
{
BulletX = BulletX + 75;
if (BulletX >= dbScreenWidth()){
Fire = 0;
BulletX = x+dbSpriteWidth(1)-50+dbSpriteWidth(2);
BulletY = y+dbSpriteHeight(1)/2-10;
dbDeleteSprite(4);
}
dbSprite(4,BulletX,BulletY,4);
}
void Weapon()
{
dbSprite(2,x+dbSpriteWidth(1)-20,y+dbSpriteHeight(1)/2+10,2);
dbHideMouse();
if (dbMouseClick()==1)
Shoot();
else{
dbDeleteSprite(3);
dbDeleteSprite(4);
}
if (Fire == 1)
Bullet();
}
void Player()
{
g = 1;
if (dbSpaceKey())
jumped = 1;
if (jumped == 1)
Jump();
if (dbRightKey())
x = x + 10*boost;
if (dbLeftKey())
x = x - 10*boost;
Weapon();
Crosshair();
dbSprite(1,x,y,1);
dbPlaySprite(1,1,g,70);
}
void Prepare()
{
dbSyncOn();
dbSyncRate(60);
dbSetDisplayMode (1280,1024,32);
dbMaximizeWindow();
dbSetImageColorKey (255,0,255);
dbCreateAnimatedSprite (1,"Sprite2.bmp",2,1,1);
dbCreateAnimatedSprite (2,"Sprite.bmp",1,1,2);
dbCreateAnimatedSprite (3,"Backdrop.bmp",1,1,3);
dbCreateAnimatedSprite (4,"Bullet.bmp",1,1,4);
dbCreateAnimatedSprite (5,"crosshair.bmp",1,1,5);
dbLoadSound ("m4a1.wav",1);
BulletX = x+dbSpriteWidth(1)-50+dbSpriteWidth(2);
BulletY = y+dbSpriteHeight(1)/2-10;
}
void Crosshair()
{
dbSprite(5,dbMouseX(),dbMouseY(),5);
}
Now i want my bullet to go to the direction of my crosshair, but I dont have any idea how to start. Any ideas?
ty