Tap to shoot

Apprentice
Posts: 13
Joined: 2009.08
Post: #1
Hello,
I'm making a shooter game and was wondering, how do you make it so when you tap on the screen the bullet goes towards where you tap. Also I wan to make my own speed for the bullet. Lastly when the bullet gets to where the user taps how do I import an explosion animation? Thanx for help
Member
Posts: 306
Joined: 2009.03
Post: #2
Step 1 record the x,y the tap happened at from the touch even
Step 2 create a bullet where you want it to start
Step 3 in your main game loop move the bullet towards Step 1's value
in a speed of your choosing
Step 4 You will need to choose a rendering engine and figure out how to draw animations. Check out coscos2d for opengl

It sounds like your asking how to do things that you think will be simple but that you may not have a solid background in programming. If that is correct this is a complicated way to start learning.
Member
Posts: 27
Joined: 2008.12
Post: #3
I'm going to assume that you're making a shmup like r-type or space invaders, where bullets are real objects and you can dodge shots. In other games - like doom and starcraft - damage is automatic, bullets are more like special effects, and no collision detection is used.

Your game probably already has an array of game objects that you call an "update" method on every frame. You just need to create a "bullet" object and add it to the array.

When it's created, the bullet needs to know:
*it's own position
*its speed and direction, probably in the form of two numbers - speedx and speedy. You can express any direction+speed with those two numbers.

The "update" method for the bullet needs to do this:
(1) move the bullet to the new position by adding positionx+=speedx and positiony+=speedy.
(2) check the new position against every object in the object list
(3) if you find a collision, remove the bullet from the list and damage the object it collided with.

EDIT: rereading your message, I see you need the formulas to find speedx and speedy based on the touch point. Here's one way to do that.
(1) get the distance from the gun to the target (pythagorean theorem.) You'll also calculate deltax and deltay in the process.
(2) divide the distance by the speed of the bullet (the amount to moves every frame.) This gives us the number of steps.
(3) speedx = deltax / steps. speedy = deltay / steps.

The "delta" means difference; so for example deltax is the difference between the x position of the gun and the x position of the touch.

-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under \$1k
Apprentice
Posts: 13
Joined: 2009.08
Post: #4
Could you guys give me a source code or an example project on this becuase it is kind of confusing. Thanx
Moderator
Posts: 1,563
Joined: 2003.10
Post: #5
9livesoftware Wrote:Could you guys give me a source code or an example project on this becuase it is kind of confusing. Thanx

That would be doing you a disservice. Being able to solve this sort of problem from your own understanding is fundamental to programming. If someone hands you a working solution and you just use it, you've learned almost nothing and you're stuck back at the same place next time you need to solve a problem like this. You become completely dependent on outside help for the most basic of tasks. I've seen it happen more times than I can count.

Read up on the basics of programming, if necessary. If you get stuck and need some specific help, come back and ask, but this is too fundamental and broad. We can't write all of your code for you. You won't be able to piece together a complete application from random snippets of code on the web without understanding how programming really works.
Apprentice
Posts: 13
Joined: 2009.08
Post: #6
Could you give me a tutorial or helper video?
Moderator
Posts: 625
Joined: 2007.09
Post: #7
9livesoftware Wrote:Could you give me a tutorial or helper video?

ThemsAllTook Wrote:Read up on the basics of programming, if necessary. If you get stuck and need some specific help, come back and ask, but this is too fundamental and broad. We can't write all of your code for you. You won't be able to piece together a complete application from random snippets of code on the web without understanding how programming really works.

Nobody wants to help someone who isn't willing to do a bit of work themselves. I'm not acquainted with iPhone dev, but I'm fairly certain there are plenty of resources online to get you started. Do some Googling, even search the iDevGames front page, and you should be able to get a start on the iPhone.

- Lincoln Green
http://www.binkworks.com/
Apprentice
Posts: 13
Joined: 2009.08
Post: #8
Hello,
I finished the hard part of the tap to shoot but need some help. I made a line to where ever you tap and when you tap it goes there and deletes itself afterwards can you tell me how to import a bullet instead of the line?
Member
Posts: 227
Joined: 2008.08
Post: #9
Kendric described this perfectly in his first reply.