Hello, I am creating a remake of the ol 'Astrosmash' game for intellevision ;)
I've drawn the background, the ship, and started putting in the soundFX, hyperspace, then when it came to bullets is where I got stuck...
I'd like to fix whats wrong with my bullets, though I can't seem to figure it out so I thought Id ask for some help!
I create an array of D3DXVECTOR3's (to hold the bullet positions) with a size of 10
I will eventually make it only let you shoot 2 bullets,(since thats how the original was) but for a cheat mode or something I want it to be able to shoot more..
the problem is when I shoot bullets/lasers whatever you want to call em;
As soon as one bullet leaves the screen all bullets disappear!!
Heres my code, I'll explain what im doing currently...
heres what I have at the top:
IDirect3D9* d3d = 0;
IDirect3DDevice9* d3dDevice = 0;
D3DPRESENT_PARAMETERS d3dpp;
ID3DXSprite* pSprite; // my sprite rendering object
IDirect3DTexture9* pBGTex; // textures for background, ship, and bullet
IDirect3DTexture9* pShipTex;
IDirect3DTexture9* pBulletTex;
D3DXVECTOR3 LaserPos[10]; // array of LaserPositions(x, y, z)[but z is made null]
D3DXVECTOR3 ShipPos, BGPos; // Ship And Background coordinates
float MoveSpeed = 5.8f; // Ship Move Speed
int LID = 0; // Laser ID
Ok now after I Initialize the window, Direct3D, and the textures, and sprite...
Heres my render function which gets called every frame from WinMain
void Render()
{
d3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
d3dDevice->BeginScene();
pSprite->Begin(D3DXSPRITE_ALPHABLEND); // transparency enabled
pSprite->Draw(pBGTex, 0, 0, &BGPos, 0xFFFFFFFF); // draw BG
pSprite->Draw(pShipTex, 0, 0, &ShipPos, 0xFFFFFFFF); // draw Ship
if(LID > 0) // if at least 1 laser has been shot
{
for(int x = 0; x < LID; x++) // iterate through laser's coordinates
{
if(LaserPos[x].x != 0 && LaserPos[x].y != 0)
{
//Draw laser if x+y != 0
pSprite->Draw(pBulletTex, 0, 0, &LaserPos[x], 0xFFFFFFFF);
}
else if(LaserPos[x].x == 0 && LaserPos[x].y == 0)
{
// not sure if I need something here
}
}
}
pSprite->End();
d3dDevice->EndScene();
d3dDevice->Present(0, 0, 0, 0);
}
LID (laser ID) gets increased upon pressing one of the shoot buttons
In WinMain I create a thread called 'HotkeyHandler' Which handles most keypresses
void HotkeyHandler()
{
int count = 0;
for(;; Sleep(10))
{
if(paused == 0)
{
if(GetAsyncKeyState(VK_LEFT))
{
ShipPos.x -= MoveSpeed;
}
if(GetAsyncKeyState(VK_RIGHT))
{
ShipPos.x += MoveSpeed;
}
if(GetAsyncKeyState(VK_DOWN))
{
HyperSpace();//generates random x coord and goes
}
if(GetAsyncKeyState(VK_SPACE) || GetAsyncKeyState(VK_CONTROL) || GetAsyncKeyState(VK_UP))
{
if(LID < 10 && count == 0)
{
LaserPos[LID] = D3DXVECTOR3((ShipPos.x + 25), (ShipPos.y - 5), 0.0f);
LID++;
count = 8;
result = systemx->playSound(FMOD_CHANNEL_FREE, Shootsound, false, &channel);
}
}
// Wall Boundries
if(ShipPos.x < -25.0f)
ShipPos.x = -25.0f;
if(ShipPos.x > 988.0f)
ShipPos.x = 988.0f;
if(count > 0)
count--;
}
}
}
this line:
LaserPos[LID] = D3DXVECTOR3((ShipPos.x + 25), (ShipPos.y - 5), 0.0f);
places the start coordinates of the current laser into the array...
LID++;
tells the render loop to start drawing...
count makes sure you have to wait a little before being able to fire again
I have another created thread which moves all lasers up the screen, and also I think where it should remove a laser from the game once it goes off the top of the screen!
void LaserThread()
{
for(;; Sleep(10))
{
for(int c = 0; c < LID; c++) // ;)
{
// move lasers up the screen
if(LaserPos[c].y > -57.0f)
{
LaserPos[c].y -= 10.0f;
}
else if(LaserPos[c].y < -57.0f) // laser is off the top
{
LaserPos[c].x = 0; // tried this but
LaserPos[c].y = 0;// seems to not have any effect
LID--; // draw 1 less laser
}
}
}
}
So what is my problem?
I have also commented that LID--; and made a hotkey to decrease it, and my results where that it was closer to what I want but, backwards pretty much
the last bullet you shot once subtracting 1 from LID is the one that gets removed from play, instead I want the one offscreen to be removed from play, and the other ones NOT to be removed until they go offscreen!
I know someone out there has done this before!
thanks to anyone that makes a post! :)
[Edited by - Steve8x on May 28, 2008 12:58:57 AM]