Need help with game maker

Archive of the first decade of Off Topic Posts
Locked
User avatar
ben-09
Rainbow Master
Posts: 764
Joined: Mon Jan 09, 2006 8:32 pm

Need help with game maker

Post by ben-09 » Tue Dec 16, 2008 2:58 am

I am making my first game maker game(apart from the tutorial one) and It involves a powerup that travels quickly in a strait line then bounces off the wall. I need help with getting the powerup to bounce off the wall in a random direction,not bouncing relative to the angle it hit the wall.


Can anyone help me :?:
Generation 59: Community experiment. The first time you see this, take the generation # and add 1. Put in your signature.
User avatar
Blast!10
Rainbow Star
Posts: 1739
Joined: Thu Nov 02, 2006 7:26 pm
Location: New Hampshire

Post by Blast!10 » Tue Dec 16, 2008 2:25 pm

Here you go. I hope this is what you meant.

In the collision event of the powerup with the wall, put the "Execute Code" action (found in the control tab) and paste this code into it:

Code: Select all

if (place_free(x+4,y)) // check if the position 4 pixels to the right of the player is collision-free
{
direction = 315+random(90) // set the direction to somewhere between 315 (down-right) and 405 (up-right)
exit // abort execution of this piece of code
}
if (place_free(x,y+4)) // check if the position 4 pixels below the player is collision-free
{
direction = 225+random(90) // set the direction to somewhere between 225 (down-left) and 315 (down-right)
exit // abort execution of this piece of code
}
if (place_free(x-4,y)) // check if the position 4 pixels to the left of the player is collision-free
{
direction = 135+random(90) // set the direction to somewhere between 135 (up-left) and 225 (down-left)
exit // abort execution of this piece of code
}
if (place_free(x,y-4)) // check if the position 4 pixels above the player is collision-free
{
direction = 45+random(90) // set the direction to somewhere between 45 (up-right) and 135 (up-left)
exit // abort execution of this piece of code
}
BTW, the "//" combination means that anything typed after it will act as a comment until the end of the line. Comments are usually used for helping the makers understand the code, and with color coding, are almost always marked green.
User avatar
ben-09
Rainbow Master
Posts: 764
Joined: Mon Jan 09, 2006 8:32 pm

Post by ben-09 » Wed Dec 17, 2008 6:53 pm

thats exactly what I was looking for.

thanks :D
Generation 59: Community experiment. The first time you see this, take the generation # and add 1. Put in your signature.
Locked