Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411771 Posts in 69692 Topics- by 58652 Members - Latest Member: APlusPlus

December 13, 2024, 08:11:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsGrandma: GM Platformer Engine
Pages: [1] 2 3 ... 7
Print
Author Topic: Grandma: GM Platformer Engine  (Read 108458 times)
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« on: April 16, 2009, 07:45:35 PM »

Download: http://mattmakesgames.com/matt/GrandmaEngine.gmk

Hopefully this will help some people out.  It's only v0.910 right now, bit definitely usable and a good foundation.  I'll slowly add stuff to it as I have time.

It's based on the Jumper Three engine, but with all J3-specifics striped out and the remainder heavily commented.  I also included an An Untitled Story-style room system because I've gotten a lot of requests to explain how I did that.

It's free to use for freeware/commercial, I just ask for a mention and link in your readme/credits.
« Last Edit: April 06, 2012, 10:27:08 PM by Matt Thorson » Logged

Fuzz
Guest
« Reply #1 on: April 16, 2009, 08:07:39 PM »

Looks interesting. Was this the engine you started on in flash?
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #2 on: April 16, 2009, 08:09:39 PM »

Looks interesting. Was this the engine you started on in flash?

No I just finished my Flash engine, but I'm not confident enough in it to release it publicly since I just started with Flash and haven't even finished a platformer in it yet. 

My Flash engine uses a lot of the same concepts, but there's no real way to "port" a GM engine to Flash (if that's what you meant by this being the Flash engine?).
Logged

ChevyRay
Guest
« Reply #3 on: April 16, 2009, 09:25:51 PM »

Hand Thumbs Up Left Grin Hand Thumbs Up Right

Quote
I also included an An Untitled Story-style room system because I've gotten a lot of requests to explain how I did that.
This reminds me... I've gotten lots of requests/questions from people regarding room/screen movement. I should take a day or two to write a thorough article on some of the various methods I use as well.

I like your approach script -- very convenient.
Logged
threesided
Pixelhead
Level 5
******


derp.


View Profile WWW
« Reply #4 on: April 19, 2009, 04:42:26 PM »

Matt, I totally incorporated your engine into what I've been working on, and it works like a dream. If I ever get what I'm working on to a playable level I will of course give you a shout-out.
Logged
GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #5 on: April 19, 2009, 04:56:35 PM »

Right, I've downloaded this and will be giving it a pretty thorough once-over this week or the next.  I'm currently trying to decide on a nice groundwork engine to built on (instead of just trying again to do one from scratch) and this may work great.  The only thing I'd worry about is that I had pretty bad framerate slowdown on my laptop while playing J3 (I don't have my own desktop right now either), so hopefully that's not due to the engine.
Logged
nayon
Level 5
*****


dickfish


View Profile
« Reply #6 on: April 20, 2009, 05:43:14 AM »

This is awesome, Matt.

Right, I've downloaded this and will be giving it a pretty thorough once-over this week or the next.  I'm currently trying to decide on a nice groundwork engine to built on (instead of just trying again to do one from scratch) and this may work great.  The only thing I'd worry about is that I had pretty bad framerate slowdown on my laptop while playing J3 (I don't have my own desktop right now either), so hopefully that's not due to the engine.

I tied it on my laptop which slows down with J3, and this runs at 60 fps.
Logged

GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #7 on: April 20, 2009, 07:42:24 AM »

Oh perfect; that's a relief.  Smiley
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #8 on: April 20, 2009, 09:48:55 AM »

Thanks guys - I'm currently sorting out an improvement to the movement engine.

As Chevy kindly pointed out, fractional speeds currently do nothing (ie: something with a constant hspd of 0.4 will never move, because this will get rounded down to zero at every movement step).  This will be fixed in v0.920, and there'll be some other new features as well.
Logged

threesided
Pixelhead
Level 5
******


derp.


View Profile WWW
« Reply #9 on: April 20, 2009, 07:14:57 PM »

Hey Matt, I think I may have found a little bug.

If you build a slope and jump into it, the vspd doesn't reset to 0. In the engine it gets stuck at -0.30 .




It messes with some of my animations (I've worked around it) but I'd say it could be a little annoying to work around.
Logged
ChevyRay
Guest
« Reply #10 on: April 20, 2009, 08:57:28 PM »

If I'm not mistaken, this should fix that.

Go into the player's step-event code and find PLAYER INPUT EVAL...

Code:
/*      PLAYER INPUT EVAL       */

var accel, fric;
if (pm_d) {
    vspd = 0;
    accel = S_RUN_ACCEL;
    fric = S_RUN_FRIC;
} else {
    accel = S_AIR_ACCEL;
    fric = S_AIR_FRIC;
}

And add "vspd = 0;" where I put it in there.
Logged
ChevyRay
Guest
« Reply #11 on: April 20, 2009, 09:04:07 PM »

Looking at it now, though, I'm wondering why the vspd is doing that... I can clearly see that Matt set it up to call horizontal and vertical wall collisions using the user events 0 and 1, and the vertical one clearly stops the vspd...
Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #12 on: April 20, 2009, 09:28:06 PM »

Looking at it now, though, I'm wondering why the vspd is doing that... I can clearly see that Matt set it up to call horizontal and vertical wall collisions using the user events 0 and 1, and the vertical one clearly stops the vspd...

I also can't reproduce the bug, and I'd hate to put a redundant vspd = 0; in the step event unless I absolutely have to.  Hmmm... I'll keep searching for it tomorrow.
Logged

ChevyRay
Guest
« Reply #13 on: April 20, 2009, 09:43:02 PM »

Easy to reproduce. Just build a long slope, and keep moving right as you jump up it. It doesn't occur in any other situation, so I'm thinking that perhaps it happens when you land on the ground before your vspd is > (-.5) but still < (.5).

Logged
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #14 on: April 22, 2009, 11:36:07 AM »

Here's v0.920!  Same download link.

Quote
v0.920 - April 20, 2009
   Changes:
      -Renamed pm_d to on_ground; moved its definition to obj_moveable's Begin Step event.
      -Removed initializations of hspd/vspd from obj_player - now calls obj_moveable's Create event for this.
      -Added the h_/v_counter variables which keep track of unused remainders in movement and allow movement by fractions.
   Fixes:
      -Fixed a bug with the room system where stageGoto() would be called even if you shouldn't change rooms.

I couldn't repro the slope bug in this version, but if it's still there let me know.
Logged

Blaster
Pixelhead
Level 1
******


*wiggle*


View Profile WWW
« 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

Pixel Art: Portfolio || Twitter: @pita_akm || Tumblr: silver deluxe
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
« 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
« 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
Pages: [1] 2 3 ... 7
Print
Jump to:  

Theme orange-lt created by panic