Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,619 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
moving panels slow down and speed up over time #177400
01/11/08 04:05
01/11/08 04:05
Joined: Jun 2004
Posts: 12
cweth Offline OP
Newbie
cweth  Offline OP
Newbie

Joined: Jun 2004
Posts: 12
I'm building a 2d game based on the alien invaders code snippet from aum1. I figured i would start at the beginning, and work my way through. Right now i just have the movement for the game worked out. The enemies constantly move down towards where the player is, and he has to shoot some of them with a missile in order to catch some of them with a bubble to spell words out of the letters on them.
The problem i'm having is that after running the game for a while, the missiles start moving super fast, and the player ship and alien ships start moving painfully slow, and the collision detection stops working some of the time.
I'm not sure where the error is happening, so i'll include all my functions.

Code:


function move_ship()
{
while(1)
{
if (key_pressed(75) == on && player_ship_pan.pos_x > 0 && key_pressed(42) == on )
{
wait(2);
player_ship_pan.pos_x -=3;
}
else {break;}
}
while(1)
{
if (key_pressed(77) == on && player_ship_pan.pos_x < 924 && key_pressed(42) == on )
{
wait(2);
player_ship_pan.pos_x +=3;
}
else {break;}
}


while(1)
{
if (key_pressed(75) == on && player_ship_pan.pos_x > 0 && key_pressed(42) == off )
{
wait(4);
player_ship_pan.pos_x -=3;
}
else {break;}
}
while(1)
{
if (key_pressed(77) == on && player_ship_pan.pos_x < 924 && key_pressed(42) == off )
{
wait(4);
player_ship_pan.pos_x +=3;
}
else {break;}
}


}


////////////////////////////////////////////////////////////////////////////////////////////
// letters movement


function set_pos_y_letters()
{
xpos= 0;
ypos = 1;
while(xpos<41)
{
str_cpy(pos_y_assign_str, pos_y_array.string[xpos]);
str_cat(pos_y_assign_str, " -= 100 * ypos;");
execute(pos_y_assign_str);
xpos +=1;
ypos+=1;
}

xpos = 0;
while(xpos<41)
{
backward:
ypos = 125 * int(random(7));
position_x_tracking_array[xpos] = ypos;



str_for_num(pos_x_track_str, ypos);
str_cpy(pos_x_assign_str, pos_x_array.string[xpos]);
str_cat(pos_x_assign_str, " = ypos");
execute(pos_x_assign_str);


xpos +=1;
}

}


function move_mobs()
{

while(1)
{

xmobs= 0;
while(xmobs<41)
{

str_cpy(pos_y_assign_str, pos_y_array.string[xmobs]);
str_cat(pos_y_assign_str, " += 1;");
execute(pos_y_assign_str);
str_cpy(move_y_str, "ymobs =");
str_cat(move_y_str, pos_y_array.string[xmobs]);
execute(move_y_str);
if (ymobs > 568)
{
str_cpy(pos_y_assign_str, pos_y_array.string[xmobs]);
str_cat(pos_y_assign_str, " -= 4100;");
execute(pos_y_assign_str);
}

xmobs +=1;
}

wait(10/level);

}

}

function shoot_rocket ()
{
while(1)
{

IF (key_space == on && player_ship_pan.VISIBLE == ON)
{
missile_pan.POS_X = player_ship_pan.POS_X;
missile_pan.POS_y = player_ship_pan.POS_y;
missile_pan.VISIBLE = ON; // show the rocket
//snd_play (missile_fire, 100, 0); // this is not working
WHILE (missile_pan.POS_Y > 10)
{
missile_pan.POS_Y -= 2; // move the rocket upwards
WAIT(1);
}
missile_pan.VISIBLE = OFF; // hide the rocket
}
WAIT (1);
}
}


function shoot_bubble ()
{
WHILE (1)
{
IF (player_ship_pan.VISIBLE == ON)
{
bubble_pan.POS_X = player_ship_pan.POS_X;
bubble_pan.POS_y = player_ship_pan.POS_y - 100;
bubble_pan.VISIBLE = ON; // show the rocket
//PLAY_SOUND rocket_snd,100;
WHILE (bubble_pan.POS_Y > 10)
{
bubble_pan.POS_Y -= 1; // move the bubble upwards
WAIT(1);
}
bubble_pan.VISIBLE = OFF; // hide the rocket
}
WAIT (1);
}
}






function set_collisions ()
{

collision_loop_count = 0;
while(1)
{

if (collision_loop_count >= 42)
{
collision_loop_count = 0;
}

str_cpy(collision_string, "enemy_pan_x_num = ");
str_cat(collision_string, pos_x_array.string[collision_loop_count]);
str_cat(collision_string, ";");
execute(collision_string);

str_cpy(collision_string2, "enemy_pan_y_num = ");
str_cat(collision_string2, pos_y_array.string[collision_loop_count]);
str_cat(collision_string2, ";");
execute(collision_string2);


if (enemy_pan_x_num <= missile_pan.pos_x
&& missile_pan.visible == on
&& enemy_pan_x_num >= missile_pan.POS_X - 125
&& enemy_pan_y_num >= missile_pan.POS_Y - 100) // enemy is hit
{
str_cpy(collision_string3, enemy_array.string[collision_loop_count]);
str_cat(collision_string3, ".visible = off;");
execute(collision_string3);
missile_pan.visible = off;
missile_pan.pos_x = 1200;

}
collision_loop_count += 1;
WAIT(1);

}
}



Re: moving panels slow down and speed up over time [Re: cweth] #177401
01/11/08 07:57
01/11/08 07:57
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hello,

you should have a look at time_step as it "is to be used for movement and frame rate compensation".


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1