Discuss Scratch

vandjac
Scratcher
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
Scratcher
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:

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
Scratcher
100+ posts

How do you make an open world game?

ErnieParke wrote:

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
Well, that might work, but there IS a simpler way (well, it may be simpler):
(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
Scratcher
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
Carpit999
Scratcher
100+ posts

How do you make an open world game?

ErnieParke wrote:

@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
The center of the sprite is where the sprite actually is.
asivi
Scratcher
1000+ posts

How do you make an open world game?

ErnieParke wrote:

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
If i am not wrong the conditions for xposition and yposition are always true.
ErnieParke
Scratcher
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:

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
Scratcher
100+ posts

How do you make an open world game?

ErnieParke wrote:

@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
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?
vandjac
Scratcher
38 posts

How do you make an open world game?

ErnieParke wrote:

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
So this would make the sprites come back on the screen in the right positions? Thanks for all the help!
Carpit999
Scratcher
100+ posts

How do you make an open world game?

vandjac wrote:

ErnieParke wrote:

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
So this would make the sprites come back on the screen in the right positions? Thanks for all the help!
Mine would too
vandjac
Scratcher
38 posts

How do you make an open world game?

Would that work with clones too?
vandjac
Scratcher
38 posts

How do you make an open world game?

ErnieParke wrote:

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
Also, do you put this script into the character or in an object?
vandjac
Scratcher
38 posts

How do you make an open world game?

Never mind my previous comment I think I figured it out.
vandjac
Scratcher
38 posts

How do you make an open world game?

How would you make an object start off of the screen?
ErnieParke
Scratcher
1000+ posts

How do you make an open world game?

vandjac wrote:

How would you make an object start off of the screen?
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.

vandjac wrote:

Would that work with clones too?
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.

Answering,

ErnieParke
vandjac
Scratcher
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
Scratcher
1000+ posts

How do you make an open world game?

vandjac wrote:

So how would you make a bunch of clones that are all in different places?
Like this:

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
Scratcher
100+ posts

How do you make an open world game?

vandjac wrote:

How would you make an object start off of the screen?
when green flag clicked
go to x: (636) y: (74467)
vandjac
Scratcher
38 posts

How do you make an open world game?

I was wondering how to make other sprites move also.
Carpit999
Scratcher
100+ posts

How do you make an open world game?

Make them move opposite of player.

Powered by DjangoBB