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


Loo, I've done the test and I don't experience any slow down. And works pretty fine, as expected:


This is the enemy with the chance I suggested


process enemy(x,y);
private
//status
string status = "on ground";
int dir = 1;
int eneHP = 10;

//location
int inc_x = 0; // horizontal speed
int inc_y = 0; // vertical speed
int y_prev = 0; //for collision

//movement
int gravity = 1;
int grav_time = 6;
int grav_timer = 6;
int jump_height = -5;
int max_vertical_speed = 6;
int char_speed = 0;
int char_max_speed = 2;

//sprites
int enemy_r, enemy_l;

//collision
int collision_bottom = 0; // down collision
int collision_top = 0; // up collision
int collision_left = 0; // left collision
int collision_right = 0; // right collision
int i = 0;
int j = 0;


begin
z = -1;
ctype = c_scroll;
//upon startup it will either move left or right
dir = rand(0,1);
//load the sprites
enemy_r = load_png("enemy_r.png");
enemy_l = load_png("enemy_l.png");
loop
if (!out_region(id , 0))

//location on screen
x+=inc_x;
y+=inc_y;

//gravity
if(grav_time>0)
grav_time--;
else
inc_y += gravity;
grav_time = grav_timer;
end
if(inc_y > max_vertical_speed)
// Change the max_vertical_speed value if you want to jump higher
inc_y = max_vertical_speed;
end

y_prev = y;

//moving
if(dir==1)
inc_x = 2;
else
inc_x = -2;
end


for(i = 0; i <= (enemy_dim_x/2); i++)
for(j = -(enemy_dim_y/4); j <= (enemy_dim_y/4); j++)
//right
collision_right=tilemap_get_pixel(map,0,x+i,y+j);
if(collision_right != RGB(255,0,0))
if(dir==1) inc_x = 2; end
else
if(dir==1) inc_x = 0; dir = -1; end
end
//left
collision_left=tilemap_get_pixel(map,0,x-(i+1),y+j);
if(collision_left != RGB(255,0,0))
if(dir==-1) inc_x = -2; end
else
if(dir==-1) inc_x = 0; dir = 1; end
end
end
end

//floor
for(i = 0; i <= (enemy_dim_x/2); i++)
for(j = -(enemy_dim_y/4); j <= (enemy_dim_y/4); j++)
collision_bottom=tilemap_get_pixel(map,0,x+j,y+i);
if(collision_bottom == RGB(255,0,0))
// Went through the floor, let's fix the position
y--;
inc_y = 0;
if(status == "in air")
status = "on ground";
end
end
end
end

//ceiling
for(i = 0; i <= (enemy_dim_y/2); i++)
for(j = -(enemy_dim_x/4); j <= (enemy_dim_x/4); j += (enemy_dim_x/4))
collision_top=tilemap_get_pixel(map,0,x+j,y-i);
if(collision_top == RGB(255,0,0))
y++;
if(inc_y < 0)
inc_y *= -1;
end
end
end
end

//sprite section
switch(dir)

case -1:
graph = enemy_l;
end
case  1:
graph = enemy_r;
end

end
end
frame;end
end






Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

thanks, with the changes you made it doesnt slow down and it fixes the problem.
werg

JaViS

Try to compare both version to find out what was causing the slowdown. I'm curious now.
Working on Anarkade. A couch multiplayer 2D shooter.

JaViS

Quote from: DoctorN on May 17, 2013, 01:56:49 AM
thanks, with the changes you made it doesnt slow down and it fixes the problem.


BTW the only changes I made are the ones I suggested you
Working on Anarkade. A couch multiplayer 2D shooter.

MisterN

I see in lines 253 and 374 of api.inc that the z is set there. How does
for (i=0; i<map.layercount; i++)
        layer     = tilemap_layer_scroll(i, map.layers[i], map.tileset,  width,  height);
        layer.x = graphic_info(0, 0, G_WIDTH)/2;
        layer.y = graphic_info(0, 0, G_HEIGHT)/2;
        SCROLL[i].z -= i;
       
        viewport.layer_scrolls[i] = layer;
    end
(lines 370-377)
work with
z = SCROLL[scroll_id].z;(line 253)
cause my enemy will spawn, and I know it spawns, but sometimes it wont appear, so I think maybe its tucked back behind one of the layers.is the z -= i thing making the z negative like my player and enemy processes? do I need to change that to the - to a + or something? thanks
werg