First Commit
This commit is contained in:
commit
0c9289cf96
98
assets/customPixelFont1.fnt
Normal file
98
assets/customPixelFont1.fnt
Normal file
@ -0,0 +1,98 @@
|
||||
info face="Consolas" size=-11 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=1,2,1,2 spacing=2,2 outline=0
|
||||
common lineHeight=13 base=10 scaleW=256 scaleH=96 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0
|
||||
page id=0 file="customPixelFont1_0.png"
|
||||
chars count=94
|
||||
char id=32 x=150 y=51 width=7 height=15 xoffset=-3 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=33 x=206 y=51 width=5 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=34 x=78 y=51 width=7 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=35 x=45 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=36 x=223 y=0 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=37 x=70 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=38 x=82 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=39 x=199 y=51 width=5 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=40 x=87 y=51 width=7 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=41 x=96 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=42 x=22 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=43 x=190 y=0 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=44 x=69 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=45 x=105 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=46 x=245 y=0 width=6 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=47 x=77 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=48 x=88 y=17 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=49 x=99 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=50 x=110 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=51 x=168 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=52 x=94 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=53 x=178 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=54 x=33 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=55 x=154 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=56 x=165 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=57 x=176 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=58 x=247 y=34 width=6 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=59 x=114 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=60 x=123 y=51 width=7 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=61 x=220 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=62 x=132 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=63 x=188 y=51 width=9 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=64 x=57 y=0 width=11 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=65 x=242 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=66 x=0 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=67 x=208 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=68 x=33 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=69 x=198 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=70 x=20 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=71 x=11 y=34 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=72 x=10 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=73 x=22 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=74 x=138 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=75 x=148 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=76 x=108 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=77 x=166 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=78 x=237 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=79 x=130 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=80 x=44 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=81 x=55 y=34 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=82 x=66 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=83 x=77 y=34 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=84 x=201 y=0 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=85 x=212 y=0 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=86 x=234 y=0 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=87 x=11 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=88 x=106 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=89 x=0 y=0 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=90 x=0 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=91 x=179 y=51 width=7 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=93 x=141 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=94 x=168 y=51 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=95 x=23 y=0 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=96 x=159 y=51 width=7 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=97 x=11 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=98 x=44 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=99 x=188 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=100 x=55 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=101 x=66 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=102 x=178 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=103 x=154 y=0 width=10 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=104 x=128 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=105 x=39 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=106 x=0 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=107 x=59 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=108 x=88 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=109 x=132 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=110 x=98 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=111 x=143 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=112 x=187 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=113 x=198 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=114 x=118 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=115 x=49 y=51 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=116 x=209 y=17 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=117 x=158 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=118 x=231 y=17 width=9 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=119 x=142 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=120 x=118 y=0 width=10 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=121 x=34 y=0 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=122 x=218 y=34 width=8 height=15 xoffset=-1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=123 x=228 y=34 width=7 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=124 x=213 y=51 width=5 height=15 xoffset=1 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=125 x=30 y=51 width=7 height=15 xoffset=0 yoffset=-1 xadvance=6 page=0 chnl=15
|
||||
char id=126 x=121 y=17 width=9 height=15 xoffset=-2 yoffset=-1 xadvance=6 page=0 chnl=15
|
BIN
assets/customPixelFont1_0.png
Normal file
BIN
assets/customPixelFont1_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
107
com/jalenwinslow/game/Handler.java
Normal file
107
com/jalenwinslow/game/Handler.java
Normal file
@ -0,0 +1,107 @@
|
||||
package com.jalenwinslow.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.jalenwinslow.game.gameobjects.GameObject;
|
||||
import com.jalenwinslow.game.gameobjects.GameObjectHandler;
|
||||
import com.jalenwinslow.game.gameobjects.Player;
|
||||
import com.jalenwinslow.game.states.*;
|
||||
import com.jalenwinslow.game.ui.UIDebug;
|
||||
import com.jalenwinslow.game.ui.UIPointer;
|
||||
import com.jalenwinslow.game.ui.UITimer;
|
||||
import com.jalenwinslow.game.utils.Assets;
|
||||
import com.jalenwinslow.game.utils.CamHandler;
|
||||
import com.jalenwinslow.game.utils.Controls;
|
||||
import java.util.Scanner;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class Handler {
|
||||
|
||||
private Main main;
|
||||
private State menuState;
|
||||
private State gameState;
|
||||
private GameObjectHandler goHandler;
|
||||
private CamHandler cam;
|
||||
public Random rand;
|
||||
public Scanner sc;
|
||||
private int time;
|
||||
private float elapsedTime;
|
||||
|
||||
public UIDebug debugger;
|
||||
public UIPointer pointer;
|
||||
public UITimer timer;
|
||||
|
||||
public Handler(Main main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Assets.init();
|
||||
goHandler = new GameObjectHandler(this);
|
||||
cam = new CamHandler(this, main.getCam(), null);
|
||||
rand = new Random();
|
||||
sc = new Scanner(System.in);
|
||||
|
||||
debugger = new UIDebug(this, null, 16, 64, true);
|
||||
pointer = new UIPointer(this, 0, 0, Assets.pointer1, true);
|
||||
timer = new UITimer(this, Assets.timerBG, true);
|
||||
main.getStage().addActor(debugger);
|
||||
main.getStage().addActor(pointer);
|
||||
main.getStage().addActor(timer);
|
||||
|
||||
menuState = new MenuState(this);
|
||||
gameState = new GameState(this);
|
||||
State.setCurrentState(gameState);
|
||||
State.getCurrentState().init(0);
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
elapsedTime += dt;
|
||||
if (elapsedTime >= 1) {
|
||||
time++;
|
||||
elapsedTime--;
|
||||
}
|
||||
|
||||
Controls.update(dt);
|
||||
if (State.getCurrentState() != null) State.getCurrentState().update(dt);
|
||||
if (goHandler != null) goHandler.update(dt);
|
||||
if (cam != null) cam.update(dt);
|
||||
|
||||
debugger.update(dt);
|
||||
timer.update(dt);
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch) {
|
||||
if (State.getCurrentState() != null) State.getCurrentState().render(batch);
|
||||
if (goHandler != null) goHandler.render(batch);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (menuState != null) menuState.dispose(); menuState = null;
|
||||
if (gameState != null) gameState.dispose(); gameState = null;
|
||||
if (goHandler != null) goHandler.dispose(); goHandler = null;
|
||||
Assets.dispose();
|
||||
}
|
||||
|
||||
//Other methods
|
||||
public void addPlayer(Player player) {
|
||||
goHandler.addPlayer(player);
|
||||
}
|
||||
public void addGameObject(GameObject gameObject) { goHandler.addGameObject(gameObject); }
|
||||
|
||||
//Getters and Setters
|
||||
public Main getMain() {return main;}
|
||||
public MenuState getMenuState() {return (MenuState) menuState;}
|
||||
public GameState getGameState() {return (GameState) gameState;}
|
||||
public GameObjectHandler getGoHandler() {return goHandler;}
|
||||
public CamHandler getCam() {return cam;}
|
||||
public int getTime() {return time;}
|
||||
|
||||
public void setTime(int time) {this.time = time;}
|
||||
|
||||
}
|
72
com/jalenwinslow/game/Main.java
Normal file
72
com/jalenwinslow/game/Main.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.jalenwinslow.game;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
public class Main extends ApplicationAdapter {
|
||||
|
||||
public static int SCREEN_WIDTH, SCREEN_HEIGHT;
|
||||
|
||||
SpriteBatch batch;
|
||||
private Handler handler;
|
||||
private Stage stage;
|
||||
private OrthographicCamera cam;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
handler = new Handler(this);
|
||||
|
||||
stage = new Stage(new ScreenViewport(), batch);
|
||||
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
|
||||
|
||||
SCREEN_WIDTH = Gdx.graphics.getWidth()/12; //Original is divided by 10
|
||||
SCREEN_HEIGHT = Gdx.graphics.getHeight()/12;
|
||||
|
||||
cam = new OrthographicCamera(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
cam.setToOrtho(false, cam.viewportWidth, cam.viewportHeight);
|
||||
handler.init();
|
||||
|
||||
cam.update();
|
||||
}
|
||||
|
||||
public void resize() {
|
||||
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
cam.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
|
||||
//Update
|
||||
handler.update(Gdx.graphics.getDeltaTime());
|
||||
|
||||
cam.update();
|
||||
batch.setProjectionMatrix(cam.combined);
|
||||
|
||||
//Render
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
batch.begin();
|
||||
handler.render(batch);
|
||||
batch.end();
|
||||
|
||||
//GUI Render (Stage)
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
handler.dispose();
|
||||
batch.dispose();
|
||||
stage.dispose();
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Stage getStage() {return stage;}
|
||||
public OrthographicCamera getCam() {return cam;}
|
||||
}
|
52
com/jalenwinslow/game/gameobjects/GameObject.java
Normal file
52
com/jalenwinslow/game/gameobjects/GameObject.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.jalenwinslow.game.gameobjects;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/16/2018.
|
||||
*/
|
||||
|
||||
public abstract class GameObject {
|
||||
|
||||
protected Handler handler;
|
||||
protected Vector2 pos;
|
||||
protected float depth;
|
||||
protected TextureRegion image;
|
||||
protected Rectangle bounds;
|
||||
|
||||
public GameObject(Handler handler, float x, float y, Texture image) {
|
||||
this.handler = handler;
|
||||
this.pos = new Vector2(x, y);
|
||||
this.depth = y;
|
||||
if (image != null) this.image = new TextureRegion(image);
|
||||
else this.image = null;
|
||||
this.bounds = new Rectangle();
|
||||
}
|
||||
|
||||
public abstract void init(int initState);
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
public boolean hasCollided(float x, float y) {
|
||||
return (x < bounds.x + bounds.width && x > bounds.x && y < bounds.y + bounds.height && y > bounds.y);
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Vector2 getPos() {return pos;}
|
||||
public float getDepth() {return depth;}
|
||||
public TextureRegion getImage() {return image;}
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
|
||||
public void setPos(Vector2 pos) {this.pos = pos;}
|
||||
public void setPos(float x, float y) {this.pos.set(x, y);}
|
||||
public void setDepth(float depth) {this.depth = depth;}
|
||||
public void setImage(TextureRegion image) {this.image = image;}
|
||||
public void setBounds(Rectangle bounds) {this.bounds = bounds;}
|
||||
|
||||
}
|
78
com/jalenwinslow/game/gameobjects/GameObjectHandler.java
Normal file
78
com/jalenwinslow/game/gameobjects/GameObjectHandler.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.jalenwinslow.game.gameobjects;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/16/2018.
|
||||
*/
|
||||
|
||||
public class GameObjectHandler {
|
||||
|
||||
private Handler handler;
|
||||
private Array<GameObject> gameObjects;
|
||||
private Player player;
|
||||
private Maze maze;
|
||||
|
||||
public GameObjectHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
this.gameObjects = new Array<GameObject>();
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
gameObjects.get(i).update(dt);
|
||||
}
|
||||
handler.debugger.msg = "gameobjects " + gameObjects.size;
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch) {
|
||||
sortGameObjects();
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
gameObjects.get(i).render(batch);
|
||||
batch.setColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
for (GameObject go: gameObjects) go.dispose();;
|
||||
gameObjects.clear();
|
||||
player = null;
|
||||
}
|
||||
|
||||
private void sortGameObjects() {
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
if (i+1 < gameObjects.size && gameObjects.get(i+1) != null) {
|
||||
if (gameObjects.get(i).getDepth() < gameObjects.get(i+1).getDepth()) {
|
||||
gameObjects.swap(i, i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addGameObject(GameObject gameObject) {
|
||||
gameObjects.add(gameObject);
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.player = player;
|
||||
gameObjects.add(player);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
gameObjects.removeValue(player, false);
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
public void removeGameObject(GameObject gameObject) {
|
||||
gameObjects.removeValue(gameObject, false);
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Array<GameObject> getGameObjects() {return gameObjects;}
|
||||
public Player getPlayer() {return player;}
|
||||
public Maze getMaze() {return maze;}
|
||||
|
||||
public void setMaze(Maze maze) {this.maze = maze;}
|
||||
}
|
60
com/jalenwinslow/game/sprite/Sprite.java
Normal file
60
com/jalenwinslow/game/sprite/Sprite.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.jalenwinslow.game.sprite;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/18/2018.
|
||||
*/
|
||||
|
||||
public abstract class Sprite {
|
||||
|
||||
protected Handler handler;
|
||||
protected Rectangle bounds;
|
||||
protected boolean manual;
|
||||
protected GameObject gameObj;
|
||||
|
||||
protected TextureRegion texture;
|
||||
protected TextureRegion[] frames;
|
||||
protected TextureRegion currentFrame;
|
||||
protected int currentFrameIndex;
|
||||
protected float fps;
|
||||
|
||||
public Sprite(Handler handler, TextureRegion texture, float x, float y, float width, float height, boolean manual, GameObject gameObj) {
|
||||
this.handler = handler;
|
||||
this.texture = texture;
|
||||
this.bounds = new Rectangle(x, y, width, height);
|
||||
this.manual = manual;
|
||||
this.gameObj = gameObj;
|
||||
|
||||
currentFrame = new TextureRegion();
|
||||
frames = new TextureRegion[0];
|
||||
currentFrameIndex = 0;
|
||||
fps = 10.0f;
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
//Getters and Setters
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
public boolean isManual() {return manual;}
|
||||
public GameObject getGameObj() {return gameObj;}
|
||||
public TextureRegion getTexture() {return texture;}
|
||||
public TextureRegion getCurrentFrame() {return currentFrame;}
|
||||
public TextureRegion[] getFrames() {return frames;}
|
||||
public int getCurrentFrameIndex() {return currentFrameIndex;}
|
||||
public float getFps() {return fps;}
|
||||
|
||||
public void setManual(boolean manual) {this.manual = manual;}
|
||||
public void setGameObj(GameObject gameObj) {this.gameObj = gameObj;}
|
||||
public void setTexture(TextureRegion image) {this.texture = image;}
|
||||
public void setFrames(TextureRegion[] frames) {this.frames = frames;}
|
||||
public void setCurrentFrameIndex(int index) {this.currentFrameIndex = index;}
|
||||
public void setFps(int fps) {this.fps = fps;}
|
||||
}
|
41
com/jalenwinslow/game/states/GameState.java
Normal file
41
com/jalenwinslow/game/states/GameState.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.MazeGenerator;
|
||||
import com.jalenwinslow.game.gameobjects.Player;
|
||||
import com.jalenwinslow.game.gameobjects.Tile;
|
||||
import com.jalenwinslow.game.utils.Assets;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class GameState extends State {
|
||||
|
||||
|
||||
public GameState(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int initState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
36
com/jalenwinslow/game/states/MenuState.java
Normal file
36
com/jalenwinslow/game/states/MenuState.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class MenuState extends State {
|
||||
|
||||
|
||||
public MenuState(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int initState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
32
com/jalenwinslow/game/states/State.java
Normal file
32
com/jalenwinslow/game/states/State.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/--.
|
||||
*/
|
||||
|
||||
public abstract class State {
|
||||
|
||||
protected Handler handler;
|
||||
private static State currentState = null, previousState = null;
|
||||
|
||||
public State(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public abstract void init(int initState);
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
//Getters and Setters
|
||||
public static State getCurrentState() {return currentState;}
|
||||
public static State getPreviousState() {return previousState;}
|
||||
|
||||
public static void setCurrentState(State state) {
|
||||
State.previousState = State.currentState;
|
||||
State.currentState = state;
|
||||
}
|
||||
}
|
43
com/jalenwinslow/game/ui/UIDebug.java
Normal file
43
com/jalenwinslow/game/ui/UIDebug.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.jalenwinslow.game.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.utils.Assets;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class UIDebug extends UIObject {
|
||||
|
||||
//private BitmapFont font;
|
||||
public String msg;
|
||||
private String debugMsg;
|
||||
|
||||
public UIDebug(Handler handler, Texture texture, float x, float y, boolean visible) {
|
||||
super(handler, texture, x, y, visible);
|
||||
//font = new BitmapFont(Gdx.files.internal(Assets.customPixelFont1));
|
||||
//font.setColor(1, 0, 0, 1);
|
||||
//font.getData().scale(2f);
|
||||
msg = "";
|
||||
debugMsg = "Debugger: ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
debugMsg = "Debugger(FPS:" + Gdx.graphics.getFramesPerSecond() + "): " + msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
//font.draw(batch, debugMsg, pos.x, pos.y);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
//font.dispose();
|
||||
remove();
|
||||
}
|
||||
}
|
45
com/jalenwinslow/game/ui/UIObject.java
Normal file
45
com/jalenwinslow/game/ui/UIObject.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.jalenwinslow.game.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/19/2018.
|
||||
*/
|
||||
|
||||
public abstract class UIObject extends Actor {
|
||||
|
||||
protected Handler handler;
|
||||
protected Texture texture;
|
||||
protected Vector2 pos;
|
||||
//protected boolean visible;
|
||||
protected Rectangle bounds;
|
||||
|
||||
public UIObject(Handler handler, Texture texture, float x, float y, boolean visible) {
|
||||
this.handler = handler;
|
||||
this.texture = texture;
|
||||
this.pos = new Vector2(x, y);
|
||||
this.setVisible(visible);
|
||||
this.bounds = new Rectangle();
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
@Override
|
||||
public abstract void draw(Batch batch, float parentAlpha);
|
||||
|
||||
//Getters and Setters
|
||||
public Texture getTexture() {return texture;}
|
||||
public Vector2 getPos() {return pos;}
|
||||
public float getPosX() {return pos.x;}
|
||||
public float getPosY() {return pos.y;}
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
|
||||
public void setTexture(Texture texture) {this.texture = texture;}
|
||||
public void setPos(float x, float y) {pos.set(x, y);}
|
||||
public void setBounds(Rectangle bounds) {this.bounds = bounds;}
|
||||
}
|
23
com/jalenwinslow/game/utils/Assets.java
Normal file
23
com/jalenwinslow/game/utils/Assets.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Files;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class Assets {
|
||||
|
||||
|
||||
|
||||
public static void init() {
|
||||
|
||||
}
|
||||
|
||||
public static void dispose() {
|
||||
|
||||
}
|
||||
}
|
63
com/jalenwinslow/game/utils/CamHandler.java
Normal file
63
com/jalenwinslow/game/utils/CamHandler.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class CamHandler {
|
||||
|
||||
private Handler handler;
|
||||
private OrthographicCamera cam;
|
||||
private float x, y;
|
||||
private float speed, acceleration;
|
||||
private GameObject objOfFocus;
|
||||
private boolean manual;
|
||||
|
||||
public CamHandler(Handler handler, OrthographicCamera cam, GameObject objOfFocus) {
|
||||
this.handler = handler;
|
||||
this.cam = cam;
|
||||
speed = 5;
|
||||
acceleration = 0;
|
||||
this.objOfFocus = objOfFocus;
|
||||
manual = false;
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
|
||||
if (objOfFocus != null && !manual) {
|
||||
x = objOfFocus.getPos().x;
|
||||
y = objOfFocus.getPos().y;
|
||||
}
|
||||
|
||||
//check collision out of game area
|
||||
gameSidesCollision();
|
||||
|
||||
//Update camera
|
||||
cam.position.set(x, y, 0);
|
||||
}
|
||||
|
||||
private void gameSidesCollision() {
|
||||
if (x - Gdx.graphics.getWidth()/24 < 0) {x = Gdx.graphics.getWidth()/24;} // check left side of screen
|
||||
if (x + Gdx.graphics.getWidth()/24 > handler.getGoHandler().getMaze().getMazeWidth()) {
|
||||
x = handler.getGoHandler().getMaze().getMazeWidth() - Gdx.graphics.getWidth()/24;
|
||||
}
|
||||
if (y - Gdx.graphics.getHeight()/24 < 0) {y = Gdx.graphics.getHeight()/24;}
|
||||
if (y + Gdx.graphics.getHeight()/24 >= handler.getGoHandler().getMaze().getMazeHeight()) {
|
||||
y = handler.getGoHandler().getMaze().getMazeHeight() - Gdx.graphics.getHeight()/24;
|
||||
}
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public OrthographicCamera getCamera() {return cam;}
|
||||
public GameObject getObjOfFocus() {return objOfFocus;}
|
||||
public boolean isManual() {return manual;}
|
||||
|
||||
public void setCamera(OrthographicCamera cam) {this.cam = cam;}
|
||||
public void setObjOfFocus(GameObject objOfFocus) {this.objOfFocus = objOfFocus;}
|
||||
public void setManual(boolean manual) {this.manual = manual;}
|
||||
}
|
16
com/jalenwinslow/game/utils/Controls.java
Normal file
16
com/jalenwinslow/game/utils/Controls.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
/**
|
||||
* Updated by jalen on 6/17/2018.
|
||||
*/
|
||||
|
||||
public class Controls {
|
||||
|
||||
|
||||
public static void update(float dt) {
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user