ZFGC

Resources => Coding => Topic started by: CociCookie on April 18, 2008, 07:13:34 am

Title: Work damn you! Work!
Post by: CociCookie on April 18, 2008, 07:13:34 am
I'm trying to code platformer movement for an un-named RPG but for some reason the code isn't allowing him to move right on the platform, or jump.

Does anyone think they could go through my code and see what needs to be done? Maybe even optimise the coding I have in there? It's getting annoying, because I have some of the more useful code (Quick weapon switching) partly done (for example, at the moment you can select any weapon)

Also, anyone feel like spriting me a new jump sprite? The one I made looks crappy :/

EDIT: Whoops, forgot the editable, I've attached it in a rar file...
Title: Re: Work damn you! Work!
Post by: gm112 on April 18, 2008, 07:19:09 am
I do not use GM, but I am going to suggest that it sounds very much like a collision error. Is it only on a platform? If so, then I'm nearly 100% sure it's a collision detection error. At least that's what it sounds like from reading your post.
Title: Re: Work damn you! Work!
Post by: Theforeshadower on April 18, 2008, 07:25:24 am
Why don't you just do a simple increase speed code? and decrease for when buttons are released?
Title: Re: Work damn you! Work!
Post by: MG-Zero on April 19, 2008, 04:16:51 pm
You have something else strange going on there.  When you move off of a platform, you float.  And if you press left while floating, you fall.  i'll have a look at it.

edit: gm and i fixed the walking issue.  Still working on jumping and falling.  Replace your step event code on the player with this:

Code: [Select]
if position_empty(x,y) = true{
    gravity = 0.5
    if playerdirection = 1{
        sprite_index = plrspr_jumpleft;
    }
    if playerdirection = 2{
        sprite_index = plrspr_jumpright;
    }
else
    gravity = 0
}
if vspeed >= 10{
    vspeed = 10
}   
if hud_plrstatscontroller.weaponchange = false{
    if keyboard_check(vk_left) = true{
        playerdirection = 1;
        sprite_index = plrspr_walkleft;
        if position_empty(x,y){
            x -= hud_plrstatscontroller.playeragility*2.5;
        }
        else
        {
            x -= hud_plrstatscontroller.playeragility*1.5;
        }
    }
    if keyboard_check(vk_right) = true{
        playerdirection = 2;
        sprite_index = plrspr_walkright;
        if position_empty(x,y){
            x += hud_plrstatscontroller.playeragility*2.5;
        }
        else
        {
            x += hud_plrstatscontroller.playeragility*1.5;
        }
    }
    if keyboard_check('Z') = true and (!position_empty(0,1)){
        vspeed=-10
    }
}
if keyboard_check_released(vk_left) = true and playerdirection = 1{
    sprite_index = plrspr_idleleft;
}
if keyboard_check_released(vk_right) = true and playerdirection = 2{
    sprite_index = plrspr_idleright;
}

edit2: falling is fixed, just have to fix the jumping now..
Title: Re: Work damn you! Work!
Post by: gm112 on April 19, 2008, 06:39:34 pm
Me and MG-Zero took some of our own time to help you out. MG-Zero has redone the collision code, and I've rewritten the mass majority of what you had in the main player object. No known bugs are present. I'll come back later when I add jumping. Or do you want to do that yourself?

EDIT: I may have missed out some stuff that you had in the original, too... When I add jumping I'll see what I missed and then I'll put those in too.
Title: Re: Work damn you! Work!
Post by: MG-Zero on April 19, 2008, 09:05:38 pm
Here's GM's with the jumping code..please don't just take the code without looking through, learn how it works to better yourself.  We've commented on everything.
Title: Re: Work damn you! Work!
Post by: gm112 on April 20, 2008, 01:49:04 am
I made some quick changes to fix some silly errors. The jumping is awkward, I know.. but I just tweaked it to work a bit better. And the collision isn't exactly perfect. But hey, this is only to help you out. I'm not going to make anymore changes from here on. Good luck with your project :).

EDIT: I made an attempt at fixing up your jump sprite.

(http://img182.imageshack.us/img182/2320/horriblespriteattemptts5.png)
http://img182.imageshack.us/img182/2320/horriblespriteattemptts5.png

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