Game Programming Questions

Apprentice
Posts: 19
Joined: 2009.03
Post: #1
Hey everyone, just got 2 questions, one is i'm making a game in which when you press a button the character shoots and here is the code for that:
- (IBAction) shoot {
if (gameState == kGameStateRunning) {
shot.hidden = NO;
shot.center = character.center;
}

then i have it in the code when the game is running the shot.center = shot.center + 2; now what its doing is when you shoot then quickly go to shoot again the shot simply goes to your characters position and fires instead of creating another shot if you could help me on how it would create a new shot instead of relocating it that would be great!

Now, this game, my plan is to have multiple enemies per level, but i don't know how to do this, would i create multiple image views and just create a new outlet for each enemy? this would involve a lot of coding is there any way to use multiple image views and apply one outlet for all the image views? sorry if this is confusing i'm trying to release this game for June and if i figure these two things out then i wont have a problem. thankyou in advance!
Quote this message in a reply
⌘-R in Chief
Posts: 1,237
Joined: 2002.05
Post: #2
1) In a nutshell, you need to actually *make* a new shot object. When you the player fires, you should create a new object, position it etc, and then stick it in an array of your player's bullets currently on screen. During your game's update cycle, you'd loop through that array and update each bullet's position do collision detection etc.

2) Sounds like you need to go back to square one. You would not use multiple image views in a game. You'd have one view, and draw everything inside of it. Typically, these days you'd do everything in OpenGL. That'll work on OS X, the iPhone, Windows, Linux... everywhere.

Your other options are to use existing game libraries so you don't need to handle the low-level nitty gritty and can just get straight into game. For the iPhone, take a look at cocos2d.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #3
hey that sounds great, but could u give me some sample code by any chance? just to get me started please?
Quote this message in a reply
Member
Posts: 59
Joined: 2007.12
Post: #4
1. Have an array of "shot" objects, the size of the maximal shots you want to be on screen at once.

2. Have a counter "actual_shot".

3. When you fire, set the properties of shots[actual_shot]. Increase actual_shot by one. If actual_shot is bigger/equal than max_shots, set it to zero.

This way, you should never run out of bullets. Wink
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #5
Thanks guys that all seems very helpful. I'll see what I can do if I can't figure it out I'll write back.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #6
ya sorry guys i can't figure it out i'm trying everything could you write some code for me to use? please and thanks
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #7
miigman Wrote:ya sorry guys i can't figure it out i'm trying everything could you write some code for me to use? please and thanks

While the people of this forum are helpful, I doubt anyone on here will 'write some code for me to use'. I would suggest posting where you are getting hung up and asking a specific question.

Use the following ideas at your own risk - I am not a game dev Smile. Anyway, for some pseudo-code:

a) Create a 'bullet' class that will keep a position variable and draw the bullet at that position.
b) When the user presses the fire button, create a new bullet instance and add it to the array.
c) You can either update the bullet position in your main code, or update it in the bullet class itself. Both of these have advantages and disadvantages - your mileage may vary.

Again, use this logic at your own risk - I am not certain whether or not it is a good idea to spread out drawing code over several classes, or whether the main file should update the bullet and draw it.

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #8
Ya i'm really sorry guys, i can't figure this out at all, i tried everything, i set up a mutable array, and had it when you press the button it adds a new object to the array but how would i actually have the object show up? would i do an image view and add it as an animation? sorry i'm so lost
Quote this message in a reply
⌘-R in Chief
Posts: 1,237
Joined: 2002.05
Post: #9
In that case, just completely abandon the wacky setup you have, and learn something the more proper way.

Games are not created using multiple image views and button controls and thing inside of a window. Instead, all drawing takes place in a single view, and you have to handle everything yourself.

You should start out by using someone else's framework so 90% of the work is done for you. Since you're asking in the iPhone forum, I can only assume you're trying to develop directly for the iPhone only. That's probably a little annoying, but at any rate, there's a framework called cocos2d for the iPhone, which also has some tutorials. I don't know how good they are though, but it's worth a shot.

http://cocos2d.org/

You're basically asking "how do I make my game" which is rather impossible to answer. You need to find some tutorials / read some books / look at simple examples created with a tool/language you can use, and start piecing it together yourself, then ask specific questions about the hard bits.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #10
FreakSoftware Wrote:In that case, just completely abandon the wacky setup you have, and learn something the more proper way.

Games are not created using multiple image views and button controls and thing inside of a window. Instead, all drawing takes place in a single view, and you have to handle everything yourself.

You should start out by using someone else's framework so 90% of the work is done for you. Since you're asking in the iPhone forum, I can only assume you're trying to develop directly for the iPhone only. That's probably a little annoying, but at any rate, there's a framework called cocos2d for the iPhone, which also has some tutorials. I don't know how good they are though, but it's worth a shot.

http://cocos2d.org/

You're basically asking "how do I make my game" which is rather impossible to answer. You need to find some tutorials / read some books / look at simple examples created with a tool/language you can use, and start piecing it together yourself, then ask specific questions about the hard bits.

Well not really, my game is 99.9% finished this is the only thing i need to figure out before i can release it. This is my second game already but my first was simple. I figured if i can't figure it out, i'll just do it so you have to recharge everytime you shoot which should be ok and add a little more difficulty. sorry for the inconveniences guys you're all a great help! Wink

http://www.wurdindustries.com

Makers of Toy Tennis, iMMUNE and the upcoming iMMUNE 2: Rise of the Salmonella!
Quote this message in a reply
⌘-R in Chief
Posts: 1,237
Joined: 2002.05
Post: #11
Huh

If your game is 99.9% done, and you don't know how to make a new object appear, I have to wonder what the other 99.9% is. Rolleyes

Explain specifically what you're trying to doing. Screenshots help. You have hardly said much of anything.
Quote this message in a reply
Member
Posts: 65
Joined: 2009.03
Post: #12
Hi miggman

I'm going through the learning curve of writing a game on the iPhone using OpenGL. As I'm learning I'm posting Video Tutorials on my blog so anyone else wanting to have a go an check out what I've done and got working in case it helps them.

Going forward I would certainly recommend you move to OpenGL for games so you may find the tutorials handy http://www.71squared.co.uk

Good luck

Mike
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Questions Using Source Code and Drag & Drop Game Makers Thunder_Strike 2 1,521 Jul 12, 2013 07:59 AM
Last Post: Thunder_Strike
  Basic Questions for a Word Game avidgamer101 4 4,310 May 19, 2012 07:26 PM
Last Post: MattDiamond
  What data format for a quiz game with nearly 10,000 questions? monteboyd 2 4,254 Dec 23, 2010 02:56 PM
Last Post: monteboyd
  New iphone game programming tutorials for newbies Eskema 2 3,066 Mar 1, 2010 01:07 PM
Last Post: Eskema
  iPhone game programming for noobs Olnex 3 3,396 Aug 27, 2009 03:31 PM
Last Post: Amphro