Skip to content

Commit

Permalink
added arms, music and bugfixed calculation between tile and px
Browse files Browse the repository at this point in the history
  • Loading branch information
mklemmingen committed Dec 10, 2023
1 parent edeb98e commit 9eb3389
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 50 deletions.
Binary file added assets/music/egyptianmusic.mp3
Binary file not shown.
Binary file added assets/music/egyptianmusic2.mp3
Binary file not shown.
Binary file added assets/music/egyptreconstruct.mp3
Binary file not shown.
Binary file added assets/textures/armabovein.png
Loading
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/textures/armbelowin.png
Loading
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/textures/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 78 additions & 28 deletions core/src/com/senetboom/game/SenetBoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.senetboom.game.backend.*;
import com.senetboom.game.frontend.actors.ExtraTurnActor;
import com.senetboom.game.frontend.sound.MusicPlaylist;
import com.senetboom.game.frontend.stages.GameStage;
import com.senetboom.game.frontend.stages.MainMenu;
import com.senetboom.game.frontend.special.RelativeResizer;
import com.senetboom.game.frontend.text.Typewriter;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand Down Expand Up @@ -72,9 +71,6 @@ public class SenetBoom extends ApplicationAdapter {
static Stage helpOverlayStage;
Texture help;
public static boolean displayHelp;

// handStage
Stage handStage;
Texture hand;
// for the pieces textures unselected
public static Texture blackpiece;
Expand Down Expand Up @@ -194,6 +190,19 @@ public class SenetBoom extends ApplicationAdapter {

public static boolean needRender;

// for the arms
public static Image armFromBelow;
public static Image armFromAbove;

// for the advanced arm stages and their respective boolean

public static Stage armFromBelowStage;
public static Stage armFromAboveStage;
public static boolean showArmFromBelowStage;
public static boolean showArmFromAboveStage;

public static MusicPlaylist musicPlaylist;

// enum of turn
private enum Turn {
PLAYERWHITE,
Expand All @@ -203,7 +212,7 @@ private enum Turn {
@Override
public void create () {
batch = new SpriteBatch();
background = new Texture("textures/egypt.png");
background = new Texture("textures/background.png");

// from scene2dUi
currentStage = new Stage();
Expand All @@ -218,14 +227,20 @@ public void create () {
typeWriterStage = new Stage();
hitStage = new Stage();
helpOverlayStage = new Stage();
handStage = new Stage();
mapStage = new Stage();
extraTurnStage = new Stage();
stickValueStage = new Stage();
deciderStage = new Stage();
hintStage = new Stage();
currentTurnStage = new Stage();

// for the arms

armFromBelowStage = new Stage();
armFromAboveStage = new Stage();
showArmFromBelowStage = false;
showArmFromAboveStage = false;

// possible Moves is a ArrayList of int values
possibleMoves = new ArrayList<Integer>();

Expand All @@ -240,8 +255,6 @@ public void create () {
// loading all textures
blackpiece = new Texture("textures/blackpiece.png");
whitepiece = new Texture("textures/whitepiece.png");
// blackpieceSelected = new Texture("textures/blackpieceSelected.png");
// whitepieceSelected = new Texture("textures/whitepieceSelected.png");
happy = new Texture("textures/happy.png");
water = new Texture("textures/water.png");
safe = new Texture("textures/safe.png");
Expand All @@ -254,6 +267,17 @@ public void create () {
whiteStarts = new Texture("textures/whiteStart.png");
blackStarts = new Texture("textures/blackStarts.png");

// arms

armFromAboveStage = new Stage();
armFromBelowStage = new Stage();

armFromAbove = new Image(new Texture("textures/armabovein.png"));
armFromBelow = new Image(new Texture("textures/armbelowin.png"));

armFromAboveStage.addActor(armFromAbove);
armFromBelowStage.addActor(armFromBelow);

// for the sticks
blackStick = new Texture("textures/blackStick.png");
whiteStick = new Texture("textures/whiteStick.png");
Expand Down Expand Up @@ -282,6 +306,21 @@ public void create () {
// for the empty tile texture
emptyTexture = new Texture("textures/empty.png");

// music Playlist

volume = 0.5f;

musicPlaylist = new MusicPlaylist();

// from youtube: https://www.youtube.com/watch?v=nBmWXmn11YE
musicPlaylist.addSong("music/egyptreconstruct.mp3");
// from youtube: https://www.youtube.com/watch?v=mECTRQ0VEyU
musicPlaylist.addSong("music/egyptianmusic.mp3");
// from youtube: https://www.youtube.com/watch?v=d7jKP_JngC8
musicPlaylist.addSong("music/egyptianmusic2.mp3");

musicPlaylist.play();

// for the empty variable (the tile that is currently moved by a bot)
emptyVariable = -1;

Expand Down Expand Up @@ -382,11 +421,6 @@ public void render () {
hintStage.draw();
}

// for the hand texture that follow the drag position of the piece
// depending on if white or black (from up or from down)
handStage.act();
handStage.draw();

// for the extra turn symbol
extraTurnStage.act();
extraTurnStage.draw();
Expand All @@ -405,6 +439,17 @@ public void render () {
return;
}

// for the arms
if(showArmFromBelowStage) {
armFromBelowStage.act();
armFromBelowStage.draw();
}

if(showArmFromAboveStage) {
armFromAboveStage.act();
armFromAboveStage.draw();
}

// for the display of the game having ended
gameEndStage.act();
gameEndStage.draw();
Expand Down Expand Up @@ -553,13 +598,14 @@ public void resize(int width, int height) {
typeWriterStage.getViewport().update(width, height, true);
hitStage.getViewport().update(width, height, true);
helpOverlayStage.getViewport().update(width, height, true);
handStage.getViewport().update(width, height, true);
gameEndStage.getViewport().update(width, height, true);
extraTurnStage.getViewport().update(width, height, true);
stickValueStage.getViewport().update(width, height, true);
deciderStage.getViewport().update(width, height, true);
hintStage.getViewport().update(width, height, true);
currentTurnStage.getViewport().update(width, height, true);
armFromAboveStage.getViewport().update(width, height, true);
armFromBelowStage.getViewport().update(width, height, true);
}
}

Expand Down Expand Up @@ -621,7 +667,7 @@ public Decider(Turn turn){
}

this.X = tileSize*8;
this.Y = tileSize*2;
this.Y = tileSize*8;
}

@Override
Expand Down Expand Up @@ -678,30 +724,34 @@ public void dispose () {
blackStarts.dispose();
}

public static Coordinate calculatePXbyTile(int x, int y) {
public static Coordinate calculatePXbyTile(int x) {
// the screen is 1536 to 896. The board is 3x10 tiles and each tile is 80x80px.
// the board is centered on the screen
int screenWidth = 1536;
int screenHeight = 896;
int boardWidth = (int) (tileSize * 10);
int boardHeight = (int) (tileSize * 3);

// Calculate starting position of the board
// Calculate starting position (upper left corner) of the board
int boardStartX = (screenWidth - boardWidth) / 2;
int boardStartY = (screenHeight - boardHeight) / 2;

// Calculate tile position
int posX, posY;
int yCoord;
int xCoord;

if (y == 1) { // Middle row (reversed)
posX = (int) (boardStartX + (9 - x) * tileSize);
} else { // Top and bottom rows
posX = (int) (boardStartX + x * tileSize);
// Calculate the tile's position
if(x <= 9){
yCoord = boardStartY + 80;
xCoord = boardStartX + (x * 80);
} else if (x <= 19){
yCoord = boardStartY;
xCoord = boardStartX + (10*80) - ((x-9)*80);
} else {
yCoord = boardStartY - (80);
xCoord = boardStartY * ((x-19) * 80);
}

posY = (int) (boardStartY + y * tileSize);

return new Coordinate(posX, posY);
return new Coordinate(xCoord, yCoord);
}

public static int calculateTilebyPx(int x, int y) {
Expand All @@ -715,7 +765,7 @@ public static int calculateTilebyPx(int x, int y) {
int boardStartX = (screenWidth - boardWidth) / 2;
int boardStartY = (screenHeight - boardHeight) / 2;

// Adjust the y-coordinate to reflect libGDX's top-left origin
// Adjust the y-coordinate to reflect libGDX's bottom-left origin
int adjustedY = screenHeight - y;

// Calculate which tile
Expand Down
5 changes: 5 additions & 0 deletions core/src/com/senetboom/game/backend/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ private boolean checkBlockade(Tile[] board, int start, int stickRoll, Piece.Colo
@Override
public void movePiece(int newIndex) {
int index = position; // starter position

Tile[] board = Board.getBoard();

Piece piece = board[index].getPiece();

// rebirth case:
Expand Down Expand Up @@ -256,18 +258,21 @@ public void movePiece(int newIndex) {
for (int i = 13; i >= 0; i--) {
if (!board[i].hasPiece()) {
board[i].setPiece(piece); // move to the earliest free tile
board[index].removePiece(); // remove the piece from the water tile
break;
}
}
} else {
// if tile 14 is free, move the piece there and give it protection
board[14].setPiece(piece);
piece.switchProtection(); // give protection to the piece
board[index].removePiece(); // remove the piece from the water tile
}
break;
case REBIRTH:
// add rebirth protection
piece.switchProtection();

break;
case SAFE:
// do nothing for SAFE state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ExtraTurnActor(){
stack.setSize(tileSize*4, tileSize*2);
stack.addActor(new Image(extraTurnTexture));
this.X = tileSize*8;
this.Y = tileSize*4;
this.Y = tileSize*8;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/senetboom/game/frontend/special/moveBotTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void startMove(int startX, int startY, int endX, int endY) {
// set the maximum duration fitting the length of the way that the soldier moves
// per 50 pixel, add 0.5f to max duration
// Begin: calculate Vector:
startPx = SenetBoom.calculatePXbyTile(startX, startY);
endPx = SenetBoom.calculatePXbyTile(endX, endY);
startPx = SenetBoom.calculatePXbyTile(startX);
endPx = SenetBoom.calculatePXbyTile(endX);

Vector2 pointA = new Vector2(startPx.getX(), startPx.getY());
Vector2 pointB = new Vector2(endPx.getX(), endPx.getY());
Expand Down
Loading

0 comments on commit 9eb3389

Please sign in to comment.