Inspiration

The game centipede was the inspiration.

What it does

It is a rough recreation of the video game centipede

How we built it

I used Java to create this game

Challenges we ran into

Getting the collision between the centipede with the laser to work properly was surprisingly difficult

Accomplishments that we're proud of

I'm proud that it is playable

What we learned

I learned that you must have a clear plan and direction when creating a game.

What's next for centipede

fully finishing the recreation including a score board and multiple modes

'code' // The "Centi" class. import java.awt.*; import hsa.Console;

public class Centi { static Console c; // The output console

public static void main (String[] args)
{
    c = new Console (35, 90);
    //setup
    int x = 30, y = 40;
    int[] [] grid = new int [x] [y];
    for (int a = 0 ; a < x ; a++)
        for (int b = 0 ; b < y ; b++)
        {
            grid [a] [b] = 0;

        }
    int[] count = new int[]
    {
        0, 0, 0, 0, 0
    }
    ;
    int[] p1Position = new int[]
    {
        5, 38
    }
    ;
    int locx = 24, locy = 34;
    int[] plants = new int [50 * 2];
    for (int t = 2 ; t < 50 ; t += 2)
    {
        do
        {
            locx = (int) (Math.random () * 24 + 2);
            locy = (int) (Math.random () * 34 + 2);
        }
        while ((plants [t - 1] <= locx + 2 && plants [t - 1] >= locx - 2) || (plants [t - 2] <= locy + 2 && plants [t - 2] >= locy - 2));
        plants [t] = locx;
        plants [t + 1] = locy;
        grid [locx] [locy] = 3;

    }
    // c.fillRect (50, 5, 30 * 16, 40 * 16);
    int[] [] centi = new int [12] [3];

    centi [0] [0] = 0;
    centi [0] [1] = 0;
    centi [1] [0] = 1;
    centi [1] [1] = 0;
    centi [2] [0] = 2;
    centi [2] [1] = 0;
    centi [3] [0] = 3;
    centi [3] [1] = 0;
    centi [4] [0] = 4;
    centi [4] [1] = 0;
    centi [5] [0] = 5;
    centi [5] [1] = 0;
    centi [6] [0] = 6;
    centi [6] [1] = 0;
    centi [7] [0] = 7;
    centi [7] [1] = 0;
    centi [8] [0] = 8;
    centi [8] [1] = 0;
    centi [9] [0] = 9;
    centi [9] [1] = 0;
    centi [10] [0] = 10;
    centi [10] [1] = 0;
    centi [11] [0] = 11;
    centi [11] [1] = 0;

    for (int b = 0 ; b < 12 ; b++)
    {
        grid [centi [b] [0]] [centi [b] [1]] = 4;
        centi [b] [2] = 0;

    }
    //starting screen
    //creating fonts
    Font fBig = new Font ("Consolas", Font.PLAIN, 30);
    Font fBiger = new Font ("Consolas", Font.PLAIN, 50);
    Font fSmall = new Font ("Consolas", Font.PLAIN, 10);
    Font f = new Font ("Consolas", Font.PLAIN, 16);


    //background
    c.setColor (Color.blue);
    c.fillRect (15, 15, 840, 640);
    c.setColor (Color.black);

    //text for starting screen
    c.setFont (fBig);
    c.fillRect (60, 90, 150 * 4, 200);
    //lets play
    //drawing the title
    //outlins words black
    c.setColor (Color.black);
    c.drawString ("CENTIPEDE", 73 + 2, 51);
    c.drawString ("CENTIPEDE", 73 + 2, 49);
    c.drawString ("CENTIPEDE", 74 + 2, 50);
    c.drawString ("CENTIPEDE", 73 + 2, 50);

    c.setColor (Color.white);
    c.drawString ("CENTIPEDE", 73 + 2, 50);

    //explaining the rules
    //changes font
    c.setFont (f);
    delay (200);
    c.setColor (Color.white);
    //drawing the rules
    c.drawString ("*** RULES OF GAME ***", 100, 130);
    c.drawString ("Destory the CENTIPEDE!!!", 130, 160);
    c.drawString (" * * * MODE(s) * * * ", 130, 180);
    //shows different modes the player can play
    c.setColor (Color.white);
    c.drawString ("* P1_Vs_TheBugs    [select] ", 130, 200);
    c.drawString ("* P1_Vs_CENTIPEDE    [select] ", 130, 220);

    //exit box for effect
    c.setColor (Color.black);
    c.fillRect (650, 30, 50, 25);
    c.setColor (Color.white);
    //changes font
    c.setFont (fSmall);
    //draws esc button
    c.drawString (" ESC ", 660, 47);
    c.setFont (f);
    delay (250);
    c.setColor (Color.white);
    delay (250);

    //waits for user to press key board
    c.setColor (Color.black);
    c.fillRect (210, 345, 250, 100);
    c.setColor (Color.white);
    //prompts user to continue
    c.drawString ("| Press to start |", 250, 400);
    c.getChar ();



    c.setColor (Color.cyan);


    c.drawString ("* P1_Vs_CENTIPEDE    [select] ", 130, 220);



    delay (750);
    c.clear ();
    c.setColor (Color.blue);
    c.fillRect (0, 0, 800, 800);

    c.setColor (Color.black);
    c.fillRect (50, 5, 300, 200);

    for (int g = 0 ; g < 2000 ; g++)
    {
        for (int i = 0 ; i < 12 ; i++)
            if (centi [i] [1] == 38)
                g = 2000;
        char p1Move = 'c';
        if (c.isCharAvail () == true)
        {
            p1Move = c.getChar ();
        }


        if (p1Move == 'a' || p1Move == 'd' || (p1Move == ' ' && !(g % 4 == 0)))
            setMove (grid, p1Move, p1Position);
        //shoot (grid);
        //centi
        //int dir=1;
        for (int i = 11 ; i >= 0 ; i--)
        {

            if (grid [centi [i] [0]] [centi [i] [1]] == 4)
            {

                grid [centi [i] [0]] [centi [i] [1]] = 0;
                for (int q = 0 ; q < 12 ; q++)
                {
                    if (centi [q] [0] == centi [i] [0] && centi [q] [1] == centi [i] [1] && q != i)
                        grid [centi [i] [0]] [centi [i] [1]] = 4;
                }
                int[] shift = new int[]
                {
                    0, 0
                }
                ;
                if ((centi [i] [1] + centi [i] [2]) % 2 == 0)
                    shift [0] = 1;
                else
                    shift [0] = -1;
                if ((centi [i] [0] == 29 && (centi [i] [1] + centi [i] [2]) % 2 == 0) || (centi [i] [0] == 0 && (centi [i] [1] + centi [i] [2]) % 2 != 0))
                    centi [i] [1]++;

                else if (grid [centi [i] [0] + shift [0]] [centi [i] [1]] == 3)
                    centi [i] [1]++;

                else if ((grid [centi [i] [0] + shift [0]] [centi [i] [1]] == 2))
                    break;

                else //if (grid [centi [i] [0] + shift [0]] [centi [i] [1]] == 0)
                    // {
                    centi [i] [0] += shift [0];


                //}
                grid [centi [i] [0]] [centi [i] [1]] = 4;
            }
            else if (grid [centi [i] [0]] [centi [i] [1]] == 0)
            {
                for (int I = i - 1 ; I >= 0 ; I--)
                    centi [I] [2] = 1;
            }


        }
        drawGrid (grid, centi, 16);
        if (g % 10 == 0)
            clock (count);
        delay (100);

        if (g == 2000)
        {
            int x1 = 30, y1 = 40, k = 5, d = 50;
            for (int a = 0 ; a < x1 ; a++)
            {
                for (int b = 0 ; b < y1 ; b++)
                {

                    c.setColor (Color.blue);


                    c.fillRect (a * 16 + d, b * 16 + k, 16, 16);
                    delay (10);
                }
                delay (10);
            }





        }

    }
} // main method


public static void drawGrid (int[] [] grid, int[] [] centi, int sizes)
{

    int x = 30, y = 40, k = 5, d = 50, size = 16;
    for (int a = 0 ; a < x ; a++)
        for (int b = 0 ; b < y ; b++)
        {

            c.setColor (Color.black);

            if (grid [a] [b] == 0)
                c.fillRect (a * sizes + d, b * sizes + k, size, size);

            if (grid [a] [b] == 1)
            {
                c.setColor (Color.white);
                c.fillRect (a * sizes + d, b * sizes + k, size, size);

            }
            else if (grid [a] [b] == 2)
            {
                c.setColor (Color.red);
                c.fillRect (a * sizes + d + 6, b * sizes + k, size - 10, size);

                grid [a] [b] = 0;
                if (b - 1 >= 0)
                {
                    if (grid [a] [b - 1] == 0 || grid [a] [b - 1] == 4)
                        grid [a] [b - 1] = 2;

                }
            }
            else if (grid [a] [b] == 3)
            {
                c.setColor (Color.yellow);
                c.fillRect (a * sizes + d, b * sizes + k, size, size);
            }
            else if (grid [a] [b] == 4)
            {


                c.setColor (Color.green);
                c.fillOval (a * sizes + d, b * sizes + k, size, size);
            }
            c.setColor (Color.black);
        }
}


public static void setMove (int[] [] grid, char p1Move, int[] position)
{

    int i = 0;
    if (p1Move == 'a')
        i = -1;
    else if (p1Move == 'd')
        i = 1;
    if (position [0] + i <= 29 && position [0] + i >= 0)
    {
        grid [position [0]] [position [1]] = 0;
        position [0] += i;
        grid [position [0]] [position [1]] = 1;
    }


    if (p1Move == ' ')
        grid [position [0]] [position [1] - 1] = 2;



}


public static void clock (int[] count)
{

    Font n = new Font ("Courier New", Font.PLAIN, 20);
    c.setFont (n);

    c.setColor (Color.black);
    c.fillRect (530, 0, 220, 50);
    c.setColor (Color.white);

    c.drawString (count [0] + " " + count [1] + " " + count [2] + " " + count [3] + " " + count [4] + "", 560, 30);

    count [4]++;
    if (count [4] > 9)
    {
        count [4] = 0;
        count [3]++;
        if (count [3] > 9)
        {
            count [3] = 0;
            count [2]++;
            if (count [2] > 9)
            {
                count [2] = 0;
                count [1]++;
                if (count [1] > 9)
                {
                    count [1] = 0;
                    count [0]++;

                }
            }
        }
    }
}



public static void delay (int millisecs)  // Delay Method
{
    try
    {
        Thread.currentThread ().sleep (millisecs);
    }


    catch (InterruptedException e)
    {
    }
}

} // Centi class

Built With

Share this project:

Updates