initial commit
commit
c5cb8373ab
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 257 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 309 B |
@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.0" orientation="orthogonal" renderorder="right-up" width="50" height="50" tilewidth="16" tileheight="16" nextobjectid="66">
|
||||
<tileset firstgid="1" name="env" tilewidth="16" tileheight="16" tilecount="64" columns="8">
|
||||
<image source="env.png" width="128" height="128"/>
|
||||
</tileset>
|
||||
<layer name="Tile Layer 1" width="50" height="50">
|
||||
<data encoding="csv">
|
||||
0,0,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,0,0,20,20,20,20,20,20,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,20,4,16,6,8,6,8,6,15,8,6,8,6,8,16,4,20,0,4,16,4,4,4,16,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,20,1,1,1,1,1,1,1,0,20,20,20,20,20,20,20,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1,1,1,0,4,5,12,13,13,14,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,
|
||||
20,20,20,20,20,20,20,20,12,13,14,20,20,20,20,20,20,20,20,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,
|
||||
3,4,16,4,16,4,16,6,7,15,7,8,16,4,16,4,16,4,5,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup name="collisions">
|
||||
<object id="2" x="112" y="272" width="240" height="40"/>
|
||||
<object id="3" x="288" y="256" width="144" height="40"/>
|
||||
<object id="4" x="416" y="288" width="64" height="24"/>
|
||||
<object id="5" x="304" y="400" width="64" height="24"/>
|
||||
<object id="6" x="400" y="400" width="64" height="24"/>
|
||||
<object id="7" x="432" y="48" width="128" height="24"/>
|
||||
<object id="10" x="160" y="352" width="192" height="40"/>
|
||||
<object id="11" x="352" y="368" width="16" height="32"/>
|
||||
<object id="12" x="400" y="368" width="16" height="32"/>
|
||||
<object id="13" x="416" y="352" width="160" height="40"/>
|
||||
<object id="14" x="512" y="240" width="96" height="72"/>
|
||||
<object id="15" x="416" y="0" width="16" height="184"/>
|
||||
<object id="16" x="432" y="240" width="48" height="48"/>
|
||||
<object id="17" x="560" y="80" width="32" height="160"/>
|
||||
<object id="18" x="256" y="384" width="48" height="176"/>
|
||||
<object id="20" x="464" y="384" width="32" height="192"/>
|
||||
<object id="22" x="336" y="560" width="96" height="40"/>
|
||||
<object id="24" x="16" y="352" width="112" height="40"/>
|
||||
<object id="25" x="0" y="544" width="64" height="40"/>
|
||||
<object id="26" x="0" y="0" width="16" height="544"/>
|
||||
<object id="28" x="96" y="544" width="112" height="40"/>
|
||||
<object id="29" x="240" y="544" width="48" height="40"/>
|
||||
<object id="30" x="144" y="560" width="16" height="72"/>
|
||||
<object id="31" x="288" y="576" width="16" height="56"/>
|
||||
<object id="32" x="336" y="592" width="32" height="104"/>
|
||||
<object id="33" x="336" y="736" width="32" height="64"/>
|
||||
<object id="34" x="368" y="768" width="256" height="32"/>
|
||||
<object id="35" x="592" y="576" width="32" height="104"/>
|
||||
<object id="37" x="-16" y="800" width="352" height="16"/>
|
||||
<object id="38" x="-16" y="528" width="16" height="272"/>
|
||||
<object id="40" x="0" y="688" width="304" height="72"/>
|
||||
<object id="41" x="144" y="672" width="16" height="16"/>
|
||||
<object id="42" x="288" y="672" width="16" height="16"/>
|
||||
<object id="43" x="464" y="560" width="160" height="40"/>
|
||||
<object id="44" x="32" y="0" width="240" height="24"/>
|
||||
<object id="45" x="304" y="0" width="112" height="24"/>
|
||||
<object id="46" x="16" y="144" width="112" height="40"/>
|
||||
<object id="47" x="160" y="144" width="128" height="40"/>
|
||||
<object id="48" x="16" y="128" width="16" height="16"/>
|
||||
<object id="49" x="272" y="128" width="16" height="16"/>
|
||||
<object id="50" x="416" y="224" width="16" height="32"/>
|
||||
<object id="51" x="288" y="112" width="16" height="88"/>
|
||||
<object id="52" x="288" y="240" width="16" height="16"/>
|
||||
<object id="53" x="304" y="112" width="48" height="40"/>
|
||||
<object id="54" x="384" y="112" width="32" height="40"/>
|
||||
<object id="55" x="16" y="0" width="16" height="40"/>
|
||||
<object id="56" x="272" y="0" width="16" height="40"/>
|
||||
<object id="57" x="288" y="-16" width="16" height="88"/>
|
||||
<object id="59" x="592" y="720" width="32" height="64"/>
|
||||
<object id="60" x="624" y="784" width="176" height="16"/>
|
||||
<object id="61" x="800" y="352" width="32" height="448"/>
|
||||
<object id="63" x="608" y="352" width="192" height="40"/>
|
||||
<object id="65" x="608" y="240" width="48" height="112"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
@ -0,0 +1,143 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.maps.MapLayer;
|
||||
import com.badlogic.gdx.maps.MapObject;
|
||||
import com.badlogic.gdx.maps.objects.RectangleMapObject;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
|
||||
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
||||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class ChuckGame extends ApplicationAdapter implements InputProcessor{
|
||||
Graphics graphics;
|
||||
EntityPlayer player;
|
||||
ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||
Comparator<Entity> zSorter;
|
||||
TiledMap tiledMap;
|
||||
TiledMapRenderer tmRenderer;
|
||||
ArrayList<Rectangle> collisions = new ArrayList<Rectangle>();
|
||||
@Override
|
||||
public void create () {
|
||||
Gdx.input.setInputProcessor(this);
|
||||
graphics = new Graphics();
|
||||
player = new EntityPlayer();
|
||||
entities.add(new EntityBox(20, 20));
|
||||
entities.add(new EntityBox(100, 100));
|
||||
entities.add(player);
|
||||
zSorter = new Comparator<Entity>(){
|
||||
|
||||
public int compare(Entity arg0, Entity arg1) {
|
||||
return (int) Math.signum(arg1.position.y - arg0.position.y);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
tiledMap = new TmxMapLoader().load("testmap.tmx");
|
||||
tmRenderer = new OrthogonalTiledMapRenderer(tiledMap);
|
||||
|
||||
MapLayer ml = tiledMap.getLayers().get("collisions");
|
||||
for(MapObject o: ml.getObjects()){
|
||||
RectangleMapObject rmo = (RectangleMapObject) o;
|
||||
Rectangle r = new Rectangle(rmo.getRectangle());
|
||||
collisions.add(r);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
|
||||
// player.update(Gdx.graphics.getDeltaTime(), entities);
|
||||
for(Entity e: entities){
|
||||
e.update(Gdx.graphics.getDeltaTime(), entities, collisions);
|
||||
}
|
||||
Collections.sort(entities, zSorter);
|
||||
|
||||
// graphics.cam.lookAt(player.position.x, player.position.y, 0);
|
||||
graphics.cam.position.x = player.position.x + 8;
|
||||
graphics.cam.position.y = player.position.y + 8;
|
||||
|
||||
graphics.cam.update();
|
||||
|
||||
|
||||
graphics.prepare();
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
tmRenderer.setView(graphics.cam);
|
||||
tmRenderer.render();
|
||||
graphics.startSprite();
|
||||
|
||||
|
||||
// player.draw(graphics);
|
||||
for(Entity e: entities){
|
||||
if(e.shouldDrawSelf)
|
||||
e.draw(graphics);
|
||||
}
|
||||
graphics.endSprite();
|
||||
// graphics.endShapes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
player.controller.acceptEvent(keycode, true, player, entities);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyUp(int keycode) {
|
||||
player.controller.acceptEvent(keycode, false, player, entities);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char character) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseMoved(int screenX, int screenY) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scrolled(int amount) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
public abstract class Entity {
|
||||
public Vector2 position = new Vector2();
|
||||
public Vector2 velocity = new Vector2();
|
||||
public EntityController controller;
|
||||
public Rectangle collision;
|
||||
float flyLength;
|
||||
public boolean isChuckable = true;
|
||||
boolean shouldDrawSelf = true;
|
||||
public Entity(){
|
||||
|
||||
}
|
||||
public abstract void update(float delta, ArrayList<Entity> entities, ArrayList<Rectangle> collisions);
|
||||
protected void doCollisions(float delta, ArrayList<Rectangle> collisions){
|
||||
position.x += velocity.x * delta;
|
||||
|
||||
collision.x = position.x;
|
||||
|
||||
for(Rectangle r: collisions){
|
||||
if(r.overlaps(collision)){
|
||||
if(velocity.x > 0){
|
||||
float overlap = collision.x + collision.width - r.x;
|
||||
position.x -= overlap;
|
||||
velocity.x = 0;
|
||||
} else if(velocity.x < 0){
|
||||
float overlap = r.x + r.width - collision.x;
|
||||
position.x += overlap;
|
||||
velocity.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
collision.x = position.x;
|
||||
|
||||
|
||||
position.y += velocity.y * delta;
|
||||
|
||||
collision.y = position.y;
|
||||
|
||||
for(Rectangle r: collisions){
|
||||
if(r.overlaps(collision)){
|
||||
if(velocity.y > 0){
|
||||
float overlap = collision.y + collision.height - r.y;
|
||||
position.y -= overlap;
|
||||
velocity.y = 0;
|
||||
} else if(velocity.y < 0){
|
||||
float overlap = r.y + r.height - collision.y;
|
||||
position.y += overlap;
|
||||
velocity.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
collision.y = position.y;
|
||||
}
|
||||
public abstract void draw(Graphics g);
|
||||
public void draw(Graphics g, float dx, float dy){
|
||||
draw(g);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class EntityBox extends Entity{
|
||||
float decel = 25;
|
||||
Texture crate = new Texture("crate.png");
|
||||
Texture shadow = new Texture("shadow.png");
|
||||
|
||||
public EntityBox(float x, float y){
|
||||
super();
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
collision = new Rectangle(x, y, 16, 16);
|
||||
}
|
||||
public void update(float delta, ArrayList<Entity> entities, ArrayList<Rectangle> collisions) {
|
||||
flyLength -= delta;
|
||||
if(flyLength <= 0)
|
||||
velocity.mulAdd(velocity, -delta * decel);
|
||||
doCollisions(delta, collisions);
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
// g.getShapes().setColor(Color.BLUE);
|
||||
// g.getShapes().rect(position.x, position.y + (float)Math.sin((1 - Math.max(flyLength, 0) / .5f) * Math.PI) * 8, 16, 16);
|
||||
draw(g, 0, 0);
|
||||
|
||||
}
|
||||
public void draw(Graphics g, float dx, float dy){
|
||||
if(flyLength >= 0){
|
||||
g.getBatch().draw(shadow, position.x, position.y-1);
|
||||
}
|
||||
float flyPerc = (Math.max(flyLength, 0) / .5f);
|
||||
if(flyPerc > 0)
|
||||
g.getBatch().draw(crate, position.x +dx, position.y + (float)Math.abs(Math.cos((1 - flyPerc) * (Math.PI * 3f / 4f) - (Math.PI / 4f))) * 15 + dy);
|
||||
else g.getBatch().draw(crate, position.x + dx, position.y + dy);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface EntityController {
|
||||
public void acceptEvent(int keycode, boolean newState, Entity owner, ArrayList<Entity> entities);
|
||||
}
|
||||
@ -0,0 +1,185 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
public class EntityPlayer extends Entity{
|
||||
Texture playerArt = new Texture("player.png");
|
||||
TextureRegion[] sprites = new TextureRegion[8];
|
||||
float moveSpeed = 100;
|
||||
float throwSpeed = 100;
|
||||
Entity holding;
|
||||
Vector2 lastVelocity;
|
||||
int lastDirectionalUsed;
|
||||
int lastXDirectional, lastYDirectional;
|
||||
private ArrayList<Integer> directionals = new ArrayList<Integer>();//Don't think I'll use this
|
||||
private boolean[] arrowKeys = new boolean[4]; //UDLR
|
||||
public EntityPlayer(){
|
||||
isChuckable = false;
|
||||
for(int i = 0;i < 4;i++){
|
||||
sprites[i] = new TextureRegion(playerArt, i * 16, 0, 16, 16);
|
||||
sprites[i + 4] = new TextureRegion(playerArt, i * 16, 16, 16,16);
|
||||
}
|
||||
lastVelocity = new Vector2();
|
||||
collision = new Rectangle(0, 0, 16, 16);
|
||||
controller = new EntityController(){
|
||||
|
||||
public void acceptEvent(int keycode, boolean newState, Entity owner, ArrayList<Entity> entities) {
|
||||
|
||||
|
||||
if(newState){
|
||||
switch(keycode){
|
||||
case Keys.SPACE:
|
||||
if(holding == null)
|
||||
for(Entity e: entities){
|
||||
if(e.collision.overlaps(collision) && e.isChuckable){
|
||||
holding = e;
|
||||
holding.shouldDrawSelf = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
holding.velocity.add(velocity).mulAdd(getDirectionalVector(), throwSpeed);
|
||||
holding.flyLength = .5f;
|
||||
holding.shouldDrawSelf = true;
|
||||
|
||||
holding = null;
|
||||
}
|
||||
}
|
||||
if(keycode == Keys.UP || keycode == Keys.DOWN || keycode == Keys.LEFT || keycode == Keys.RIGHT){
|
||||
lastDirectionalUsed = keycode;
|
||||
directionals.add(keycode - Keys.UP);
|
||||
arrowKeys[keycode - Keys.UP] = newState;
|
||||
}
|
||||
if(Math.abs(velocity.x) > 0)
|
||||
lastVelocity.x = velocity.x;
|
||||
if(Math.abs(velocity.y) > 0)
|
||||
lastVelocity.y = velocity.y;
|
||||
|
||||
} else {
|
||||
if(keycode == Keys.UP || keycode == Keys.DOWN || keycode == Keys.LEFT || keycode == Keys.RIGHT){
|
||||
directionals.remove(new Integer(keycode - Keys.UP));
|
||||
arrowKeys[keycode - Keys.UP] = newState;
|
||||
}
|
||||
|
||||
switch(keycode){
|
||||
case Keys.LEFT:
|
||||
case Keys.RIGHT:
|
||||
case Keys.UP:
|
||||
case Keys.DOWN:
|
||||
int t = getNewerPressEvent(getNewerPressEvent(0, 1), getNewerPressEvent(2, 3));
|
||||
if (t < 0){
|
||||
lastDirectionalUsed = keycode;
|
||||
} else
|
||||
lastDirectionalUsed = Keys.UP + t;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
private int getNewerPressEvent(int i, int j){
|
||||
for(int k = directionals.size() - 1;k >= 0;k--){
|
||||
if(directionals.get(k).equals(i)) return i;
|
||||
if(directionals.get(k).equals(j)) return j;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
private void doControls(ArrayList<Entity> entities){
|
||||
for(int i = 0;i < 4;i++){
|
||||
switch(i){
|
||||
case 0: //UP
|
||||
if(getNewerPressEvent(0, 1) == 0)
|
||||
velocity.y = moveSpeed;
|
||||
break;
|
||||
case 1: //DOWN
|
||||
if(!arrowKeys[0] && !arrowKeys[1]){
|
||||
//no up/down directions are pressed
|
||||
velocity.y = 0;
|
||||
break;
|
||||
}
|
||||
if(getNewerPressEvent(0, 1) == 1)
|
||||
velocity.y = -moveSpeed;
|
||||
break;
|
||||
case 2: //LEFT
|
||||
if(getNewerPressEvent(2, 3) == 2)
|
||||
velocity.x = -moveSpeed;
|
||||
break;
|
||||
case 3: //RIGHT
|
||||
if(!arrowKeys[2] && !arrowKeys[3]){
|
||||
velocity.x = 0;
|
||||
}
|
||||
if(getNewerPressEvent(2,3) == 3)
|
||||
velocity.x = moveSpeed;
|
||||
break;
|
||||
}
|
||||
if(Math.abs(velocity.x) > 0 && Math.abs(velocity.y) > 0){
|
||||
velocity.x = Math.signum(velocity.x) * ((float)Math.sqrt(2) / 2f) * moveSpeed;
|
||||
velocity.y = Math.signum(velocity.y) * ((float)Math.sqrt(2) / 2f) * moveSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void update(float delta, ArrayList<Entity> entities, ArrayList<Rectangle> collisions){
|
||||
|
||||
//test array based controls
|
||||
|
||||
doControls(entities);
|
||||
|
||||
|
||||
|
||||
doCollisions(delta, collisions);
|
||||
|
||||
|
||||
if(holding != null){
|
||||
holding.position.x = position.x;
|
||||
holding.position.y = position.y;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
g.getBatch().draw(pickSprite(), position.x, position.y);
|
||||
if(holding != null){
|
||||
holding.draw(g, 0, 12);
|
||||
}
|
||||
}
|
||||
private TextureRegion pickSprite(){
|
||||
switch(lastDirectionalUsed){
|
||||
case Keys.UP:
|
||||
return sprites[2 + (holding != null ? 4 : 0)];
|
||||
case Keys.LEFT:
|
||||
return sprites[1 + (holding != null ? 4 : 0)];
|
||||
case Keys.DOWN:
|
||||
return sprites[0 + (holding != null ? 4 : 0)];
|
||||
case Keys.RIGHT:
|
||||
return sprites[3 + (holding != null ? 4 : 0)];
|
||||
}
|
||||
return sprites[0];
|
||||
|
||||
}
|
||||
private Vector2 getDirectionalVector(){
|
||||
switch(lastDirectionalUsed){
|
||||
case Keys.UP:
|
||||
return new Vector2(0, 1);
|
||||
case Keys.LEFT:
|
||||
return new Vector2(-1, 0);
|
||||
case Keys.DOWN:
|
||||
return new Vector2(0, -1);
|
||||
case Keys.RIGHT:
|
||||
return new Vector2(1, 0);
|
||||
}
|
||||
return new Vector2(0, -1);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.toasted.chuck;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
|
||||
public class Graphics {
|
||||
private SpriteBatch spriteBatch;
|
||||
private ShapeRenderer shapeRenderer;
|
||||
OrthographicCamera cam;
|
||||
public Graphics(){
|
||||
cam = new OrthographicCamera();
|
||||
spriteBatch = new SpriteBatch();
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
|
||||
cam.setToOrtho(false, 16 * 32, 9 * 32);
|
||||
|
||||
}
|
||||
public int getWidth(){
|
||||
return Gdx.graphics.getWidth();
|
||||
}
|
||||
public int getHeight(){
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
public void startShapes(ShapeType shapeType){
|
||||
shapeRenderer.begin(shapeType);
|
||||
}
|
||||
public void endShapes(){
|
||||
shapeRenderer.end();
|
||||
}
|
||||
public void startSprite(){
|
||||
spriteBatch.begin();
|
||||
}
|
||||
public void endSprite(){
|
||||
spriteBatch.end();
|
||||
}
|
||||
public SpriteBatch getBatch(){
|
||||
return spriteBatch;
|
||||
}
|
||||
public ShapeRenderer getShapes(){
|
||||
return shapeRenderer;
|
||||
}
|
||||
public void prepare(){
|
||||
shapeRenderer.setProjectionMatrix(cam.combined);
|
||||
spriteBatch.setProjectionMatrix(cam.combined);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.toasted.chuck.desktop;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||
import com.toasted.chuck.ChuckGame;
|
||||
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||
config.width = 1280;
|
||||
config.height = 720;
|
||||
new LwjglApplication(new ChuckGame(), config);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue