Graphics.Initialize( 800, 600 );
Key.Initialize();
Timers.Initialize();
var t = Timers.Create();
Timers.Start( t );
var speed = 500;
var acc = 500;
var pos = 0;
var xPos = 480;
var ristPos = 1000;
var ristSide = ( Math.random() > 0.5 );
var nextRist = Math.random() * 1000;
while ( !Key.Pressed( vk_escape() ) && !Key.Pressed( vk_windowx() ) )
{
var dt = Timers.SplitTime( t );
if ( Key.Pressed( vk_up() ) ) {
speed += acc * dt;
if ( speed > 1200 ) {
speed = 1200;
}
}
if ( Key.Pressed( vk_down() ) ) {
speed -= acc * dt;
if ( speed < 0 ) {
speed = 0;
}
}
if ( Key.Pressed( vk_left() ) && speed > 100 ) {
xPos -= 100 * dt;
if ( xPos < 300 ) {
xPos = 300;
}
}
if ( Key.Pressed( vk_right() ) && speed > 100 ) {
xPos += 100 * dt;
if ( xPos > 500 ) {
xPos = 500;
}
}
pos = ( pos + speed * dt ) % 750;
ristPos += speed * dt;
nextRist -= speed * dt;
if ( nextRist < 0 ) {
nextRist = Math.random() * 1000 + 1000;
ristPos = 0;
ristSide = ( Math.random() > 0.5 );
}
Graphics.Clear( argb( 255, 50, 105, 0 ) );
Graphics.SetRect( 250, 0, 300, 600, argb( 255, 100, 100, 100 ) );
DrawLine( 400, pos-100, 50 );
DrawLine( 400, (pos + 150) % 750 - 100, 50 );
DrawLine( 400, (pos + 300) % 750 - 100, 50 );
DrawLine( 400, (pos + 450) % 750 - 100, 50 );
DrawLine( 400, (pos + 600) % 750 - 100, 50 );
DrawLine( 250, 300, 600 );
DrawLine( 550, 300, 600 );
DrawRist( ristPos - 100, ristSide );
DrawCar( xPos, 450 );
Graphics.Display();
System.ProcessMessages();
}
Key.Terminate();
Graphics.Terminate();
function DrawLine( x, y, length )
{
Graphics.SetRect( x - 5, y - length / 2, 10, length, argb( 205, 255, 255, 255 ) );
}
function DrawRist( y, side )
{
var x = 275;
if ( side ) {
x = 525;
}
Graphics.SetRect( x-20, y-20, 40, 40, argb( 255, 155, 155, 155 ) );
for ( var i = 0; i < 5; i++ ) {
Graphics.SetRect( x-17 + i * 8, y-16, 2, 32, argb( 255, 0, 0, 0 ) );
}
}
function DrawCar( x, y )
{
Graphics.SetRect( x - 54, y - 82, 108, 25, argb( 255, 155, 155, 155 ) );
Graphics.SetRect( x - 54, y + 66, 108, 15, argb( 255, 155, 155, 155 ) );
Graphics.SetRect( x - 50, y - 75, 100, 150, argb( 255, 255, 0, 0 ) );
Graphics.SetRect( x - 40, y - 35, 80, 20, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x - 46, y - 25, 2, 30, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x + 44, y - 25, 2, 30, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x - 46, y + 15, 2, 30, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x + 44, y + 15, 2, 30, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x - 40, y + 35, 80, 16, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x - 54, y - 54, 4, 32, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x + 50, y - 54, 4, 32, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x - 54, y + 32, 4, 32, argb( 255, 0, 0, 0 ) );
Graphics.SetRect( x + 50, y + 32, 4, 32, argb( 255, 0, 0, 0 ) );
}