Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58430 Members - Latest Member: Jesse Webb

April 26, 2024, 10:57:31 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Game maker Knytt style world movement?
Pages: [1]
Print
Author Topic: Game maker Knytt style world movement?  (Read 3603 times)
nayon
Level 5
*****


dickfish


View Profile
« on: February 10, 2009, 08:27:28 AM »

Well the topic name sucks, but anyway.

If I want to do room transitions in such a way where a room has multiple exits and entrances, and I have lots of rooms, is the only way to do it:

obj_goto_room_x1y2

kind of stuff for each room to go to, or can I create a system which implicitly handles this stuff? Because this is extremely unelegant, it is tiresome, it isn't good practice, and it basically sucks.

All that comes to mind is having an external file which tells which room has exits, where it has them, and where each exit leads.

Any other ideas?

And did I make the topic question clear?
Logged

Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #1 on: February 10, 2009, 09:54:59 AM »

Well, Knytt wasn't actually different rooms, I think. It just moved the camera when you met the edge.
Logged

nayon
Level 5
*****


dickfish


View Profile
« Reply #2 on: February 10, 2009, 10:21:21 AM »

Is that even possible in game maker?

Wouldn't one have to create all objects in the "fake room" in the current GM room?

Sounds infeasible...
Logged

Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #3 on: February 10, 2009, 10:23:18 AM »

I bet it's doable. I have no idea though because I don't use Game Maker.
Logged

nayon
Level 5
*****


dickfish


View Profile
« Reply #4 on: February 10, 2009, 10:34:36 AM »

No, no, I'm not saying it's not doable, it's actually perfectly doable, but knowing game maker, every room switch would be accompanied by 2-10 seconds lag with relatively large rooms... And I'm not even sure whether tiles (background tiles that aren't objects, they aren't interactable) can even be generated dynamically...

I mean it's doable, but I'm doubtful as to the end result.


EDIT:

A more viable way of doing it the way I proposed first might be objects with custom creation code (ctrl+righclick stuff), which is a LOT better, I can actually do this, but still if anyone has any suggestions I am open.
« Last Edit: February 10, 2009, 10:38:17 AM by nayon » Logged

Devlin
Guest
« Reply #5 on: February 10, 2009, 11:42:56 AM »

There are two methods.

there is the single-room shifting-view method OR the multi-room method.

the single-room has the potential to be VERY SLOW (due to the massive amount of objects).

the multi-room is quicker(less objects) , BUT has the caveat of sacrificing a little seamlessness(lag between rooms)

Example for single-room movement; This code isn't mine, but I discovered it looking for exactly what this does.

Code:
To be placed in the player CREATE event
_wait = false; // Whether we need to wait for the transition or not
_trdir = 0; // Transition direction
-----
Code:
To be placed in the player STEP event
// Transition control
if (x >= view_xview[0]+view_wview[0]) {
    _wait = true;
    _newx = view_xview[0]+(view_wview[0]*2);
    _trdir = 0;
}
if (x <= view_xview[0]) {
    _wait = true;
    _newx = view_xview[0]-view_wview[0];
    _trdir = 180;
}
if (_wait == true) {
    if (_trdir == 0) {
        if (view_xview[0]+view_wview[0] != _newx-4) {
            view_xview[0] += 4;
        } else {
            _wait = false;
        }
    }
    if (_trdir == 180) {
        if (view_xview[0] != _newx+4) {
            view_xview[0] -= 4;
        } else {
            _wait = false;
        }
    }
}
-----
Code:
To be placed in a o_ViewControl object's CREATE event
view_wview = 256 // SHOULD BE VIEW SIZE xD
view_hview = 224
follow = oPlayer; //object to follow (can be an id)

width = 240;
height = 208;

view_xview = 0;
view_yview = 0;
-----
Code:
To be placed in o_ViewControl's STEP event
x = floor(x/(width))*width;
y = floor(y/(height))*height;
with(follow)
{
    other.x = floor(((bbox_left+bbox_right)/2)/other.width)*other.width
    other.y = floor(((bbox_top+bbox_bottom)/2)/other.height)*other.height
}

view_xview += ((x-view_xview));
view_yview += ((y-view_yview));


EDIT :: The slowness of the single-room method can be stifled quite nicely by way of deactivating objects outside the view.
« Last Edit: February 11, 2009, 11:07:42 AM by David Williams » Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #6 on: February 10, 2009, 12:10:43 PM »

The fact that you compared it to Knytt makes me assume you want each "level" in the game to be a single screen.

The easy way is to name each room according to its co-ords on the map (ex: rm_5_10, rm_3_4, etc) then use execute_string() and some global variables to track the current map co-ords.

Example code for leaving the right side of the screen of a "level":
Code:
room_x += 1;
execute_string( "room = rm_" + string( room_x ) + "_" + string( room_y ) + ";" );
obj_player.x = 0;  //If the player is persistent, move him so it seems like he is just walking in from the left

So if you're in room "rm_3_5" (room_x = 3, room_y = 5) and you leave the right side, you'll be sent to "rm_4_5".

I personally love this method because it absolves you of any responsibility to maintain a map grid or array.  If you don't like where a room is on the map, you just have to rename it (and edit the blocks around the edges to match up with the new rooms around it).  You can also write a level_start() script to put in every room creation which does stuff like updates the player's map if you have one.
« Last Edit: February 10, 2009, 12:15:22 PM by YMM » Logged

nayon
Level 5
*****


dickfish


View Profile
« Reply #7 on: February 10, 2009, 12:44:48 PM »

The fact that you compared it to Knytt makes me assume you want each "level" in the game to be a single screen.

The easy way is to name each room according to its co-ords on the map (ex: rm_5_10, rm_3_4, etc) then use execute_string() and some global variables to track the current map co-ords.

Example code for leaving the right side of the screen of a "level":
Code:
room_x += 1;
execute_string( "room = rm_" + string( room_x ) + "_" + string( room_y ) + ";" );
obj_player.x = 0;  //If the player is persistent, move him so it seems like he is just walking in from the left

So if you're in room "rm_3_5" (room_x = 3, room_y = 5) and you leave the right side, you'll be sent to "rm_4_5".

I personally love this method because it absolves you of any responsibility to maintain a map grid or array.  If you don't like where a room is on the map, you just have to rename it (and edit the blocks around the edges to match up with the new rooms around it).  You can also write a level_start() script to put in every room creation which does stuff like updates the player's map if you have one.


Wow Matt, that's incredibly awesome :D I'd always wondered how I could put execute_string to use :D

I shalt put your name in the credits when I have something that resembles an end product :D

By the way, you sound like you also have a solution for rooms bigger than the view, right? Can you share that too?

Actually, does it even matter?
« Last Edit: February 10, 2009, 12:48:33 PM by nayon » Logged

Devlin
Guest
« Reply #8 on: February 10, 2009, 12:46:48 PM »

oh, YMM pretty much explained the multi-room method :D
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #9 on: February 10, 2009, 06:46:27 PM »

For rooms bigger than the window size, you can still use the exact method above IF every room is the same size (or you don't mind the spatial discontinuity).

If rooms are variable in size, weird things can happen.  Here's a diagram:

Code: (Example Map)
.__ __ __
|__|__|__|
|_____|__|
 

Imagine that each box is a room.  The top row is rooms rm_1_1, rm_2_1, and rm_3_1 in that order.  The bottom row is rooms rm_1_2 and rm_2_2.  Now, if you left rm_2_1 off the bottom of the screen, you would be sent to rm_2_2 instead of the right side of rm_1_2 as you would expect. 

To fix this you'd have to use a different method where you'd maintain lists of all the x's/y's/widths/heights/references-to for every room, then compare that to the player's x/y on room change.

Now, you can still have variable-sized rooms and use the same-size method (best of both worlds) if you're very careful about it.  Example:

Code: (Example Map)
.__ __ __
|__|__|__|_____
|__|__|________|
|__|__|__|
 

In the above diagram the rooms might as well be the same size, because there's no way the player can exit the weird-sized one with x/y co-ords that could screw it up.  You could even do stuff like:

Code: (Example Map)
.__ __          __ __
|__|__|________|__|__|
|__|__|________|__|__|
|__|__|        |__|__|
 

Although this is stretching it (no pun intended) because if you draw your map on the pause screen or something with a simple loop of drawing rectangles, this long room will appear to be normal size on said map and won't reflect the actual distance.

I guess the rule of thumb with this method is: if the player's x co-ord is above what it could be in a normal-sized room, she shouldn't be allowed to leave the room off the top or bottom.  If the y co-ord is above normal, she shouldn't be able to leave off the left or right.
« Last Edit: February 10, 2009, 07:01:14 PM by YMM » Logged

nayon
Level 5
*****


dickfish


View Profile
« Reply #10 on: February 11, 2009, 12:36:04 AM »

Yeah I get it now. One other thing.

Either I suck, or when I try to do this kind of movement, I lose information of keys being held. For example if I'm holding some button for, I don't know, sprinting, and when the room transitions, the character is no longer sprinting.

Is there a way around this or is this the point we accept game maker's limitations? (Or is it the case where I simply suck at game maker :D )
Logged

Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #11 on: February 11, 2009, 09:34:08 AM »

Yeah I get it now. One other thing.

Either I suck, or when I try to do this kind of movement, I lose information of keys being held. For example if I'm holding some button for, I don't know, sprinting, and when the room transitions, the character is no longer sprinting.

Is there a way around this or is this the point we accept game maker's limitations? (Or is it the case where I simply suck at game maker :D )

Yeah this is a really annoying "feature" of GM.

You could try using keyboard_check_direct() (which has no _pressed() functions unfortunately).  You might be able to work some voodoo with io_clear() and maybe setting the keystates yourself on room start?  I don't remember all the possible fixes for this.
Logged

nayon
Level 5
*****


dickfish


View Profile
« Reply #12 on: February 11, 2009, 10:57:25 AM »

Yeah I get it now. One other thing.

Either I suck, or when I try to do this kind of movement, I lose information of keys being held. For example if I'm holding some button for, I don't know, sprinting, and when the room transitions, the character is no longer sprinting.

Is there a way around this or is this the point we accept game maker's limitations? (Or is it the case where I simply suck at game maker :D )

Yeah this is a really annoying "feature" of GM.

You could try using keyboard_check_direct() (which has no _pressed() functions unfortunately).  You might be able to work some voodoo with io_clear() and maybe setting the keystates yourself on room start?  I don't remember all the possible fixes for this.


Yugh, that sounds torturous :D

Well, thanks anyway! I guess this concludes this thread :D
Logged

pgil
Guest
« Reply #13 on: February 11, 2009, 05:32:03 PM »

This is kind of off topic, but what's this lag between rooms people are talking about? I'm using game maker, and my rooms switch instantly (at least on my computer).. Is this something I should look out for?
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #14 on: February 11, 2009, 05:50:34 PM »

It really isn't a big deal.  There can be some lag, but even if there is it's not a terrible time to have lag anyways.
Logged

GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #15 on: February 11, 2009, 06:41:07 PM »

I'm sure it's there, but I found it totally unnoticeable while playing An Untitled Story.  So yeah, minimal.
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #16 on: February 11, 2009, 06:53:50 PM »

And a lot was happening on room switch in An Untitled Story.

The most expensive things off the top of my head:
  • Removing from video memory the background/foreground images for the previous room.
  • Loading into video memory the background/foreground images for the new room (two 630x480 PNG files).
  • Updating the map (accessing and writing to a ds_grid structure).
  • Clearing particle systems.
  • Miscellaneous room-specific code (initializing weather effects and what-have-you).

So yeah.  In general don't worry about it.

(Ugh, thinking about An Untitled Story makes me feel guilty for all the tiny memory leaks.  Should go back and fix those some day)
Logged

Graham Lexie
Level 0
**



View Profile
« Reply #17 on: February 13, 2009, 11:30:28 AM »

For large rooms you could check the player's position in the room when transitioning, to see by how much you need to offset the room's coordinates.
Say, if a standard room were 2000x1500 pixels, something like:
room_x += floor(player.x/2000)
room_y += floor(player.y/1500)
(I've no idea if this code is quite right since I don't know Game Maker)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic