polygon logic...

master
GammelJAN 5 years ago
parent 1a4793d22f
commit 9f31ec270c

@ -7,6 +7,7 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@ -29,6 +30,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
SpriteBatch batch; SpriteBatch batch;
ShapeRenderer renderer; ShapeRenderer renderer;
PolygonSpriteBatch polygonSpriteBatch;
Timer wallTimer; Timer wallTimer;
Model model; Model model;
View view; View view;
@ -40,6 +42,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
public void create () { public void create () {
batch = new SpriteBatch(); batch = new SpriteBatch();
renderer = new ShapeRenderer(); renderer = new ShapeRenderer();
polygonSpriteBatch = new PolygonSpriteBatch();
model = new Model(); model = new Model();
view = new View(); view = new View();
@ -47,6 +50,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
wallTimer.scheduleTask(new Timer.Task() { wallTimer.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
screen.timer();
if(screen.getId() == 1) { if(screen.getId() == 1) {
model.timerStep(); model.timerStep();
} }
@ -86,7 +90,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius()); renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius());
} }
renderer.end(); renderer.end();
model.getMonster().drawMonster(renderer); model.getMonster().drawMonster(renderer,polygonSpriteBatch);
} }
} }

@ -1,12 +1,20 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.graphics.Color; 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.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Polygon;
import com.trs.game.StaticMath; import com.trs.game.StaticMath;
public class Monster { public class Monster {
private final int SPEED = 3; private final int SPEED = 5;
private int xPos; private int xPos;
private int yPos; private int yPos;
@ -18,12 +26,12 @@ public class Monster {
public Monster(int xPos, int yPos){ public Monster(int xPos, int yPos){
this.xPos = xPos; this.xPos = xPos;
this.yPos = yPos; this.yPos = yPos;
generateNewTarget();
} }
public void drawMonster(ShapeRenderer renderer){ public void drawMonster(ShapeRenderer renderer, PolygonSpriteBatch polygonSpriteBatch){
if(renderer.isDrawing()) renderer.end(); if(renderer.isDrawing()) renderer.end();
renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.begin(ShapeRenderer.ShapeType.Line);
//BODY //BODY
renderer.setColor(Color.BLACK); renderer.setColor(Color.BLACK);
renderer.rect(xPos, yPos, 50,50); renderer.rect(xPos, yPos, 50,50);
@ -36,21 +44,61 @@ public class Monster {
renderer.rect(xPos + 10, yPos + 10, 30, 10); renderer.rect(xPos + 10, yPos + 10, 30, 10);
//TEETH //TEETH
renderer.setColor(Color.RED); renderer.setColor(Color.RED);
renderer.triangle(xPos+15,yPos+20,xPos+23,yPos+20,xPos+19,yPos+13); // TOP
renderer.triangle(xPos+27,yPos+20,xPos+35,yPos+20,xPos+31,yPos+13); 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(); 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(){ public void move(){
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();
//}
if(Math.random() >= 0.9){
this.generateNewTarget(); this.generateNewTarget();
} }
} }

@ -14,8 +14,7 @@ public class EndScreen extends Screen {
public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ public EndScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2); super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 2);
buttons.add(new Button(-1,0,0,200,200,"EndScreen", Color.BLACK,Color.WHITE)); buttons.add(new Button(-1,0,0,200,80,"EndScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHREEHREEHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", 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)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));

@ -14,8 +14,7 @@ public class GameScreen extends Screen {
public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ public GameScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1); super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 1);
buttons.add(new Button(-1,0,0,200,200,"GameScreen", Color.BLACK,Color.WHITE)); //buttons.add(new Button(-1,0,0,200,80,"GameScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHREEHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", 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)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));

@ -14,8 +14,7 @@ public class MainMenuScreen extends Screen {
public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){ public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0); super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0);
buttons.add(new Button(-1,0,0,200,200,"MainMenuScreen", Color.BLACK,Color.WHITE)); buttons.add(new Button(-1,0,0,200,80,"MainMenuScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(500,500,"EHRE",Color.RED));
buttons.add(new Button(0,0,800,200,100, "MainMenu", 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)); buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));

Loading…
Cancel
Save