• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need help with transition between rooms

L

LordNoob

Guest
Hi!, excuse the poor english.
I dont know if anyone is following friendlycosmonaut tutorial in how to make a farming rpg, my question comes from there:
For tje transition between rooms she uses an enumerator for declaring directions, (90 is right, 180 is down, 270 left, 0 up).
Then she creates an object: obj_transition
Then she uses variables in the creation code of each instance of obj_transition, the one that matters is "playerfacingbefore" with that variable if obj_player is coliding with obj_transition in ( lets call it "x direction") then the transition occurs, if collides but is not the right direction, there's not a transition.
PROBLEM IS: she uses 4 directions and a grid format. My game has 8 directions, so when i collide with direction down and left, the transition doesnt happen.
How can i make the transition happen when the player is walking down, or down and left, or down and right?

Weird thing is: the same doesnt happen if the transition is "right, down" the transition does happen, guessing is because the order in wich the variables right or down were declared, dont remember from the top of my head.

Also im a big giant noob in this, so if you could help me with code i'll apreciate that very much.

Thanks in advance for any help provided.
 

samspade

Member
I did watch that video a long time ago, so I remember what she did, but I don't remember how she did it. You should post your code.

In general though, can you just add or statements to the check? For example:

Code:
if (collision with transition) {
    if (left) || (left up) || (left down) {
        change rooms
    }
}
 
L

LordNoob

Guest
hey samspade thank you for your time: so here are the interesting parts of the code

in the instance of the transition object

Creation code:

Code:
targetroom = rm_outsidehouse;
targetX = 310;
targetY = 225;
playerfacingbefore = dir.down;
playerfacingafter = dir.down;
in the create event for obj_transition

Code:
targetroom = -1;
targetX = 0;
targetY = 0;
playerfacingbefore = -1;
playerfacingafter = -1;

in the player object (obj_player):

Create

Code:
facing = 0;
Step
Code:
if (moveX != 0) {
    switch (sign(moveX)){
        case 1 : facing = dir.right; break;
        case -1 : facing = dir.left; break;
    }
} else if (moveY != 0) {
    switch (sign(moveY)){
        case 1 : facing = dir.down; break;
        case -1 : facing = dir.up; break;
    }
} else {
    facing = -1;
}

var inst = instance_place (x,y,obj_transition);
if(inst != noone and facing == inst.playerfacingbefore) {
    with (game){
        if (!dotransition) {
            spawnroom = inst.targetroom;
            spawnX = inst.targetX;
            spawnY = inst.targetY;
            spawnplayerfacing = inst.playerfacingafter;
            dotransition = true;
        }
    }
}
Draw

Code:
var anim_length = 9;
var frame_size = 64;
var anim_speed = 12

if        (moveX < 0) y_frame = 9
else if (moveX > 0) y_frame = 11
else if (moveY < 0) y_frame = 8
else if (moveY > 0) y_frame = 10
else                x_frame = 0

switch (facing) {
    case dir.left:    y_frame = 9;    break;
    case dir.right:  y_frame = 11;    break;
    case dir.up:    y_frame = 8;    break;
    case dir.down:    y_frame = 10;    break;
    case -1:        x_frame = 0;    break;
}

var xx = x - x_offset;
var yy = y - y_offset;
Now this MAY not be necessary but please remember i'm a big noob and i'm copying everything i see and sometimes i dont know what the hell each thing does so, apologies if it isnt.


in the "game" object (metadata obj)
Create

Code:
spawnroom = -1;
spawnX = 0;
spawnY = 0;
spawnplayerfacing = -1;
dotransition = false;

enum dir {
    right = 0,
    up = 90,
    left = 180,
    down = 270,
}
Draw gui

Code:
if (dotransition = true){
    if (room != spawnroom){
        blackalpha += 0.1;
        if (blackalpha >= 1) {room_goto(spawnroom)}
    } else {
        blackalpha -= 0.1;
        if (blackalpha <= 0) {dotransition = false;}
     
 
    }
    draw_set_alpha(blackalpha);
    draw_rectangle_color(0, 0, gui_width, gui_height, c_black, c_black, c_black, c_black, false);
    draw_set_alpha(1);
}
Room Start
Code:
if (spawnroom == -1) exit;
obj_Player.x = spawnX;
obj_Player.y = spawnY;
obj_Player.facing = spawnplayerfacing;

with (obj_Player) {
switch (facing) {
        case dir.left:    y_frame = 9;    break;
        case dir.right:  y_frame = 11;    break;
        case dir.up:    y_frame = 8;    break;
        case dir.down:    y_frame = 10;    break;
        case -1:        x_frame = 0;    break;
    }
}
Also I can't post any links because of the forum rules for spam, but if anyone is interested is FriendlyCosmonaut's video called: Room Transitions | Farming RPG Tutorial: GMS2 [6].
Not promoting or spamming, she probably can explain it better that i do.

Thanks in advance and sorry for all the unimportant code!
 

samspade

Member
This is the line that checks for the transition?

Code:
if(inst != noone and facing == inst.playerfacingbefore) {
   with (game){
       if (!dotransition) {
           spawnroom = inst.targetroom;
           spawnX = inst.targetX;
           spawnY = inst.targetY;
           spawnplayerfacing = inst.playerfacingafter;
           dotransition = true;
       }
   }
}
If so, my initial suggestion would work.
 
L

LordNoob

Guest
This is the line that checks for the transition?
yes i believe that's the line, but (i think) i found the problem, i dont have 8 directions program, i only have 4, so putting (left) || (left down) doesn't work because i don't have a "left down", so before doing that i'll have man up! and program the other 4.
Also i believe the way this code works is 1. check for collision 2. if player is walking the same way the instance is says he should be, then do the transition, i believe it is made like that so you can walk over the transition object without triggering it.
so here's a few things i tried and their results

Code:
playerfacingbefore = dir.down;
playerfacingbefore = dir.left;
playerfacingbefore = dir.right;
playerfacingafter = dir.down;
this one triggers only if the player goes right (even right up, and is not even in the code)

Code:
playerfacingbefore = (dir.down) || (dir.right) || (dir.left);
does nothing

Code:
playerfacingbefore = {(dir.down) || (dir.right) || (dir.left)};
a whole plethora of syntax errors

Code:
playerfacingbefore = (dir.down) || (dir.down) && (dir.left) || (dir.down) && (dir.right);
nothing

Code:
playerfacingbefore = mb_any
works if the player is standing still in any place in the transition, and without pressing the mouse button

so yeah... that last one was a desperation move...
any other suggestions? is not that i don't want to program 8 directions, i know i'm gonna have to do it in some point, but of course, i'm gonna need another tutorial, and new sprites, if there's another way it will be way better

thank you for your time
 
Top