Tiled parser library with Cardiac Runner as example

Started by JaViS, January 30, 2013, 02:35:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JaViS

Quote from: DoctorN on February 18, 2013, 03:32:57 PM
have you had the chance to look at it? thanks


I came back today and I'm at work roght now, I'll take a look asap and let you know.
Working on Anarkade. A couch multiplayer 2D shooter.


JaViS

Ok


I couldn't fix it, basically for two main reasons:


* You are checking the collision with the floor only after a JUMP, but you have to realize you're always falling, that's how gravity works. So what you must do is to check the bottom collision in all frames and add a vertical (y) speed until you collide with the floor.


* In all the frames you have to make a fix left and right collision too, if you collide with the left, you have to move your character to the right until you are no longer colliding with the wall. Same thing with the wall at the right.


So basically if you want me to fix your code I would be rewritting most of the logic of the player.


I'll be posting a basic example of how hardness map should be implemented in a character process soon.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

I was really hoping I could have something working soon. I need to get done what I need to get done very soon. This is the only other thing I could think of:
//ground detection
        for(i = 0; i <= 16; i++)
            collision=tilemap_get_pixel(map,0,x,y+i);
            if(collision != RGB(255,0,0))
                if(status != "jumping")
                    status = "falling";
                end
                can_jump = false;
            else
                status = "";
                v = 0;
                can_jump = true;
            end
        end
       
        //falling
        if(status == "falling")
            if(v_timer > 0)
                v_timer--;
            else
                if(v < v_max)
                    v++;
                end
                v_timer = v_timer_max;
            end
        end
       
        //jumping
        if(key_jump)
            if(can_jump == true)
                status = "jumping";
            end
        end
        if(status == "jumping")
            if(apex < apex_reached)
                if(apex_timer > 0)
                    apex_timer--;
                else
                    apex++;
                    apex_timer = apex_timer_max;
                end
            else
                status = "falling";
            end
            if(v_timer > 0)
                v_timer--;
            else
                if(v > v_min)
                    v--;
                end
                v_timer = v_timer_max; //5
            end
        else
            apex = 0;
            apex_timer = apex_timer_max; //5
        end[code]
the problem with this:
*no ceiling (yet)
*jumping is very weird (you jump higher)
*you can fall through the edge blocks
*sometimes you land 1/2 pixels into a block and that screws everything up
*when you are on the platforms that are 2x1, you will sink
werg

MisterN

please man, ive been twidling my thumbs and trying to make code. nothing works. can you help me?
werg

JaViS

ok, I think you need to rewrite your character process. Take a look at the example we've provided and try to understand it.


the keys of the logic are the following :


have 2 vars for the movement. inc_c and inc_y are the value on pixels the player will move on every frame.


on your loop:


<code>

                inc_y += gravity; // ALWAYS falling




      if(inc_y > max_vertical_speed)
         inc_y = max_vertical_speed;
      end
</code>
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

I'm sorry but the code to your cardiac is too proprietary for what I need to do. I really need to get this done, you realize how much time I have spent not getting anything done because I am trying to get the players physics to work? I won't rest until it's done and it's killing me, it's keeping me up at night trying to figure out how come it isn't working. I see that the tiles are rendered the same way as in my platform example, but you don't have the same style of collision
tile[(x-player.dimx/2)/block_size][(y-player.dimy/3)/block_size]
and I don't know where to put it in the code or how to make it work since it isn't looking for kind it's looking for rgb. I have realized that the english section of this forum is dead but this is the only active place for bennu help. I am so lost at this point that this is all I can comprehend at the moment.

process player(x,y);
private
    //location
    int y_prev = 0; //for collision
    //key presses
    bool key_right = false;
    bool key_left = false;
    bool key_jump = false;
    //status
    string status = "falling";
    //movements
    int v = 0; //velocity
    int v_min = -4; //the minimum a velocity can get
    int v_max = 4; //the maximum a velocity can get
    int v_timer = 5; //a counter that will steadily increase/decrease v
    int v_timer_max = 5; //the max time a v_timer will set itself to
    int fall;

    int dir = 0;
    int h_speed = 1.5;
    int y_formula;
    bool falling = false;
    bool jumping = false;
    bool on_ground = false;
    bool moving = false;
    //collision
    int i = 0;
    int j = 0;

    int collision = 0;
begin
graph = load_png("player.png");
ctype = c_scroll;
    loop
        write(0,0,0,0,"STATS:");
        write(0,0,8,0,"dir: "); write_var(0,56,8,0,dir);
        write(0,0,16,0,"v: ");  write_var(0,56,16,0,v);
        write(0,0,24,0,"v_timer: "); write_var(0,56,24,0,v_timer);
        write(0,0,32,0,"status: "); write_string(0,56,32,0,&status);
        //formula for moving
            x += dir*h_speed;
            //y_formula = (fall-v);
            y_prev = y;
            //y = y + y_formula;
            y = y + v;
       
        if(key(_right) and !key(_left))
            key_right=true;
        else
            key_right=false;
        end
        if(key(_left) and !key(_right))
            key_left=true;
        else
            key_left=false;
        end
       
        if(key(_control))
            key_jump = true;
        else
            key_jump = false;
        end
       
        //moving
        if(key_right)
            collision=tilemap_get_pixel(map,0,x+16,y);
            if(collision != RGB(255,0,0))
                dir = 1;
            else
                dir = 0;
            end
            collision=tilemap_get_pixel(map,0,x+16,y+16);
            if(collision != RGB(255,0,0))
                dir = 1;
            else
                dir = 0;
            end
            collision=tilemap_get_pixel(map,0,x+16,y-16);
            if(collision != RGB(255,0,0))
                dir = 1;
            else
                dir = 0;
            end
        end
        if(key_left)
            collision=tilemap_get_pixel(map,0,x-15,y);
            if(collision != RGB(255,0,0))
                dir = -1;
            else
                dir = 0;
            end
            collision=tilemap_get_pixel(map,0,x-15,y+16);
            if(collision != RGB(255,0,0))
                dir = -1;
            else
                dir = 0;
            end
            collision=tilemap_get_pixel(map,0,x-15,y-16);
            if(collision != RGB(255,0,0))
                dir = -1;
            else
                dir = 0;
            end
        end
        if((!key_right and !key_left) or (key_right and key_left))
            dir = 0;
        end
       
        //air movement
        if(!jumping)
            collision=tilemap_get_pixel(map,0,x,y+16);
            if(collision != RGB(255,0,0))
                falling = true;
                on_ground = false;
            else
                v = 0;
                v_timer = v_timer_max;
                on_ground = true;
                falling = false;
            end
            collision=tilemap_get_pixel(map,0,x+16,y+16);
            if(collision != RGB(255,0,0))
                falling = true;
                on_ground = false;
            else
                v = 0;
                v_timer = v_timer_max;
                on_ground = true;
                falling = false;
            end
            collision=tilemap_get_pixel(map,0,x-15,y+16);
            if(collision != RGB(255,0,0))
                falling = true;
                on_ground = false;
            else
                v = 0;
                v_timer = v_timer_max;
                on_ground = true;
                falling = false;
            end
        end
        if(falling)
            if(v < 0)
                v = 0;
            end
            if(v < v_max)
                if(v_timer > 0)
                    v_timer--;
                else
                    v++;
                    v_timer = v_timer_max;
                end
            end
        end
        if(jumping)
            if(v > v_min)
                if(v_timer > 0)
                    v_timer--;
                else
                    v--;
                    v_timer = v_timer_max;
                end
            else
                falling = true;
                jumping = false;
            end
        end
       
        say(falling);
       
        if(key_jump)
            if(!falling and !jumping and on_ground)
                jumping = true;
                on_ground = false;
            end
        end

    frame;end
end


And this current revision (revision 207) is incomplete. Will I still work on it after I post this, yes? Because I can't twiddle my thumbs any longer. You should already have my velocity.prg, nothing in that has changed. Please, help me out. I just want things to be checked on a +16 and -16 scale. Can you please sit down and help a guy out? Thanks
werg

JaViS

Hey sorry for the late reply, I'm really busy this week.


Let me take a look at what you've done.


Maybe this saturday I can come up with an simpler character example.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

okay thanks, will you take into mind what i said about the 16 pixel thing?
werg

JaViS

Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

just checking to see how you are at with progress
werg

DCelso

Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

handsource-dyko


DCelso

Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

MisterN

i read the files inside the library (they could be renamed .prg's and still work) they read the .txt file that tiled makes.
werg