Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [GM8]Having problems programming slopes  (Read 2299 times)

0 Members and 1 Guest are viewing this topic.

King Tetiro

Leader of Phoenix Heart
[GM8]Having problems programming slopes
« on: August 06, 2011, 04:57:56 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
Howdy folks, let's start off with my code.

Code: [Select]
for(i = abs(argument0); i > 0; i = i - 1)
{
    if (i < 0)
        i = 0;
    dis = sign(argument0) * i;
   
    if (!place_meeting(x + dis, y, BckSObj))
    {
        x = x + dis;
        mving = 1;
        break;
    }
    if (!place_meeting(x + dis, y - i, BckSObj))
    {
        y = y - (i / 2);
        mving = 1;
    }
    if (!place_meeting(x + dis, y + i, BckSObj))
    {
        y = y + (i / 2);
        mving = 1;
    }
}

Now this normally works with slopes in my 2.5D engine however now it's in a side scroller engine and now it work won't. Could someone help me fix this?

For notice, the BckSObjs are ALWAYS at co-ordinates that a multiple of 16 and it's mask sprite has the points of origin 0,0.

The character has his points of origin at the bottom middle of the mask_sprite.

I'd really appreciate the help.
Logged
  • Phoenix Heart
Re: [GM8]Having problems programming slopes
« Reply #1 on: August 07, 2011, 12:39:02 am »
  • AKA "Micah DS"
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1347
I've gone about this a quite differently, but I'll show you how I do it and maybe it'll shed some light on this problem for you.

Pretty much I have two variables for x movement: xcount and xspeed.
The "xcount" variable might not be needed for you, because it's only used for "part-pixel" movement. Simply put, it allows the character to move at speeds under 1 pixel per step. If your graphics are high res, then you might not need such precision, but I'll put it in because it's pretty simple to understand anyway.
Now the "xspeed" variable is how fast the character is going. All of the code for adding or subtracting to the character's speed is put before the actual x movement (of course). For example, you can have all of your friction and whatnot taken into the equation beforehand.

Some terms you may need to know:
- "frac" gets the part of a number after the decimal point (e.g. "3.452" would return ".452").
- "abs" gets the absolute value, so a "-5" would return as just "5"
- "sign" can only return -1, 0, or 1 (i.e if the value of xspeed is greater than 0, sign returns a 1, if it's 0, sign returns a 0, and if it's lower than 0, sign returns -1)

Now that you know all that, here is an example of the code I'm using in my game:

Code: [Select]
//GET "PART-PIXEL" MOVEMENT
//xcount number = last fraction of xspeed plus current xspeed
xcount = frac(xcount) + abs(xspeed);

//X MOVEMENT AND SLOPE MOVEMENT
//do movement only if xcount = 1 or over
if xcount >= 1{
    repeat (abs(floor(xcount))){
        //if there's nothing solid at next x position, move 1 pixel over
        if place_free(x+sign(xspeed),y){
            x += sign(xspeed);
            //if there is a solid 2 pixels below and no solid at 1 pixel below, move character down 1 pixel (for descending slopes)
            if !place_free(x,y+2) && place_free(x,y+1){
                y += 1;
            }
        }
        //"else" just means there is something solid at next x position
        else{
            //(by already asking "else" we know there is a solid 1 over, so we ask..) if there is NO solid at position 1 over and 1 up, climb slope
            if place_free(x+sign(xspeed),y-1){
                y -= 1;
                x += sign(xspeed);
            }
            else{
                xspeed = 0;
                break;
            }
        }
    }
}

I hope I commented properly so it's easy enough to understand as opposed to sounding more complicated than it really is. I also took out a lot of code that takes special platforms into consideration (like platforms that you may jump up through and land on top of, etc).

I know your coding is very different, but I hope you can take something away from my code to figure out what is wrong with yours. Also, y movement is pretty much the same idea; if you understand the concept in this code, you'll have no problem with that.

One more thing: Game Maker kinda sucks with collision checking. The code I've shown is using the whole character's mask for checking, and it seems that yours is as well, which means that points of origin are kinda meaningless in this case. If your collision is as simple as a tall rectangle, this should work great, but you may need to have a mask the checks only the "feet" for this to work really well. In my game I was forced to frequently switch between multiple masks because the character's head is bigger than his body (which presents multiple problems, believe it or not).

Anyway, I hope I helped somehow, even though my approach is a little different. :-\
« Last Edit: August 07, 2011, 12:53:57 am by Frozenç‚Ž »
Logged
  • My Music

King Tetiro

Leader of Phoenix Heart
Re: [GM8]Having problems programming slopes
« Reply #2 on: August 07, 2011, 08:36:53 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
Thanks for your help Frozen. Have a cookie :)

I fixed the error myself. I had left the slope sprite's unique frame masks thing unchecked.

I'm currently making a tribute to Game Maker by creating a mildly Smash Bros inspired game
Logged
  • Phoenix Heart
Re: [GM8]Having problems programming slopes
« Reply #3 on: August 08, 2011, 01:04:14 am »
  • AKA "Micah DS"
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1347
I fixed the error myself. I had left the slope sprite's unique frame masks thing unchecked.
Ah, that would do it all right. Glad you figured it out and got it fixed. ^_^

I'm currently making a tribute to Game Maker by creating a mildly Smash Bros inspired game
Sounds cool, good luck!
Logged
  • My Music

King Tetiro

Leader of Phoenix Heart
Re: [GM8]Having problems programming slopes
« Reply #4 on: August 08, 2011, 02:35:49 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
I also have a commercial RPG series in the cogs of progress but taking a couple of week's break from it.

As for the tribute game, already have

Tetiro from Legena : The New Dawn
Blue from Assassin Blue
Robbie Swifthand from Robbie Swifthand and the Orb of Mysteries
Arda from the cancelled GMCG project, Eve
Logged
  • Phoenix Heart
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.078 seconds with 47 queries.

anything