Acceleration code for Sonic

Non-platform specific questions.

Acceleration code for Sonic

Postby CrimsonTheDarkBat » Wed Oct 13, 2010 9:42 am

Hey folks,

Has someone got the code to make the players speed start of slow and gradually get faster?
And also, a code to limit his speed to a certain level?

Thanks
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Acceleration code for Sonic

Postby TSO » Wed Oct 13, 2010 5:49 pm

I think more advanced ppl would do it on the fly.


Add event -> key down: right arrow -> script editor:
Code: Select all

//not sure how to declare variables but they might help in this bit of code...
//Also not sure if it redeclares them...
//Varibles can simply be replaced with set numbers.

int speed;
int topspeed=10;
int delay;

delay++;
if (delay=5)
{
  if (speed!=topspeed)
  {
  speed++;
  xvelocity+speed;
  }
  delay=0;
}


Something along those lines... would probably have to make a key up code to do the slow down with much less delay.
My syntax probably incorrect in a few places but the effect should achieve a 'sonic' style of speeding up I think and allow you to change speed limit...
just add some if statements to change to faster animations as speed increases...
probably make 'speed' a global variable for changing animations when changing direction and stuff in other key events.
TSO
 
Posts: 87
Joined: Thu Sep 02, 2010 5:53 pm
Score: 4 Give a positive score

Re: Acceleration code for Sonic

Postby lcl » Wed Oct 13, 2010 8:18 pm

TSO, that code won't work. :P
CrimsonTheDarkBat, here's code that works for moving on x axis. :D

Sonic - key down - key right - repeat: yes - script editor:
Code: Select all
xvelocity ++;  //increase xvelocity


Sonic - key down - key left - repeat: yes - script editor:
Code: Select all
xvelocity --;  //decrease xvelocity


Sonic - draw actor - script editor:
Code: Select all
if (xvelocity > 10) //10 is the limit value, you can change it to what you want
{
    xvelocity = 10;
}
if (xvelocity < - 10) //- 10 is the limit value, you can change it to what you want
{
    xvelocity = - 10;
}

xvelocity *= .95; //make it slow down if not pressing any key


:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Acceleration code for Sonic

Postby TSO » Wed Oct 13, 2010 11:31 pm

Yea i did say my syntax was off =P

Nice simple code.
TSO
 
Posts: 87
Joined: Thu Sep 02, 2010 5:53 pm
Score: 4 Give a positive score

Re: Acceleration code for Sonic

Postby CrimsonTheDarkBat » Fri Oct 29, 2010 11:13 pm

Thanks for the help guys!

But still in a pickle :/ TSO's code works to a certain extent, but Sonic accelerates too fast and stops too suddenly.
I've tried modifying the code in the way you said, but then Sonics overall speed decreases as a result.

Is there any other code to make Sonic accelerate slowly untill he gradually reaches a set speed? And then when the player releases the key, for him to slow down gradually untill he reaches a halt?

Thanks anybody who can help!
Sonic Velocity Development Thread --> http://game-editor.com/forum/viewtopic.php?f=4&t=11461

Completed Games:
Sonic: War of the Emeralds
Sonic: Empire of Nightmares
Sonic.EXE - The Game
Alice: Crimson Omen
Epsilon 27
User avatar
CrimsonTheDarkBat
 
Posts: 223
Joined: Fri Mar 21, 2008 10:54 am
Score: 20 Give a positive score

Re: Acceleration code for Sonic

Postby zxcvbnm » Sat Oct 30, 2010 12:59 am

Ok go in the game demo section and download my canabalt game. It that suits your need , just ask me for any modification.
Check out Momo AlienStarcatcher , featured in apples new and noteworthy and has 5 star reviews!!!
http://itunes.apple.com/us/app/momo-ali ... 61779?mt=8
zxcvbnm
 
Posts: 248
Joined: Sun Aug 22, 2010 7:57 pm
Score: 10 Give a positive score

Re: Acceleration code for Sonic

Postby NERDnotGEEK » Sat Oct 30, 2010 2:35 am

lcl's code works fine for what you want.
heres how id write it to give you let you have a little more controll later

Sonic - key down - key right - repeat: yes - script editor:
Code: Select all
run = 1;


Sonic - key up- key right - script editor:
Code: Select all
run = 0;


Sonic - draw actor - script editor:
Code: Select all
float accel = 0.1; // change to set the acceleration
float decel = 0.2; // change to set the deceleration
int maxspeed = 20; // change to set the max
if (run == 1)
{
    if (xvelocity < maxspeed)
    {
        xvelocity = xvelocity + accel;
    }
}
if (run == 0)
{
    if (xvelocity > 0)
    {
        xvelocity = xvelocity - decel;
    }
}


i think :) still getting to grips with ge myself
NERDnotGEEK
 
Posts: 75
Joined: Sat Oct 30, 2010 1:48 am
Score: 12 Give a positive score

Re: Acceleration code for Sonic

Postby lcl » Mon Nov 01, 2010 1:06 pm

That's nice one. :D Though you still don't have code for moving left... :P
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Acceleration code for Sonic

Postby NERDnotGEEK » Mon Nov 01, 2010 5:06 pm

no one wants to be spoon fed, i just provided the general idea, obviously for a left, just add a run = 2, to keydown left, and run = 0 to keyup left, and then add this to the draw actor :)
Code: Select all
if (run == 2)
{
    if (xvelocity > -maxspeed)
    {
        xvelocity = xvelocity - accel;
    }
}
NERDnotGEEK
 
Posts: 75
Joined: Sat Oct 30, 2010 1:48 am
Score: 12 Give a positive score

Re: Acceleration code for Sonic

Postby lcl » Mon Nov 01, 2010 5:11 pm

Yeah, I knew how to do that but crimsonthedarkbat maybe didnt. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Acceleration code for Sonic

Postby lcl » Mon Nov 01, 2010 5:11 pm

EDIT: ehh... actually this is some weird double post... can't delete, so I decided to edit it... :P
Last edited by lcl on Mon Nov 01, 2010 7:02 pm, edited 1 time in total.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Acceleration code for Sonic

Postby NERDnotGEEK » Mon Nov 01, 2010 5:56 pm

ehh true :) but im sure he would have worked it out if he needed it :)
NERDnotGEEK
 
Posts: 75
Joined: Sat Oct 30, 2010 1:48 am
Score: 12 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest