Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Trying To Create A 2D Projectile In C++(DarkGDK)

Author
Message
Lysander610
7
Years of Service
User Offline
Joined: 5th Mar 2012
Location:
Posted: 5th Mar 2012 17:37
I am having a problem with creating a moving projectile in C++ I can't get it to move on its own

i have used dbMoveSprite but i want to show it moving
WLGfx
12
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Mar 2012 21:04
Have you got your test code so we can see where you are at?

Usually it's an easy problem to solve.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Lysander610
7
Years of Service
User Offline
Joined: 5th Mar 2012
Location:
Posted: 6th Mar 2012 17:07
This is my code i dont know if the code snippit will work or not

[/code]

#include "DarkGDK.h"

// constant for dbSync
const int RATE = 10;

//constants for sprites
const int TANK_IMG = 1;
const int TANK_SPRITE = 1;
const int PROJ_IMG = 2;
const int PROJ_SPRITE = 2;
//tank starting points
const int START_X = 0;
const int START_Y = 300;


int tankx = START_X;
int tanky = START_Y;

//prototypes
void getTankCoordinates(int &,int &);
void setUp();

void DarkGDK(){

dbSyncOn();
dbSyncRate(RATE);

while( LoopGDK() ){

setUp();
getTankCoordinates(tankx,tanky);
dbSprite(TANK_SPRITE,tankx,tanky,TANK_IMG);


int projx = tankx+170;
int projy = tanky-20;
if (dbSpaceKey() ){


dbSprite(PROJ_SPRITE,projx,projy,PROJ_IMG);
dbRotateSprite(PROJ_SPRITE,315);

//THIS IS WERE MY PROBLEM IS
while (projx<0&&projy<0){
projx-=10;
projy-=10;

}
dbSprite(PROJ_SPRITE,projx,projy,PROJ_IMG);

}






dbSync();

}


}


void setUp() {
dbSetImageColorKey(0,255,0);
dbLoadImage("proj3.bmp",PROJ_IMG);
dbLoadImage("tank2.bmp",TANK_IMG);
dbSprite(TANK_SPRITE,START_X,START_Y,TANK_IMG);
dbScaleSprite(TANK_SPRITE,75);
}
void getTankCoordinates(int &x,int &y)
{
if(y>-20){
if( dbUpKey() ) y--;
if(dbUpKey()&&dbShiftKey() ) y-=5;


}
if(y<400){
if (dbDownKey() ) y++;
if(dbDownKey()&&dbShiftKey() ) y+=5;
}
if(x>0){
if( dbLeftKey() ) x--;
if(dbLeftKey()&&dbShiftKey() ) x-=5;

}
if(x<580){
if( dbRightKey() ) x++;
if(dbRightKey()&&dbShiftKey() ) x+=5;

}
}
[code]

Attachments

Login to view attachments
Lysander610
7
Years of Service
User Offline
Joined: 5th Mar 2012
Location:
Posted: 9th Mar 2012 17:41
PROBLEM SOLVED thanks
DeadTomGC
9
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 11th Mar 2012 03:33 Edited at: 11th Mar 2012 03:35
The things need to be in the reverse order.

kinda like {code} stuff {/code} except with [] instead of {}


and things
stuff

Edit: It doesn't seem to work? Does it? hmmm....


Login to post a reply

Server time is: 2020-02-26 07:39:54
Your offset time is: 2020-02-26 07:39:54