Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-14-2011, 04:22 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 4
Superly is on a distinguished road
Default Avoid platforms to overlap?

I have followed Eagle1100's YouTube tutorial on how to build a simple iPhone game to get an idea of how that would work. In the series a PapiJump-like game is created. I've got it al running now but want to work further on it.

I've increased the number of platforms from 5 to 20 which works fine. However, when the initial 20 platforms move off screen I want 10 of them to show in a random spot. They do appear but often one or more overlap each other.

I have cracked my newb-brains over this, hope someone can help. How can I make the platforms appear random but not overlap each other?

This is a part of the code used to make the platforms appear in a random spot at the top of the screen.

//If the platforms move off the screen, then reset them at a random spot at the top
if (platform1.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 25.0f;
float y = (random() % 20)-8;
platform1.center = CGPointMake(x,y);
}

if (platform2.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 25.0f;
float y = (random() % 20)-8;
platform2.center = CGPointMake(x,y);
}

... and so on for 10 platforms.

Thanks!!
Superly is offline   Reply With Quote
Old 02-14-2011, 06:59 PM   #2 (permalink)
Registered Member
 
missing_no's Avatar
 
Join Date: Feb 2011
Posts: 41
missing_no is on a distinguished road
Default

Quote:
Originally Posted by Superly View Post
I have followed Eagle1100's YouTube tutorial on how to build a simple iPhone game to get an idea of how that would work. In the series a PapiJump-like game is created. I've got it al running now but want to work further on it.

I've increased the number of platforms from 5 to 20 which works fine. However, when the initial 20 platforms move off screen I want 10 of them to show in a random spot. They do appear but often one or more overlap each other.

I have cracked my newb-brains over this, hope someone can help. How can I make the platforms appear random but not overlap each other?

This is a part of the code used to make the platforms appear in a random spot at the top of the screen.

//If the platforms move off the screen, then reset them at a random spot at the top
if (platform1.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 25.0f;
float y = (random() % 20)-8;
platform1.center = CGPointMake(x,y);
}

if (platform2.center.y >= (self.view.bounds.size.height + 8)) {
float x = random() % iViewWidthMinusPlatformWidth;
x = x + 25.0f;
float y = (random() % 20)-8;
platform2.center = CGPointMake(x,y);
}

... and so on for 10 platforms.

Thanks!!

you need to have a global variable (prevX/prevY) that saves the x (and/or y) info that is randomly generated by the first platform. then set a nested if statement for the next platform to be placed randomly, and make it create a random number until it does all of these: not outside screen width, not at more than (random() % 20)-8 above screen, and not within prevX/prevY + width of platform.

also make sure you stagger the height (the y placement) of the generated platforms or they will overlap.

p.s. Is this just a proof of concept? Or are you actually making another game like this?

Last edited by missing_no; 02-14-2011 at 07:02 PM.
missing_no is offline   Reply With Quote
Old 02-15-2011, 01:51 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 4
Superly is on a distinguished road
Default

Quote:
Originally Posted by missing_no View Post
you need to have a global variable (prevX/prevY) that saves the x (and/or y) info that is randomly generated by the first platform. then set a nested if statement for the next platform to be placed randomly, and make it create a random number until it does all of these: not outside screen width, not at more than (random() % 20)-8 above screen, and not within prevX/prevY + width of platform.

also make sure you stagger the height (the y placement) of the generated platforms or they will overlap.

p.s. Is this just a proof of concept? Or are you actually making another game like this?
Thanks for your reply! I get what you're saying but how would I put this in code?

This is just a POC, or do you see room for another jump game? ;-)
Superly is offline   Reply With Quote
Old 02-15-2011, 02:43 PM   #4 (permalink)
Registered Member
 
missing_no's Avatar
 
Join Date: Feb 2011
Posts: 41
missing_no is on a distinguished road
Default

Quote:
Originally Posted by Superly View Post
Thanks for your reply! I get what you're saying but how would I put this in code?

This is just a POC, or do you see room for another jump game? ;-)
Hey if you bring something new to plate there is always room and people will buy it. Doodle Jump ousted PapiJump because it had more charm, style, and support, so right now it's king of that category. But Kings are meant to be overthrown right?

post some pics of the overlap problem, so I know how to approach setting the variables. i can't promise anything since I'm also working feverishly on my game right now, but I'll try. Plus someone else might be able to help with some visual aid.
missing_no is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 424
9 members and 415 guests
7twenty7, chemistry, ChrisYates, hussain1982, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:11 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0