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.

Newcomers DBPro Corner / 2D Shooting

Author
Message
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 8th Sep 2010 20:15
Hi guys,
I've been trying to start a 2D Shmup but i ran into a snag.

If you take a look at the code it will create a bullet in front of the ship which took a lot of time to do in the first place. I did have the bullet fire across the screen but i wanted multiple so i had a go and just couldnt get it to work.

The problem is i cannot get an X Coord for the bullet sprite. If done a Sprite Exist(N) Check and this return positive for a second then the sprite apparently no longer exsists.

Any help would be appreciated it my first time with arrays and i just cannot get the x position of the bullet.

Thanks for your time.

(Graphics Included in Rar)

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 9th Sep 2010 17:48
This code will at least get you going:



Let me know if you have any questions about it.

So many games to code.......so little time.
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 29th Sep 2010 18:22
To LBFN:
Thanks very much after a couple of weeks of breaking it up and testing it out i finally understand the code you used. So thanks very much for your help.

To save a double post i'll just add more on the end here.

Im very confused as i wrote my enemy spawning code to understand LBFN's bullet code. It all works perfectly in its seperate project folder but if i add the code to the main game code, for some reason it tells me that the animated sprite for the enemy ships i think at line 120 alreadys exists.

I've tried allsorts to get it working but doesnt seem to like that animated sprite for some reason. Any debugging help would be much appreciated.

Thanks for reading,
Chris



Ps. Media included, please credit if used.

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Sep 2010 18:49 Edited at: 29th Sep 2010 18:51
The reason it gives an error is because sprite 1 already exists and you are trying to recreate it in your EnemySpawn subroutine. When you are referencing a sprite for the EnemyExist array, you need to add a number to it so that you are not duplicating that same sprite. For example, I added 100 to the sprite number in the attached code and it worked fine.




LB

EDIT:
Quote: "Chris"
That is a nice name; has a nice ring to it.

I'm not really a programmer.....I only play one on TGC.
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 29th Sep 2010 20:06
Oh fantastic =D Thank you, the + number part of the bullet code was what i could'nt understand. It makes a lot more sense now.

Thanks for the name love too =D

Always a pleasure,
Chris

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 29th Sep 2010 20:57 Edited at: 30th Sep 2010 01:32
Hi again, im having trouble with collision between the bullets and the enemies and even the enemies and the player. Because the bullets and ships are stored in seperate arrays and sub routines i dont understand where to put the Collision command.

I would assume that
this would be the code needed to check collision between a bullet and an enemy the only problem i have is that it tells me that the sprite doesn't exist when it reads this line, i'm assuming it can only see the N + 10 bullet sprites in the bullet sub routines and the enemy A + 100 sprites in their sub routines.

Can't really fathom this at all i tried searching for sprite collision help but all i can get is how to do pixel perfect collision, which i wouldn't mind learning how to do, if only i could get this one to work. Lol

Thanks for your time,
Chris

EDIT:

Well after some fiddling i managed to get the player sprite (Sprite No. 1) to delete itself when spacebar is pressed with Sprite Collision (N+10,1), not sure what this indicates maybe the N + 10 command is returning a positive sprite collision on something else such as the background sprite?

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
Zen Master
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location:
Posted: 30th Sep 2010 16:55
Bump

"Face it, if crime didnt pay there would be very few criminals."
Laughton Lewis Burdock
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Sep 2010 17:33
I re-did your arrays to help you be more organized with them. I thought about making them TYPE variables, but that is a little more advanced topic and a better understanding of arrays would be first on the list. This code has proper collision between the bullets and the enemies. The explosion is placed at the collision, but it just sits there until the next explosion, and is not animated.



Also, you will need to code where an enemy can collide with the player. I couldn't figure out why the enemies weren't showing up and tried all sorts of ways to get them to show and realized that the sprite priority had not been set on them.

Hope this helps you. If you have any questions, please ask.

LB

I'm not really a programmer.....I only play one on TGC.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Sep 2010 17:36 Edited at: 1st Oct 2010 04:25
Quote: "Hi again, im having trouble with collision between the bullets and the enemies and even the enemies and the player. Because the bullets and ships are stored in seperate arrays and sub routines i dont understand where to put the Collision command."


Without looking at your code you can use the SPRITE EXIST() command to check if the sprite actually exists before you check for collision. Checking if the sprite exists right before a collision check is the easiest method to use when dealing with multiple sprites that may or may not exist during a game.

If you use a zero instead of a number for the target sprite the SPRITE COLLISION command returns the number of the sprite it's colliding with. If it's not colliding with anything it'll return a zero. Doing collision that way makes it easier because you don't have to repeat collision code for bullets hitting just bad guys or bullets hitting just walls or bullets hitting just the player. You use one collision check for bullets then determine what to do based on which sprite number it's hitting.

Login to post a reply

Server time is: 2024-11-24 10:29:55
Your offset time is: 2024-11-24 10:29:55