From 9f31ec270cdcd27a03fc85e1d863b17f12c34617 Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Fri, 25 Sep 2020 23:20:19 +0200 Subject: [PATCH] polygon logic... --- core/src/com/trs/game/Controller.java | 6 +- core/src/com/trs/game/model/Monster.java | 66 ++++++++++++++++--- .../com/trs/game/view/Screens/EndScreen.java | 3 +- .../com/trs/game/view/Screens/GameScreen.java | 3 +- .../trs/game/view/Screens/MainMenuScreen.java | 3 +- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index c7b915f..9662e1b 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; @@ -29,6 +30,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { SpriteBatch batch; ShapeRenderer renderer; + PolygonSpriteBatch polygonSpriteBatch; Timer wallTimer; Model model; View view; @@ -40,6 +42,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { public void create () { batch = new SpriteBatch(); renderer = new ShapeRenderer(); + polygonSpriteBatch = new PolygonSpriteBatch(); model = new Model(); view = new View(); @@ -47,6 +50,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { wallTimer.scheduleTask(new Timer.Task() { @Override public void run() { + screen.timer(); if(screen.getId() == 1) { model.timerStep(); } @@ -86,7 +90,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius()); } renderer.end(); - model.getMonster().drawMonster(renderer); + model.getMonster().drawMonster(renderer,polygonSpriteBatch); } } diff --git a/core/src/com/trs/game/model/Monster.java b/core/src/com/trs/game/model/Monster.java index d3405c8..75ccdf2 100644 --- a/core/src/com/trs/game/model/Monster.java +++ b/core/src/com/trs/game/model/Monster.java @@ -1,12 +1,20 @@ package com.trs.game.model; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.PolygonRegion; +import com.badlogic.gdx.graphics.g2d.PolygonSprite; +import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Intersector; +import com.badlogic.gdx.math.Polygon; import com.trs.game.StaticMath; public class Monster { - private final int SPEED = 3; + private final int SPEED = 5; private int xPos; private int yPos; @@ -18,12 +26,12 @@ public class Monster { public Monster(int xPos, int yPos){ this.xPos = xPos; this.yPos = yPos; - + generateNewTarget(); } - public void drawMonster(ShapeRenderer renderer){ + public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch){ if(renderer.isDrawing()) renderer.end(); - renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.begin(ShapeRenderer.ShapeType.Line); //BODY renderer.setColor(Color.BLACK); renderer.rect(xPos, yPos, 50,50); @@ -36,21 +44,61 @@ public class Monster { renderer.rect(xPos + 10, yPos + 10, 30, 10); //TEETH renderer.setColor(Color.RED); - renderer.triangle(xPos+15,yPos+20,xPos+23,yPos+20,xPos+19,yPos+13); - renderer.triangle(xPos+27,yPos+20,xPos+35,yPos+20,xPos+31,yPos+13); + // TOP + renderer.triangle(xPos+10,yPos+20,xPos+10,yPos+15,xPos+13,yPos+20); + renderer.triangle(xPos+13,yPos+20,xPos+16,yPos+15,xPos+19,yPos+20); + renderer.triangle(xPos+19,yPos+20,xPos+22,yPos+15,xPos+25,yPos+20); + renderer.triangle(xPos+25,yPos+20,xPos+28,yPos+15,xPos+31,yPos+20); + renderer.triangle(xPos+31,yPos+20,xPos+34,yPos+15,xPos+37,yPos+20); + renderer.triangle(xPos+37,yPos+20,xPos+40,yPos+15,xPos+40,yPos+20); + // BOTTOM + renderer.triangle(xPos+10,yPos+10,xPos+13,yPos+15,xPos+16,yPos+10); + renderer.triangle(xPos+16,yPos+10,xPos+19,yPos+15,xPos+22,yPos+10); + renderer.triangle(xPos+22,yPos+10,xPos+25,yPos+15,xPos+28,yPos+10); + renderer.triangle(xPos+28,yPos+10,xPos+31,yPos+15,xPos+34,yPos+10); + renderer.triangle(xPos+34,yPos+10,xPos+37,yPos+15,xPos+40,yPos+10); 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(){ checkTarget(); - this.xPos += this.movementX; - this.yPos += this.movementY; + //this.xPos += this.movementX; + //this.yPos += this.movementY; } private void checkTarget(){ - if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){ + //if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){ + // this.generateNewTarget(); + //} + if(Math.random() >= 0.9){ this.generateNewTarget(); } } diff --git a/core/src/com/trs/game/view/Screens/EndScreen.java b/core/src/com/trs/game/view/Screens/EndScreen.java index 0c4d3b6..773df1b 100644 --- a/core/src/com/trs/game/view/Screens/EndScreen.java +++ b/core/src/com/trs/game/view/Screens/EndScreen.java @@ -14,8 +14,7 @@ public class EndScreen extends Screen { public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2); - buttons.add(new Button(-1,0,0,200,200,"EndScreen", Color.BLACK,Color.WHITE)); - texts.add(new Text(500,500,"EHREEHREEHRE",Color.RED)); + buttons.add(new Button(-1,0,0,200,80,"EndScreen", Color.BLACK,Color.WHITE)); buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE)); diff --git a/core/src/com/trs/game/view/Screens/GameScreen.java b/core/src/com/trs/game/view/Screens/GameScreen.java index 6ac43ed..710ae5b 100644 --- a/core/src/com/trs/game/view/Screens/GameScreen.java +++ b/core/src/com/trs/game/view/Screens/GameScreen.java @@ -14,8 +14,7 @@ public class GameScreen extends Screen { public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1); - buttons.add(new Button(-1,0,0,200,200,"GameScreen", Color.BLACK,Color.WHITE)); - texts.add(new Text(500,500,"EHREEHRE",Color.RED)); + //buttons.add(new Button(-1,0,0,200,80,"GameScreen", Color.BLACK,Color.WHITE)); buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE)); diff --git a/core/src/com/trs/game/view/Screens/MainMenuScreen.java b/core/src/com/trs/game/view/Screens/MainMenuScreen.java index 12e305f..6a8b0b9 100644 --- a/core/src/com/trs/game/view/Screens/MainMenuScreen.java +++ b/core/src/com/trs/game/view/Screens/MainMenuScreen.java @@ -14,8 +14,7 @@ public class MainMenuScreen extends Screen { public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0); - buttons.add(new Button(-1,0,0,200,200,"MainMenuScreen", Color.BLACK,Color.WHITE)); - texts.add(new Text(500,500,"EHRE",Color.RED)); + buttons.add(new Button(-1,0,0,200,80,"MainMenuScreen", Color.BLACK,Color.WHITE)); buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));