External Exam Download Resources Web Applications Games Recycle Bin

portals | gml



Add new objects objPortalA and objPortalB 20px width x 64px height:



Two new lines of gml code on bottom of objPlayerCreate event, we add a teleported Boolean and a portal_deactivate_timer constant so i can safely clear portal without ending up in an infinite portal loop:

objPlayer Create

grav = 1;
horiz = 0;
vert = 0;
move_speed = 7;
jump_speed = -15;
frict = 0.9;

//new variables for portals:
teleported = false;
portal_deactivate_timer = room_speed div 2; //half sec

objPlayer Step

if (keyboard_check(vk_right)){ horiz = move_speed; };
if (keyboard_check(vk_left)){ horiz = -move_speed; };
if (keyboard_check(vk_nokey)){ horiz = horiz * frict; };
vert = vert + grav;

if (place_meeting(x, y+1, objBlock)) and (keyboard_check(vk_up)) { vert = jump_speed; }
    
if (place_meeting(x+horiz, y, objBlock)) { 
    while (!place_meeting(x+sign(horiz), y, objBlock)) { 
        x = x + sign(horiz); 
    }
    horiz = 0;
}
x = x + horiz;

if (place_meeting(x, y+vert, objBlock)) {
    while (!place_meeting(x, y+sign(vert), objBlock)) {
        y = y + sign(vert);
    }
    vert = 0;
}
y = y + vert;

//---------------------------- PORTALS:

if place_meeting(x, y, objPortalA) and !(teleported) {
    teleported = true;
    y = objPortalB.y; 
    x = objPortalB.x + (x-xprevious);
} 
if place_meeting(x, y, objPortalB) and !(teleported) {
    teleported = true;
    y = objPortalA.y;
    x = objPortalA.x + (x-xprevious);
}
if (teleported) portal_deactivate_timer -= 1;
if (portal_deactivate_timer < 1){
    teleported = false;
    portal_deactivate_timer = room_speed div 2; //half sec
}

Challenge:

1. Implement the above code.

2. CHALLENGE try making an "invisible portal". This is like a hidden portal that is a bonus for the player to find.

3. CHALLENGE if you can find the invisible portal, make it visible once found.

4. Find a cool, possibly animated sprite or appearance for your "portal".

5. Vertical portals... very difficult!