Merge branch 'main' of github.com:Wil-Ro/gamejam2024
This commit is contained in:
commit
810ab1880b
4 changed files with 62 additions and 2 deletions
|
@ -109,4 +109,7 @@ public class Die extends Actor {
|
|||
this.selected = selected;
|
||||
}
|
||||
|
||||
public Face[] getFaces() {
|
||||
return faces;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,16 @@ import com.badlogic.gdx.Gdx;
|
|||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import org.w3c.dom.css.Rect;
|
||||
|
||||
import static com.badlogic.gdx.graphics.GL20.*;
|
||||
|
||||
public class DieNetUi extends Actor{
|
||||
private Die die;
|
||||
public void setGame(Game game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
private Game game;
|
||||
private Rectangle rect;
|
||||
private boolean visible;
|
||||
|
||||
|
@ -21,6 +26,10 @@ public class DieNetUi extends Actor{
|
|||
public void render(SpriteBatch batch) {
|
||||
if (!visible)
|
||||
return;
|
||||
if (game.getSelectedDice().size() == 0)
|
||||
return;
|
||||
|
||||
Die die = game.getSelectedDice().get(0);
|
||||
|
||||
|
||||
batch.end();
|
||||
|
@ -36,12 +45,36 @@ public class DieNetUi extends Actor{
|
|||
|
||||
batch.begin();
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Face face = die.getFaces()[i];
|
||||
Rectangle rect = getDieFaceLocation(i);
|
||||
rect.width = Gdx.graphics.getWidth()/4;
|
||||
rect.height = Gdx.graphics.getWidth()/4;;
|
||||
|
||||
face.renderAtRect(batch, rect);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getDieFaceLocation(int i)
|
||||
private Rectangle getDieFaceLocation(int i)
|
||||
{
|
||||
Rectangle result = new Rectangle();
|
||||
switch(i){
|
||||
case 0:
|
||||
result.x = (Gdx.graphics.getWidth()/4)*3;
|
||||
result.y = (Gdx.graphics.getHeight()/3)*2;
|
||||
break;
|
||||
case 5:
|
||||
result.x = (Gdx.graphics.getWidth()/4)*3;
|
||||
result.y = (Gdx.graphics.getHeight()/3)*0;
|
||||
break;
|
||||
default:
|
||||
result.x = (Gdx.graphics.getWidth()/4)*i;
|
||||
result.y = (Gdx.graphics.getHeight()/3)*1;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setVisible(boolean b) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.monjaro.gamejam.main;
|
|||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -122,6 +123,12 @@ public class Face extends Actor{
|
|||
transform.y + transform.height*y/100f - (float)pipSprite.getHeight()/2);
|
||||
}
|
||||
|
||||
public Vector2 calculatePipLocation(Vector2 percentages, Rectangle rect) {
|
||||
return new Vector2(
|
||||
rect.x + rect.width/100f - (float)pipSprite.getWidth()/2,
|
||||
rect.y + rect.height/100f - (float)pipSprite.getHeight()/2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
|
||||
|
@ -144,4 +151,20 @@ public class Face extends Actor{
|
|||
}
|
||||
}
|
||||
|
||||
public void renderAtRect(SpriteBatch batch, Rectangle rect) {
|
||||
Sprite face = new Sprite(blankFaceSprite, 64*faceNumber, 0, (int)rect.width, (int)rect.height);
|
||||
face.setOrigin(rect.getWidth()/2, rect.getHeight()/2);
|
||||
//face.rotate(transform.getRotation());
|
||||
face.setPosition(rect.x-rect.getWidth()/2, rect.y-rect.getHeight()/2);
|
||||
|
||||
face.draw(batch);
|
||||
|
||||
for(Pip pip : pips){
|
||||
Vector2 position = calculatePipLocation(pip.getVectorLocation(), rect);
|
||||
batch.draw(pipSprite,
|
||||
position.x,
|
||||
position.y);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class Game extends ApplicationAdapter {
|
|||
ui = new UI(this, 50, 280);
|
||||
|
||||
dieNet = new DieNetUi();
|
||||
dieNet.setGame(this);
|
||||
|
||||
shopeUi = new ShopeUi();
|
||||
ShopeUi.setGame(this);
|
||||
|
|
Loading…
Add table
Reference in a new issue