203 lines
4.3 KiB
Java
203 lines
4.3 KiB
Java
import java.util.ArrayList;
|
|
|
|
/**
|
|
* This defines the renderable shape of objects such as triangles, squares, etc.
|
|
* The Shape is defined via a list of vertices (x,y coordinates -> x,y)
|
|
* SpaceSpiel can read these vertices in the renderObject method and render the object.
|
|
* @author vanitas
|
|
*
|
|
*/
|
|
public class Shape
|
|
{
|
|
//Lists containing the vertices' x and y coordinates
|
|
private ArrayList<Float> x;
|
|
private ArrayList<Float> y;
|
|
private float size;
|
|
//the color of the shape
|
|
private float[] color;
|
|
|
|
//Template IDs
|
|
public static final int S_SHIP = 0001;
|
|
public static final int S_TURRET = 0002;
|
|
public static final int S_ITEM = 0003;
|
|
public static final int S_METROID = 0004;
|
|
public static final int S_BULLET = 0005;
|
|
public static final int S_BUTTON = 0006;
|
|
public static final int S_MENU = 0007;
|
|
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public Shape()
|
|
{
|
|
//Initialize
|
|
x = new ArrayList<Float>();
|
|
y = new ArrayList<Float>();
|
|
color = new float[]{1.0f,0.2f,0.2f};
|
|
}
|
|
/**
|
|
* Second constructor (Creates an Object from a template)
|
|
* @param blueprint id of the template to create
|
|
*/
|
|
public Shape(int blueprint)
|
|
{
|
|
//Initialize
|
|
x = new ArrayList<Float>();
|
|
y = new ArrayList<Float>();
|
|
//Fill with data
|
|
this.createFromBlueprint(blueprint);
|
|
}
|
|
/**
|
|
* Create a shape from a template
|
|
* @param b id of the template
|
|
*/
|
|
public void createFromBlueprint(int b)
|
|
{
|
|
switch(b)
|
|
{
|
|
case S_SHIP:
|
|
{ //Create the shape of a ship
|
|
x.add(0f); y.add(20f); //Spitze
|
|
x.add(10f); y.add(-10f); //rechts hinten
|
|
x.add(-10f); y.add(-10f); //links hinten
|
|
this.setColor(1f, 0.2f, 0.2f);
|
|
break;
|
|
}
|
|
case S_TURRET:
|
|
{ //Create the shape of a Turret
|
|
x.add(-1f); y.add(10f); //Spitze
|
|
x.add(1f); y.add(10f);
|
|
x.add(5f); y.add(-5f); //rechts hinten
|
|
x.add(-5f); y.add(-5f); //links hinten
|
|
this.setColor(0.2f, 0.2f, 0.2f);
|
|
break;
|
|
}
|
|
case S_BULLET:
|
|
{
|
|
//Create a bullet
|
|
this.add(2.5f, 7.5f);
|
|
this.add(-2.5f, 7.5f);
|
|
this.add(-2.5f, -7.5f);
|
|
this.add(2.5f, -7.5f);
|
|
this.setColor(1f, 1f, 0f);
|
|
break;
|
|
}
|
|
case S_MENU:
|
|
{
|
|
this.add(SpaceSpiel.frameSizeX/2, SpaceSpiel.frameSizeY/2);
|
|
this.add(-SpaceSpiel.frameSizeX/2, SpaceSpiel.frameSizeY/2);
|
|
this.add(-SpaceSpiel.frameSizeX/2, -SpaceSpiel.frameSizeY/2);
|
|
this.add(SpaceSpiel.frameSizeX/2, -SpaceSpiel.frameSizeY/2);
|
|
this.setColor(0f, 0f, 0f);
|
|
break;
|
|
}
|
|
case S_BUTTON: //TODO: Mit dem Uhrzeigersinn
|
|
{
|
|
//create a Button
|
|
this.add(100f, 15f);
|
|
this.add(-0f, 15f);
|
|
this.add(-0f, -15f);
|
|
this.add(100f, -15f);
|
|
this.setColor(1f, 1f, 1f);
|
|
break;
|
|
}
|
|
case S_METROID:
|
|
{
|
|
this.add(4f, 7f);
|
|
this.add(8f,0f);
|
|
this.add(4f,-7f);
|
|
this.add(-4f,-7f);
|
|
this.add(-8f,0f);
|
|
this.add(-4f,7f);
|
|
this.setColor(0.15f, 0.15f, 0.15f);
|
|
break;
|
|
}
|
|
default:
|
|
this.setColor(0.2f, 0.2f, 0.2f);
|
|
//TODO: Add shape of multiple ammunition types and items
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add a new vertex to the shape
|
|
* @param nx
|
|
* @param ny
|
|
*/
|
|
public void add(float nx, float ny)
|
|
{
|
|
this.x.add(nx);
|
|
this.y.add(ny);
|
|
}
|
|
/**
|
|
* Modify the vertex on position pos
|
|
* @param pos position of the vertex
|
|
* @param nx new x value
|
|
* @param ny new y value
|
|
*/
|
|
public void modify(int pos, float nx, float ny)
|
|
{
|
|
this.x.set(pos, nx);
|
|
this.y.set(pos, ny);
|
|
}
|
|
|
|
/**
|
|
* return the x component of a specific vertex
|
|
* @param pos position of the vertex in the list
|
|
* @return x component
|
|
*/
|
|
public float getX(int pos)
|
|
{
|
|
return x.get(pos);
|
|
}
|
|
/**
|
|
* return the y component of a specific vertex
|
|
* @param pos position of the vertex in the list
|
|
* @return y component
|
|
*/
|
|
public float getY(int pos)
|
|
{
|
|
return y.get(pos);
|
|
}
|
|
/**
|
|
* returns the Length of the x list representative for how many vertices are in the list.
|
|
* x.size() and y.size() should be equal all the time.
|
|
* @return size of the arrays
|
|
*/
|
|
public int getLength()
|
|
{
|
|
return x.size();
|
|
}
|
|
/**
|
|
* set the color of the shape
|
|
* @param r red
|
|
* @param g green
|
|
* @param b blue
|
|
*/
|
|
public void setColor(float r, float g, float b)
|
|
{
|
|
color = new float[3];
|
|
color[0]=r;
|
|
color[1]=g;
|
|
color[2]=b;
|
|
}
|
|
|
|
/**
|
|
* returns the color of the shape
|
|
* @return color
|
|
*/
|
|
public float[] getColor()
|
|
{
|
|
//System.out.println(""+color[0]+""+color[1]+""+color[2]);
|
|
return color;
|
|
}
|
|
public void setSize(float s)
|
|
{
|
|
this.size = s;
|
|
}
|
|
public float getSize()
|
|
{
|
|
return this.size;
|
|
}
|
|
}
|