Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1034994 Posts in 41753 Topics- by 33346 Members - Latest Member: jboadas

August 22, 2014, 11:39:06 AM
TIGSource ForumsDeveloperTutorialsGrandma: GM Platformer Engine
Pages: 1 [2] 3 4 ... 9
Print
Author Topic: Grandma: GM Platformer Engine  (Read 59028 times)
Blaster
Pixelhead
Level 1
******


*wiggle*


View Profile WWW Email
« Reply #15 on: April 23, 2009, 08:13:55 PM »

Great! Thanks for this, I'm trying to understand how it works now. (I'm still learning the ropes)

I just discovered a little quirk.

If you jump (without performing a double jump) into a new room, without letting go of the jump key, the player will double jump by itself shortly after entering. A small bug but deadly if you were making a masocore-type platformer.
Logged

ChevyRay
Guest
« Reply #16 on: April 23, 2009, 08:47:18 PM »

Yeah, the slope problem is fixed now. Switching to the counter-based movement must have fixed it Smiley
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW Email
« Reply #17 on: April 24, 2009, 10:44:58 AM »

Great! Thanks for this, I'm trying to understand how it works now. (I'm still learning the ropes)

I just discovered a little quirk.

If you jump (without performing a double jump) into a new room, without letting go of the jump key, the player will double jump by itself shortly after entering. A small bug but deadly if you were making a masocore-type platformer.

Thanks, I'll add that to my list for the next version!
Logged

threesided
Pixelhead
Level 5
******


derp.


View Profile WWW Email
« Reply #18 on: April 24, 2009, 11:23:21 AM »

Ok, so if I was working from v.0.910, what would i adjust to make the slope problem gone now? I don't want to go through and re-download if I can just as easily move things around and not worry about renaming variables etc.
Logged
ChevyRay
Guest
« Reply #19 on: April 24, 2009, 06:45:49 PM »

Okay, save a backup version of your game, and I'll see if I can walk you through it.


In the step event for all objects that have obj_moveable as a parent, delete this line:
Code:
/*      PLAYER PHYSICS      */
event_inherited();
It is no longer needed, because the physics object's events are going to be moved to the Begin-Step and End-Step events, where they will automatically be inherited. Only if the object is already using the Being/End-Step events will you have to add the event_inherited() line to that event's code to make sure that it's performing the code of its parent.


Next, go into obj_moveable. In its creation event, initialize the following variables:
Code:
h_counter = 0;
v_counter = 0;

on_ground = 0;


I don't know if you changed obj_moveable at all, but now we are going to break it's step event into the begin-step event and end-step event. So create those events, and in the begin-step, put the following:
Code:
on_ground = checkBelow();
And your end-step event will now be this:
Code:
var h, v, collide, slope;

//Add to the counters, then get the h and v (pixels to move this step) from them.
h_counter += hspd;
v_counter += vspd;

h = round( h_counter );
v = round( v_counter );

h_counter -= h;
v_counter -= v;

/* This loop will move the object based on hspd.  The object will never
actually collide with a floor object, because this loop (and the next one for vspd)
will always position it right next to them without overlapping.  If the
object collides with a wall, it will call one of two events:
User Event 0 - if the collision is horizontal
User Event 1 - if the collision is vertical */
collide = false;
slope = false;
repeat (abs(h)) {
   
    if (place_meeting( x+sign(h), y, obj_floor )) {
        if (!place_meeting( x+sign(h), y-1, obj_floor )) {
            //Running up slopes
            y -= 1;
            x += sign(h);
            slope = true;
        } else {
            //Hit a wall
            collide = true;
            break;
        }
    } else {
        if (on_ground) {
            if (!place_meeting( x+sign(h), y+1, obj_floor ) && place_meeting( x+sign(h), y+2, obj_floor )) {
                //Running down slopes
                y += 1;
            }
        }
        x += sign(h); 
    }

}

if (collide)
    event_perform( ev_other, ev_user0 );
   
if (slope)
    hspd = approach( hspd, 0, S_SLOPE_SLOW );
   
   
collide = false;
repeat (abs(v)) {
   
    if (vspd <= 0) {
        //Going upward you don't have to worry about jumpthru platforms
        if (place_meeting( x, y+sign(v), obj_floor )) {
            collide = true;
            break;
        } else
            y += sign(v);
    } else if (checkBelow()) {
        collide = true;
        break;
    } else
        y += sign(v);

}

if (collide)
    event_perform( ev_other, ev_user1 );
Make sure you scroll down to get it all. You'll notice a large comment in there that explains how the counters work.


Now we have to do is go into all moveable objects' step event and rename all instances of the variable pm_d to on_ground. If you go into your code editor, you'll see this button at the top:

Click on that, and you can automatically replace all "pm_d" in the code with "on_ground".


Also, this line must be added to the top of all moveable object's creation events:
Code:
event_inherited();
And the following lines deleted from it:
Code:
pm_d = false;       //Whether the player is currently standing on solid ground

hspd = 0;           //Player's horizontal speed
vspd = 0;           //Player's vertical speed
Because those variable initializations are now handled by obj_moveable, and will be created when event_inherited() is called. Also, pm_d no longer exists.


And that should be it. What this does is makes so you can set your moveable objects with a hspd or vspd that is less than 1, and they will move at that rate. So if your object's speed is .5, it will move 1 pixel every two steps (before, it would have just rounded this to 1 and moved 1 pixel ever step, and anything lower would have rounded to 0 and not moved at all).


Hopefully that all works for you. If this fails, feel free to PM me your GMK to me and I'll fix it up for you.
« Last Edit: April 24, 2009, 10:02:06 PM by ChevyRay » Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW Email
« Reply #20 on: April 24, 2009, 06:50:00 PM »

Thanks Chevy!

Yeah, I should've warned people that the fundamentals of the engine could still change before v1.00.
Logged

ChevyRay
Guest
« Reply #21 on: April 24, 2009, 06:53:28 PM »

I made a slight edit, to call event_inherited() in the creation event.

I didn't account for the room tranfer issue that you apparently ran into, as I'm not sure what you changed to fix that.
Logged
GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #22 on: May 04, 2009, 05:51:08 PM »

OK, I've played around with it and I can officially say it makes me proud to be an Albertan.  Yeah Matt!  Hand Thumbs Up Left Grin  Hand Shake Right

Also, I realized that you can just draw any solid shape, set the parent to the floor object, and if the slope is never more than 45 degrees the character can walk up it (I'm 100% sure Matt/Chevy know this, but I thought I'd mention it for whoever else might not).

But yes, this is awesome, and I'm already significantly fucking with the character code to turn it into a bird.  (jump=flap wings; slow glide down; walks slowly; etc.)
Logged
PureQuestion
Level 4
****



View Profile Email
« Reply #23 on: May 04, 2009, 06:02:12 PM »

Fantastic Job. Gentleman

As can be seen in Feedback, I've begun work on a game using this.
It's basically how I learned the GM coding language, as well. That and rampant decompilation of Games I had lying around. It's fun to get a look at how things tick.

Great job, keep an eye out for my game, and thanks for helping me learn GML, to sum everything up.
Logged

Matt Thorson
Level 7
**

c'est la vie


View Profile WWW Email
« Reply #24 on: May 04, 2009, 06:27:34 PM »

Fantastic Job. Gentleman

As can be seen in Feedback, I've begun work on a game using this.
It's basically how I learned the GM coding language, as well. That and rampant decompilation of Games I had lying around. It's fun to get a look at how things tick.

Great job, keep an eye out for my game, and thanks for helping me learn GML, to sum everything up.

I'm really glad this is helping you learn GM!

Coming in the next version:
-A standardized, reusable menu
-Pausing (which uses the above menu as well)
-An alternative player object which will demonstrate how to do ledge grabbing
Logged

Damian
Level 3
***



View Profile Email
« Reply #25 on: May 06, 2009, 12:40:44 PM »

This would of been extremely useful when I was trying to do the room transitions.
Mines a bit big code wise and has many flaws/bugs. So I hope you don't mind me looking at this for interest sake.
 Panda
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW Email
« Reply #26 on: May 06, 2009, 12:53:57 PM »

This would of been extremely useful when I was trying to do the room transitions.
Mines a bit big code wise and has many flaws/bugs. So I hope you don't mind me looking at this for interest sake.
 Panda


Not at all.  Feel free to steal my code even Gentleman
Logged

PureQuestion
Level 4
****



View Profile Email
« Reply #27 on: May 06, 2009, 02:36:59 PM »

Fantastic Job. Gentleman

As can be seen in Feedback, I've begun work on a game using this.
It's basically how I learned the GM coding language, as well. That and rampant decompilation of Games I had lying around. It's fun to get a look at how things tick.

Great job, keep an eye out for my game, and thanks for helping me learn GML, to sum everything up.

I'm really glad this is helping you learn GM!

Coming in the next version:
-A standardized, reusable menu
-Pausing (which uses the above menu as well)
-An alternative player object which will demonstrate how to do ledge grabbing

I'm worried about managing to apply these updates to my current game. Sounds like it's gonna be annoying. I would like pausing, though.

On the subject of edge grabbing, why not wall jumping? That should be a lot simpler, and it's in all 3 jumpers. in fact, I'm perplexed by why certain things were removed when you changed the J3 engine into this. Mainly springs and wall jumping. those seem pretty useful to me. I've already made springs, but...
Logged

ChevyRay
Guest
« Reply #28 on: May 06, 2009, 03:44:13 PM »

Quote
I'm worried about managing to apply these updates to my current game. Sounds like it's gonna be annoying. I would like pausing, though.
Pausing is easy. You can add it to virtually any game without disrupting the current content at all. If you study YMM's code for it, you'll discover that it's easy to apply if you just separate out the pause system from the rest of it, because it's designed to work independently of everything else. Or at least that's what I assume.
Logged
GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #29 on: May 06, 2009, 05:28:15 PM »

it's designed to work independently of everything else. Or at least that's what I assume.
Yeah, I think you can easily add some code that freezes all instances in a room except the "controller" object.  You don't have to change other stuff to add that, you just have to have a controller object that's "above" pausing and unpausing.
« Last Edit: May 07, 2009, 08:42:04 PM by GregWS » Logged
Pages: 1 [2] 3 4 ... 9
Print
Jump to:  

Theme orange-lt created by panic