Hunter

A dumb vertical driving "game" with no purpose. All graphics are drawn using rectangles.

The source is in JScript, so open the file through the File->Open menu item in the editor.

// By u9 nov 2007
// u9 AT kallnet D0T fo
 
Graphics.Initialize( 800, 600 );
Key.Initialize();
Timers.Initialize();
var t = Timers.Create();
Timers.Start( t );
 
var speed = 500; // Pixels per second
var acc = 500;
var pos = 0;
var xPos = 480;
 
var ristPos = 1000; // Start off-screen
var ristSide = ( Math.random() > 0.5 ); // Evaluates to true or false
var nextRist = Math.random() * 1000; // Number of pixels until next one arrives
 
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 ) );
 
    // Dashed lines in middle of road
    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 );
 
    // Outer lines framing road
    DrawLine( 250, 300, 600 );
    DrawLine( 550, 300, 600 );
 
    // Pot-hole-drain thingy on the side of the road
    DrawRist( ristPos - 100, ristSide );
 
    DrawCar( xPos, 450 );
 
    Graphics.Display();
    System.ProcessMessages();
}
 
Key.Terminate();
Graphics.Terminate();
 
// Functions
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 )
{
    // Bumpers
    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 ) );
 
    // Body
    Graphics.SetRect( x - 50, y - 75, 100, 150, argb( 255, 255, 0, 0 ) );
 
    // Windows
    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 ) );
 
    // tires
    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 ) );
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.