Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you make an open world game?
- vandjac
-
38 posts
How do you make an open world game?
I was really interested in making a top-down open world fantasy game, but I couldn't figure out how to have the objects go off the screen when it is out of the range of the character, but then come back in when the character is within the range of it. I would really appreciate it if you could help me with this!
- ErnieParke
-
1000+ posts
How do you make an open world game?
You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
*scroll x/y
*enemy x/y
In this case, all you need to do is this:
set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
Last edited by ErnieParke (March 29, 2016 15:52:05)
- Carpit999
-
100+ posts
How do you make an open world game?
Well, that might work, but there IS a simpler way (well, it may be simpler): You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
(Put this in all the sprites you want to disappear when off screen)
when green flag clicked
forever
repeat (any number)
if <<(x position) > [240]> or <<(x position) < [-240]> or <<(y position) > [180]> or <(y position) < [-180]>>>> then
hide
end
if <<(x position) < [240]> and <<(x position) > [-240]> and <<(y position) < [180]> and <(y position) > [-180]>>>> then
show
end
- ErnieParke
-
1000+ posts
How do you make an open world game?
@Carpit999:
That method actually has a tiny flaw. Most sprites can actually move beyond -240 to 240 and -180 and 180. It would be nice to still shows sprites then, no?
My thoughts,
ErnieParke
That method actually has a tiny flaw. Most sprites can actually move beyond -240 to 240 and -180 and 180. It would be nice to still shows sprites then, no?
My thoughts,
ErnieParke
- Carpit999
-
100+ posts
How do you make an open world game?
The center of the sprite is where the sprite actually is. @Carpit999:
That method actually has a tiny flaw. Most sprites can actually move beyond -240 to 240 and -180 and 180. It would be nice to still shows sprites then, no?
My thoughts,
ErnieParke
- asivi
-
1000+ posts
How do you make an open world game?
If i am not wrong the conditions for xposition and yposition are always true. You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
- ErnieParke
-
1000+ posts
How do you make an open world game?
@asivi:
If you are off screen, the conditions for x position and y position are not correct. Try this script, and you should see:
@Carpit999:
You are correct. The interesting part is that Scratch allows the center of the sprite to go outside of the -240/240/-180/180 region by a little bit, depending on the dimensions of the sprite.
Clarifying,
ErnieParke
If you are off screen, the conditions for x position and y position are not correct. Try this script, and you should see:
set x to (9000)
set y to (9000)
if <<(x position) = (9000)> and <(y position) = (9000)>> then
show
else
hide
end
@Carpit999:
You are correct. The interesting part is that Scratch allows the center of the sprite to go outside of the -240/240/-180/180 region by a little bit, depending on the dimensions of the sprite.
Clarifying,
ErnieParke
- Carpit999
-
100+ posts
How do you make an open world game?
Moving beyong -240,240,180,and -180 is because in the “costumes” thingy, you can set the center of the costume with the “+” button. This acts as the center of the sprite and therefore the actual coordinates of every sprite are at the set center. By default, SCRATCH costumes are automagically in the center. Get it? @asivi:
If you are off screen, the conditions for x position and y position are not correct. Try this script, and you should see:set x to (9000)
set y to (9000)
if <<(x position) = (9000)> and <(y position) = (9000)>> then
show
else
hide
end
@Carpit999:
You are correct. The interesting part is that Scratch allows the center of the sprite to go outside of the -240/240/-180/180 region by a little bit, depending on the dimensions of the sprite.
Clarifying,
ErnieParke
- vandjac
-
38 posts
How do you make an open world game?
So this would make the sprites come back on the screen in the right positions? Thanks for all the help! You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
- Carpit999
-
100+ posts
How do you make an open world game?
Mine would tooSo this would make the sprites come back on the screen in the right positions? Thanks for all the help! You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
- vandjac
-
38 posts
How do you make an open world game?
Also, do you put this script into the character or in an object? You will need these variables, although you probably already have them:
*scroll x/y
*enemy x/y
In this case, all you need to do is this:set x to (((0) - (scroll x)) + (enemy x))
set y to (((0) - (scroll y)) + (enemy y))
if <<(x position) = (((0) - (scroll x)) + (enemy x))> and <(y position) = (((0) - (scroll y)) + (enemy y))>>
show
else
hide
end
The code works because if a sprite is off screen, the sprite cannot go to that position. It has to stay on screen. So if the sprite goes to the position but is not at it, it is off screen, at which point we can hide it. Make sense?
Showing,
ErnieParke
- vandjac
-
38 posts
How do you make an open world game?
Never mind my previous comment I think I figured it out.
- vandjac
-
38 posts
How do you make an open world game?
How would you make an object start off of the screen?
- ErnieParke
-
1000+ posts
How do you make an open world game?
To make the object start off of the screen, just set enemy x and y to something off screen. The code above will handle positioning and if the Sprite should show or not. How would you make an object start off of the screen?
It should, although you will need to make sure enemy x and y are for this Sprite only, so that each clone can get a copy of it. Would that work with clones too?
Answering,
ErnieParke
- vandjac
-
38 posts
How do you make an open world game?
So how would you make a bunch of clones that are all in different places?
- ErnieParke
-
1000+ posts
How do you make an open world game?
Like this: So how would you make a bunch of clones that are all in different places?
when gf clicked
hide
repeat (50)
create clone of [myself v]
end
when I start as a clone
set [enemy x v] to (pick random (-500) to (500))
set [enemy y v] to (pick random (-500) to (500))
forever
...//enemy code
end
Again, remember that (enemy x) and (enemy y) need to be for this sprite only.
Showing,
ErnieParke
- Carpit999
-
100+ posts
How do you make an open world game?
How would you make an object start off of the screen?
when green flag clicked
go to x: (636) y: (74467)
- vandjac
-
38 posts
How do you make an open world game?
I was wondering how to make other sprites move also.
- Carpit999
-
100+ posts
How do you make an open world game?
Make them move opposite of player.
- Discussion Forums
- » Help with Scripts
-
» How do you make an open world game?