2017-04-08 13:08:55


Can you give me an example code walktimer such, which goes four directions?
So forward, backward, right, left.

Please help me!


Thumbs up +1

2017-04-08 18:02:25

Run a timer. You can check how much time has passed like this:
void main()
timer mytimer;
show_game_window("timer test");
while(mytimer.elapsed < 5000)//milliseconds
What does this do? Creates a timer, watches it until it reports that 5000 milliseconds (or 5 seconds) have passed and then quits.
Now let's look at the movement side of things. Let's say you have a player class like this:
class player
int x_position;
int y_position;
timer movement_speed;
void move()
//Check if movement_speed.elapsed is greater than the interval at which you want to move.
if(movement_speed.elapsed >= 250)//four steps per second, about the step interval of human running.
//do your checks here.
walk(forward);//forward should be defined as a const int.


//and here's where you might handle walking itself.
void walk(int direction)
if(direction == forward)
y++;//geometry. If you're moving up and down you're moving along the Y axis. If you're moving left and right you're moving along the x axis.
//code to play footstep sounds goes here.


Of course this isn't complete and working, but it should give you an idea of where to start. There's more to it if you want to make a complicated game, like checking where the player is trying to step and making sure it can actually step there (for instance, making sure you can't step inside a wall).

Proud to be the official hosting provider for http://www.vgstorm.com!

Thumbs up +1

2017-04-08 18:51:32

This might also work.
int x;
int y;
timer walktime;
sound step1;
void main(){
show_game_window("walktimer test");
if(key_down(KEY_UP) and walktime.elapsed>=300)
if(key_down(KEY_DOWN) and walktime.elapsed>=200)
and so you will carry on with the y command.
I always say, to learn from an example will be the best way to learn.
This is reely easy, tell me if you don't understand something, i am reely not the best with bgt, but i will try to help where i can.

best regards
never give up on what ever you are doing.

2017-04-08 20:56:18

Thanks! And in this game what the fault?
Please, tell me.
For some reason, you don't walk, simply nothing happens.
The game sourcecode link.

http://www.tdstudios.esy.es/side scroller.zip

Thumbs up +1

2017-04-09 11:11:29

Maby look i made a mistake. the walk timer should be restarted after it is elapsed.

best regards
never give up on what ever you are doing.

2017-04-30 10:05:56

int x,y;
double cooldown;
void main() {
while(!key_pressed(KEY_ESCAPE)) {
if(cooldown>0.0) cooldown-=0.005;
if(cooldown<0.0) cooldown=0.0;
if((key_down(KEY_UP))&&(y<10)) walk(0,1);
else if((key_down(KEY_LEFT))&&(x>0)) walk(-1,0);
else if((key_down(KEY_DOWN))&&(y>0)) walk(0,-1);
else if((key_down(KEY_RIGHT))&&(x<10)) walk(1,0);
bool walk(int x_increment,int y_increment) {
if(cooldown!=0.0) return false;
return true;
For me the best way is handling timers through double variables.

Thumbs up