Can anyone explain why when I comment out
dbInstanceObject(3 + i, 3);
dbPositionObject(3 + i, cur->x, cur->y, 0);
The space ship flies correctly on 2 axis, but when I uncomment those lines the spaceship only flies along the y-axis with no z-movement? (Assuming spacebar has been pressed?)
This bug makes no sense to me!!!!
Also if you want to try out my game, "Asteroids 2008: The Duel", no resources are required, just plug & play with the code.
It might also make a good tutorial! PS - Game not complete or even working very much.
#include "DarkGDK.h"
class Bullet {
public:
float x,y,xvel,yvel, radius;
Bullet *next;
};
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 0 );
dbRandomize ( dbTimer ( ) );
//dbSetWindowSize(1024,768);
//dbSetWindowOff();
dbSetAmbientLight(80);
dbHideMouse();
dbColorBackdrop(dbRGB(0,10,10));
dbMakeObjectCone(1,1);
//dbLoadObject("ship1.3ds",1);
dbMakeObjectCone(2,1);
dbMakeObjectSphere(3,.3,3,3);
dbHideObject(3);
float p1x=0, p1y=0, p2x=10, p2y=0;
float p1rot = 0, p2rot = 180;
float p1xvel=0, p1yvel=0, p2xvel=0, p2yvel=0;
float speed = .001;
float zoom = 40;
int numBullets = 0;
Bullet *head = NULL;
while ( LoopGDK ( ) )
{
if ( dbUpKey ( ) )
{
p1xvel -= speed * dbSin(p1rot);
p1yvel += speed * dbCos(p1rot);
}
if(dbLeftKey())
p1rot -= 1.5;
if(dbRightKey())
p1rot += 1.5;
if(dbKeyState(44)) // z key
zoom *= 1.05;
if(dbKeyState(30)) // a key
zoom *= .95;
if(dbKeyState( 57 ))
{
Bullet *b = new Bullet;
b->x = p1x - (1 * dbSin(p1rot) * 3.1);
b->y = p1y + (1 * dbCos(p1rot) * 3.1);
b->xvel = p1xvel - (.3 * (1 * dbSin(p1rot)));
b->yvel = p1yvel + (.3 * (1 * dbCos(p1rot)));
b->next = NULL;
if(head == NULL)
{
head = b;
dbShowObject(3);
}
else
{
Bullet *cur;
cur = head;
while(cur->next != NULL)
cur = cur->next;
cur->next = b;
}
numBullets++;
}
Bullet *cur = head;
for(int i=0;i<numBullets;i++)
{
dbInstanceObject(3 + i, 3);
// dbPositionObject(3 + i, cur->x, cur->y, 0);
cur = cur->next;
}
dbPositionCamera(p1x,p1y,zoom);
dbPointCamera(p1x,p1y,0);
dbPositionObject(1,p1x,p1y,0);
dbPositionObject(2,p2x,p2y,0);
dbRotateObject(1,0,0,p1rot);
dbRotateObject(2,0,0,p2rot);
p1x+=p1xvel;
p1y+=p1yvel;
dbSync ( );
}
return;
}
http://overspace.panddpictures.net
SourceForge: OverSpace