ready for android

master
GammelJan 6 years ago
parent 234d6020dd
commit 376d8f0ff9

@ -321,17 +321,17 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
x = (int)((float)x / (float)Gdx.graphics.getWidth() * (float)GAME_WORLD_WIDTH);
y = (int)GAME_WORLD_HEIGHT-(int)((float)y / Gdx.graphics.getHeight() * GAME_WORLD_HEIGHT);
if(ts != null){
if(x > 0.05 * GAME_WORLD_WIDTH){
//if(x > 0.05 * GAME_WORLD_WIDTH){ // LEVELEDITOR AUSKOMMENTIERT
ts.dispose();
ts = null;
//ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
cs = new Chapterscreen(5, 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{
// ts.dispose();
// ts = null;
// le = new Leveleditor(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
//}
}
else if(ls != null){
int n = ls.touchDown(x,y);
@ -357,8 +357,18 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
}
}
else if(gs != null){
if(!level.get(currentChapter).get(currentLevel).released()){
level.get(currentChapter).get(currentLevel).projectileReleased();
if(gs.touchDown(x,y) == -1){
if(!level.get(currentChapter).get(currentLevel).released()){
level.get(currentChapter).get(currentLevel).projectileReleased();
}
}
else if(gs.touchDown(x, y) == 0){
gs.step(level.get(currentChapter).get(currentLevel));
level.get(currentChapter).get(currentLevel).reset();
gs.dispose();
stepTimer.stop();
ls = new Levelscreen(beatenLevel, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
gs = null;
}
}
else if(ws != null){

@ -57,7 +57,7 @@ public class Chapterscreen{
buttons.add(new Button("Chapter 3", (int)(0.15 * GAME_WORLD_WIDTH + buttons.get(0).getWidth()*2 - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.7 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 3));
buttons.add(new Button("Chapter 4", (int)(0.05 * GAME_WORLD_WIDTH - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 4));
buttons.add(new Button("Chapter 5", (int)(0.1 * GAME_WORLD_WIDTH + buttons.get(0).getWidth() - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 5));
//buttons.add(new Button("User Level",(int)(0.15 * GAME_WORLD_WIDTH + buttons.get(0).getWidth()*2 - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), 0));
buttons.add(new Button("coming soon ...",(int)(0.15 * GAME_WORLD_WIDTH + buttons.get(0).getWidth()*2 - 0.5 * 3/80 * GAME_WORLD_WIDTH), (int)(0.3 * GAME_WORLD_HEIGHT), (int)((1f/3f) * 0.8 *GAME_WORLD_WIDTH), (int)(0.2 * GAME_WORLD_HEIGHT), -1));
buttons.add(new Button("< back", 20,10,200,80,6));
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));

@ -9,7 +9,10 @@ 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;
@ -19,6 +22,7 @@ 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;
@ -57,6 +61,15 @@ public class Gamescreen{
ArrayList<Rectangle> objectRectsBottom;
ArrayList<Rectangle> objectRectsLeft;
ArrayList<Rectangle> objectRectsRight;
// BUTTONS
ArrayList<Button> buttons;
// BITMAP FONT
BitmapFont font;
boolean win;
@ -78,7 +91,23 @@ public class Gamescreen{
objectRectsBottom = new ArrayList<>();
objectRectsLeft = new ArrayList<>();
objectRectsRight = new ArrayList<>();
// CREATE DEFAULT BUTTONS
buttons = new ArrayList<>();
buttons.add(new Button("<", (int)(GAME_WORLD_WIDTH * 0.02),(int) (GAME_WORLD_HEIGHT - (GAME_WORLD_HEIGHT * 0.02) - 80), 80, 80, 0));
// CREATE BITMAP FONT
font = new BitmapFont();
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 21;
font = generator.generateFont(parameter);
generator.dispose();
font.setColor(Color.BLACK);
win = false;
@ -117,7 +146,8 @@ public class Gamescreen{
g = level.getGoal();
objects = level.getObjects();
batch.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
@ -178,6 +208,21 @@ public class Gamescreen{
shapeRenderer.rect(object.getX(), object.getY(), object.getWidth(), object.getHeight());
}
}
shapeRenderer.setColor(Color.BLACK);
for(Button button : buttons){
shapeRenderer.rectLine(button.getxPos(), button.getyPos(), button.getxPos() + button.getWidth(), button.getyPos(), 4);
shapeRenderer.rectLine(button.getxPos(), button.getyPos(), button.getxPos(), button.getyPos() + button.getHeight(), 4);
shapeRenderer.rectLine(button.getxPos(), button.getyPos()+button.getHeight(), button.getxPos()+button.getWidth(), button.getyPos() + button.getHeight(), 4);
shapeRenderer.rectLine(button.getxPos() + button.getWidth(), button.getyPos(),button.getxPos() + button.getWidth(), button.getyPos() + button.getHeight(), 4);
shapeRenderer.end();
batch.begin();
font.getData().setScale(2.4f);
font.draw(batch, button.getText(),button.getxPos() + (float) button.getWidth()/2 - getTextWidth(button.getText())/2, button.getyPos() + (float) button.getHeight()/2 + getTextHeight(button.getText())/2);
batch.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
}
@ -187,6 +232,7 @@ public class Gamescreen{
shapeRenderer.end();
batch.begin();
@ -226,4 +272,23 @@ public class Gamescreen{
public ArrayList<Rectangle> getObjectRectsLeft(){
return objectRectsLeft;
}
public float getTextWidth(String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.width;
}
public float getTextHeight(String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.height;
}
public int touchDown(int x, int y){
Rectangle mouse = new Rectangle(x,y,1,1);
if(Intersector.overlaps(buttons.get(0).getRectangle(), mouse)){
return 0;
}
else{
return -1;
}
}
}

@ -118,31 +118,11 @@ public class Levelscreen{
public void render(SpriteBatch batch, Level level) {
// LEFT - RIGHT BUTTON
if(selectedLevel > 0){
buttonLeft.draw(batch);
}
if(selectedLevel < levelAmount){
buttonRight.draw(batch);
}
// LEVEL NAME
font.getData().setScale(6);
font.draw(batch,"LEVEL: "+ (selectedLevel + 1), GAME_WORLD_WIDTH / 2 - getTextWidth("LEVEL: "+ selectedLevel) / 2, GAME_WORLD_HEIGHT * 0.95f);
font.getData().setScale(2);
font.draw(batch, "click to start ...", GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2, GAME_WORLD_HEIGHT * 0.1f);
batch.end();
// PREVIEW
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
// BORDER
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.15f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.85f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
float previewX = 0.15f * GAME_WORLD_WIDTH;
float previewY = 0.15f * GAME_WORLD_HEIGHT;
@ -170,6 +150,20 @@ public class Levelscreen{
for(Rectangle rect : level.getObjects()){
shapeRenderer.rect(previewX + rect.getX() * 0.7f, previewY + rect.getY() * 0.7f, rect.getWidth() * 0.7f, rect.getHeight() * 0.7f);
}
// OVERDRAWING TOO BIG OBJECTS
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.rect(0, 0, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT * 0.15f );
shapeRenderer.rect(0, 0, GAME_WORLD_WIDTH * 0.15f, GAME_WORLD_HEIGHT );
shapeRenderer.rect(0, GAME_WORLD_HEIGHT * 0.85f, GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT * 0.15f);
shapeRenderer.rect(GAME_WORLD_WIDTH * 0.85f, 0, GAME_WORLD_WIDTH * 0.15f, GAME_WORLD_HEIGHT);
// BORDER
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.15f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.85f * GAME_WORLD_WIDTH, 0.15f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
shapeRenderer.rectLine(0.15f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 0.85f * GAME_WORLD_WIDTH, 0.85f * GAME_WORLD_HEIGHT, 3);
//
// BUTTONS
@ -188,6 +182,21 @@ public class Levelscreen{
shapeRenderer.end();
batch.begin();
// LEFT - RIGHT BUTTON
if(selectedLevel > 0){
buttonLeft.draw(batch);
}
if(selectedLevel < levelAmount){
buttonRight.draw(batch);
}
// LEVEL NAME
font.getData().setScale(6);
font.draw(batch,"LEVEL: "+ (selectedLevel + 1), GAME_WORLD_WIDTH / 2 - getTextWidth("LEVEL: "+ selectedLevel) / 2, GAME_WORLD_HEIGHT * 0.95f);
font.getData().setScale(2);
font.draw(batch, "click to start ...", GAME_WORLD_WIDTH / 2 - getTextWidth("click to start ...") / 2, GAME_WORLD_HEIGHT * 0.1f);
// END
}

Loading…
Cancel
Save