advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement


NightDriver


Java Source:


import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Event;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.MediaTracker;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;

public final class NightDriver extends Applet implements Runnable, ActionListener {

    private Graphics m_Graphics;
    private Image offscreenImage;
    private AudioClip sound;
    private AudioClip sound2;
    private Image cracked;
    private Image backdrop;
    private Image post;
    private Image tree;
    private Image bush;
    private Image bush2;
    private Graphics finishedGraphics;
    private Graphics offscreenGraphics;
    private Font updateFont;
    private Font startMouse;
    private Font tooSlow;
    private int[] val2;
    private int[] track;
    private int[] trackZ;
    private int time;
    private int carPosition;
    private int facing;
    private int roadFacing;
    private int trackLoc;
    private double[] zoom;
    private int driverCount;
    private int[][] roadSigns;
    private int[] roadType;
    private int[] trees;
    private int[] bushes;
    private int[] bushestwo;
    private int facingZ;
    private long sleeper;
    public int dimmer;
    private long startTime;
    private int levtime;
    private int cpoint;
    private boolean gas;
    private boolean brake;
    private boolean left;
    private boolean right;
    private Font title;
    URL url1;
    String str = "http://www.4webgames.com";
    Button b1 = new Button( "check my homepage and search for more games" );
    private Thread m_DUI = null;
    private int level = 1;
    private int lives = 3;
    private int speed = 180;
    private int soundvar = 0;
    private boolean wrecked = false;
    private boolean m_fAllLoaded = false;
    private int dn = 2;
    public boolean autopilot = true;
    private Image[][] cars = new Image[3][2];
    private int[] driverY = new int[50];
    private Image[] signs = new Image[3];
    private int[] driverCar = new int[50];
    private int[] driverDir = new int[50];
    private int[][] upcomingCars = new int[21][2];
    public boolean running = false;
    private Color[] road = new Color[21];
    private Color[] darkRoad = new Color[21];
    private Color[] darkLines = new Color[21];
    private Color[] hill = new Color[21];
    private Color[] barricade = new Color[21];
    private Color[] tunnel = new Color[21];
    private Color[] wood = new Color[21];
    private int[] xvals = new int[4];
    private int[] yvals = new int[4];
    private int[] xm = new int[6];
    private int[] ym = new int[6];

    public void actionPerformed(ActionEvent ActionEvent1)
    {
        try
        {
            url1 = new URL( str );
            getAppletContext().showDocument( url1, "_blank" );
        }
        catch( MalformedURLException MalformedURLException2 )
        {
            System.out.println( "Error " + MalformedURLException2 );
        }
    }

    private void copyRight()
    {
        Font Font1 = new Font( "TimesNewRoman", 1, 14 );

        offscreenGraphics.setFont( Font1 );
        offscreenGraphics.setColor( Color.white );
        offscreenGraphics.drawString( "Original '3d Driver' by Derek Ramey", 85, 250 );
        offscreenGraphics.drawString( "Visit: http://www.4webgames.com", 90, 270 );
        
    }

    public void destroy()
    {
    }

    private void dimImage()
    {
        int int1;

        offscreenGraphics.setColor( Color.black );
        for( int1 = 0; int1 < 1000; ++int1 )
        {
            int int2 = (int) (Math.random() * 400.0);
            int int3 = (int) (Math.random() * 300.0);

            offscreenGraphics.fillRect( int2, int3, 4, 4 );
        }
    }

    public void drawBG(Graphics Graphics1)
    {
        int int2;
        int int3;
        int int4;

        if( dn == 2 )
            Graphics1.setColor( new Color( 0, 14, 108 ) );
        else
            Graphics1.setColor( new Color( 43, 69, 255 ) );
        Graphics1.fillRect( 0, 0, 800, 600 );
        if( dn == 2 )
        {
            Graphics1.setColor( Color.white );
            for( int2 = 0; int2 < 250; ++int2 )
            {
                int3 = (int) Math.round( Math.random() * 800.0 );
                int4 = (int) Math.round( Math.random() * 600.0 );
                Graphics1.drawLine( int3, int4, int3, int4 );
            }
        }
        Graphics1.setColor( Color.gray );
        for( int2 = 0; int2 < 750; ++int2 )
        {
            int3 = (int) Math.round( Math.random() * 800.0 );
            int4 = (int) Math.round( Math.random() * 600.0 );
            Graphics1.drawLine( int3, int4, int3, int4 );
        }
    }

    private void ending()
    {
        Font Font1 = new Font( "TimesNewRoman", 1, 18 );

        offscreenGraphics.setFont( Font1 );
        offscreenGraphics.setColor( Color.white );
        offscreenGraphics.drawString( "Congratulations!!! ", 145, 172 );
        offscreenGraphics.drawString( "You have won at Level " + level, 125, 200 );
        offscreenGraphics.drawString( "Click for next Level ", 145, 222 );
        ++level;
        levtime = level * 10 + 40;
        cpoint = 100 + level * 50;
        running = false;
        if( level == 4 )
        {
            Font Font2;

            dn = 1;
            init();
            Font2 = new Font( "SansSerif", 1, 18 );
            offscreenGraphics.setFont( Font2 );
            offscreenGraphics.setColor( Color.blue );
            offscreenGraphics.drawString( "Soon NightDriver wont be Nightdriver", 15, 182 );
            offscreenGraphics.drawString( "anymore, because it is already morning", 15, 202 );
            offscreenGraphics.drawString( "click to go on", 55, 222 );
        }
    }

    public String getAppletInfo()
    {
        return "Name: DUI\r\nAuthor: Derek Ramey\r\n";
    }

    public void init()
    {
        Panel Panel1 = new Panel();
        int int2;
        int int3;

        add( Panel1 );
        setLayout( new BorderLayout() );
        add( b1, "South" );
        b1.addActionListener( this );
        resize( 400, 300 );
        zoom = new double[26];
        for( int2 = 0; int2 < 25; ++int2 )
            zoom[int2] = 200.0 / (double) (int2 + 1) - 8.0;
        offscreenImage = createImage( 400, 300 );
        offscreenGraphics = offscreenImage.getGraphics();
        sound = getAudioClip( getCodeBase(), "music.au" );
        sound2 = getAudioClip( getCodeBase(), "shortwah.au" );
        cracked = getImage( getCodeBase(), "cracked.gif" );
        cars[0][0] = getImage( getCodeBase(), "car1f.gif" );
        cars[0][1] = getImage( getCodeBase(), "car1b.gif" );
        cars[1][0] = getImage( getCodeBase(), "car2f.gif" );
        cars[1][1] = getImage( getCodeBase(), "car2b.gif" );
        cars[2][0] = getImage( getCodeBase(), "car3f.gif" );
        cars[2][1] = getImage( getCodeBase(), "car3b.gif" );
        signs[0] = getImage( getCodeBase(), "banner1.gif" );
        signs[1] = getImage( getCodeBase(), "banner2.gif" );
        signs[2] = getImage( getCodeBase(), "banner3.gif" );
        tree = getImage( getCodeBase(), "tree1" + dn + ".gif" );
        bush = getImage( getCodeBase(), "tree2" + dn + ".gif" );
        bush2 = getImage( getCodeBase(), "tree3" + dn + ".gif" );
        post = getImage( getCodeBase(), "post.gif" );
        backdrop = createImage( 800, 600 );
        drawBG( backdrop.getGraphics() );
        updateFont = new Font( "TimesNewRoman", 1, 12 );
        startMouse = new Font( "TimesNewRoman", 1, 18 );
        tooSlow = new Font( "TimesNewRoman", 1, 32 );
        title = new Font( "Serif", 3, 42 );
        for( int3 = 0; int3 < 21; ++int3 )
        {
            if( dn == 2 )
            {
                hill[int3] = new Color( 70, 126 - int3 * 5, 30 );
                road[int3] = new Color( 150 - int3 * 4, 150 - int3 * 4, 150 - int3 * 4 );
                barricade[int3] = new Color( 255 - int3 * 6, 255 - int3 * 6, 255 - int3 * 6 );
                wood[int3] = new Color( 150 - int3 * 4, 100 - int3 * 3, 50 - int3 * 2 );
                tunnel[int3] = new Color( 75 - int3 * 3, 50 - int3 * 2, 50 - int3 * 2 );
                darkRoad[int3] = new Color( 75 - int3 * 3, 75 - int3 * 3, 75 - int3 * 3 );
                darkLines[int3] = new Color( 150 - int3 * 4, 150 - int3 * 4, 0 );
            }
            else
            {
                hill[int3] = new Color( 99, 183 - int3 * 5, 43 );
                road[int3] = new Color( 150 - int3 * 4, 150 - int3 * 4, 150 - int3 * 4 );
                barricade[int3] = new Color( 255 - int3 * 6, 255 - int3 * 6, 255 - int3 * 6 );
                wood[int3] = new Color( 150 - int3 * 4, 100 - int3 * 3, 50 - int3 * 2 );
                tunnel[int3] = new Color( 75 - int3 * 3, 50 - int3 * 2, 50 - int3 * 2 );
                darkRoad[int3] = new Color( 75 - int3 * 3, 75 - int3 * 3, 75 - int3 * 3 );
                darkLines[int3] = new Color( 150 - int3 * 4, 150 - int3 * 4, 0 );
            }
        }
    }

    public boolean keyDown(Event Event1, int int2)
    {
        if( int2 == 1006 )
        {
            left = true;
            return true;
        }
        else if( int2 == 1007 )
        {
            right = true;
            return true;
        }
        else if( int2 == 97 || int2 == 65 )
        {
            gas = true;
            return true;
        }
        else if( int2 == 100 || int2 == 68 )
        {
            dn = 1;
            return true;
        }
        else if( int2 == 122 || int2 == 90 )
        {
            brake = true;
            return true;
        }
        else
        {
            if( int2 == 115 || int2 == 83 )
            {
                if( soundvar == 0 )
                {
                    sound.loop();
                    soundvar = 1;
                }
                else
                {
                    sound.stop();
                    soundvar = 0;
                }
            }
            return false;
        }
    }

    public boolean keyUp(Event Event1, int int2)
    {
        if( int2 == 1006 )
            left = false;
        else if( int2 == 1007 )
            right = false;
        else if( int2 == 97 || int2 == 65 )
            gas = false;
        else
        {
            if( int2 != 122 && int2 != 90 )
                return false;
            brake = false;
        }
        return true;
    }

    private void lose()
    {
        Font Font1;

        if( dn == 1 )
        {
            dn = 2;
            init();
            offscreenGraphics.drawString( "Game Over", 145, 222 );
            offscreenGraphics.drawString( "Click to start", 145, 222 );
        }
        Font1 = new Font( "TimesNewRoman", 1, 18 );
        offscreenGraphics.setFont( Font1 );
        offscreenGraphics.setColor( Color.white );
        offscreenGraphics.drawString( "you have lost the game", 125, 160 );
        offscreenGraphics.drawString( "Click to restart", 145, 176 );
        level = 1;
        levtime = level * 10 + 40;
        cpoint = 100 + level * 50;
        running = false;
        lives = 3;
    }

    public boolean mouseDown(Event Event1, int int2, int int3)
    {
        if( !running )
        {
            newGame();
            running = true;
        }
        return true;
    }

    public void newGame()
    {
        carPosition = 100;
        facing = 0;
        roadFacing = 0;
        trackLoc = 0;
        speed = 100;
        wrecked = false;
        autopilot = false;
        randomizeDrivers();
        randomizeTrack();
        startTime = System.currentTimeMillis();
        dimmer = 0;
    }

    private final void nextFrame(int int1)
    {
        int int2 = int1;
        int int3 = 0;
        int[] int_1darray4 = new int[26];
        int[] int_1darray5 = new int[26];
        int int6;
        int int7;
        int int8;
        int int9;
        int int10;
        int int11;
        int int12;
        int int13;

        int_1darray4[0] = track[trackLoc];
        int6 = 0;
        int7 = 0;
        int8 = facing * 10;
        int9 = facingZ * 10;
        while( int8 < 0 )
            int8 += 800;
        while( int8 > 800 )
            int8 -= 800;
        while( int9 < 0 )
            int9 += 600;
        while( int9 > 600 )
            int9 -= 600;
        offscreenGraphics.clipRect( 0, 0, 400, 300 );
        offscreenGraphics.drawImage( backdrop, -int8, -int9, (ImageObserver) this );
        offscreenGraphics.drawImage( backdrop, -int8 + 800, -int9, (ImageObserver) this );
        offscreenGraphics.drawImage( backdrop, -int8 + 800, -int9 + 600, (ImageObserver) this );
        offscreenGraphics.drawImage( backdrop, -int8, -int9 + 600, (ImageObserver) this );
        for( int10 = 1; int10 < 21; ++int10 )
        {
            int6 += track[int10 + trackLoc];
            int7 += trackZ[int10 + trackLoc];
            for( int11 = int10; int11 < 25; ++int11 )
            {
                int_1darray4[int11] += int6;
                int_1darray5[int11] += int7;
            }
        }
        for( int11 = 0; int11 < 21; ++int11 )
        {
            upcomingCars[int11][0] = 999;
            upcomingCars[int11][1] = 999;
        }
        for( int12 = 0; int12 < 50; ++int12 )
        {
            if( driverY[int12] >= trackLoc && driverY[int12] <= trackLoc + 20 )
            {
                if( upcomingCars[driverY[int12] - trackLoc][0] == 999 )
                    upcomingCars[driverY[int12] - trackLoc][0] = int12;
                else
                    upcomingCars[driverY[int12] - trackLoc][1] = int12;
            }
        }
        for( int13 = 20; int13 > 0; --int13 )
        {
            int int14 = int_1darray4[int13] - carPosition / (int13 + 1) + 200 - int2 * int13;
            int int15 = int_1darray4[int13 - 1] - carPosition / int13 + 200 - int2 * int13 + int2;
            int int16;
            int int17;
            int int19;
            int int20;

            xvals[0] = int14 - (int) (zoom[int13] * 4.0);
            xvals[1] = int14 + (int) (zoom[int13] * 4.0);
            xvals[3] = int15 - (int) (zoom[int13 - 1] * 4.0);
            xvals[2] = int15 + (int) (zoom[int13 - 1] * 4.0);
            yvals[0] = 200 + (int) (zoom[int13] + (double) int_1darray5[int13]);
            yvals[1] = yvals[0];
            yvals[2] = 200 + (int) (zoom[int13 - 1] + (double) int_1darray5[int13 - 1]);
            yvals[3] = yvals[2];
            int16 = (int) (zoom[int13] * 4.0);
            int17 = (int) (zoom[int13 - 1] * 4.0);
            if( roadType[trackLoc + int13] == 0 )
            {
                xm[0] = xvals[0];
                ym[0] = yvals[0];
                xm[1] = xvals[3];
                ym[1] = yvals[3];
                xm[2] = xm[1];
                ym[2] = 300;
                xm[3] = xm[0] - (300 - yvals[0]);
                ym[3] = 300;
                offscreenGraphics.setColor( hill[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 4 );
            }
            if( roadType[trackLoc + int13] == 1 )
            {
                xm[0] = xvals[3];
                ym[0] = yvals[3];
                xm[1] = xvals[3];
                ym[1] = yvals[3] - (int) zoom[int13 - 1];
                xm[2] = xvals[0];
                ym[2] = yvals[0] - (int) zoom[int13];
                xm[3] = xvals[0];
                ym[3] = yvals[0];
                offscreenGraphics.setColor( barricade[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 4 );
            }
            if( roadType[trackLoc + int13] == 2 )
            {
                xm[0] = xvals[3];
                ym[0] = yvals[3];
                xm[1] = xvals[3];
                ym[1] = yvals[3] - (int) (zoom[int13 - 1] * 5.0);
                xm[2] = xvals[0];
                ym[2] = yvals[0] - (int) (zoom[int13] * 5.0);
                xm[3] = xvals[0];
                ym[3] = yvals[0];
                offscreenGraphics.setColor( tunnel[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 4 );
            }
            if( yvals[2] > yvals[0] )
            {
                float float18;

                xm[0] = int14 - int16;
                xm[1] = int14 + int16;
                xm[2] = int15 + int17;
                xm[3] = int15 - int17;
                float18 = (float) (trackLoc + int13) / 100.0F;
                if( float18 == (float) Math.round( float18 ) )
                    offscreenGraphics.setColor( new Color( 255 - int13 * 2, 0, 0 ) );
                else if( trackLoc + int13 > 5000 )
                    offscreenGraphics.setColor( new Color( 0, 255 - int13 * 4, 0 ) );
                else
                {
                    if( roadType[trackLoc + int13] == 1 )
                        offscreenGraphics.setColor( wood[int13] );
                    if( roadType[trackLoc + int13] == 2 )
                        offscreenGraphics.setColor( darkRoad[int13] );
                    if( roadType[trackLoc + int13] == 0 )
                        offscreenGraphics.setColor( road[int13] );
                }
                offscreenGraphics.fillPolygon( xm, yvals, 4 );
                int19 = trackLoc + int13;
                if( (float) int19 / 2.0F == (float) (int19 / 2) )
                {
                    xm[0] = int14 - (int) (zoom[int13] / 8.0) - 1;
                    xm[1] = int14 + (int) (zoom[int13] / 8.0) + 1;
                    xm[3] = int15 - (int) (zoom[int13 - 1] / 8.0) - 1;
                    xm[2] = int15 + (int) (zoom[int13 - 1] / 8.0) + 1;
                    ym[0] = yvals[0];
                    ym[1] = yvals[0];
                    ym[2] = yvals[2];
                    ym[3] = yvals[2];
                    if( roadType[trackLoc + int13] == 2 )
                        offscreenGraphics.setColor( darkLines[int13] );
                    else
                        offscreenGraphics.setColor( Color.yellow );
                    offscreenGraphics.fillPolygon( xm, ym, 4 );
                }
            }
            if( roadType[trackLoc + int13] == 0 )
            {
                xm[0] = xvals[1];
                ym[0] = yvals[1];
                xm[1] = xm[0] + yvals[1];
                ym[1] = 0;
                xm[2] = 400;
                ym[2] = 0;
                xm[3] = 400;
                ym[3] = 300;
                xm[4] = xvals[2];
                ym[4] = 300;
                xm[5] = xvals[2];
                ym[5] = yvals[2];
                offscreenGraphics.setColor( hill[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 6 );
            }
            if( roadType[trackLoc + int13] == 1 )
            {
                xm[0] = xvals[2];
                ym[0] = yvals[2];
                xm[1] = xvals[2];
                ym[1] = yvals[2] - (int) zoom[int13 - 1];
                xm[2] = xvals[1];
                ym[2] = yvals[1] - (int) zoom[int13];
                xm[3] = xvals[1];
                ym[3] = yvals[1];
                offscreenGraphics.setColor( barricade[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 4 );
            }
            if( roadType[trackLoc + int13] == 2 )
            {
                xm[0] = xvals[2];
                ym[0] = yvals[2];
                xm[1] = xvals[2];
                ym[1] = yvals[2] - (int) (zoom[int13 - 1] * 5.0);
                xm[2] = xvals[1];
                ym[2] = yvals[1] - (int) (zoom[int13] * 5.0);
                xm[3] = xvals[1];
                ym[3] = yvals[1];
                offscreenGraphics.setColor( tunnel[int13] );
                offscreenGraphics.fillPolygon( xm, ym, 4 );
                xm[0] = xvals[0];
                xm[1] = xvals[1];
                xm[2] = xvals[2];
                xm[3] = xvals[3];
                ym[0] = yvals[0] - (int) (zoom[int13] * 5.0);
                ym[1] = ym[0];
                ym[2] = yvals[2] - (int) (zoom[int13 - 1] * 5.0);
                ym[3] = ym[2];
                offscreenGraphics.fillPolygon( xm, ym, 4 );
                if( xvals[0] > 0 )
                {
                    xm[0] = xvals[3];
                    ym[0] = yvals[3] - (int) (zoom[int13 - 1] * 10.0);
                    xm[1] = xm[0];
                    ym[1] = 300;
                    xm[2] = xm[0] - (300 - ym[0]);
                    ym[2] = 300;
                    offscreenGraphics.setColor( hill[int13] );
                    offscreenGraphics.fillPolygon( xm, ym, 3 );
                    ym[1] = yvals[3] - (int) (zoom[int13 - 1] * 5.0);
                    ym[2] = ym[1];
                    xm[2] = 400;
                    xm[3] = 400;
                    ym[3] = ym[0] - (400 - xm[0]);
                    offscreenGraphics.fillPolygon( xm, ym, 4 );
                    xm[0] = xvals[2];
                    xm[1] = xvals[2];
                    xm[2] = 400;
                    xm[3] = 400;
                    ym[0] = ym[1];
                    ym[1] = 300;
                    ym[2] = 300;
                    ym[3] = ym[0];
                    offscreenGraphics.fillPolygon( xm, ym, 4 );
                }
            }
            if( upcomingCars[int13][0] != 999 )
            {
                int20 = upcomingCars[int13][0];
                int19 = int15 + int17 * (driverDir[int20] - 1) + int17 / 8;
                offscreenGraphics.drawImage( cars[driverCar[int20]][driverDir[int20]], int19, yvals[2] - int17 * 3 / 4, int17 * 3 / 4, int17 * 3 / 4, (ImageObserver) this );
            }
            if( upcomingCars[int13][1] != 999 )
            {
                int20 = upcomingCars[int13][1];
                int19 = int15 + int17 * (driverDir[int20] - 1) + int17 / 8;
                offscreenGraphics.drawImage( cars[driverCar[int20]][driverDir[int20]], int19, yvals[2] - int17 * 3 / 4, int17 * 3 / 4, int17 * 3 / 4, (ImageObserver) this );
            }
            if( roadType[trackLoc + int13] == 0 )
            {
                if( roadSigns[trackLoc + int13][0] > 0 )
                {
                    int20 = int15 - int17 * 2;
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * 3.0);
                    offscreenGraphics.drawImage( signs[roadSigns[trackLoc + int13][0] - 1], int20, int19, int17, int17 / 3, (ImageObserver) this );
                    offscreenGraphics.drawImage( post, int20 + int17 * 19 / 40, int19 + int17 / 3, int17 / 20, int17, (ImageObserver) this );
                }
                if( roadSigns[trackLoc + int13][1] > 0 )
                {
                    int20 = xvals[2];
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * 6.0);
                    offscreenGraphics.drawImage( signs[roadSigns[trackLoc + int13][1] - 1], int20, int19, int17, int17 / 3, (ImageObserver) this );
                    offscreenGraphics.drawImage( post, int20 + int17 * 19 / 40, int19 + int17 / 3, int17 / 20, int17, (ImageObserver) this );
                }
                if( trees[trackLoc + int13] > 0 )
                {
                    int20 = int15 + (int) (zoom[int13 - 1] * (double) (trees[trackLoc + int13] + 1));
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * (double) (trees[trackLoc + int13] + 6));
                    if( int20 < 400 )
                        offscreenGraphics.drawImage( tree, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
                if( bushes[trackLoc + int13] > 0 )
                {
                    int20 = int15 + (int) (zoom[int13 - 1] * (double) (bushes[trackLoc + int13] + 1));
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * (double) (bushes[trackLoc + int13] + 6));
                    if( int20 < 400 )
                        offscreenGraphics.drawImage( bush, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
                if( bushestwo[trackLoc + int13] > 0 )
                {
                    int20 = int15 + (int) (zoom[int13 - 1] * (double) (bushestwo[trackLoc + int13] + 1));
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * (double) (bushestwo[trackLoc + int13] + 6));
                    if( int20 < 400 )
                        offscreenGraphics.drawImage( bush2, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
                if( trees[trackLoc + int13] == -1 )
                {
                    int20 = int15 - (int) (zoom[int13 - 1] * 9.0);
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * 4.0);
                    if( int20 > -((int) (zoom[int13 - 1] * 4.0)) )
                        offscreenGraphics.drawImage( tree, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
                if( bushes[trackLoc + int13] == -1 )
                {
                    int20 = int15 - (int) (zoom[int13 - 1] * 9.0);
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * 4.0);
                    if( int20 > -((int) (zoom[int13 - 1] * 4.0)) )
                        offscreenGraphics.drawImage( bush, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
                if( bushestwo[trackLoc + int13] == -1 )
                {
                    int20 = int15 - (int) (zoom[int13 - 1] * 9.0);
                    int19 = yvals[2] - (int) (zoom[int13 - 1] * 4.0);
                    if( int20 > -((int) (zoom[int13 - 1] * 4.0)) )
                        offscreenGraphics.drawImage( bush2, int20, int19, (int) (zoom[int13 - 1] * 4.0), (int) (zoom[int13 - 1] * 7.0), (ImageObserver) this );
                }
            }
        }
        offscreenGraphics.setColor( Color.white );
        offscreenGraphics.setFont( updateFont );
        time = (int) ((System.currentTimeMillis() - startTime) / 1000L);
        offscreenGraphics.drawString( "Checkpoints: " + (trackLoc / 100) + " (" + (cpoint / 100) + ") Speed: " + (speed / 2) + " Driving Time: " + time + " (" + levtime + ") Level: " + level + " Lives: " + lives, 5, 15 );
    }

    public void paint(Graphics Graphics1)
    {
        Graphics1.drawImage( offscreenImage, 0, 0, (ImageObserver) this );
    }

    private void randomizeDrivers()
    {
        int int1;

        for( int1 = 0; int1 < 50; ++int1 )
        {
            driverDir[int1] = (int) (Math.random() * 2.0);
            driverY[int1] = (int) (Math.random() * 4990.0) + 10;
            driverCar[int1] = (int) (Math.random() * 3.0);
        }
    }

    public void randomizeTrack()
    {
        int int1;
        int int2;
        int int3;
        int int4;
        int int5;
        int int6;
        int int7;

        track = new int[5100];
        trackZ = new int[5100];
        roadType = new int[5100];
        roadSigns = new int[5100][2];
        trees = new int[5100];
        bushes = new int[5100];
        bushestwo = new int[5100];
        for( int1 = 0; int1 < 25; ++int1 )
            roadSigns[int1 * 200 + (int) (Math.random() * 200.0)][(int) (Math.random() * 2.0)] = (int) (Math.random() * 3.0) + 1;
        for( int2 = 0; int2 < 100; ++int2 )
        {
            int3 = int2 * 50 + (int) (Math.random() * 50.0);
            int4 = 0;
            int5 = 0;
            switch( (int) (Math.random() * 3.0) )
            {
                case 0:
                    int4 = (int) (Math.random() * 5.0) + 1;
                    break;
                case 1:
                    int4 = 1;
                    break;
                case 2:
                    int4 = -1;
                    break;
                default:
                    break;
            }
            trees[int3] = int4;
        }
        for( int3 = 0; int3 < 50; ++int3 )
        {
            int4 = (int) (Math.random() * 5000.0);
            int5 = (int) (Math.random() * 2.0) + 1;
            int6 = 1;
            if( int5 == 1 )
                int6 = (int) (Math.random() * 10.0) + 5;
            if( int5 == 2 )
                int6 = (int) (Math.random() * 25.0) + 10;
            for( int7 = 0; int7 < int6; ++int7 )
                roadType[int4 + int7] = int5;
        }
        for( int4 = 0; int4 < 100; ++int4 )
        {
            int5 = int4 * 50 + (int) (Math.random() * 50.0);
            int6 = 0;
            int7 = 0;
            switch( (int) (Math.random() * 3.0) )
            {
                case 0:
                    int6 = (int) (Math.random() * 5.0) + 1;
                    int7 = (int) (Math.random() * 5.0) + 1;
                    break;
                case 1:
                    int6 = 1;
                    int7 = -1;
                    break;
                case 2:
                    int6 = -1;
                    int7 = 1;
                    break;
                default:
                    break;
            }
            bushes[int5] = int6;
            bushestwo[int5] = int7;
        }
        for( int5 = 1; int5 < 6; ++int5 )
        {
            int int8;
            int int9;
            int int10;

            switch( int5 )
            {
                case 1:
                    int6 = 0;
                    int7 = 500;
                    int8 = 1;
                    int9 = 1;
                    break;
                case 2:
                    int6 = 500;
                    int7 = 1500;
                    int8 = 2;
                    int9 = 1;
                    break;
                case 3:
                    int6 = 1500;
                    int7 = 2500;
                    int8 = 3;
                    int9 = 2;
                    break;
                case 4:
                    int6 = 2500;
                    int7 = 3500;
                    int8 = 4;
                    int9 = 2;
                    break;
                default:
                    int6 = 3500;
                    int7 = 5000;
                    int8 = 5;
                    int9 = 3;
                    break;
            }
            for( int10 = 0; int10 < int5 * 30; ++int10 )
            {
                int int11 = (int) (Math.random() * (double) (int7 - int6) + (double) int6);

                switch( (int) (Math.random() * 10.0) )
                {
                    case 0:
                    case 6:
                    case 7:
                        track[int11] = (int) (Math.random() * (double) (int8 * 2 + 1)) - int8;
                        break;
                    case 1:
                        track[int11] = -int8;
                        track[int11 + 1] = -(int8 * 2);
                        track[int11 + 2] = -(int8 * 3);
                        track[int11 + 3] = -(int8 * 2);
                        track[int11 + 4] = -int8;
                        break;
                    case 2:
                        track[int11] = int8;
                        track[int11 + 1] = int8 * 2;
                        track[int11 + 2] = int8 * 3;
                        track[int11 + 3] = int8 * 2;
                        track[int11 + 4] = int8;
                        break;
                    case 3:
                    case 8:
                    case 9:
                        trackZ[int11] = (int) (Math.random() * (double) (int9 * 2 + 1) - (double) int9) / 2;
                        break;
                    case 4:
                        trackZ[int11] = -int9;
                        trackZ[int11 + 1] = -(int9 * 2);
                        trackZ[int11 + 2] = -int9;
                        break;
                    case 5:
                        trackZ[int11] = int9;
                        trackZ[int11 + 1] = int9 * 2;
                        trackZ[int11 + 2] = int9;
                        break;
                    default:
                        break;
                }
            }
        }
    }

    public final void run()
    {
        int int3;
        int int4;
        double double8;

        if( !m_fAllLoaded )
        {
            MediaTracker MediaTracker1 = new MediaTracker( this );
            int int2;

            MediaTracker1.addImage( cracked, 0 );
            MediaTracker1.addImage( post, 0 );
            MediaTracker1.addImage( tree, 0 );
            MediaTracker1.addImage( bush, 0 );
            MediaTracker1.addImage( bush2, 0 );
            for( int2 = 0; int2 < 3; ++int2 )
                MediaTracker1.addImage( signs[int2], 0 );
            for( int3 = 0; int3 < 3; ++int3 )
            {
                for( int4 = 0; int4 < 2; ++int4 )
                    MediaTracker1.addImage( cars[int3][int4], 0 );
            }
            try
            {
                MediaTracker1.waitForAll();
                m_fAllLoaded = !MediaTracker1.isErrorAny();
            }
            catch( InterruptedException unused10 )
            {
            }
            if( !m_fAllLoaded )
            {
                stop();
                m_Graphics.drawString( "Error loading images!", 10, 40 );
                return;
            }
        }
        randomizeTrack();
        randomizeDrivers();
        startTime = System.currentTimeMillis();
        levtime = level * 14 + 40;
        time = (int) ((System.currentTimeMillis() - startTime) / 1000L);
        cpoint = 2 * (level * 70);
        double8 = 0.0;
        int3 = 0;
        for( ;; )
        {
            try
            {
                long long9;

                sleeper = System.currentTimeMillis();
                int4 = facing;
                if( running || autopilot )
                {
                    nextFrame( int4 + roadFacing );
                    ++double8;
                    if( !autopilot )
                    {
                        int int5;
                        int int6;
                        int int7;

                        if( lives < 1 )
                            lose();
                        if( carPosition < -500 || carPosition > 500 )
                        {
                            --lives;
                            wrecked = true;
                        }
                        if( levtime > 0 && trackLoc > cpoint )
                            ending();
                        if( upcomingCars[1][0] != 999 )
                        {
                            int5 = driverDir[upcomingCars[1][0]];
                            int6 = -200 + int5 * 400;
                            int7 = 300;
                            if( driverCar[upcomingCars[1][0]] == 2 )
                                int7 = 150;
                            if( carPosition < int6 + int7 && int5 == 0 )
                            {
                                --lives;
                                wrecked = true;
                            }
                            if( carPosition > int6 - int7 && int5 == 1 )
                            {
                                --lives;
                                wrecked = true;
                            }
                        }
                        if( upcomingCars[1][1] != 999 )
                        {
                            int5 = driverDir[upcomingCars[1][1]];
                            int6 = -200 + int5 * 400;
                            int7 = 300;
                            if( driverCar[upcomingCars[1][1]] == 2 )
                                int7 = 150;
                            if( carPosition < int6 + int7 && int5 == 0 )
                                wrecked = true;
                            if( carPosition > int6 - int7 && int5 == 1 )
                            {
                                wrecked = true;
                                --lives;
                            }
                        }
                        if( upcomingCars[0][0] != 999 )
                        {
                            int5 = driverDir[upcomingCars[0][0]];
                            int6 = -200 + int5 * 400;
                            int7 = 300;
                            if( driverCar[upcomingCars[0][0]] == 2 )
                                int7 = 150;
                            if( carPosition < int6 + int7 && int5 == 0 )
                                wrecked = true;
                            if( carPosition > int6 - int7 && int5 == 1 )
                            {
                                --lives;
                                wrecked = true;
                            }
                        }
                        if( upcomingCars[0][1] != 999 )
                        {
                            int5 = driverDir[upcomingCars[0][1]];
                            int6 = -200 + int5 * 400;
                            int7 = 300;
                            if( driverCar[upcomingCars[0][1]] == 2 )
                                int7 = 150;
                            if( carPosition < int6 + int7 && int5 == 0 )
                            {
                                --lives;
                                wrecked = true;
                            }
                            if( carPosition > int6 - int7 && int5 == 1 )
                            {
                                --lives;
                                wrecked = true;
                            }
                        }
                    }
                    if( wrecked == true )
                    {
                        speed = 0;
                        running = false;
                    }
                    if( 200.0 / (double) (speed + 1) < double8 && speed > 0 )
                    {
                        double8 -= 200.0 / (double) (speed + 1);
                        ++trackLoc;
                        roadFacing -= track[trackLoc];
                        if( autopilot == true )
                            facing += track[trackLoc];
                        facingZ += trackZ[trackLoc];
                        if( trackLoc > 5000 )
                        {
                            running = false;
                            speed = 0;
                        }
                        carPosition += (facing + roadFacing) * speed / 20;
                    }
                    if( !wrecked )
                        updateDrivers();
                    else
                    {
                        offscreenGraphics.drawImage( cracked, 0, 0, 400, 300, (ImageObserver) this );
                        if( soundvar == 1 )
                            sound2.play();
                    }
                }
                if( wrecked == true )
                {
                    dimImage();
                    ++dimmer;
                    if( dimmer > 50 )
                    {
                        offscreenGraphics.setFont( startMouse );
                        offscreenGraphics.setColor( Color.cyan );
                        offscreenGraphics.drawString( "Click mouse to restart", 115, 150 );
                        copyRight();
                    }
                }
                if( autopilot )
                {
                    offscreenGraphics.setColor( Color.yellow );
                    offscreenGraphics.setFont( title );
                    offscreenGraphics.drawString( "Night Driver", 120, 60 );
                    offscreenGraphics.setFont( updateFont );
                    offscreenGraphics.drawString( "Version 3.0", 175, 75 );
                    offscreenGraphics.setColor( Color.white );
                    offscreenGraphics.setFont( startMouse );
                    offscreenGraphics.drawString( "Click with the mouse to start", 80, 100 );
                    offscreenGraphics.setFont( updateFont );
                    offscreenGraphics.drawString( "A - Gas", 180, 130 );
                    offscreenGraphics.drawString( "Z - Brake", 175, 150 );
                    offscreenGraphics.drawString( "LEFT/RIGHT ARROWS - Turn", 120, 170 );
                    offscreenGraphics.drawString( "S - Sound on/off", 175, 190 );
                    copyRight();
                }
                long9 = 80L - (System.currentTimeMillis() - sleeper);
                repaint();
                if( long9 < 10L )
                    long9 = 10L;
                Thread.sleep( long9 );
                if( left == true )
                {
                    facing -= 2;
                    if( facing - roadFacing == -1 )
                        facing = roadFacing;
                }
                if( right == true )
                {
                    facing += 5;
                    if( facing - roadFacing == 1 )
                        facing = roadFacing;
                }
                if( gas == true )
                {
                    speed += 300 / (speed + 20) + 1;
                    if( speed > 200 )
                        speed = 200;
                }
                if( brake != true )
                    continue;
                speed -= 700 / (speed + 5) + 2;
                if( speed >= 0 )
                    continue;
                speed = 0;
                continue;
            }
            catch( InterruptedException unused11 )
            {
                stop();
                continue;
            }
        }
    }

    public void start()
    {
        if( m_DUI == null )
        {
            sound.loop();
            soundvar = 1;
            m_DUI = new Thread( this );
            m_DUI.start();
        }
    }

    public void stop()
    {
        sound.stop();
        if( m_DUI != null )
        {
            m_DUI.stop();
            m_DUI = null;
        }
    }

    public void update(Graphics Graphics1)
    {
        paint( Graphics1 );
    }

    private void updateDrivers()
    {
        ++driverCount;
        if( driverCount > 3 )
        {
            int int1;

            for( int1 = 0; int1 < 50; ++int1 )
            {
                driverCount = 0;
                if( driverDir[int1] == 0 )
                {
                    --driverY[int1];
                    if( driverY[int1] == -1 )
                        driverY[int1] = 4999;
                }
                else
                {
                    ++driverY[int1];
                    if( driverY[int1] == 5000 )
                        driverY[int1] = 0;
                }
            }
        }
    }
}

Back to NightDriver

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs