Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

bitsy

a little engine for little games, worlds, and stories · By adam le doux

How would you change room when the player moves anywhere?

A topic by Pablo created 15 days ago Views: 106 Replies: 2
Viewing posts 1 to 3

Hi folks! I'm working on a Bitsy where the character fell off their spaceship, which appears to move away into the background. I'd like players to be able to move around in any direction, and each step taken puts the ship further away.

I managed to do this with a very dumb solution, and I wanted to ask if there's a clever way.

https://kednar.itch.io/i-fell-off-my-ship

As you see in the video linked below, the spaceship appears to move away by changing rooms. The dumb part is that I used one-way-exits to move to the next room, and since I want players to move in any direction while the room changes, I had to add a ton of exits. This took time and my dignity.

https://drive.google.com/file/d/1UI8tiCEbZUmznuHsgoHUrMt44sTnkabZ/view?usp=shari...

Another way I tried is to use the edit-room-from-dialog hack to erase and draw the ship sprites when the player picks up an item around them, instead of changing rooms. I used the same hack to draw this item everywhere with "drawAll", to allow players to move in any direction. However, this method is cumbersome as I cannot preview the results in the editor.

The best idea I had was to change room when players pick up an item that's around them (using the aforementioned hack to draw it everywhere). However, changing room from the item dialog requires specific coordinates where the avatar will be put, and we want the avatar to stay where it was when it moved and picked up the item.

So here's the rub: I want the player avatar to stay in the same location where they picked up the item that takes them to another room (the location of the item is not known as it's instanced everywhere). Basically, I need to have the exit from dialog act as a proper one-way-exit.

Something like:

{exit "0" player.x player,y}

Alternatively, do you have a different solution in mind for what I'm trying to do?

Thanks so much!

(1 edit)

You can access the x, y, and room as variables by modifying the direction in dialog hack.


First add these lines to the last part of the hack code (in bold):

before('startDialog', function () {

    var direction = keys[bitsy.curPlayerDirection];

    if (direction) {

        bitsy.scriptInterpreter.SetVariable('playerDirection', direction);

    }

    //Extra variables

    bitsy.scriptInterpreter.SetVariable('playerRoom', bitsy.player().room);

    bitsy.scriptInterpreter.SetVariable('playerX', bitsy.player().x);

    bitsy.scriptInterpreter.SetVariable('playerY', bitsy.player().y);

});

})(window);


In your case I don't think you'll need to save the room, so save X and Y to new variables (play_last_x, play_last_y) before you move, then load them when you exit to the new room.

Save:

{play_last_x = playerX}{play_last_y = playerY}

Exit/Load (replace with your room):

{exit "2" play_last_x play_last_y }

If you run into problems, make sure you save the variables in a different set of code than the one that loads them. Since this a hack, you won't be able to see it in the editor. I recommend uploading to itch to test following this guide.

Oooh that's clever. Will try it at some point. Thank you!