Skip to content

Commit

Permalink
Introducing the warning (sign that is used on the base before attack)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirslav committed Sep 9, 2016
1 parent 0b41d62 commit 4a2ff24
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 1 deletion.
9 changes: 8 additions & 1 deletion android/assets/packed/game.atlas
@@ -1,6 +1,6 @@

game.png
size: 64,32
size: 128,32
format: RGBA8888
filter: Nearest,Nearest
repeat: none
Expand Down Expand Up @@ -32,3 +32,10 @@ wall
orig: 16, 16
offset: 0, 0
index: -1
warning
rotate: false
xy: 56, 6
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
Binary file modified android/assets/packed/game.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/warning.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions core/src/com/coldwild/dodginghero/Resources.java
Expand Up @@ -17,6 +17,7 @@ public class Resources {

public Sprite player;
public TextureRegion base;
public TextureRegion warning;

public static final int TILE_SIZE = 16;

Expand All @@ -28,6 +29,7 @@ public Resources()

player = new Sprite(gameSprites.findRegion("player"));
base = gameSprites.findRegion("base");
warning = gameSprites.findRegion("warning");
}

public void dispose()
Expand Down
45 changes: 45 additions & 0 deletions core/src/com/coldwild/dodginghero/graph/effects/Effect.java
@@ -0,0 +1,45 @@
package com.coldwild.dodginghero.graph.effects;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Pool;

/**
* Created by comrad_gremlin on 9/9/2016.
*/
public abstract class Effect implements Pool.Poolable {

protected boolean isAlive;
protected float timeAlive;

public Effect()
{
isAlive = false;
timeAlive = 0;
}

@Override
public void reset() {

}

public void init(EffectEngine parent)
{
isAlive = true;
timeAlive = 0;
parent.add(this);
}

public void update(float delta)
{
timeAlive += delta;
}

public abstract void draw(SpriteBatch batch);

public boolean isAlive()
{
return isAlive;
}

public abstract void release();
}
58 changes: 58 additions & 0 deletions core/src/com/coldwild/dodginghero/graph/effects/EffectEngine.java
@@ -0,0 +1,58 @@
package com.coldwild.dodginghero.graph.effects;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import java.util.ArrayList;
import java.util.List;

/**
* Created by comrad_gremlin on 9/9/2016.
*/
public class EffectEngine {

List<Effect> effects;
public EffectEngine()
{
effects = new ArrayList<Effect>();
}

public void add(Effect effect)
{
effects.add(effect);
}

public void update(float delta)
{
int i = 0;
while (i < effects.size())
{
effects.get(i).update(delta);
if (effects.get(i).isAlive())
{
i++;
}
else
{
effects.get(i).release();
effects.remove(i);
}
}
}

public void draw(SpriteBatch batch)
{
for (int i = 0; i < effects.size(); i++)
{
effects.get(i).draw(batch);
}
}

public void clear()
{
while (effects.size() > 0)
{
effects.get(0).release();
effects.remove(0);
}
}
}
74 changes: 74 additions & 0 deletions core/src/com/coldwild/dodginghero/graph/effects/WarningEffect.java
@@ -0,0 +1,74 @@
package com.coldwild.dodginghero.graph.effects;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Pool;
import com.coldwild.dodginghero.Resources;
import com.coldwild.dodginghero.graph.SizeEvaluator;

/**
* Created by comrad_gremlin on 9/9/2016.
*/
public class WarningEffect extends Effect {

private static final float WARNING_TIME = 2.0f;
private int fieldX;
private int fieldY;
private SizeEvaluator sizeEvaluator;
private Resources resources;

public static WarningEffect Create(int fx,
int fy,
EffectEngine engine,
SizeEvaluator sz,
Resources res)
{
WarningEffect effect = warningPool.obtain();
effect.init(fx, fy, engine, sz, res);
return effect;
}

public WarningEffect()
{

}

public void init(int fx, int fy, EffectEngine parent, SizeEvaluator sz, Resources res)
{
fieldX = fx;
fieldY = fy;
sizeEvaluator = sz;
resources = res;
super.init(parent);
}

@Override
public void draw(SpriteBatch batch) {
batch.begin();
batch.draw(resources.warning,
sizeEvaluator.getBaseScreenX(fieldX),
sizeEvaluator.getBaseScreenY(fieldY));
batch.end();
}

@Override
public void update(float delta)
{
super.update(delta);
if (timeAlive > WARNING_TIME)
{
isAlive = false;
}
}

@Override
public void release() {
warningPool.free(this);
}

static Pool<WarningEffect> warningPool = new Pool<WarningEffect>() {
@Override
protected WarningEffect newObject() {
return new WarningEffect();
}
};
}
13 changes: 13 additions & 0 deletions core/src/com/coldwild/dodginghero/logic/GameLogic.java
@@ -1,6 +1,7 @@
package com.coldwild.dodginghero.logic;

import com.badlogic.gdx.math.MathUtils;
import com.coldwild.dodginghero.graph.effects.EffectEngine;
import com.coldwild.dodginghero.logic.objects.Player;

/**
Expand All @@ -12,19 +13,26 @@ public class GameLogic {
public static final int MAX_BASE_Y = 3;

Player player;
EffectEngine effectEngine;

public GameLogic() {
player = new Player(
MathUtils.random(MAX_BASE_X),
MathUtils.random(MAX_BASE_Y)
); // 0..3
effectEngine = new EffectEngine();
}

public Player getPlayer()
{
return player;
}

public void update(float delta)
{
effectEngine.update(delta);
}

public boolean CanMove(int fx, int fy)
{
return (fx >= 0 && fx <= MAX_BASE_X) &&
Expand All @@ -36,4 +44,9 @@ public void AssignPlayerPosition(int fx, int fy)
player.setFieldX(fx);
player.setFieldY(fy);
}

public EffectEngine getEffectEngine()
{
return effectEngine;
}
}
4 changes: 4 additions & 0 deletions core/src/com/coldwild/dodginghero/screens/GameScreen.java
Expand Up @@ -11,6 +11,7 @@
import com.coldwild.dodginghero.Resources;
import com.coldwild.dodginghero.graph.Background;
import com.coldwild.dodginghero.graph.SizeEvaluator;
import com.coldwild.dodginghero.graph.effects.WarningEffect;
import com.coldwild.dodginghero.logic.GameLogic;
import com.coldwild.dodginghero.logic.objects.Player;

Expand Down Expand Up @@ -52,11 +53,13 @@ public GameScreen(DodgingHero _game) {
RefreshPlayer();

Gdx.input.setInputProcessor(this);
WarningEffect.Create(0, 0, logic.getEffectEngine(), sizeEvaluator, game.res);
}

public void update(float delta)
{
gameStage.act(delta);
logic.update(delta);
}

public void drawBases()
Expand Down Expand Up @@ -87,6 +90,7 @@ public void render(float delta)

bg.draw(gameStage, game.res);
drawBases();
logic.getEffectEngine().draw(batch);

batch.begin();
player.draw(batch);
Expand Down

0 comments on commit 4a2ff24

Please sign in to comment.