How to make boundaries for the shooturial

6 posts

Flag Post

I couldnt help but notice that your “Hero Ship” is allowed to leave the 600 × 300 frame. Can anyone help me make a code to limit the Hero Ships movement to the 600 × 300 frame? It doesnt make sense to allow it to move freely since the enemies self destruct after a certain range so to “Beat” the game all you have to do is go outside the boundary. Thanks for your help.

 
Flag Post

How about putting a if condition? if ship’s y position is greater than the stage’s width, equal that to the stage’s width. and same with x pos.

 
Flag Post

Okay thanks to the suggestion from Danny_Phantom_ I figured out how to make “boundaries” and I thought I’d share my code with others in case they need some direction.
The code below makes it so that if the OBJECT goes beyond the 600 range width of the stage, then the OBJECT is “teleported” back to the position of 600, making it impossible to ever really go pass the 600 range width.

if (_x > 600)
{
_x = 600
}

 
Flag Post

But the above code still allows the OBJECT or “HERO SHIP” to go beyond the point of 0 or go all the way to the left of screen without stopping. To prevent this add the code below. The code below makes it so that when the OBJECT or “HERO SHIP” goes beyond the width of 0 (or all the way to the left) it will “teleport” it back to 0, which never actually lets the OBJECT go beyond 0 or in other words prevents it from scrolling to the left infinitely.

if (_x < 1)
{
_x = 0
}

 
Flag Post

And of course to prevent OBJECT or “HERO SHIP” from scrolling infinitely UP and DOWN, you use the same coding but tweak it to change the _x to _y. And example to stop it from scrolling infinitely down is below. Use all that you learned here to make the boundary for preventing your ship to infinitely scroll UP.

if (_y > 300)
{
_y = 300
}

 
Flag Post

::There’s a “Edit post” right under your username, use it if you want to add more to your post.

You’ve done it quite right. I don’t know AS2, but your code seems to be quite right.