Projectile drawn as Polygon

master
GammelJAN 5 years ago
parent 2df26f9662
commit ba2e228919

@ -113,7 +113,16 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
// DRAW PROJECTILES // DRAW PROJECTILES
renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.begin(ShapeRenderer.ShapeType.Filled);
for(Projectile projectile : model.getProjectiles()){ for(Projectile projectile : model.getProjectiles()){
renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius()); PolygonSprite poly;
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
projectile.getPolygon().getVertices(), new short[] {
0, 1, 2, // Two triangles using vertex indices.
0, 2, 3 // Take care of the counter-clockwise direction.
});
poly = new PolygonSprite(polyReg);
polygonSpriteBatch.begin();
poly.draw(polygonSpriteBatch);
polygonSpriteBatch.end();
} }
renderer.end(); renderer.end();

@ -33,7 +33,7 @@ public class Monster {
public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch){ public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch){
if(renderer.isDrawing()) renderer.end(); if(renderer.isDrawing()) renderer.end();
renderer.begin(ShapeRenderer.ShapeType.Line); renderer.begin(ShapeRenderer.ShapeType.Filled);
//BODY //BODY
renderer.setColor(Color.BLACK); renderer.setColor(Color.BLACK);
renderer.rect(xPos, yPos, 50,50); renderer.rect(xPos, yPos, 50,50);
@ -62,44 +62,19 @@ public class Monster {
renderer.end(); renderer.end();
/* POLYGON LOGIC (DRAWING)
PolygonSprite poly;
Texture textureSolid;
// Creating the color filling (but textures would work the same way)
Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pix.setColor(Color.BLACK); // DE is red, AD is green and BE is blue.
pix.fill();
textureSolid = new Texture(pix);
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
new float[] { // Four vertices
200, 200, // Vertex 0 3--2
300, 200, // Vertex 1 | /|
400, 500, // Vertex 2 |/ |
300, 500 // Vertex 3 0--1
}, new short[] {
0, 1, 2, // Two triangles using vertex indices.
0, 2, 3 // Take care of the counter-clockwise direction.
});
poly = new PolygonSprite(polyReg);
polygonSpriteBatch.begin();
poly.draw(polygonSpriteBatch);
polygonSpriteBatch.end();
*/
} }
public void move(ArrayList<Wall> walls){ public void move(ArrayList<Wall> walls){
checkTarget(); checkTarget();
//this.xPos += this.movementX; this.xPos += this.movementX;
//this.yPos += this.movementY; this.yPos += this.movementY;
} }
private void checkTarget(){ private void checkTarget(){
//if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){ if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){
// this.generateNewTarget(); this.generateNewTarget();
//} }
if(Math.random() >= 0.9){ if(Math.random() >= 0.9){
this.generateNewTarget(); this.generateNewTarget();
} }

Loading…
Cancel
Save