scenes.Debris.java Source code

Java tutorial

Introduction

Here is the source code for scenes.Debris.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package scenes;

import com.badlogic.gdx.graphics.Color;
import java.awt.Point;

/**
 * 
 * @author <a href="mailto:martin.drost@student.fontys.nl">Martin Dorst</a>
 */
public class Debris implements Comparable {
    private Point position;
    private double speed;
    private int radius;
    private int type;
    private Color color;

    public Debris(int windowWidth, int windowHeight) {
        int size = (int) Math.round(Math.random() * 2);
        if (size == 0)
            setSmall();
        else if (size == 1)
            setMedium();
        else if (size == 2)
            setLarge();

        this.type = (int) Math.round(Math.random());

        int x = (int) Math.round(Math.random() * windowWidth);
        int y = windowHeight + ((int) (Math.random() * windowHeight));
        this.position = new Point(x, y);
    }

    private void setSmall() {
        this.speed = 1;
        this.radius = 10;
        this.color = new Color(0.95f, 0.95f, 0.95f, 0);
    }

    private void setMedium() {
        this.speed = 2;
        this.radius = 20;
        this.color = new Color(0.9f, 0.9f, 0.9f, 0);
    }

    private void setLarge() {
        this.speed = 3;
        this.radius = 30;
        this.color = new Color(0.8f, 0.8f, 0.8f, 0);
    }

    public Point getPosition() {
        return this.position;
    }

    public int getRadius() {
        return this.radius;
    }

    public double getSpeed() {
        return this.speed;
    }

    public int getType() {
        return this.type;
    }

    public Color getColor() {
        return this.color;
    }

    public void update() {
        this.position.y -= this.getSpeed();
    }

    @Override
    public int compareTo(Object o) {
        return this.radius - ((Debris) o).radius;
    }
}