All pastes #519031 Raw Edit

bgdrxbg

public text v1 · immutable
#519031 ·published 2007-05-29 14:47 UTC
rendered paste body
//Gauntlet -> Random Monster Spawn
import java.awt.*;
import java.util.*;
import java.applet.*;

public class Monster
{
    //Variables============================================

    //position and speed of monster
    private int x_pos;
    private int y_pos;
    private int x_speed;
    private int y_speed;

    //sides of the monster
    private int monster_top;
    private int monster_bottom;
    private int monster_left;
    private int monster_right;

    //String score1 = Integer.toString (scoreP1);

    //boundaries
    private static final int right_out = 390;
    private static final int left_out = 10;
    private static final int down_out = 290;
    private static final int up_out = 10;


    //sets ball position/speed
    public Monster (int x_pos, int y_pos)
    {
        this.x_pos = x_pos;
        this.y_pos = y_pos;
        x_speed = 10;
        y_speed = 10;
    }


    public void move ()
    {
        x_pos += x_speed;
        y_pos += y_speed;
        isMonsterOut ();
    }


    public void isMonsterOut ()
    {
        if (x_speed < 0)
        {
            if (x_pos < left_out)
            {
                x_pos = x_pos;
                y_pos = y_pos;
                x_speed = -x_speed;

            }
        }

        else if (x_speed > 0)
        {
            if (x_pos > right_out)
            {
                x_pos = x_pos;
                y_pos = y_pos;
                x_speed = -x_speed;

            }
        }

        if (y_speed < 0)
        {
            if (y_pos < up_out)
            {
                x_pos = x_pos;
                y_pos = y_pos;
                y_speed = -y_speed;
            }
        }

        else if (y_speed > 0)
        {
            if (y_pos > down_out)
            {
                x_pos = x_pos;
                y_pos = y_pos;
                y_speed = -y_speed;
            }
        }
    }


    /* public void testForCollisionMonster (Paddle player1)
     {
         ball_top = y_pos - radius;
         ball_bottom = y_pos + radius;
         ball_left = x_pos - radius;
         ball_right = x_pos + radius;

         player_top1 = player1.getYPos ();
         player_bottom1 = player1.getYPos () + player1.getYSize ();
         player_right1 = player1.getXPos () + player1.getXSize ();
         player_left1 = player1.getXPos ();

     }*/


    public int getXSpeed ()
    {
        return x_speed;
    }


    public int getYPos ()
    {
        return y_pos;
    }


    public void paint (Graphics g)
    {
        g.setColor (Color.green);
        g.drawRect (x_pos, y_pos, x_pos + 10, y_pos + 10);

    }
}