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: SplinterGU on February 02, 2013, 06:07:11 PM
javis... the lib must include the imports that it need.


Right, I missed that one, please include the mod required by that function. (mod_screen)


I'll fix it in future versions.


thanks!
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

okay I got half of it working right now. pay no attention to the player.prg, its just movement stuff.
//Velocity And Movement Tester
//By: Nicholas Wolf
//Date: 1/29/2013
program velocity_test;

import "mod_grproc";
import "mod_wm"
import "mod_key"
import "mod_proc"
import "mod_video"
import "mod_text"
import "mod_map"
import "mod_draw"
import "mod_debug"
import "mod_say";
import "mod_screen";
import "mod_math";
import "mod_time";
import "mod_dir";
import "mod_joy";
import "mod_sound";

include "libraries/tiledmap/tiledmap.lib";

global
//the name we will give our level
_tiled_map map; // the map we'll load
_tiledmap_viewport viewport; //a scroller window

//the dimmensions of objects
player_dim_x = 32;
player_dim_y = 32;

//the object of the player
character_process player_s;

private
//The resolution of the game
game_width = 320;
game_height = 240;
game_color_depth = 16;
//The resolution of the screen
screen_width = 640;
screen_height = 480;

begin
//get the size of the monitor you are using
get_desktop_size(&screen_width, &screen_height);
say("Monitor is: " + screen_width + "x" + screen_height);
//set the games resolution
set_mode(game_width,game_height,game_color_depth);
set_fps(60,0);

render_level();

//spawn the player
//player(320/2,240-(player_dim_y/2));

    loop
        //the scroller
        viewport.x = player_s.x - (game_width/2);
        viewport.y = player_s.y-160;
        //press esc or click X to exit game
        if(key(_esc) or exit_status)
            exit("goodbye",0);
        end
    frame;end
   
    tiledmap_stop(viewport);
    tilemap_unload_map(map);
end

include "player.prg"

process render_level();
public
int i,j;
begin
//load the tiled map file
    tilemap_load_map(map,"test.tmx");
    tilemap_start(viewport, map, 320, 240);
//spawn the objects in the tiled map file
    for (i=0; i< map.objectgroup_count ; i++)
        for (j=0; j< map.objectgroups[i].objectcount ; j++)
            switch(map.objectgroups[i].objects[j].typename)
                case "player":
                    player(map.objectgroups[i].objects[j].x,map.objectgroups[i].objects[j].y);
                end                       
            end
        end
    end
end

the problem is with this line of code
tilemap_start(viewport, map, 320, 240);
if I leave it there, the game crashes. if I //comment is, the game runs, but there are no tiles. now, I will upload my source. im not reuploading the library since I havent modified it at all.
werg

JaViS

#17
I found the problem


Right now, and maybe forever, I can only load tmx files saved with the Store tile layer data option set to CSV. (you can change that in the preferences dialog) You have it selected to Base64.


I've also modified your code to assign the player process to the player_s variable.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

#18
Ok. I know we are grateful that you released the code you made to run .tmx files but its still haveily set up to work with your game. I have no idea what to touch. The only thing I got working was getting processes to be placed.
werg

JaViS

Quote from: DoctorN on February 04, 2013, 01:40:25 AM
Ok. I know we are grateful that you released the code you made to run .tmx files but its still haveily set up to work with your game. I have no idea what to touch. The only thing I got working was getting processes to be placed.


Just ask any question I'll help you as far as I can.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

werg

JaViS

#21
Quote from: DoctorN on February 04, 2013, 02:05:26 AM
did you get it to work?


yap, I've replied you already. I've edited the message before you reply.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

thanks! now I have got my game working now. I couldnt figure out a good way to auto-fall (when there is nothing bellow you) and you are standing (havent incorporated walking yet). check line 171 of player.prg
werg

JaViS

When I get home after work I'll take a look at your code. In the mean time, I suggest you to take a look at the character process included with the game, it uses a hardness map (a hidden tiled map layer) and a function to check the color of the pixel below the player, to check if it's over the floor or not.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

I got some stuff down, but i want to make it simplier so you can have it with your library
werg

JaViS

Quote from: DoctorN on February 05, 2013, 10:15:16 PM
I got some stuff down, but i want to make it simplier so you can have it with your library


Would be great to include a simplier example with the library, but I wouldn't include that AS PART of the library, since it's game logic and depends much on what you want your character to behave like. Just lets say you want to use the engine to make a strategic game like C&C and not a platformer, then the library wouldn't be useful.
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

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 = 0; //a counter that will steadily increase/decrease v
    int v_timer_max = 5; //the max time a v_timer will set itself to
    int dir = 0;
    int h_speed = 1.5;
    int y_formula;
    bool can_jump = true;
    bool landing = false;
    bool moving = false;
    //collision
    int i = 0;
    int j = 0;
    int collision_bottom_l = 0;
    int collision_bottom_r = 0;
    int collision_top_l = 0;
    int collision_top_r = 0;
    int collision_left = 0;
    int collision_right = 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=pow(v,1);
            y_prev = y;
            y+=y_formula;
       
        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)
            for(i = -8; i <= 8; i++)
                collision=tilemap_get_pixel(map,0,x+16,y+i);
                if(collision != RGB(255,0,0))
                    dir = 1;
                else
                    dir = 0;
                end
            end
        end
        if(key_left)
            for(i = -8; i <= 8; i++)
                collision=tilemap_get_pixel(map,0,x-16,y+i);
                if(collision != RGB(255,0,0))
                    dir = -1;
                else
                    dir = 0;
                end
            end
        end
        if((!key_right and !key_left) or (key_right and key_left))
            dir = 0;
        end
       
        //jump key
        if(key_jump)
            if(can_jump)
                status = "jumping";
                can_jump = false;
            end
        else
            if(status == "jumping")
                status = "falling";
            end
            if(status == "");
                can_jump = true;
            end
        end
       
        //jumping
        if(status == "jumping")
            if(v>v_min) //since you are //jumping, you want v to reach v_max
                if(v_timer>0)
                    v_timer--;
                else
                    v--;
                    v_timer = v_timer_max;
                end
            else //if v is the minimum it can get, begin falling
                v_timer = 0;
                status = "falling";
            end
            for(i = 0; i <= 16; i++) //hitting the cieling
                collision=tilemap_get_pixel(map,0,x,y-i);
                if(collision == RGB(255,0,0))
                    if(v<0)
                        v = 0;
                    end
                    v_timer = 0;
                    status = "falling";
                end
            end
        end
       
        //falling
        if(status == "falling")
            if(v<v_max) //since you are falling, you want v to reach v_min, which is -v_max
                if(v_timer>0)
                    v_timer--;
                else
                    v++;
                    v_timer = v_timer_max;
                end
            end
            for(i = 0; i <= 16; i++) //hitting the ceiling
                collision=tilemap_get_pixel(map,0,x,y-i);
                if(collision == RGB(255,0,0))
                    if(v<0)
                        v = 0;
                    end
                    v_timer = 0;
                    status = "falling";
                end
            end
            for(i = 0; i <= 16; i++) //landing on the floor
                collision=tilemap_get_pixel(map,0,x,y+i);
                if(collision == RGB(255,0,0))
                    v = 0;
                    v_timer = 0;
                    status = "";
                    y-=v;
                end
            end
        end
    frame;end
end[code]

Okay, I have repotimized my code, it works a little better, but I need your help because you made the tile engine, so I need your expertise in it. Once I got it down, im good.

PROBLEMS:
1. you can fall if there is no free space, I didnt put it in this code because the status will always be "falling". I will need help on this

2. If you add this to ceiling code:
[code]collision=tilemap_get_pixel(map,0,x-16,y-i);
                if(collision == RGB(255,0,0))
                    if(v<0)
                        v = 0;
                    end
                    v_timer = 0;
                    status = "falling";
                end
collision=tilemap_get_pixel(map,0,x+16,y-i);
                if(collision == RGB(255,0,0))
                    if(v<0)
                        v = 0;
                    end
                    v_timer = 0;
                    status = "falling";
                end

and this to the fall code
collision=tilemap_get_pixel(map,0,x+16,y+i);
                if(collision == RGB(255,0,0))
                    v = 0;
                    v_timer = 0;
                    status = "";
                    y-=v;
                end
collision=tilemap_get_pixel(map,0,x-16,y+i);
                if(collision == RGB(255,0,0))
                    v = 0;
                    v_timer = 0;
                    status = "";
                    y-=v;
                end

you will instead stick to the wall, doesnt matter if there is ground below you. but these are needed so that you can the corners (otherwise you will go through half the block).

So those are the problems that I can't fix and have wasted a long time trying to fix. I would like to see a reply soon :). thanks
werg


JaViS

Hi, I'm out of the city for the weekend. Let me check this as soon as I get back home. It should't be hard to fix.

Thanks
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

werg