I'm making a game where the player can walk around using the arrow keys, and I want them to be able to walk into buildings. So I want the background to change when they step in front of the door to enter the building
Offline
This script will also allow the player to exit the building.
For the player:
when gf clicked forever if <touching [door v]?> if <(building)=[outside]> set [building v] to [inside] end if <(building)=[inside]> set [building v] to [outside]For the Stage:
when gf clicked forever if <(building)=[outside]> switch to background [outside v] end if <(building)=[inside]> switch to background [inside v]I hope that's clear.
Last edited by PhirripSyrrip (2012-07-22 08:27:17)
Offline
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:when gf clicked forever if <touching [door v]?> if <(building)=[outside]> set [building v] to [inside] end if <(building)=[inside]> set [building v] to [outside]For the Stage:when gf clicked forever switch to background (building)I hope that's clear.
Simpler
Offline
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:when gf clicked forever if <touching [door v]?> if <(building)=[outside]> set [building v] to [inside] else set [building v] to [outside]For the Stage:when gf clicked forever switch to background (building)I hope that's clear.Simpler
even more simple
when it touches the door and the backround changes, be sure to make it go to the correct position.
Offline
thebriculator wrote:
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:when gf clicked forever if <touching [door v]?> if <(building)=[0]> set [building v] to [1] else set [building v] to [0]For the Stage:when gf clicked forever switch to background (building)I hope that's clear.Simpler
even more simple
when it touches the door and the backround changes, be sure to make it go to the correct position.
You guys are missing something: The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter. Fixed.
Offline
berberberber wrote:
thebriculator wrote:
Prestige wrote:
Simplereven more simple
when it touches the door and the backround changes, be sure to make it go to the correct position.You guys are missing something: The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter. Fixed.
For the purposes of the thread, and for simplicity and clarity in the project, I think mine will cause the least confusion.
Offline
It WILL work it it's a word, I just tried it.
but with numbers, it could be even more simple:
when gf clicked set [building v] to [0] forever if <touching [door v]?> set [building v] to ((1)-(building)) when gf clicked forever switch to costume (building)
Offline
thebriculator wrote:
It WILL work it it's a word, I just tried it.
but with numbers, it could be even more simple:when gf clicked set [building v] to [0] forever if <touching [door v]?> set [building v] to ((1)-(building)) when gf clicked forever switch to costume (building)
Costume numbering in scratch begins at 1, so, though your script could be applied, it is counter intuitive, so you should set "building" to 1 originally and replace "1-building" with "(3)-(building)"
The (potential) problem with all the scripts above is that, if you're touching the door for too long. If this is a problem, use this:
when gf clicked set [buildiing v] to [1] forever if <touching [door v]?> set [building v] to ((3)-(building)) wait until <not<touching [door v]?>> when gf clicked forever switch to costume (building)Of course, if there are only two costumes, it is even easier:
when gf clicked forever if <touching [door v]?> broadcast [change v] wait until <not<touching [door v]?>> When I Receive [change v] next costume
Offline
thebriculator wrote:
Prestige wrote:
PhirripSyrrip wrote:
This script will also allow the player to exit the building.
For the player:when gf clicked forever if <touching [door v]?> if <(building)=[outside]> set [building v] to [inside] else set [building v] to [outside]For the Stage:when gf clicked forever switch to background (building)I hope that's clear.Simpler
even more simple
when it touches the door and the backround changes, be sure to make it go to the correct position.
Can you maybe make this and upload it? I don't understand
Offline
We've been assuming that you're storing the interior of the building as a costume in the background, and that the door itself is a sprite. Basically, whenever the user touches the door it changes the costume that the background is currently in. A more universal script (just realized you probably have more than one building) would be this:
when gf clicked forever whatever your current movement script is if<touching [door1 v]?> broadcast [enter building 1 v] and wait go to x:(starting x position for building 1) y:(starting y position for building 1) end if<touching [door2 v]?> broadcast [enter building 2 v] and wait go to x:(starting x position for building 2) y:(starting y position for building 2) end etc.And for the stage:
when I receive [enter building 1 v] switch to costume [building 1 v] when I receive [enter building 2 v] switch to costume [building 2 v]
Offline