Skip to content
Snippets Groups Projects
Commit 416a450c authored by dro024's avatar dro024
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	src/main/java/inf112/skeleton/app/Checkpoint.java
	src/main/java/inf112/skeleton/app/Enemy.java
	src/main/java/inf112/skeleton/app/Game.java
	src/main/java/inf112/skeleton/app/KeyHandler.java
	src/main/java/inf112/skeleton/app/Player.java
	src/main/java/inf112/skeleton/app/Tree.java
	src/main/java/inf112/skeleton/app/Waffle.java
	src/main/java/inf112/skeleton/app/Wall.java
parents 56199f45 e51f2a46
No related branches found
No related tags found
No related merge requests found
Showing
with 1133 additions and 15 deletions
### Waffle-Run
> Her skal det komme en beskrivelse av appen
> *Waffle-Run* er et plattformspill basert på vaffeltorsdag der man skal navigere en spiller gjennom en bane for å rekke frem til premien i enden av løypen, en nystekt vaffel.
> Her skal det komme en beskrivelse av hvordan man setter opp og kjører appen
> Du kjører appen ved å navigere til Main.java klassen i mappen src/main/java/inf112.skeleton.app og kjøre main metoden i denne klassen.r
File moved
# Oblig 2 - *Waffle-Run*
## Team: *team_2* (Gruppe 2): *Daniel Mjøs Røli, Erik Holmeide, Martin Elias Toftevåg, Sigurd Blakkestad, Årne Reime*
Link til projectboard i [Asana](https://app.asana.com/0/1201785608693491/board)
### Deloppgave 1: Team og prosjekt
- Rollene har fungert bra og vi har ikke gjort noen endringer på de.
- Andre roller?
-
### Deloppgave 2: Krav
Krav (gitt nedenfor som) fra MVP vi har prioritert for implementering denne sprinten er (beskrevet med brukerhistorier, akseptansekrav, og arbeidsoppgaver):
- Poeng *(Jeg som spiller ønsker å tilegne poeng i spillet som gir et mål på hvor bra jeg gjør det)*
- **Akseptansekriterier**:
- Det skal være en synlig poengscore på skjermen
- Det skal finnes poengobjekt som spiller kan se på skjermen
- Når spiller beveger seg over poengobjekt skal poengscore endres og objektet fjernes
- **Arbeidsoppgaver**:
- Fiender
- At spiller tar skade
- Game Over Screen
- Multiplayer
- Designe et utvidet spillbrett
- Vaffel målsymbol
### Deloppgave 3: Produkt og kode
- Dette har vi fikset siden sist:
Link til projectboard i [Asana](https://app.asana.com/0/1201785608693491/board)
Krav fra MVP som er proiritert for implementering ved innlevering oblig 2 (skal spesifiseres med bedre bedskrivelser og akseptansekriterier):
- Poeng
- Fiender
- At spiller tar skade
- Game Over Screen
- Multiplayer
- Designe et utvidet spillbrett
- Vaffel målsymbol
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
public class Checkpoint implements IGameObject {
private int x, y, w, h;
Image checkpointImg = new Image("file:src/PlayerImage/checkpoint.png");
boolean drawText;
public Checkpoint(int X, int Y) {
this.x = X;
this.y = Y;
this.w = 40;
this.h = 60;
}
@Override
public int getHeight() {
return this.h;
}
@Override
public int getWidth() {
return this.w;
}
@Override
public int getX() {
return this.x;
}
@Override
public int getY() {
return this.y;
}
@Override
public int getSpeed() {
return 0;
}
@Override
public int getGravity() {
return 0;
}
public void drawCheckpoint(GraphicsContext gc, Player player) {
gc.drawImage(checkpointImg, (this.x - this.w/2.0) - player.getX() + player.screenX, this.y - this.h/2.0, this.w, this.h);
}
public void drawCheckpointText(GraphicsContext gc) {
int width = 240;
int height = 50;
double x = (900/2.0) - width/2.0;
double y = 100;
gc.setFill(Color.rgb(0, 0, 0, 0.8));
gc.fillRoundRect(x, y, width, height, 35, 35);
gc.setFill(Color.WHITE);
gc.setFont(new Font("Comic sans MS", 20));
gc.fillText("Checkpoint updated", x + 20, y + 30);
gc.restore();
}
}
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Enemy implements IGameObject{
int x, y, w, h, drawW, distance;
Image r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12;
Image image;
int walkSpeed = 2;
int sum = 0;
private int gravity = 5;
public int runCounter = 0;
boolean canMoveDown = true;
int direction = 1;
public Enemy(int X, int Y, int distance) {
GetEnemyImage();
this.x = X;
this.y = Y;
this.w = 40;
this.h = 60;
this.drawW = 70;
this.distance = distance;
}
@Override
public int getHeight() {
return this.h;
}
@Override
public int getWidth() {
return this.w;
}
@Override
public int getX() {
return this.x;
}
@Override
public int getY() {
return this.y;
}
@Override
public int getSpeed() {
return this.walkSpeed;
}
@Override
public int getGravity() {
return this.gravity;
}
public void walk() {
if(direction == 1) {
this.x += walkSpeed;
sum += walkSpeed;
}
else {
this.x -= walkSpeed;
sum -= walkSpeed;
}
if (sum >= distance) direction = -1;
else if (sum < 0) direction = 1;
if (canMoveDown) {
this.y += gravity;
}
}
public void GetEnemyImage() {
this.r1 = new Image("file:src/PlayerImage/enemyWalk1.png");
this.r2 = new Image("file:src/PlayerImage/enemyWalk2.png");
this.r3 = new Image("file:src/PlayerImage/enemyWalk3.png");
this.r4 = new Image("file:src/PlayerImage/enemyWalk4.png");
this.r5 = new Image("file:src/PlayerImage/enemyWalk5.png");
this.r6 = new Image("file:src/PlayerImage/enemyWalk6.png");
this.r7 = new Image("file:src/PlayerImage/enemyWalk7.png");
this.r8 = new Image("file:src/PlayerImage/enemyWalk8.png");
this.r9 = new Image("file:src/PlayerImage/enemyWalk9.png");
this.r10 = new Image("file:src/PlayerImage/enemyWalk10.png");
this.r11 = new Image("file:src/PlayerImage/enemyWalk11.png");
this.r12 = new Image("file:src/PlayerImage/enemyWalk12.png");
}
public void drawEnemy(GraphicsContext gc, Player player) {
if (runCounter > 55) {
runCounter = 0;
}
//draw moving
switch (runCounter) {
case 0 -> this.image = r1;
case 5 -> this.image = r2;
case 10 -> this.image = r3;
case 15 -> this.image = r4;
case 20 -> this.image = r5;
case 25 -> this.image = r6;
case 30 -> this.image = r7;
case 35 -> this.image = r8;
case 40 -> this.image = r9;
case 45 -> this.image = r10;
case 50 -> this.image = r11;
case 55 -> this.image = r12;
}
runCounter++;
int enemy_w = this.drawW;
int enemy_h = this.h;
double enemy_xPos = (this.x - enemy_w*direction / 2.0) - 10*direction - player.getX() + player.screenX;
double enemy_yPos = (this.y - enemy_h / 2.0);
//hitbox
//gc.fillRect((this.x - w/2.0) - player.getX() + player.screenX, y - h/2.0, w, h);
gc.drawImage(image, enemy_xPos, enemy_yPos, enemy_w*direction, enemy_h);
}
}
package inf112.skeleton.app;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
public class Game extends Application {
private AnimationTimer timer;
private Canvas canvas;
private long nanosPerStep = 1000_000_000L / 60L;
private long timeBudget = nanosPerStep;
private long lastUpdateTime = 0L;
public double height = 600;
public double width = 1000;
double moveSky = 0.1;
private List<Wall> ListWalls = new ArrayList<>();
private List<Waffle> ListWaffle = new ArrayList<>();
private List<Enemy> ListEnemy = new ArrayList<>();
private List<Tree> ListTrees = new ArrayList<>();
private List<Checkpoint> ListCheckpoint = new ArrayList<>();
public Player player;
public Waffle wafflePoint = new Waffle(1, 1);
private Scene scene;
Image hearts = new Image("file:src/PlayerImage/heart.png");
Image waffleImg = new Image("file:src/PlayerImage/waffle.png");
Image background1 = new Image("file:src/PlayerImage/freecutetileset/FreeCuteTileset/BG1.png");
Image background2 = new Image("file:src/PlayerImage/freecutetileset/FreeCuteTileset/BG2.png");
Image background3 = new Image("file:src/PlayerImage/freecutetileset/FreeCuteTileset/BG3.png");
CollisionDetection cd = new CollisionDetection();
public int gameState;
public final int titleState = 0;
public final int playState = 1;
public final int deathState = 2;
public final int howToPlayState = 3;
public static void startIt(String[] args) {
launch(args);
}
public Scene getScene() {
return this.scene;
}
@Override
public void start(Stage stage) {
double width = this.width;
double height = this.height;
StackPane root = new StackPane();
this.scene = new Scene(root, width, height);
stage.setScene(scene);
canvas = new Canvas(width, height);
canvas.widthProperty().bind(scene.widthProperty());
canvas.heightProperty().bind(scene.heightProperty());
setupStart();
timer = new AnimationTimer() {
@Override
public void handle(long now) {
// System.out.println("Elapsed: " + (now -
// lastUpdateTime)/(double)millisPerStep);
if (lastUpdateTime > 0) {
timeBudget = Math.min(timeBudget + (now - lastUpdateTime), 10 * nanosPerStep);
}
lastUpdateTime = now;
while (timeBudget >= nanosPerStep) {
// System.out.println("Budget: " + timeBudget);
timeBudget = timeBudget - nanosPerStep;
step();
}
draw();
}
};
root.getChildren().add(canvas);
timer.start();
stage.show();
}
public void setupStart() {
gameState = titleState;
KeyHandlerStart keyS = new KeyHandlerStart(this);
scene.setOnKeyPressed(keyS::keyPressed);
}
public void setupDeath() {
gameState = deathState;
KeyHandlerStart keyS = new KeyHandlerStart(this);
scene.setOnKeyPressed(keyS::keyPressed);
}
public void howToPlay() {
gameState = howToPlayState;
KeyHandlerStart keyS = new KeyHandlerStart(this);
scene.setOnKeyPressed(keyS::keyPressed);
}
public void setup() {
gameState = playState;
ListEnemy.clear();
ListWalls.clear();
ListWaffle.clear();
ListTrees.clear();
ListCheckpoint.clear();
player = new Player(this);
KeyHandler keyH = new KeyHandler(player);
scene.setOnKeyPressed(keyH::keyPressed);
scene.setOnKeyReleased(keyH::keyReleased);
//SECTION 1
ListTrees.add(new Tree(296, 315, "tree"));
ListTrees.add(new Tree(900, 385, "tree"));
ListWalls.add(new Wall(200, 480, 100, 100, "grass"));
ListWalls.add(new Wall(296, 480, 100, 100, "grass"));
int idx1 = 64;
for (int i = 0; i < 12; i++) {
ListWalls.add(new Wall(idx1, 550, 100, 100, "grass"));
idx1 += 96;
}
ListEnemy.add(new Enemy(700, 250, 200));
ListWaffle.add(new Waffle(300, 350));
ListWaffle.add(new Waffle(1000, 400));
//BREAK
ListWalls.add(new Wall(1300, 390, 60, 60, "box"));
ListWalls.add(new Wall(1360, 390, 60, 60, "box"));
ListWalls.add(new Wall(1420, 390, 60, 60, "box"));
//SECTION 2
int idx2 = 1799;
for (int i = 0; i < 5; i++) {
ListWalls.add(new Wall(idx2, 440, 100, 100, "grass"));
idx2 += 96;
}
int idx3 = 1696;
for (int i = 0; i < 7; i++) {
ListWalls.add(new Wall(idx3, 480, 100, 100, "grass"));
idx3 += 96;
}
int idx4 = 1600;
for (int i = 0; i < 8; i++) {
ListWalls.add(new Wall(idx4, 550, 100, 100, "grass"));
idx4 += 96;
}
ListTrees.add(new Tree(1880, 275, "tree"));
ListWaffle.add(new Waffle(2300, 400));
ListWalls.add(new Wall(2200, 360, 60, 60, "box"));
//BREAK
ListWalls.add(new Wall(2500, 360, 60, 60, "box"));
ListWalls.add(new Wall(2800, 360, 60, 60, "box"));
ListWalls.add(new Wall(3100, 360, 60, 60, "box"));
//SECTION 3
int idx5 = 3400;
for (int i = 0; i < 10; i++) {
ListWalls.add(new Wall(idx5, 550, 100, 100, "grass"));
idx5 += 96;
}
ListCheckpoint.add(new Checkpoint(3600, 470));
ListTrees.add(new Tree(3500, 385, "pine"));
ListEnemy.add(new Enemy(3700, 250, 400));
ListEnemy.add(new Enemy(3800, 250, 300));
ListTrees.add(new Tree(4000, 385, "pine"));
ListTrees.add(new Tree(4100, 385, "pine"));
ListTrees.add(new Tree(4200, 385, "pine"));
//BREAK
ListWalls.add(new Wall(4400, 470, 60, 60, "box"));
ListWalls.add(new Wall(4410, 325, 60, 60, "box"));
ListWalls.add(new Wall(4720, 320, 60, 60, "box"));
int idx6 = 5000;
for (int i = 0; i < 10; i++) {
ListWalls.add(new Wall(idx6, 320, 60, 60, "box"));
idx6 += 60;
}
ListEnemy.add(new Enemy(5100, 200, 350));
ListWaffle.add(new Waffle(5300, 120));
}
protected void step() {
if (gameState == playState) {
player.canMoveLeft = true;
player.canMoveRight = true;
player.canMoveDown = true;
player.canMoveUp = true;
for (Wall wall : ListWalls) {
if (cd.checkCollision(player, wall, "right")) {
player.canMoveRight = false;
}
if (cd.checkCollision(player, wall, "left")) {
player.canMoveLeft = false;
}
if (cd.checkCollision(player, wall, "down")) {
player.canMoveDown = false;
player.onGround = true;
}
if (cd.checkCollision(player, wall, "up")) {
player.canMoveUp = false;
player.jump = false;
player.frames = 0;
}
}
for (Waffle waffle : new ArrayList<Waffle>(ListWaffle)) {
if (cd.checkCollision(player, waffle, "left") || cd.checkCollision(player, waffle, "right") ||
cd.checkCollision(player, waffle, "up") || cd.checkCollision(player, waffle, "down")) {
player.waffleScore++;
ListWaffle.remove(waffle);
}
}
for (Enemy enemy : new ArrayList<Enemy>(ListEnemy)) {
enemy.walk();
if (cd.checkCollision(player, enemy, "down") && !player.jump) {
ListEnemy.remove(enemy);
}
if (cd.checkCollision(player, enemy, "left") && !player.invincible) {
player.hearts--;
player.invincible = true;
}
if (cd.checkCollision(player, enemy, "right") && !player.invincible) {
player.hearts--;
player.invincible = true;
}
for (Wall wall : ListWalls) {
if (cd.checkCollision(enemy, wall, "down")) {
enemy.canMoveDown = false;
}
}
}
if (player.invincible) {
if (player.invincibleTimer == 0) {
player.invincible = false;
player.invincibleTimer = 100;
}
player.invincibleTimer--;
}
player.Move();
for (Checkpoint checkpoint : ListCheckpoint) {
if (cd.checkCollision(player, checkpoint, "left") || cd.checkCollision(player, checkpoint, "right") ||
cd.checkCollision(player, checkpoint, "up") || cd.checkCollision(player, checkpoint, "down")) {
player.spawnX = checkpoint.getX();
player.spawnY = checkpoint.getY() - player.getHeight()/2;
checkpoint.drawText = true;
}
else {
checkpoint.drawText = false;
}
}
if (player.getY() - player.getHeight() / 2.0 - 30 > this.height) {
player.Dead();
}
if (player.hearts <= 0) {
setupDeath();
}
}
}
protected void draw() {
GraphicsContext context = canvas.getGraphicsContext2D();
context.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
if (gameState == titleState) {
Color c = Color.rgb(245, 187, 131);
context.setFill(c);
context.fillRect(0, 0, this.width, this.height);
double x = this.width / 2;
double y = this.height / 3;
context.setFill(Color.WHITE);
context.setFont(new Font("Comic sans MS", 60));
context.fillText("Waffle Thursday", x - 240, y);
context.setFont(new Font("Comic sans MS", 30));
context.fillText("Press enter to play", x - 140, y + 80);
context.fillText("Press h for how to play", x - 170, y + 130);
context.restore();
} else if (gameState == deathState) {
Color c = Color.rgb(245, 187, 131);
context.setFill(c);
context.fillRect(0, 0, this.width, this.height);
double x = this.width / 2;
double y = this.height / 3;
context.setFill(Color.WHITE);
context.setFont(new Font("Comic sans MS", 60));
context.fillText("Game Over", x - 160, y);
context.setFont(new Font("Comic sans MS", 30));
context.fillText("You died", x - 70, y + 70);
context.fillText("Press enter to continue", x - 170, y + 120);
context.restore();
} else if (gameState == howToPlayState) {
Color c = Color.rgb(245, 187, 131);
context.setFill(c);
context.fillRect(0, 0, this.width, this.height);
double x = this.width / 2;
double y = this.height / 3;
context.setFill(Color.WHITE);
context.setFont(new Font("Comic sans MS", 30));
context.fillText("Reach the end of the map and \nacquire the final waffle to win.\n" +
"Jump on enemies to kill them.\n" +
"Collide with wooden posts to\n" +
"update your respawn location.", x - 210, y);
context.fillText("Press esc to go back", x - 150, y + 300);
context.restore();
} else {
context.drawImage(background1, 0, 0, this.width, this.height);
int bg2Index = (int) (-moveSky / this.width) - 1;
for (int i = 0; i < 3; i++)
context.drawImage(background2, this.width * (bg2Index + i) - moveSky, 0, this.width, this.height);
moveSky += 0.1;
int bg3Index = (int) (player.getX() * 0.15 / this.width) - 1;
for (int i = 0; i < 3; i++)
context.drawImage(background3, this.width / 2 + this.width * (bg3Index + i) - player.getX() * 0.15 + player.screenX, 0, this.width, this.height);
//TREE
for (Tree tree : ListTrees) {
tree.drawTree(context, player);
}
//WAFFLE DISPLAY
context.drawImage(waffleImg, 10, 55, 50, 50);
wafflePoint.waffleCount(context, player);
if (player.getX() < 200) {
wafflePoint.drawWaffleText(context, this.width, this.height);
}
//WALLS
for (Wall wall : ListWalls) {
wall.drawWall(context, player);
}
//ENEMY
for (Enemy enemy : ListEnemy) {
enemy.drawEnemy(context, player);
}
//WAFFLE
for (Waffle waffle : ListWaffle) {
waffle.drawWaffle(context, player);
}
for (Checkpoint checkpoint : ListCheckpoint) {
checkpoint.drawCheckpoint(context, player);
if (checkpoint.drawText) {
checkpoint.drawCheckpointText(context);
}
}
//PLAYER
player.drawPlayer(context);
//HEARTS
for (int i = 1; i <= player.hearts; i++) {
int w = 45;
int h = 45;
double x = 50 * i - w / 2.0;
double y = 50 - h / 2.0;
context.drawImage(hearts, x - w / 2.0, y - h / 2.0, w, h);
}
}
}
}
package inf112.skeleton.app;
import javafx.scene.input.KeyCode;
public class KeyHandler {
Player player;
public KeyHandler(Player player){
this.player = player;
}
public void keyPressed(javafx.scene.input.KeyEvent evt) {
KeyCode key = evt.getCode();
if (key == KeyCode.LEFT) {
player.move_left = true;
}
if (key == KeyCode.RIGHT) {
player.move_right = true;
}
if ((key == KeyCode.UP || key == KeyCode.SPACE) && player.onGround) {
player.jump = true;
player.runCounter = 0;
}
}
public void keyReleased(javafx.scene.input.KeyEvent evt) {
KeyCode key = evt.getCode();
if (key == KeyCode.LEFT ) {
player.move_left = false;
player.runCounter = 0;
}
if (key == KeyCode.RIGHT) {
player.move_right = false;
player.runCounter = 0;
}
}
}
......@@ -5,7 +5,6 @@ import inf112.skeleton.app.view.Game;
public class Main {
public static void main(String[] args) {
//BallDemo.startIt(args);
Game.startIt(args);
}
}
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Player implements IGameObject{
private int x, y, w, h, drawW;
public int speed = 5;
public int gravity = 5;
public int hearts = 3;
public int waffleScore = 0;
public int frames = 0;
public int runCounter = 0;
public int invincibleTimer = 100;
int spawnX = 45;
int spawnY = 50;
boolean move_left = false;
boolean move_right = false;
boolean jump = false;
boolean onGround = false;
boolean invincible = false;
boolean canMoveLeft, canMoveRight, canMoveDown, canMoveUp;
public final double screenX;
public final double screenY;
int direction = 1;
Image r1, r2, r3, r4, r5, r6, r7, r8;
Image i1, i2, i3, i4, i5, i6, i7, i8;
Image j1, j2;
Image f1, f2;
Image image;
public Player(Game game) {
PlayerValues();
GetPlayerImage();
screenX = game.height/2;
screenY = game.width/1.3;
}
/**
* Denne kontruktøren brukes bare for testing!
*/
public Player(){
PlayerValues();
//GetPlayerImage();
screenX = 0;
screenY = 0;
}
public void PlayerValues() {
this.x = 45;
this.y = 50;
this.w = 40;
this.h = 80;
this.drawW = 70;
}
public int getHeight() {
return this.h;
}
public int getWidth() {
return this.w;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getSpeed() {
return this.speed;
}
public int getGravity() {
return this.gravity;
}
public void GetPlayerImage() {
this.r1 = new Image("file:src/PlayerImage/Run1.png");
this.r2 = new Image("file:src/PlayerImage/Run2.png");
this.r3 = new Image("file:src/PlayerImage/Run3.png");
this.r4 = new Image("file:src/PlayerImage/Run4.png");
this.r5 = new Image("file:src/PlayerImage/Run5.png");
this.r6 = new Image("file:src/PlayerImage/Run6.png");
this.r7 = new Image("file:src/PlayerImage/Run7.png");
this.r8 = new Image("file:src/PlayerImage/Run8.png");
this.i1 = new Image("file:src/PlayerImage/Idle1.png");
this.i2 = new Image("file:src/PlayerImage/Idle2.png");
this.i3 = new Image("file:src/PlayerImage/Idle3.png");
this.i4 = new Image("file:src/PlayerImage/Idle4.png");
this.i5 = new Image("file:src/PlayerImage/Idle5.png");
this.i6 = new Image("file:src/PlayerImage/Idle6.png");
this.i7 = new Image("file:src/PlayerImage/Idle7.png");
this.i8 = new Image("file:src/PlayerImage/Idle8.png");
this.j1 = new Image("file:src/PlayerImage/Jump1.png");
this.j2 = new Image("file:src/PlayerImage/Jump2.png");
this.f1 = new Image("file:src/PlayerImage/Fall1.png");
this.f2 = new Image("file:src/PlayerImage/Fall2.png");
}
public void Move() {
if (move_left && canMoveLeft) {
direction = -1;
this.x -= this.speed;
}
if (move_right && canMoveRight){
direction = 1;
this.x += this.speed;
}
if (jump && canMoveUp) {
onGround = false;
if(frames < 25) {
frames++;
this.y -= 6;
}
else {
frames = 0;
jump = false;
runCounter = 0;
}
}
if(!jump && canMoveDown) {
this.y += gravity;
onGround = false;
}
}
public void drawPlayer(GraphicsContext gc) {
if (runCounter > 35) {
runCounter = 0;
}
//draw moving left
if (move_left && onGround) {
switch (runCounter) {
case 0 -> this.image = r1;
case 5 -> this.image = r2;
case 10 -> this.image = r3;
case 15 -> this.image = r4;
case 20 -> this.image = r5;
case 25 -> this.image = r6;
case 30 -> this.image = r7;
case 35 -> this.image = r8;
}
}
//draw moving right
if (move_right && onGround) {
switch (runCounter) {
case 0 -> this.image = r1;
case 5 -> this.image = r2;
case 10 -> this.image = r3;
case 15 -> this.image = r4;
case 20 -> this.image = r5;
case 25 -> this.image = r6;
case 30 -> this.image = r7;
case 35 -> this.image = r8;
}
}
//draw not moving
if (!move_left && !move_right && onGround) {
switch (runCounter) {
case 0 -> this.image = i1;
case 5 -> this.image = i2;
case 10 -> this.image = i3;
case 15 -> this.image = i4;
case 20 -> this.image = i5;
case 25 -> this.image = i6;
case 30 -> this.image = i7;
case 35 -> this.image = i8;
}
}
//draw jumping
if (jump) {
switch (runCounter) {
case 0 -> this.image = j1;
case 15 -> this.image = j2;
}
}
//draw falling
if (!jump && !onGround) {
switch (runCounter) {
case 0 -> this.image = f1;
case 15 -> this.image = f2;
}
}
runCounter++;
//hitbox
//gc.fillRect(screenX - w/2.0, y - h/2.0, w, h);
gc.drawImage(image, screenX-10*direction - drawW*direction/2.0, y - h/2.0, drawW * direction, h);
}
public void Dead() {
this.x = this.spawnX;
this.y = this.spawnY;
this.hearts --;
}
}
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Tree implements IGameObject{
int x, y, w, h;
String type;
Image treeImg = new Image("file:src/PlayerImage/tree.png");
Image pineImg = new Image("file:src/PlayerImage/pine.png");
public Tree(int X, int Y, String type) {
this.x = X;
this.y = Y;
this.w = 200;
this.h = 230;
this.type = type;
}
public int getHeight() {
return this.h;
}
public int getWidth() {
return this.w;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
@Override
public int getSpeed() {
return 0;
}
@Override
public int getGravity() {
return 5;
}
public void drawTree(GraphicsContext gc, Player player) {
int tree_w = this.w;
int tree_h = this.h;
double tree_xPos = (this.x - tree_w / 2.0) - player.getX() + player.screenX;
double tree_yPos = (this.y - tree_h / 2.0);
if (this.type == "tree") {
gc.drawImage(treeImg, tree_xPos, tree_yPos, tree_w, tree_h);
}
else if (this.type == "pine") {
gc.drawImage(pineImg, tree_xPos, tree_yPos, tree_w, tree_h);
}
}
}
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
public class Waffle implements IGameObject {
private int x, y, w, h;
Image waffleImg = new Image("file:src/PlayerImage/waffle.png");
public Waffle(int X, int Y) {
this.x = X;
this.y = Y;
this.w = 50;
this.h = 50;
}
public int getHeight() {
return this.h;
}
public int getWidth() {
return this.w;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
@Override
public int getSpeed() {
return 0;
}
@Override
public int getGravity() {
return 0;
}
public void drawWaffle(GraphicsContext gc, Player player) {
int waffle_w = this.w;
int waffle_h = this.h;
double waffle_xPos = (this.x - waffle_w / 2.0) - player.getX() + player.screenX;
double waffle_yPos = (this.y - waffle_h / 2.0);
gc.drawImage(waffleImg, waffle_xPos, waffle_yPos, waffle_w, waffle_h);
}
public void drawWafflePoints(GraphicsContext gc, double x, double y, int w, int h) {
gc.drawImage(waffleImg, x - w/2.0, y - h/2.0, w, h);
}
public void drawWaffleText(GraphicsContext gc, double w, double h) {
int width = 400;
int height = 200;
double x = w/2 - width/2;
double y = h/3.5 - height/2;
gc.setFill(Color.rgb(0, 0, 0, 0.8));
gc.fillRoundRect(x, y, width, height, 35, 35);
gc.setFill(Color.WHITE);
gc.setFont(new Font("Comic sans MS", 20));
gc.fillText("Hi! Waffle Thursday is closed and due\n to an error in the system, the very\n last waffle is made for " +
"two people,\n you and Anya!!! Battle against Anya\n to secure the last waffle.", x + 20, y + 50);
gc.restore();
}
public void waffleCount(GraphicsContext gc, Player player) {
gc.setFill(Color.WHITE);
gc.setFont(Font.font("Verdana", FontWeight.BOLD, 35));
gc.fillText("x" + player.waffleScore, 65, 95);
gc.restore();
}
}
package inf112.skeleton.app;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Wall implements IGameObject{
private int x, y, w, h;
String type;
Image platformGrass = new Image("file:src/PlayerImage/grassplatform.png");
Image box = new Image("file:src/PlayerImage/box.png");
public Wall(int X, int Y, int W, int H, String type) {
this.x = X;
this.y = Y;
this.w = W;
this.h = H;
this.type = type;
}
public int getHeight() {
return this.h;
}
public int getWidth() {
return this.w;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
@Override
public int getSpeed() {
return 0;
}
@Override
public int getGravity() {
return 0;
}
public void drawWall(GraphicsContext gc, Player player) {
int walls_w = this.w;
int walls_h = this.h;
double walls_xPos = (this.x - walls_w / 2.0) - player.getX() + player.screenX;
double walls_yPos = (this.y - walls_h / 2.0);
if (this.type == "grass") {
gc.drawImage(platformGrass, walls_xPos, walls_yPos, walls_w, walls_h);
}
else if (this.type == "box") {
gc.drawImage(box, walls_xPos, walls_yPos, walls_w, walls_h);
}
}
}
......@@ -8,7 +8,7 @@ public class TreeTest{
Tree tree;
@BeforeEach
void setup() {
this.tree = new Tree(0, 0, 200, 230);
this.tree = new Tree(0, 0, "tree");
}
@Test
......
......@@ -8,7 +8,7 @@ public class WaffleTest{
Waffle waffle;
@BeforeEach
void setup() {
this.waffle = new Waffle(0, 0, 50, 50);
this.waffle = new Waffle(0, 0);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment