From 52af84e65276037d5c3140f606ca8726e24e1261 Mon Sep 17 00:00:00 2001 From: GammelJan Date: Sun, 21 Jun 2020 23:01:58 +0200 Subject: [PATCH] lol --- core/src/controller/Controller.java | 35 ++++- core/src/model/Button.java | 124 ++++++++++++++++++ core/src/model/Level.java | 14 +- core/src/view/Gamescreen.java | 13 +- core/src/view/Leveleditor.java | 195 ++++++++++++++++++++++++++++ 5 files changed, 373 insertions(+), 8 deletions(-) create mode 100644 core/src/model/Button.java create mode 100644 core/src/view/Leveleditor.java diff --git a/core/src/controller/Controller.java b/core/src/controller/Controller.java index a0e7e92..11085c8 100644 --- a/core/src/controller/Controller.java +++ b/core/src/controller/Controller.java @@ -9,9 +9,11 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import model.Goal; import model.Level; @@ -24,6 +26,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.Viewport; +import view.Leveleditor; import view.Titlescreen; import view.Winscreen; @@ -41,6 +44,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ Levelscreen ls; Gamescreen gs; Winscreen ws; + Leveleditor le; int levelAmount; SpriteBatch batch; Timer stepTimer; @@ -63,6 +67,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ ls = null; gs = null; ws = null; + le = null; levelAmount = 9; batch = new SpriteBatch(); Gdx.input.setInputProcessor(this); @@ -181,6 +186,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } else if(ws != null) ws.render(batch); + else if(le != null){ + le.render(batch); + } batch.end(); } @@ -208,9 +216,16 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ @Override public boolean touchDown(int x, int y, int i2, int i3) { if(ts != null){ - ts.dispose(); - ts = null; - ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); + if(x > 0.05 * Gdx.graphics.getWidth()){ + ts.dispose(); + ts = null; + ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); + } + else{ + ts.dispose(); + ts = null; + le = new Leveleditor(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined); + } } else if(ls != null){ if(x < Gdx.graphics.getWidth() * 0.15){ @@ -250,13 +265,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ } } + else if(le != null){ + le.touchDown(x,y); + } return true; } @Override public boolean touchUp(int i, int i1, int i2, int i3) { - if(gs != null){ - } return true; } @@ -267,6 +283,15 @@ public class Controller extends ApplicationAdapter implements InputProcessor{ @Override public boolean mouseMoved(int i, int i1) { + float x = ((float)i / (float)Gdx.graphics.getWidth()) *(float) GAME_WORLD_WIDTH; + float y = GAME_WORLD_HEIGHT - ((float)i1 / (float)Gdx.graphics.getHeight()) * (float)GAME_WORLD_HEIGHT; + //System.out.println("x:" + x + " y:" + y); + if(gs != null){ + gs.setMousePos(x, y); + } + if(le != null){ + le.setMousePos(x, y); + } return false; } diff --git a/core/src/model/Button.java b/core/src/model/Button.java new file mode 100644 index 0000000..3f40a5d --- /dev/null +++ b/core/src/model/Button.java @@ -0,0 +1,124 @@ +/* + * 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 model; + +import com.badlogic.gdx.math.Rectangle; + +/** + * + * @author Jan + */ +public class Button { + + private String text; + private int xPos; + private int yPos; + private int width; + private int height; + private int id; + private int listId; + private Rectangle rect; + + public Button(String text, int xPos, int yPos, int width, int height, int id, int listId){ + this.text = text; + this.xPos = xPos; + this.yPos = yPos; + this.width = width; + this.height = height; + this.id = id; //0: pivot, 1: goal, 2: rect, 3: addRect + this.listId = listId; + rect = new Rectangle(xPos, yPos, width, height); + } + + /** + * @return the text + */ + public String getText() { + return text; + } + + /** + * @param text the text to set + */ + public void setText(String text) { + this.text = text; + } + + /** + * @return the xPos + */ + public int getxPos() { + return xPos; + } + + /** + * @param xPos the xPos to set + */ + public void setxPos(int xPos) { + this.xPos = xPos; + } + + /** + * @return the yPos + */ + public int getyPos() { + return yPos; + } + + /** + * @param yPos the yPos to set + */ + public void setyPos(int yPos) { + this.yPos = yPos; + } + + /** + * @return the width + */ + public int getWidth() { + return width; + } + + /** + * @param width the width to set + */ + public void setWidth(int width) { + this.width = width; + } + + /** + * @return the height + */ + public int getHeight() { + return height; + } + + /** + * @param height the height to set + */ + public void setHeight(int height) { + this.height = height; + } + + public void setRectangle(Rectangle rect){ + this.rect = rect; + } + + public Rectangle getRectangle(){ + return rect; + } + + public void setId(int id){ + this.id = id; + } + public int getId(){ + return id; + } + public int getListId(){ + return listId; + } + +} diff --git a/core/src/model/Level.java b/core/src/model/Level.java index fd918df..528c9e0 100644 --- a/core/src/model/Level.java +++ b/core/src/model/Level.java @@ -90,7 +90,7 @@ public class Level { angleSpeed += 0.0001; angle -= angleSpeed; - System.out.println(Math.toDegrees(angle)); + //System.out.println(Math.toDegrees(angle)); Vector2 newPosVector = math.pivotGetNewPos(this.angle, this.xPosPivot, this.yPosPivot, RADIUS); this.projectile.setxPos(xPosPivot + (int) newPosVector.x); @@ -155,4 +155,16 @@ public class Level { public void addRectangle(int x, int y, int width, int height){ objects.add(new Rectangle(x,y,width,height)); } + + public void setPivot(int x, int y){ + xPosPivot = x; + yPosPivot = y; + } + public void setGoal(int x, int y){ + goal.setxPos(x); + goal.setyPos(y); + goal.setSizeX(300); + goal.setSizeY(200); + } + } diff --git a/core/src/view/Gamescreen.java b/core/src/view/Gamescreen.java index fa7e277..e1f726a 100644 --- a/core/src/view/Gamescreen.java +++ b/core/src/view/Gamescreen.java @@ -6,6 +6,7 @@ package view; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -56,6 +57,9 @@ public class Gamescreen{ boolean win; + float mouseX; + float mouseY; + public Gamescreen(Level level, float width, float height, Matrix4 matrix){ GAME_WORLD_WIDTH = width; GAME_WORLD_HEIGHT = height; @@ -115,6 +119,8 @@ public class Gamescreen{ shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(Color.BLACK); + shapeRenderer.circle(mouseX, mouseY, 5); + if(level.released()) { for (int i = 0; i < level.traces.length; i++) { if(level.isTraceInitialised[i]){ @@ -127,8 +133,6 @@ public class Gamescreen{ shapeRenderer.rectLine((float) level.getPivotX(), (float) level.getPivotY(), (float) level.getProjectile().getxPos(), (float) level.getProjectile().getyPos(), 3); } - - shapeRenderer.setColor(Color.BLACK); shapeRenderer.rect(x, y,th * w, h); shapeRenderer.rect(x + th * w,y, th*3 * w,th * h); @@ -201,6 +205,11 @@ public class Gamescreen{ public ArrayList getObjectRects(){ return objectRects; } + + public void setMousePos(float x, float y){ + mouseX = x; + mouseY = y; + } } diff --git a/core/src/view/Leveleditor.java b/core/src/view/Leveleditor.java new file mode 100644 index 0000000..70a6366 --- /dev/null +++ b/core/src/view/Leveleditor.java @@ -0,0 +1,195 @@ +/* + * 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 view; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Circle; +import com.badlogic.gdx.math.Intersector; +import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Polygon; +import com.badlogic.gdx.math.Vector2; +import java.awt.Point; +import java.util.ArrayList; +import model.Button; + +import model.Goal; +import model.Level; +import model.Projectile; + +/** + * + * @author Jan + */ +public class Leveleditor{ + + ShapeRenderer shapeRenderer; + + float GAME_WORLD_WIDTH; + float GAME_WORLD_HEIGHT; + + ArrayList