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.

AppGameKit Classic Chat / Problem with shooting laser function

Author
Message
Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 20th Apr 2012 01:12 Edited at: 20th Apr 2012 01:27
Hello everyone I have been working on a space shooter and am stuck on how to get the player's ship to fire a laser a second time. I have no problems getting the player's ship to fire once, and can move the sprite with no issues. I can also get the player's laser to delete once the sprite has left the screen or upon collision with another sprite. However, when I press the fire button again it will not recreate the sprite and execute the function. I've tried a couple of different ways including using a plaser1.active variable to try and determine when the laser is active but that still didn't seem to work. Any help is greatly appreciated.

My laser test setup is like this


Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Apr 2012 01:34
You need to initialise the plaser1.x# and plaser2.x# values when you create the laser sprites.

Currently, they default to zero (probably) and get incremented until they exceed 700 and never get reset back to the start.

They are probably displaying very briefly, one sync cycle, but off the side of the display (assuming 700 is the edge).

Cheers,
Ancient Lady
Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 20th Apr 2012 01:49 Edited at: 20th Apr 2012 01:53
Ah yea because if I decide to shoot again the plaser1.x# variable would be off the screen. I have no idea why I didn't think of that Thank you for your help Ancient Lady it works perfectly And I've now got to go in and add a slight change to how the lasers are getting deleted since the button can be pressed again before they reach 700 and will just sit frozen (x < 700)

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Apr 2012 01:51
Always glad to help.

Good luck with your game!

Cheers,
Ancient Lady
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 21st Apr 2012 18:55
As a tip, I would avoid deleting sprites and creating them while the game runs. I just hide the sprites, and reposition as needed in Obliterator (my current project, listed in shooter WIP, on the showcase forum). I always find things go far slower creating/cloning and deleting sprites.
You could also allow more bullets than one at a time, if you have a count you can cycle through. So first press sends bullet one off. A second press bullet 2.. Once you get to the max bullets you loop around and re-start from the first.



That bit of code is the sort of thing I mean. You would have to also have a little loop to check the actual button press, position the bullet at the start position (your ship co-ords), increase the bullet count and set it to be visible. Then the code snippet above will automatically move it right until it reaches the edge of the screen. I use an array to hold the x,y co-ords and update that, but you could easily use getspritex() command instead, and add a speed value to it instead.

Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 22nd Apr 2012 03:38 Edited at: 30th Apr 2012 04:45
Thank you for the tip DVader I will go ahead and use that method. I'm wanting a weapon that shoots just a single shot and also have secondary weapons that will require multiple lasers so that will work very well for that. I'm hoping to put a WIP thread up in a few weeks to show the game and get some input.

Here is an image showing the basic layout of my game so far. I've got the smoke on there. It comes up whenever the player's health is less than 25.



Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-23 08:39:06
Your offset time is: 2024-11-23 08:39:06