The Daily Click ::. Forums ::. Klik Coding Help ::. Gravity of falling boxes
 

Post Reply  Post Oekaki 
 

Posted By Message

eyeangle



Registered
  12/06/2003
Points
  1683
28th February, 2008 at 23:14:21 -

I know how to make gravity of an object. But how can I make it so that there is a stack of boxes, say 40x40 each, and when you shoot the bottom box they all fall and bouce off each other and scatter over the floor.

 
theonecardgame.com

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
29th February, 2008 at 00:07:03 -

Give each object an X & Y velocity variables, as well as more precise X & Y position variables (so at the start of the level, its PosXvar = X(object) * 1000, and such). Then, implement it so that every single frame of gameplay, it follows this algorithm:


(Loop)
>>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP
>>>Set Position X of "Detector" = PosXvar(object) + VelocityX(object)
>>>Set Position Y of "Detector" = PosYvar(object) + VelocityY(object)
IF: Detector isn't colliding with any other objects/backdrops, THEN:
>>>Set PosXvar(object) += VelocityX(object);
>>>Set PosYvar(object) += VelocityY(object);
>>>Set X(object) = PosXvar(object) / 1000;
>>>Set Y(object) = PosYvar(object) / 1000;
ELSE:
>>>Set PosXvar(object) = X(object) * 1000;
>>>Set PosYvar(object) = Y(object) * 1000;
>>>Set VelocityX(object) = 0;
>>>Set VelocityY(object) = 0;
ENDIF:
>>>Set VelocityY(object) += Gravity;
(/Loop)


 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

eyeangle



Registered
  12/06/2003
Points
  1683
29th February, 2008 at 01:30:08 -

Thanks, but I don't understand that...

"Give each object an X & Y velocity variables, as well as more precise X & Y position variables (so at the start of the level, its PosXvar = X(object) * 1000, and such)."

So I've changed 4 of the boxes alterable values to:
VelXvar (for X volocity)
VelYvar (for Y volocity)
PosXvar (for X position)
PosYvar (for Y position)

At start of level > Set AltPosition X (Box) to X Position(Box)*1000
> Set AltPosition Y (Box) to Y Position(Box)*1000

"Then, implement it so that every single frame of gameplay, it follows this algorithm"

How do I do this?

"(Loop)
>>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP"

How do I do this?

">>>Set Position X of "Detector" = PosXvar(object) + VelocityX(object)
>>>Set Position Y of "Detector" = PosYvar(object) + VelocityY(object) "

Are there detectors? How many, because I'm trying to make 50 boxes fall all over each other, does that mean I have to have 50 different active object boxes and 50 different detectors for each?

"ENDIF:
>>>Set VelocityY(object) += Gravity;
(/Loop)"

What does ENDIF mean, and +=Gravity?

Sorry I didn't get it but I gave it my best...

 
theonecardgame.com

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
29th February, 2008 at 01:43:36 -

he put it in programming terms instead of mmf terms =\

 
n/a

viva/volt

Awesome Sauce

Registered
  26/08/2006
Points
  1694

Game of the Week WinnerSilverNova MemberKlikCast StarVIP Member
29th February, 2008 at 01:55:54 -

This seems like a job for the physics object really... But anyway.

"Then, implement it so that every single frame of gameplay, it follows this algorithm" Run it in an always event.

"(Loop) >>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP" You need to spread values through the boxes and run a loop comparing their values to the loop index.

"ENDIF: >>>Set VelocityY(object) += Gravity; (/Loop)" He just means that this happens every loop regardless, += means current value + Gravity.


 
Image
http://bfollington.tumblr.com

eyeangle



Registered
  12/06/2003
Points
  1683
29th February, 2008 at 02:38:57 -

Where does one get this physics object?

 
theonecardgame.com

viva/volt

Awesome Sauce

Registered
  26/08/2006
Points
  1694

Game of the Week WinnerSilverNova MemberKlikCast StarVIP Member
29th February, 2008 at 05:26:16 -

http://www.phizix.tk/ word word word.

 
Image
http://bfollington.tumblr.com

Deleted User
29th February, 2008 at 05:51:19 -

Y("box") = Y("box") + 1

!!

 

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
29th February, 2008 at 11:23:54 -


Originally Posted by Furby Consciousness
Y("box") = Y("box") + 1

!!



Yeah, that's what I was thinking too lol.

 
--

"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!

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
29th February, 2008 at 13:05:06 -

Yeah, I wrote that in pseudocode; you need to use the pseudocode compiler to run it. I think theres a language add-on for java support


And btw ben; spreading values is not a very efficient way of picking an object during a loop. This means its tough to add in new objects or remove old ones, as well as taking up one of your alterable values (a very big deal in TGF, at least). Instead, you can have a single object picked at random at the beginning of your loop, and turn on a flag for it, then refer to the object by that flag, then kill the flag at the end of the loop.

So like:

ON HITTING THE "SPACE BAR" KEY:
=DO: Set "OBJECT" Flag 0 off;
=DO: Start LOOP TRIGGER "FOO" for #Count("OBJECT") LOOPS;

ON LOOP TRIGGER "FOO":
+OBJECT FLAG 0 IS OFF
=DO: Pick an "OBJECT" at random;
=DO: SET "OBJECT" Flag 0 ON;
=DO: SET "OBJECT" Flag 1 ON;

ON LOOP TRIGGER "FOO":
+OBJECT FLAG 1 IS ON
=DO: (STUFF INSIDE YOUR LOOP)

ON LOOP TRIGGER "FOO":
+OBJECT FLAG 1 IS ON
=DO: SET "OBJECT" Flag 1 OFF;



^that above code for TGF/MMF/MMF2 will iterate through every single object in a random order and only hit each one time. It will specify the object for the inside of the loop.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
29th February, 2008 at 13:05:32 -

Although pseudocode compiler sure would be fun

Loop 10 times{
Add one to X
Set Y to a letter at random from "Waffles"
Add Y and then the 26-letter alphabet equivalent of X to the end of Z
}
If Z is now a really garbled string, make me a sandwich
Otherwise, RETURN Z;

Image Edited by the Author.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456
   

Post Reply



 



Advertisement

Worth A Click