Hey guys I have now implemented shooting into my top down shooter game and there are a couple of things im not sure how to do or fix.
First off I can only shoot once....lol I know its lame but im not sure exactly how to make more than one.
Also second thing I need it to fire directly from the ship but right now it will only fire from the center of the screen meaning: if I start the game and move my shop to the far right when I hit fire it the bullet appears in the center instead in front of my ship and fires away.
Firing function
#ifndef _FIRE_H
#define _FIRE_H
#include "PlayerShip.h"
#include "game.h"
class Fire
{
public:
int x , y; // Variables to handle Coordinates
int movex , movey;
int width , height;
void FireBasicGun(); // Function Prototypes
void FireSpecial(); //---------------------
};
#endif
// Fire.h Implementation File
#include "Fire.h"
void Fire::FireBasicGun()
{
Fire::y -= Fire::movey;
if(Fire::y > 0)
{
Fire::y -= Fire::movey;
}
}
void Fire::FireSpecial()
{
// Code for firing special
// weapon
}
gun_fire = LoadTexture("firegun1.bmp",D3DCOLOR_XRGB(255,0,255));
if (gun_fire == NULL)
return 0;
Gun.x = Player.x;
Gun.y = Player.y;
Gun.width = 24;
Gun.height = 32;
Gun.movey = 10;
Gun.movex = 10;
void Game_Run(HWND hwnd)
{
//make sure the Direct3D device is valid
if (d3ddev == NULL)
return;
Poll_Mouse();
Poll_Keyboard();
//after short delay, ready for next frame?
//this keeps the game running at a steady frame rate
if (GetTickCount() - start >= 30)
{
//reset timing
start = GetTickCount();
//move the sprite
Player.CallMovement();
if(Key_Down(DIK_SPACE))
{
isFire = true;
}
if(FIRE == true)
{
Gun.FireBasicGun();
}
//update the scrolling view
UpdateScrollPosition();
//start rendering
if (d3ddev->BeginScene())
{
//erase the entire background
d3ddev->StretchRect(tiles, NULL, backbuffer, NULL, D3DTEXF_NONE);
//start sprite handler
sprite_handler->Begin(D3DXSPRITE_ALPHABLEND);
//create vector to update sprite position
D3DXVECTOR3 position((float)Player.x, (float)Player.y, 0);
D3DXVECTOR3 position2((float)Gun.x, (float)Gun.y, 0);
//draw tiles onto the scroll buffer
DrawTiles();
//draw the scroll window onto the back buffer
DrawScrollWindow();
if(isFire == true)
{
sprite_handler->Draw(
gun_fire,
NULL,
NULL,
&position2,
D3DCOLOR_XRGB(255,255,255));
FIRE = true;
}
//draw the sprite
sprite_handler->Draw(
player_ship,
NULL,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));
sprite_handler->End();
//stop rendering
d3ddev->EndScene();
}
}
//display the back buffer on the screen
d3ddev->Present(NULL, NULL, NULL, NULL);
//check for escape key (to exit program)
if (Key_Down(DIK_ESCAPE))
DestroyWindow(hwnd);
}
So if someone could help me it would br great and if you can explain the steps for me that would be nice since I am learning and that way I will learn from you instead of just copying your code.
Thanks!