master
GammelJan 6 years ago
parent a9f3bdbe04
commit 5eb77f5074

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

@ -11,12 +11,17 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.MapLayers;
import com.badlogic.gdx.maps.MapObjects;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.dungeoncrawler.view.*;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.DungeonGenerator;
@ -24,11 +29,20 @@ import com.dungeoncrawler.model.entities.*;
import com.dungeoncrawler.model.Entity;
import com.badlogic.gdx.utils.Timer;
import com.dungeoncrawler.model.ItemContainer;
import com.sun.org.apache.xpath.internal.operations.Or;
import java.util.ArrayList;
public class Controller extends ApplicationAdapter implements InputProcessor{
float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT;
// CAMERA
OrthographicCamera camera;
Viewport viewport;
SpriteBatch batch;
Dungeon d;
DungeonGenerator dg;
@ -75,7 +89,13 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override
public void create(){
GAME_WORLD_HEIGHT = 900;
GAME_WORLD_WIDTH = 1600;
camera = new OrthographicCamera();
viewport = new FitViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
viewport.apply();
camera.position.set(GAME_WORLD_WIDTH / 2, GAME_WORLD_HEIGHT / 2, 0);
checkDoor = true;
checkDie = true;
@ -302,19 +322,23 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
}
@Override
public void resize(int width, int height){
viewport.update(width, height);
camera.position.set(GAME_WORLD_WIDTH / 2, GAME_WORLD_HEIGHT / 2, 0);
}
@Override
public void render(){
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(end == true){
if(es == null){
isPaused = true;
entityMovement.stop();
gs.end();
gs.getCamera().update();
batch.setProjectionMatrix(gs.getCamera().combined);
gs = null;
hc = null;
es = new EndScreen(kills);
@ -332,7 +356,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
cs.render(batch);
}
if(ps != null){
ps.render(batch, volume, gs.getCamera());
ps.render(batch, volume, camera);
}
//PASSIERT IN GAMESCREEN
@ -357,8 +381,8 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
// Render methode zum rendern der einzelnen Sprites wird aufgerufen
if(gs != null){;
d.getPlayer().updateItems();
gs.render(batch, d.getPlayer(), d.getCurrentEntities(), tileX, tileY, level, roomPosX, roomPosY);
hc.updateHud(batch, d.getPlayer());
gs.render(batch, d.getPlayer(), d.getCurrentEntities(), tileX, tileY, level, roomPosX, roomPosY, camera);
}
}
@ -709,7 +733,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
d.getPlayer().useItem(d.getPlayer().getInv().getSelected());
}
}
/*
if(keycode == Input.Keys.ESCAPE && !end){
if(gs != null && gs.getIsLoading() == false && isPaused == false){
stop();
@ -718,7 +742,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
resume();
}
}
*/
if(keycode == Input.Keys.LEFT){
if(mm != null){}
if(gs != null && gs.getIsLoading() == false && !d.getPlayer().isToDelete()){
@ -754,7 +778,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
if(mm != null){}
if(gs != null && gs.getIsLoading() == false && !d.getPlayer().isToDelete()){
Entity lol = d.getPlayer().shoot((int) d.getPlayer().getxPos() + 1, (int) d.getPlayer().getyPos());
for(int k = 5; k < d.getCurrentEntities().length; k++){
if(d.getCurrentEntities()[k] == null && gs.player.getSecondaryAttackState() != 1){
d.getCurrentEntities()[k] = lol;
@ -901,13 +925,25 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button)
{
//if(button == Input.Buttons.LEFT){
if(gs == null){
switch(click(screenX, screenY)){
case -1: // -1: nothing hit -- 0: go ingame -- 1: EXIT game -- 2: goto settings -- 3: goto controls -- 4: goto MainMenuScreen -- 9: volume down -- 10: volume up -- 11: restart game
break;
case 0:
mm.cleanUp();
mm = null;
GAME_WORLD_WIDTH = 700;
GAME_WORLD_HEIGHT = 380;
camera = null;
viewport = null;
camera = new OrthographicCamera();
camera.update();
viewport = new FitViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
viewport.apply();
camera.position.set(GAME_WORLD_WIDTH / 2 - 170, GAME_WORLD_HEIGHT / 2 + 20, 0);
camera.update();
batch.setProjectionMatrix(camera.combined);
gs = new GameScreen(d, volume);
gs.generateEntitySprites(d.getCurrentEntities());
hc = new HudContainer();
@ -977,31 +1013,33 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
create();
break;
}
}
if(gs == null){
mm.cleanUp();
mm = null;
gs = new GameScreen(d, volume);
gs.generateEntitySprites(d.getCurrentEntities());
hc = new HudContainer();
gs.startLoadingScreen();
}
else if(gs != null && gs.getIsLoading() == false) {
if (screenX < 0.25 * Gdx.graphics.getWidth()) {
d.getPlayer().setMovementX(-d.getPlayer().getMovementSpeed());
}
else if (screenX > 0.75 * Gdx.graphics.getWidth()) {
d.getPlayer().setMovementX(d.getPlayer().getMovementSpeed());
}
if (screenX > 0.25 * Gdx.graphics.getWidth() && screenX < 0.75 * Gdx.graphics.getWidth() && screenY > 0.5 * Gdx.graphics.getHeight()) {
d.getPlayer().setMovementY(d.getPlayer().getMovementSpeed());
}
else if(screenX > 0.25 * Gdx.graphics.getWidth() && screenX < 0.75 * Gdx.graphics.getWidth() && screenY < 0.5 * Gdx.graphics.getHeight()){
d.getPlayer().setMovementY(-d.getPlayer().getMovementSpeed());
}
if(gs != null){
switch(gs.click(screenX, screenY)){ // -1: nix, 0: left, 1: up, 2: right, 3: down, 4: attackLeft, 5: attackUp, 6: attackRight, 7: attackDown
case 0:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementX(-d.getPlayer().getMovementSpeed());
}
break;
case 1:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementX(d.getPlayer().getMovementSpeed());
}
break;
case 2:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementY(-d.getPlayer().getMovementSpeed());
}
break;
case 3:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementY(d.getPlayer().getMovementSpeed());
}
break;
}
//}
}
return true;
}
@ -1022,19 +1060,53 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
return cs.click(x, y);
}
if(gs != null && isPaused == true){
return gs.click(x,y);
}
return -1;
}
@Override
public boolean touchUp(int i, int i1, int i2, int i3) {
return false;
public boolean touchUp(int screenX, int screenY, int i2, int i3) {
if(gs != null){
if(click(screenX,screenY) == 0 || click(screenX,screenY) == 1 || click(screenX,screenY) == 2 || click(screenX,screenY) == 3){
d.getPlayer().setMovementX(0);
d.getPlayer().setMovementY(0);
d.getPlayer().setMovementX(0);
d.getPlayer().setMovementY(0);
}
}
return true;
}
@Override
public boolean touchDragged(int i, int i1, int i2) {
public boolean touchDragged(int screenX, int screenY, int i2) {
d.getPlayer().setMovementX(0);
d.getPlayer().setMovementY(0);
d.getPlayer().setMovementX(0);
d.getPlayer().setMovementY(0);
switch(click(screenX, screenY)){ // -1: nix, 0: left, 1: up, 2: right, 3: down, 4: attackLeft, 5: attackUp, 6: attackRight, 7: attackDown
case 0:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementX(-d.getPlayer().getMovementSpeed());
}
break;
case 1:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementX(d.getPlayer().getMovementSpeed());
}
break;
case 2:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementY(-d.getPlayer().getMovementSpeed());
}
break;
case 3:
if(!d.getPlayer().isToDelete()){
d.getPlayer().setMovementY(d.getPlayer().getMovementSpeed());
}
break;
}
return false;
}
@ -1061,13 +1133,36 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
entityMovement.stop();
gs.stop();
cs = null;
GAME_WORLD_WIDTH = 1600;
GAME_WORLD_HEIGHT = 900;
camera = null;
viewport = null;
camera = new OrthographicCamera();
camera.update();
viewport = new FitViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
viewport.apply();
camera.position.set(GAME_WORLD_WIDTH / 2, GAME_WORLD_HEIGHT / 2, 0);
camera.update();
ps = new PauseScreen();
}
public void resume(){
GAME_WORLD_WIDTH = 700;
GAME_WORLD_HEIGHT = 380;
camera = null;
viewport = null;
camera = new OrthographicCamera();
camera.update();
viewport = new FitViewport(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera);
viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
viewport.apply();
camera.position.set(GAME_WORLD_WIDTH / 2 - 170, GAME_WORLD_HEIGHT / 2 + 20, 0);
camera.update();
isPaused = false;
entityMovement.start();
gs.resume();
ps = null;
gs.startLoadingScreen();
}

@ -0,0 +1,73 @@
package com.dungeoncrawler.view;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
public class Button {
Sprite sprite;
int xPos;
int yPos;
int width;
int height;
int id;
public Button(String texture, int x, int y, int id) {
this.sprite = new Sprite(new Texture(texture));
this.xPos = x;
this.yPos = y;
this.width = (int) sprite.getWidth();
this.height = (int) sprite.getHeight();
sprite.setX(x);
sprite.setY(y);
this.id = id;
}
public Sprite getSprite() {
return sprite;
}
public void setSprite(Sprite sprite) {
this.sprite = sprite;
}
public int getxPos() {
return xPos;
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
public int getyPos() {
return yPos;
}
public void setyPos(int yPos) {
this.yPos = yPos;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

@ -13,6 +13,7 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Timer;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.Entity;
@ -39,7 +40,6 @@ public class GameScreen {
private Map m;
TiledMapRenderer tmr;
TiledMap tm;
OrthographicCamera camera;
public ArrayList<AnimatedObject> objects;
public ArrayList<AnimatedObject> mapItems;
public ArrayList<AnimatedObject> doors;
@ -65,6 +65,9 @@ public class GameScreen {
public Music music;
//Inventory TEST
// CONTROLS
ArrayList<Button> controls;
float animationSpeed = 0.1f;
@ -102,8 +105,6 @@ public class GameScreen {
float h = Gdx.graphics.getHeight();
m = new Map();
camera = new OrthographicCamera(1, h/w);
camera.translate(175f, 215f);
Texture[] tempTextures = new Texture[d.getLevel().length];
@ -175,10 +176,19 @@ public class GameScreen {
}
}
},0, 0.03f);
// CONTROLS
controls = new ArrayList();
int hudX = -170;
int hudY = 20;
controls.add(new Button("sprites/controls/arrowLeft.png", hudX + 0, hudY + 50, 0));
controls.add(new Button("sprites/controls/arrowUp.png", hudX + 50, hudY + 100, 1));
controls.add(new Button("sprites/controls/arrowRight.png", hudX + 100, hudY + 50, 2));
controls.add(new Button("sprites/controls/arrowDown.png", hudX + 50, hudY + 0, 3));
}
public void render (SpriteBatch batch, Player p, Entity[] e, int tileX, int tileY, int level, int roomPosX, int roomPosY) {
public void render (SpriteBatch batch, Player p, Entity[] e, int tileX, int tileY, int level, int roomPosX, int roomPosY, OrthographicCamera camera) {
entities = e;
@ -210,10 +220,6 @@ public class GameScreen {
tmr.setView(camera);
tmr.render();
camera.zoom = 700f; // Standart 700f
camera.update();
batch.setProjectionMatrix(camera.combined);
updateEntitySprites(e);
ArrayList<EntitySprite> temp = new ArrayList<>();
@ -266,6 +272,10 @@ public class GameScreen {
font.draw(batch, text, dmgContainer[x].getCurrentX(), dmgContainer[x].getCurrentY());
}
}
for(Button button : controls){
button.getSprite().draw(batch);
}
batch.end();
}
@ -496,20 +506,14 @@ public class GameScreen {
}
public void stop(){
camera.zoom = 1600;
camera.translate(625f, 241f);
animations.stop();
animatePlayer.stop();
}
public void resume(){
camera.zoom = 700;
camera.translate(-625f, -241f);
animations.start();
animatePlayer.start();
}
public void end(){
camera.zoom = 1600;
camera.translate(625f, 241f);
animations.stop();
animatePlayer.stop();
cleanUp();
@ -523,8 +527,15 @@ public class GameScreen {
}
}
}
public OrthographicCamera getCamera(){
return camera;
public int click(int x, int y){
x = (int)((float)x / (float)Gdx.graphics.getWidth() * 1600f) - 170;
y = 900-(int)((float)y / Gdx.graphics.getHeight() * 900);
Rectangle mouse = new Rectangle(x,y,1,1);
for(Button button : controls){
if(Intersector.overlaps(mouse, button.getSprite().getBoundingRectangle())){
return button.getId();
}
}
return -1;
}
}

@ -233,4 +233,20 @@ public class HudContainer {
public void setSelected(int i){
selected = i;
}
public float getHudPosX() {
return HudPosX;
}
public void setHudPosX(float hudPosX) {
HudPosX = hudPosX;
}
public float getHudPosY() {
return HudPosY;
}
public void setHudPosY(float hudPosY) {
HudPosY = hudPosY;
}
}

Loading…
Cancel
Save