The Daily Click ::. Forums ::. Klik Coding Help ::. Object disappear and reappear at 'selected' random places
 

Post Reply  Post Oekaki 
 

Posted By Message

Dean Avanti



Registered
  01/11/2006
Points
  130
14th September, 2007 at 14:40:27 -

How can we control objects to make them disappear and re appear to our specifications


Say object disappears and will appear randomly at any place on the screen?

Or in certain ('areas' not place) of the screen, that we can define?

Or leave the screen and reappear at any place at the edges of the screen?




 
http://www.avantivita.com
Video game developers and home of video game development assets.

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
14th September, 2007 at 15:14:01 -

What exactly do you want to do? I can't make that up from what you are saying.

 
Old member (~2004-2007).

-Liam-

Cake Addict

Registered
  06/12/2008
Points
  556

Wii OwnerIt's-a me, Mario!Hero of TimeStrawberry
14th September, 2007 at 17:50:59 -

When "this" happens position object "here"? *Shrug*

Image Edited by the Author.

 
Image

Tell 'em Babs is 'ere...

Tim

I'm on here way too much

Registered
  25/08/2006
Points
  132

You've Been Circy'd!Clickzine StaffSilverNova MemberVIP MemberTurtle Power!Evil klikerWii OwnerHero of TimeGhostbuster!Pokemon Ball!
14th September, 2007 at 19:23:08 -


Originally Posted by Slínk
When "this" happens position object "here"? *Shrug*

Image Edited by the Author.



Then "make object invisible"? *super-shrug*

 
http://www.SilverNova.co.uk


-Liam-

Cake Addict

Registered
  06/12/2008
Points
  556

Wii OwnerIt's-a me, Mario!Hero of TimeStrawberry
14th September, 2007 at 20:32:49 -

Oh yeah, and that. ~Shuggington~

 
Image

Tell 'em Babs is 'ere...

Milo



Registered
  17/09/2005
Points
  223
14th September, 2007 at 21:24:45 -

For specific locations make a list.
Parse the string and get the coordinates from a random one.

Areas is
Start X/Y + random (Width/height)

Edges is a little trickier. Try something with the Mod thing.

 
I've wasted my life.
I don't plan on stopping.

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th September, 2007 at 05:32:55 -

Random point...

+whenever...
set x to rand(screen_width)
set y to rand(screen_height)


Random point in an area...

+object outside screen
set x to max(min(area_left_x + rand(area_width), 0), screen_width)
set y to max(min(area_top_y + rand(area_height), 0), screen_height)

(you don't really need the min/max as the event would repeat if the new position was outside the screen - in other words, what Milo said)


Random point at a screen edge...

+ object outside screen
+ value = 0
set x to rand(2)*screen_width
set y to rand(screen_height)
set value to rand(2)

+object outside screen
+ value = 1
set x to rand(screen_width)
set y to rand(2)* screen_height
set value to rand(2)


Random point within a certain distance...

+whenever...
set valueA to rand(360)
set valueB to rand(max_dist)
set x to x + cos(valueA)*valueB
set y to y - sin(valueA)*valueB

You could add a fixed value to the random distance to create a random point *beyond* a certain distance.


I like the rand() function
I may write an article about interesting ways to use it someday.


Image Edited by the Author.

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
15th September, 2007 at 07:07:41 -

And you might want to put a condition like (if "appearing object" is not overlapping a backdrop) in there too, or your things will teleport inside solid walls. Unless there are no walls or you don't mind.

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th September, 2007 at 10:07:26 -

Yeah, you'd probably want to use the collision mask or create a detector object for that. You have to be a bit careful with randomly generated stuff - you can't just use the same formula for the detector and the new location as they will be randomly generated separately, and therefore probably not the same.

incidentally, in my second example I got the "min" and "max" the wrong way round. careless...

 
n/a

Dean Avanti



Registered
  01/11/2006
Points
  130
15th September, 2007 at 12:07:43 -



for the last one, object leaves the screen and reappear at any place at the edges of the screen phizzy wrote this.


This code will make it so that when your powerup object leaves the screen, it will appear at a random point around the edge of the screen. -Phizzy

http://www.create-games.com/oe/forum_24873_3430824.png

Event:
- Powerup leaves the frame on the top, bottom, left or right
Action:
--> Set Powerup's Alterable Value A to random(4) + 1

Event:
- Powerup Alterable Value A = 1
Actions:
--> Set Powerup's X Position to 0
--> Set Powerup's Y Position to random(frame height)
--> Set Powerup's Direction to [purple directions]

Event:
- Powerup Alterable Value A = 2
Actions:
--> Set Powerup's X Position to Frame Width
--> Set Powerup's Y Position to random(frame height)
--> Set Powerup's Direction to [blue directions]

Event:
- Powerup Alterable Value A = 3
Actions:
--> Set Powerup's Y Position to 0
--> Set Powerup's X Position to random(frame width)
--> Set Powerup's Direction to [yellow directions]

Event:
- Powerup Alterable Value A = 4
Actions:
--> Set Powerup's Y Position to Frame Height
--> Set Powerup's X Position to random(frame width)
--> Set Powerup's Direction to [green directions]

Event:
- Powerup Alterable Value A > 0
Action:
--> Set Alterable Value A to 0.


 
http://www.avantivita.com
Video game developers and home of video game development assets.

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
15th September, 2007 at 12:07:51 -

To spawn the enemies for Necropolis Rising, I had an invisible box the same size as the enemies bounce around at the start of the frame. Then when the box collided with the player (and the box wasn't overlapping a backdrop, another enemy, or treasure chest) it would spawn at that point and subtract 1 from the total amount of enemies allowed to be on that screen at any one time. (Different areas had different possible max enemies).

It's really basic, but it worked and none of the enemies ever wound up stuck in walls as far as I know.

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!
   

Post Reply



 



Advertisement

Worth A Click