How do you make my sprite shoot a bullet?
How can I get a sprite to appear on the screen when I press a button and then keep moving and bouncing around then press the key again and do the same thing?
How do you add sprite to back buffer and flip it to the main buffer
This is what I have
But it will not put the bullet to the primary surface when I hit the space bar. Why won’t it work?
This is what I have
LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){…..…..……else if (wParam==VK_SPACE) { Bsprite(); return(0); } …….………..}/////////////////int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){…..…..….. ShowWindow(hwnd, nShowCmd);Game_Int(); Splash();//message pump for(;;) {…..………..}Game_Main();}//////////////////////int Game_Int(){…..…..…..g_pddbullet = DDLoadBitmap(g_pdd,"Bullit.bmp",0,0); DDSetColorKey( g_pddbullet, RGB(0, 0, 255));……..……..}/////////////////////int Game_Main(){ r.left = 0; r.top = 0; r.right = 800; r.bottom = 600; lpBackBuffer->BltFast(0, 0, g_pddground, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); //the bug r.left = cl; r.top = ct; r.right = cr; r.bottom = cb; lpBackBuffer->BltFast(x, y, g_pddbug, &r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); ////////Spider movmentr.left = 0;r.top = 0;r.right = 64;r.bottom = 64;lpBackBuffer->BltFast(sx, sy, g_pddspider, &r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);r.left = 65;r.top = 0;r.right = 128;r.bottom = 64;lpBackBuffer->BltFast(500,500,g_pddhouse,&r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);g_pddsprimary->Flip(NULL, DDFLIP_WAIT);return(1);}////////////////////////int Bsprite(){ bx =x; by =y; for( i = 0; i < 50; ++i ) { float xspeed = 1; float yspeed = 1; bx =x + xspeed; by =y+ yspeed; } r.left =0; r.top =0; r.right =64; r.bottom=64; lpBackBuffer->BltFast(bx,by,g_pddbullet, &r, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); return (1); }
But it will not put the bullet to the primary surface when I hit the space bar. Why won’t it work?
What you effectively have is a particle system with:
A bullet is just a special kind of particle. If you want other kinds of particles, (eg. snow, smoke, fire), consider writing a generic class and deriving from it, for each type of particle you need to implement.
Have a look on gamedev for Particle System should be one, else try google.
- Position
- Velocity
- Colour
- Life (time before particle dies)
A bullet is just a special kind of particle. If you want other kinds of particles, (eg. snow, smoke, fire), consider writing a generic class and deriving from it, for each type of particle you need to implement.
Have a look on gamedev for Particle System should be one, else try google.
You really could do with getting your head around classes and objects before attempting something like this. It is far easier to understand than masses of variables, arrays and functions.
How do you clone an image and have it display the same image every time a key is pressed?
I would suggest learning classes and the like before you worry about how to do this. Once you understand the concept of it, and have built a bullet class (or just a bullet manager), you'll want to define an array of active bullets. Each time a certain key is pressed, you'll just 'activate' another bullet and it will take off from there. Of course, it'd be a good idea to first set the bullet position to the chars (as well as the direction), but that's a bit minor
How do you call a mouse click in the middle of a function?
Okay, you've lost me on this one. What you do is setup a function to handle mouse-clicks...each click of the mouse will cause the program to run through this particular function. You could use it for the bullets just like the key stroke listed above.
I would suggest learning classes and the like before you worry about how to do this. Once you understand the concept of it, and have built a bullet class (or just a bullet manager), you'll want to define an array of active bullets. Each time a certain key is pressed, you'll just 'activate' another bullet and it will take off from there. Of course, it'd be a good idea to first set the bullet position to the chars (as well as the direction), but that's a bit minor
How do you call a mouse click in the middle of a function?
Okay, you've lost me on this one. What you do is setup a function to handle mouse-clicks...each click of the mouse will cause the program to run through this particular function. You could use it for the bullets just like the key stroke listed above.
So this is what I have
This still does not work
struct TSprite{ int top,left; //Top left of section to make sprite from int right, bottom; //Bottom Right of sprite section int Screenx; // were to put the sprite on the screen int Screeny; }Sprite;//////////////////////////////////TSprite Bullet[5];///////////////////////////////// else if (wParam==VK_SPACE) { screenx= x; screeny = y; bullettest =1; for (int Loop = 1; Loop<(rate);Loop++) { Bullet[Loop].Screenx = Bullet[Loop].Screenx + 50; Loop = rate; }//////////////////////////////////////////////for ( int Loop = 1; Loop< rate;Loop++) { Bullet[Loop].top = 0; Bullet[Loop].bottom =64; Bullet[Loop].right =64; Bullet[Loop].left =0; Bullet[Loop].Screenx= screenx; Bullet[Loop].Screeny= screeny; } /////////////////////////////////int test(){ if(screenx< 0 || screenx> mapX ) xspeed *= -1; if(screeny < 0 || screeny > mapY ) yspeed *= -1; for (int Loop = 1; Loop < rate; Loop++){ screenx += xspeed; screeny += yspeed; bltsprite(Bullet[Loop]);} } ////////////////////////////////////////int Game_Main(){ if (g_pddsprimary == NULL) { return(0);} //collistion(); if ( bullettest == 1) { backgournd(); test(); players(); foreground(); Flip(); } else if (bullettest == 0) { backgournd(); players(); foreground(); Flip(); }return(1);}
This still does not work
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement