Oppdaterer visning av programmeringskort med teksturer for hver korttype Closes #80

This commit is contained in:
Kristian Knarvik 2020-04-28 21:13:45 +02:00
parent 0fb3c76e7e
commit 1747f1ea21
5 changed files with 63 additions and 73 deletions

View File

@ -202,6 +202,7 @@ public class BoardActiveScreen extends InteractiveScreen {
/**
* Draws the damage of the player
*
* @param batch The sprite batch to use for drawing
* @param robot The robot which has visited the flag
* @param index The index of the robot in the robot list
@ -228,6 +229,7 @@ public class BoardActiveScreen extends InteractiveScreen {
/**
* Draws the lives of the player
*
* @param batch The sprite batch to use for drawing
* @param robot The robot which has visited the flag
* @param index The index of the robot in the robot list
@ -246,6 +248,7 @@ public class BoardActiveScreen extends InteractiveScreen {
/**
* Draws the last flag the player visited
*
* @param batch The sprite batch to use for drawing
* @param robot The robot which has visited the flag
* @param index The index of the robot in the robot list

View File

@ -5,6 +5,7 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
@ -18,15 +19,15 @@ import inf112.fiasko.roborally.gamewrapper.SimpleButton;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
import inf112.fiasko.roborally.utility.TextureConverterUtil;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import static com.badlogic.gdx.graphics.Color.BLACK;
import static com.badlogic.gdx.graphics.Color.GRAY;
import static com.badlogic.gdx.graphics.Color.RED;
import static com.badlogic.gdx.graphics.Color.WHITE;
import static com.badlogic.gdx.graphics.Color.YELLOW;
/**
* This screen is used to let the user choose their program
@ -202,77 +203,47 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
* Renders the base shape of cards
*/
private void renderCards() {
roboRallyWrapper.batch.begin();
for (CardRectangle cardRectangle : cardRectangles) {
if (cardRectangle.selected) {
shapeRenderer.setColor(RED);
shapeRenderer.rect(cardRectangle.rectangle.x - 10, cardRectangle.rectangle.y - 10,
cardRectangle.rectangle.width + 20, cardRectangle.rectangle.height + 20);
shapeRenderer.rectLine(cardRectangle.rectangle.x, cardRectangle.rectangle.y,
cardRectangle.rectangle.x + cardRectangle.rectangle.width, cardRectangle.rectangle.y +
cardRectangle.rectangle.height, 2);
}
shapeRenderer.setColor(GRAY);
shapeRenderer.rect(cardRectangle.rectangle.x, cardRectangle.rectangle.y,
cardRectangle.rectangle.width, cardRectangle.rectangle.height);
TextureRegion cardTexture = TextureConverterUtil.convertElement(cardRectangle.card);
Rectangle rectangle = cardRectangle.rectangle;
roboRallyWrapper.batch.draw(cardTexture.getTexture(), rectangle.getX(), rectangle.getY(),
rectangle.getWidth() / 2, rectangle.getHeight() / 2,
rectangle.getWidth(), rectangle.getHeight(), 1, 1, 0,
cardTexture.getRegionX(), cardTexture.getRegionY(),
cardTexture.getRegionWidth(), cardTexture.getRegionHeight(),
false, false);
}
roboRallyWrapper.batch.end();
}
/**
* Renders the text displayed on cards
*/
private void renderCardText() {
roboRallyWrapper.font.setColor(YELLOW);
for (CardRectangle cardRectangle : cardRectangles) {
roboRallyWrapper.font.getData().setScale(0.8f);
GlyphLayout layout = new GlyphLayout(roboRallyWrapper.font,
Integer.toString(cardRectangle.card.getPriority()));
float fontX = (int) (cardRectangle.rectangle.x + (cardRectangle.rectangle.width - layout.width) / 2.0);
float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 30;
float fontX = (int) (cardRectangle.rectangle.x + (cardRectangle.rectangle.width - layout.width) - 28);
float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 21;
roboRallyWrapper.font.draw(roboRallyWrapper.batch, layout, fontX, fontY);
drawCardSymbol(cardRectangle);
int chosenIndex = chosenCards.indexOf(cardRectangle);
if (chosenIndex != -1) {
roboRallyWrapper.font.setColor(BLACK);
roboRallyWrapper.font.setColor(YELLOW);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(chosenIndex + 1),
cardRectangle.rectangle.x + cardRectangle.rectangle.width - 20, cardRectangle.rectangle.y + cardRectangle.rectangle.height - 5);
roboRallyWrapper.font.setColor(WHITE);
cardRectangle.rectangle.x + 30, cardRectangle.rectangle.y + cardRectangle.rectangle.height - 20);
}
}
}
/**
* Draws the symbol on a card
*
* @param cardRectangle The card rectangle to draw
*/
private void drawCardSymbol(CardRectangle cardRectangle) {
String text;
switch (cardRectangle.card.getAction()) {
case MOVE_1:
text = "Move 1 forward";
break;
case MOVE_2:
text = "Move 2 forward";
break;
case MOVE_3:
text = "Move 3 forward";
break;
case BACK_UP:
text = "Back up";
break;
case ROTATE_LEFT:
text = "Rotate left";
break;
case ROTATE_RIGHT:
text = "Rotate right";
break;
case U_TURN:
text = "U Turn";
break;
default:
throw new IllegalArgumentException("Invalid action on CardRectangle.");
}
GlyphLayout layout = new GlyphLayout();
layout.setText(roboRallyWrapper.font, text, WHITE, cardRectangle.rectangle.width - 20,
1, true);
float fontX = cardRectangle.rectangle.x;
float fontY = cardRectangle.rectangle.y + cardRectangle.rectangle.height - 80;
roboRallyWrapper.font.draw(roboRallyWrapper.batch, layout, fontX, fontY);
roboRallyWrapper.font.setColor(WHITE);
}
@Override

View File

@ -8,7 +8,6 @@ import inf112.fiasko.roborally.elementproperties.TileType;
import inf112.fiasko.roborally.elementproperties.WallType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -242,7 +241,7 @@ public class Board {
}
/**
* removes one damage for a given robot given that it has taken som damage before
* Removes one damage for a given robot given that it has taken som damage before
*
* @param robotID the ID of the robot
*/
@ -253,7 +252,7 @@ public class Board {
}
/**
* sets the damage taken of robots in power down to 0
* Sets the damage taken of robots in power down to 0
*/
public void executePowerDown() {
for (Robot robot : robots.values()) {
@ -316,23 +315,8 @@ public class Board {
if (tile == null) {
return false;
}
switch (tile.getTileType()) {
case CONVEYOR_BELT_SLOW:
case CONVEYOR_BELT_FAST:
case CONVEYOR_BELT_FAST_LEFT:
case CONVEYOR_BELT_FAST_RIGHT:
case CONVEYOR_BELT_FAST_SIDE_ENTRANCE_LEFT:
case CONVEYOR_BELT_FAST_SIDE_ENTRANCE_RIGHT:
case CONVEYOR_BELT_FAST_SIDE_ENTRANCES:
case CONVEYOR_BELT_SLOW_LEFT:
case CONVEYOR_BELT_SLOW_RIGHT:
case CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT:
case CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT:
case CONVEYOR_BELT_SLOW_SIDE_ENTRANCES:
return true;
default:
return false;
}
int tileTypeId = tile.getTileType().getTileTypeID();
return tileTypeId >= 5 && tileTypeId <= 16;
}
/**

View File

@ -10,6 +10,7 @@ import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.elementproperties.TileType;
import inf112.fiasko.roborally.elementproperties.WallType;
import inf112.fiasko.roborally.objects.Particle;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.Robot;
import inf112.fiasko.roborally.objects.Tile;
import inf112.fiasko.roborally.objects.Wall;
@ -30,6 +31,7 @@ public final class TextureConverterUtil {
private static final Texture textureSheet = new Texture(Gdx.files.internal("assets/tiles.png"));
private static final Texture robotsTexture = new Texture(Gdx.files.internal("assets/robots.png"));
private static final Texture effectsTexture = new Texture(Gdx.files.internal("assets/effects.png"));
private static final Texture programmingCardsTexture = new Texture(Gdx.files.internal("assets/programmingcards.png"));
private static Map<TileType, TextureConverterContainer> tileSheetTileTextureMappings;
private static Map<TileType, Boolean> tileSheetTileHasRotatedTextureMappings;
private static Map<ParticleType, TextureConverterContainer> tileSheetParticleTextureMappings;
@ -40,8 +42,36 @@ public final class TextureConverterUtil {
private TextureConverterUtil() {
}
/**
* Gets the texture representing the programming card
*
* @param card The card to draw
* @return The texture to draw
*/
public static TextureRegion convertElement(ProgrammingCard card) {
switch (card.getAction()) {
case MOVE_1:
return new TextureRegion(programmingCardsTexture, 0, 0, 250, 400);
case MOVE_2:
return new TextureRegion(programmingCardsTexture, 250, 0, 250, 400);
case MOVE_3:
return new TextureRegion(programmingCardsTexture, 2 * 250, 0, 250, 400);
case ROTATE_LEFT:
return new TextureRegion(programmingCardsTexture, 3 * 250, 0, 250, 400);
case ROTATE_RIGHT:
return new TextureRegion(programmingCardsTexture, 4 * 250, 0, 250, 400);
case BACK_UP:
return new TextureRegion(programmingCardsTexture, 5 * 250, 0, 250, 400);
case U_TURN:
return new TextureRegion(programmingCardsTexture, 6 * 250, 0, 250, 400);
default:
throw new IllegalArgumentException("Invalid action encountered.");
}
}
/**
* Returns the texture to use to display damage tokens
*
* @return The damage token texture
*/
public static TextureRegion getDamageTokenCriticalTexture() {
@ -50,6 +80,7 @@ public final class TextureConverterUtil {
/**
* Returns the texture to use to display damage tokens
*
* @return The damage token texture
*/
public static TextureRegion getDamageTokenTexture() {
@ -58,6 +89,7 @@ public final class TextureConverterUtil {
/**
* Returns the texture to use to display lives
*
* @return The life texture
*/
public static TextureRegion getLifeTexture() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB