Added Teams
This commit is contained in:
parent
efcd34ebff
commit
bfc181b8a5
@ -9,20 +9,24 @@ import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.Collis
|
|||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
import de.samdev.cannonshooter.ZLayers;
|
import de.samdev.cannonshooter.ZLayers;
|
||||||
|
import de.samdev.cannonshooter.teams.Team;
|
||||||
|
|
||||||
public class Cannon extends Entity {
|
public class Cannon extends Entity {
|
||||||
|
public Team team;
|
||||||
|
|
||||||
private CannonBarrel barrel;
|
private CannonBarrel barrel;
|
||||||
private CannonHearth hearth;
|
private CannonHearth hearth;
|
||||||
|
|
||||||
public float power = 1f; // 1 = active | 0 = neutral
|
public float power; // 1 = active | 0 = neutral
|
||||||
|
|
||||||
public Cannon(float x, float y) {
|
public Cannon(float x, float y, Team t) {
|
||||||
super(Textures.cannon_body, 2, 2);
|
super(Textures.cannon_body, 2, 2);
|
||||||
|
|
||||||
setPosition(x, y);
|
setPosition(x, y);
|
||||||
|
|
||||||
setZLayer(ZLayers.LAYER_CANNON_BODY);
|
setZLayer(ZLayers.LAYER_CANNON_BODY);
|
||||||
|
|
||||||
|
team = t;
|
||||||
|
power = (t.isNeutral) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,12 +42,12 @@ public class Cannon extends Entity {
|
|||||||
public void beforeUpdate(float delta) {
|
public void beforeUpdate(float delta) {
|
||||||
if (owner.owner.settings.debugEnabled.get())
|
if (owner.owner.settings.debugEnabled.get())
|
||||||
{
|
{
|
||||||
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.DOWN))
|
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.DOWN) && ! team.isNeutral)
|
||||||
{
|
{
|
||||||
power = Math.max(0, power - 0.01f);
|
power = Math.max(0, power - 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.UP))
|
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.UP) && ! team.isNeutral)
|
||||||
{
|
{
|
||||||
power = Math.min(1, power + 0.01f);
|
power = Math.min(1, power + 0.01f);
|
||||||
}
|
}
|
||||||
@ -55,6 +59,10 @@ public class Cannon extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTeam(Team newteam) {
|
||||||
|
team = newteam;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
//
|
//
|
||||||
|
@ -10,14 +10,16 @@ import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.Collis
|
|||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
import de.samdev.cannonshooter.ZLayers;
|
import de.samdev.cannonshooter.ZLayers;
|
||||||
|
import de.samdev.cannonshooter.level.StandardLevel;
|
||||||
|
|
||||||
public class CannonHearth extends Entity {
|
public class CannonHearth extends Entity {
|
||||||
private static final Color COLOR_NEUTRAL = new Color(0.75f, 0.75f, 0.75f, 1f);
|
private static final Color COLOR_HEARTLESS = new Color(0.75f, 0.75f, 0.75f, 1f);
|
||||||
private static final float ROTATION_SPEED = 0.125f;
|
private static final float ROTATION_SPEED = 0.125f;
|
||||||
|
|
||||||
private float rotation = 0;
|
private float rotation = 0;
|
||||||
|
|
||||||
private Cannon cannon;
|
private Cannon cannon;
|
||||||
|
private StandardLevel level;
|
||||||
|
|
||||||
public CannonHearth(Cannon owner) {
|
public CannonHearth(Cannon owner) {
|
||||||
super(Textures.cannon_hearth[0], 2, 2);
|
super(Textures.cannon_hearth[0], 2, 2);
|
||||||
@ -30,11 +32,11 @@ public class CannonHearth extends Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(SpriteBatch sbatch, ShapeRenderer srenderer) {
|
public void render(SpriteBatch sbatch, ShapeRenderer srenderer) {
|
||||||
sbatch.setColor(COLOR_NEUTRAL);
|
sbatch.setColor(COLOR_HEARTLESS);
|
||||||
|
|
||||||
renderTexture(sbatch, Textures.cannon_hearth[63], 0, 0);
|
renderTexture(sbatch, Textures.cannon_hearth[63], 0, 0);
|
||||||
|
|
||||||
sbatch.setColor(Color.RED);
|
sbatch.setColor(cannon.team.teamColor);
|
||||||
|
|
||||||
renderTexture(sbatch, Textures.cannon_hearth[(int)(cannon.power * 63)], 0, 0);
|
renderTexture(sbatch, Textures.cannon_hearth[(int)(cannon.power * 63)], 0, 0);
|
||||||
|
|
||||||
@ -43,17 +45,20 @@ public class CannonHearth extends Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeUpdate(float delta) {
|
public void beforeUpdate(float delta) {
|
||||||
if (cannon.power < 1)
|
if (cannon.power < 1) {
|
||||||
{
|
if (rotation != 0 && cannon.power > 0) {
|
||||||
if (rotation != 0)
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
||||||
{
|
|
||||||
rotation = (rotation - delta * ROTATION_SPEED);
|
|
||||||
if (rotation < 0) rotation = 0;
|
if (rotation < 0) rotation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cannon.power == 0){
|
||||||
|
if (! cannon.team.isNeutral) cannon.setTeam(level.team_neutral);
|
||||||
|
|
||||||
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
||||||
|
if (rotation < 0) rotation += 45;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
||||||
rotation = (rotation - delta * ROTATION_SPEED);
|
|
||||||
if (rotation < 0) rotation += 45;
|
if (rotation < 0) rotation += 45;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +70,7 @@ public class CannonHearth extends Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayerAdd(GameLayer layer) {
|
public void onLayerAdd(GameLayer layer) {
|
||||||
//
|
level = (StandardLevel) layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package de.samdev.cannonshooter.level;
|
package de.samdev.cannonshooter.level;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import de.samdev.absgdx.framework.AgdxGame;
|
import de.samdev.absgdx.framework.AgdxGame;
|
||||||
@ -9,19 +13,43 @@ import de.samdev.absgdx.framework.map.background.RepeatingBackground;
|
|||||||
import de.samdev.absgdx.framework.map.mapscaleresolver.ShowCompleteMapScaleResolver;
|
import de.samdev.absgdx.framework.map.mapscaleresolver.ShowCompleteMapScaleResolver;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
import de.samdev.cannonshooter.entities.Cannon;
|
import de.samdev.cannonshooter.entities.Cannon;
|
||||||
|
import de.samdev.cannonshooter.teams.Team;
|
||||||
|
|
||||||
public class StandardLevel extends GameLayer {
|
public class StandardLevel extends GameLayer {
|
||||||
|
|
||||||
|
private List<Team> teams = new ArrayList<Team>();
|
||||||
|
|
||||||
|
public Team team_neutral = Team.GenerateTeamNeutral();
|
||||||
|
public Team team_player = Team.GenerateTeamPlayer();
|
||||||
|
|
||||||
|
private Team team_computer1 = new Team(10, Team.COL_P2, false, true, false, Team.MULTIPLIER_AI_D0);
|
||||||
|
private Team team_computer2 = new Team(11, Team.COL_P3, false, true, false, Team.MULTIPLIER_AI_D0);
|
||||||
|
private Team team_computer3 = new Team(12, Team.COL_P4, false, true, false, Team.MULTIPLIER_AI_D0);
|
||||||
|
|
||||||
public StandardLevel(AgdxGame owner) {
|
public StandardLevel(AgdxGame owner) {
|
||||||
super(owner, TileMap.createEmptyMap(32, 20));
|
super(owner, TileMap.createEmptyMap(32, 20));
|
||||||
|
|
||||||
addBackground(new RepeatingBackground(Textures.texbackground, 1/32f));
|
initTeams();
|
||||||
|
|
||||||
|
initMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMap() {
|
||||||
|
addBackground(new RepeatingBackground(Textures.texbackground, 1/32f));
|
||||||
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
||||||
|
|
||||||
addEntity(new Cannon(7, 13));
|
addEntity(new Cannon(7, 13, team_player));
|
||||||
addEntity(new Cannon(14, 5));
|
addEntity(new Cannon(14, 5, team_computer1));
|
||||||
addEntity(new Cannon(20, 13));
|
addEntity(new Cannon(20, 13, team_neutral));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTeams() {
|
||||||
|
teams.add(team_neutral);
|
||||||
|
teams.add(team_player);
|
||||||
|
|
||||||
|
teams.add(team_computer1);
|
||||||
|
teams.add(team_computer2);
|
||||||
|
teams.add(team_computer3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
48
core/src/de/samdev/cannonshooter/teams/Team.java
Normal file
48
core/src/de/samdev/cannonshooter/teams/Team.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package de.samdev.cannonshooter.teams;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
public class Team {
|
||||||
|
|
||||||
|
public static final Color COL_NEUTRAL = new Color(127/255f, 127/255f, 127/255f, 1.0f);
|
||||||
|
public static final Color COL_P1 = new Color(38/255f, 127/255f, 0/255f, 1.0f);
|
||||||
|
public static final Color COL_P2 = new Color(255/255f, 0/255f, 0/255f, 1.0f);
|
||||||
|
public static final Color COL_P3 = new Color(0/255f, 0/255f, 255/255f, 1.0f);
|
||||||
|
public static final Color COL_P4 = new Color(255/255f, 216/255f, 0/255f, 1.0f);
|
||||||
|
public static final Color COL_P5 = new Color(0/255f, 255/255f, 255/255f, 1.0f);
|
||||||
|
public static final Color COL_P6 = new Color(178/255f, 0/255f, 255/255f, 1.0f);
|
||||||
|
|
||||||
|
public static final float MULTIPLIER_PLAYER = 1;
|
||||||
|
public static final float MULTIPLIER_NEUTRAL = 0.5f;
|
||||||
|
public static final float MULTIPLIER_AI_D0 = 0.80f;
|
||||||
|
public static final float MULTIPLIER_AI_D1 = 0.875f;
|
||||||
|
public static final float MULTIPLIER_AI_D2 = 0.95f;
|
||||||
|
public static final float MULTIPLIER_AI_D3 = 1.0f;
|
||||||
|
|
||||||
|
public final int ID;
|
||||||
|
|
||||||
|
public final Color teamColor;
|
||||||
|
|
||||||
|
public final boolean isUserControllable;
|
||||||
|
public final boolean isComputerControllable;
|
||||||
|
public final boolean isNeutral; //Non-Combatant
|
||||||
|
|
||||||
|
public final float speedMultiplier;
|
||||||
|
|
||||||
|
public Team(int id, Color col, boolean user, boolean computer, boolean neutral, float mult) {
|
||||||
|
this.ID = id;
|
||||||
|
this.teamColor = col;
|
||||||
|
this.isUserControllable = user;
|
||||||
|
this.isComputerControllable = computer;
|
||||||
|
this.isNeutral = neutral;
|
||||||
|
this.speedMultiplier = mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Team GenerateTeamNeutral() {
|
||||||
|
return new Team(0, COL_NEUTRAL, false, true, true, MULTIPLIER_NEUTRAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Team GenerateTeamPlayer() {
|
||||||
|
return new Team(0, COL_P1, true, false, false, MULTIPLIER_PLAYER);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user