Permalink
Browse files

Separating the logic from the main game class, introducing texture pa…

…cker
  • Loading branch information...
vladimirslav committed Sep 6, 2016
1 parent c37a929 commit d02228f6ecb39fdbf98bb4ad54e57b5fb8f29b73
@@ -0,0 +1,20 @@
game.png
size: 64,32
format: RGBA8888
filter: Nearest,Nearest
repeat: none
ground
rotate: false
xy: 2, 2
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
wall
rotate: false
xy: 20, 2
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -1,33 +1,24 @@
package com.coldwild.dodginghero;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.coldwild.dodginghero.screens.GameScreen;
public class DodgingHero extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
public class DodgingHero extends Game {
public Resources res;
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
@Override
public void dispose () {
batch.dispose();
img.dispose();
}
@Override
public void create () {
res = new Resources();
setScreen(new GameScreen(this));
}
@Override
public void dispose () {
res.dispose();
}
}
@@ -0,0 +1,28 @@
package com.coldwild.dodginghero;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
/**
* Created by comrad_gremlin on 9/6/2016.
*/
public class Resources {
TextureAtlas gameSprites;
public TextureRegion ground;
public TextureRegion wall;
public Resources()
{
gameSprites = new TextureAtlas(Gdx.files.internal("packed/game.atlas"));
ground = gameSprites.findRegion("ground");
wall = gameSprites.findRegion("wall");
}
public void dispose()
{
gameSprites.dispose();
}
}
@@ -0,0 +1,53 @@
package com.coldwild.dodginghero.screens;
import com.badlogic.gdx.Screen;
import com.coldwild.dodginghero.DodgingHero;
/**
* Created by comrad_gremlin on 9/6/2016.
*/
public class DefaultScreen implements Screen {
protected DodgingHero game;
DefaultScreen(DodgingHero _game)
{
game = _game;
}
@Override
public void show() {
}
@Override
public void render(float delta) {
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
@@ -0,0 +1,38 @@
package com.coldwild.dodginghero.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.coldwild.dodginghero.DodgingHero;
/**
* Created by comrad_gremlin on 9/6/2016.
*/
public class GameScreen extends DefaultScreen {
SpriteBatch batch;
public GameScreen(DodgingHero _game) {
super(_game);
batch = new SpriteBatch();
}
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(game.res.ground, 0, 0);
batch.draw(game.res.wall, 0, 16);
batch.end();
}
@Override
public void dispose()
{
batch.dispose();
}
}
@@ -2,11 +2,24 @@
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import com.coldwild.dodginghero.DodgingHero;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new DodgingHero(), config);
}
static void pack()
{
TexturePacker.Settings settings = new TexturePacker.Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.pot = true;
// WORKING DIR: G:\programming\gamedev\libgdx\dodginghero\android\assets
TexturePacker.process(settings, "../../assets", "packed", "game");
}
public static void main (String[] arg) {
pack();
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new DodgingHero(), config);
}
}

0 comments on commit d02228f

Please sign in to comment.