diff --git a/src/Images1/car.png b/src/Images1/car.png deleted file mode 100644 index 43926969c2db7ec7b03645d3b89ca2318b8ae74a..0000000000000000000000000000000000000000 Binary files a/src/Images1/car.png and /dev/null differ diff --git a/src/Images1/cloud.png b/src/Images1/cloud.png deleted file mode 100644 index 90825a3777dac7549459dc94b2f5fa973657490d..0000000000000000000000000000000000000000 Binary files a/src/Images1/cloud.png and /dev/null differ diff --git a/src/Images1/dinosaur.png b/src/Images1/dinosaur.png deleted file mode 100644 index c8ca237211f03535801067d4b638c1cb2babd6bb..0000000000000000000000000000000000000000 Binary files a/src/Images1/dinosaur.png and /dev/null differ diff --git a/src/Images1/fly.png b/src/Images1/fly.png deleted file mode 100644 index d967e9553eb7379d5076ae3fc21cf1ca9d2e9bba..0000000000000000000000000000000000000000 Binary files a/src/Images1/fly.png and /dev/null differ diff --git a/src/Images1/h-banana.png b/src/Images1/h-banana.png deleted file mode 100644 index 55598ff54c3c757aec322dffcc0ecb1b477c0dc4..0000000000000000000000000000000000000000 Binary files a/src/Images1/h-banana.png and /dev/null differ diff --git a/src/Images1/heart.png b/src/Images1/heart.png deleted file mode 100644 index 417d80ac9510e8e089b02b121f6bf792f47766f4..0000000000000000000000000000000000000000 Binary files a/src/Images1/heart.png and /dev/null differ diff --git a/src/Images1/player2_sliding.png b/src/Images1/player2_sliding.png deleted file mode 100644 index f87ac1d9abc8b7348ea582dbc05a762f9d26c34c..0000000000000000000000000000000000000000 Binary files a/src/Images1/player2_sliding.png and /dev/null differ diff --git a/src/Images1/player_sliding.png b/src/Images1/player_sliding.png deleted file mode 100644 index 57476f650e1d481d0c83eee28e6fbb8a315e73f0..0000000000000000000000000000000000000000 Binary files a/src/Images1/player_sliding.png and /dev/null differ diff --git a/src/Images1/runner.png b/src/Images1/runner.png deleted file mode 100644 index 04660d17d9d980bd6c8c4e7a7ecf5156ecbed4e1..0000000000000000000000000000000000000000 Binary files a/src/Images1/runner.png and /dev/null differ diff --git a/src/Images1/smiley.png b/src/Images1/smiley.png deleted file mode 100644 index 78d8e15103c52e570431aaf4a81091a81c439584..0000000000000000000000000000000000000000 Binary files a/src/Images1/smiley.png and /dev/null differ diff --git a/src/Images1/tree.png b/src/Images1/tree.png deleted file mode 100644 index f92878e3f692fac8f738d3b6c63d81844fde9db4..0000000000000000000000000000000000000000 Binary files a/src/Images1/tree.png and /dev/null differ diff --git a/src/Images1/woman-running.png b/src/Images1/woman-running.png deleted file mode 100644 index 84cfab13a42b0d01201adb9af05da4888614fe99..0000000000000000000000000000000000000000 Binary files a/src/Images1/woman-running.png and /dev/null differ diff --git a/src/constants/Constants.java b/src/constants/Constants.java index e73a1847ef494d84f28d875f03ec0cc136260ee6..c83009cc7cf37ea5104b41a479df964ae526d459 100644 --- a/src/constants/Constants.java +++ b/src/constants/Constants.java @@ -1,26 +1,11 @@ package constants; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javafx.scene.image.Image; - +/** + * @author oscarwiberg, filipyhde + * Definerar globala konstanter som vi använder återkommande i andra klasser. + */ public interface Constants { - /** - * In this file we define some global constants. - * - * An interface is one way to store variables that are truly constants and not - * subject to change during run time. - * - * Please note that the problem with global variables is that anyone can change - * them whenever. This makes it extremely hard to reason about your code. But - * for constants, this is not a problem since we cannot change them, and - * therefore they stay the same during the entire execution of the program. - */ - /* - * Define the size of the window - */ final int screenWidth = 1000; final int screenHeight = 500; diff --git a/src/main/GameFrame.java b/src/main/GameFrame.java index cd07d05fb3efd6106a6502c7f2d0e42d8793d92b..714617d10cd73e03e577e1b6aa692debf90fa257 100644 --- a/src/main/GameFrame.java +++ b/src/main/GameFrame.java @@ -1,16 +1,15 @@ package main; import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; import states.GameModel; /** + * @author oscarwiberg, filipyhde * This class Wraps a HBox: A HBox is a second level JavaFX container used * organize contents in the window (Stage/Scene). * * The GameFrame, in this case, has the job of creating the game panel, and * adding it to itself in order for it to show. - * */ public class GameFrame extends HBox { private GamePanel g; diff --git a/src/main/GamePanel.java b/src/main/GamePanel.java index b966fd014f457b5dfa1aa8d518fa290d6f1e4369..008711c4763dd88f60786d02509f727057a22c85 100644 --- a/src/main/GamePanel.java +++ b/src/main/GamePanel.java @@ -1,10 +1,10 @@ package main; import states.GameModel; - import javafx.scene.canvas.Canvas; /** + * @author oscarwiberg, filipyhde * The GamePanel wraps a Canvas * * The main responsibilities of the GamePanel are: diff --git a/src/main/Main.java b/src/main/Main.java index 07ed30ea344cd456d3c4fe6d94c87442cc4a46d0..bdf7150c8be3bc60a5557ffbad2ed422932898fd 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,16 +1,13 @@ package main; import states.GameModel; - import constants.Constants; - import javafx.animation.AnimationTimer; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.stage.Stage; -//FFfffffffff /** * This Class is the entry point of the application. * <p> @@ -33,11 +30,6 @@ import javafx.stage.Stage; * @author magni54, alomi60 */ public class Main extends Application { - - private GameModel model; - private Scene gameScene; - private GameFrame frame; - public static void main(String[] args) { launch(args); diff --git a/src/states/Antagonist.java b/src/states/Antagonist.java deleted file mode 100644 index 22bb85fcce88080a5aa19a3f85646f21363250ab..0000000000000000000000000000000000000000 --- a/src/states/Antagonist.java +++ /dev/null @@ -1,61 +0,0 @@ -package states; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javafx.scene.image.Image; - -public abstract class Antagonist { - - protected double x; - protected double y; - protected Image img; - protected boolean collisionDetected; - - - public Antagonist(String image, double x, double y) { - this.x = x; - this.y = y; - this.collisionDetected = false; - - try { - this.img = new Image(new FileInputStream(image)); - - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public Antagonist(String image) { - this.collisionDetected = false; - - try { - this.img = new Image(new FileInputStream(image)); - - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public abstract boolean playerAntagonistCollision(Player player); - - public void setAntagonistX(double pos) { - this.x = pos; - } - - public double getX() { - return x; - } - - public double getY() { - return y; - } - - - public Image getImage() { - return img; - } - -} diff --git a/src/states/Bomb.java b/src/states/Bomb.java deleted file mode 100644 index d629f6623cf1bc856a4b68d186aaedd541efea01..0000000000000000000000000000000000000000 --- a/src/states/Bomb.java +++ /dev/null @@ -1,53 +0,0 @@ -package states; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import constants.Constants; -import javafx.geometry.Bounds; -import javafx.scene.image.Image; -import javafx.scene.shape.Rectangle; - -public class Bomb extends Object{ - - - - - public Bomb(String bombImg, double x, double y, double h, double w) { - super(bombImg, x, y, h, w); - - - } - -// public Bounds getBoundingBox() { -// return new Rectangle(startX, posY, Constants.bombWidth, Constants.bombHeight).getBoundsInParent(); -// } -// -// -// -// public double getX() { -// return startX; -// } -// -// -// -// -// public double getY() { -// return posY; -// } -// -// -// -// -// public Image getImage() { -// return image; -// } -// - public void render(int speed) { - this.posY += speed; - } - - - - -} diff --git a/src/states/Enemy.java b/src/states/Enemy.java index 406981d706e1c5a31d2d85a17954245628031ab8..c90c308b2a136b0971d10d9e8db93cb13ab8fe71 100644 --- a/src/states/Enemy.java +++ b/src/states/Enemy.java @@ -1,15 +1,10 @@ package states; -import java.io.FileInputStream; - -import java.io.FileNotFoundException; - -import constants.Constants; -import javafx.geometry.Bounds; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.shape.Rectangle; - +/** + * @author oscarwiberg, filipyhde + * Enemy(groundenemy), gör inte så mycket unikt och använder mest den fördefinierade funktionaliteten som finns objekt classen + * Bomben som flyingenemy är en instan av enemy. + */ public class Enemy extends Object{ diff --git a/src/states/ExtraLifePowerUp.java b/src/states/ExtraLifePowerUp.java index 8493c735aed93ba8395911fc509bdca87d2bff66..e65f26a8e54dd373f23c1592f67e2448acf8e4ce 100644 --- a/src/states/ExtraLifePowerUp.java +++ b/src/states/ExtraLifePowerUp.java @@ -1,10 +1,15 @@ package states; +/** + * @author oscarwiberg, filipyhde + * Usefunktionen är abstract eftersom powerupsen ger olika fördelar, denna återställer spelarens liv, oberoende hur många den har sen innan. + * Du kan därmed aldrig få mer liv än 3 som du startar med. + */ + public class ExtraLifePowerUp extends PowerUp { public ExtraLifePowerUp(String image, double x, double y, double h, double w) { super(image, x, y, h, w); - // TODO Auto-generated constructor stub } @Override diff --git a/src/states/FlyingEnemy.java b/src/states/FlyingEnemy.java index 4321ed3c4b355f57d925e1b3917345f10655fa03..d7b93d077accd6663488af2ccf737bc5d9d07261 100644 --- a/src/states/FlyingEnemy.java +++ b/src/states/FlyingEnemy.java @@ -1,17 +1,21 @@ package states; -import java.util.ArrayList; import constants.Constants; import java.util.Random; -import javafx.scene.image.Image; - +/** + * @author oscarwiberg, filipyhde + * FlyingEnemy är en klass som extendar object. + * Den flygande enemyn är en enemy som slöpper bomber på player. + * Första bomben släpps på random, därefter tar den in players posiotion fär att försöka släppa på player. + * Går att konfigurera den om man vill att den tar in player xpos efter senaste passeringen eller här och nu(det blir svårare) + * + */ public class FlyingEnemy extends Object{ private Random drop; private int margin = 50; - private Bomb bomb; private double bombDropX; private boolean bombDropped = false; @@ -24,7 +28,6 @@ public class FlyingEnemy extends Object{ } -//ceow private double dropNextBombX() { int minX = margin; @@ -34,10 +37,10 @@ public class FlyingEnemy extends Object{ //om man vill kan man skicka med players x pos på dirren, blir lite svårare då ba - public Bomb dropBomb(Player p) { + public Enemy dropBomb(Player p) { if (!bombDropped && this.getX() >= bombDropX - 50 && this.getX() <= bombDropX + 50) { - Bomb bomb = new Bomb(Constants.bombImg, bombDropX, 50, Constants.bombHeight, Constants.bombWidth); // Drop the bomb at bombDropX + Enemy bomb = new Enemy(Constants.bombImg, bombDropX, 50, Constants.bombHeight, Constants.bombWidth); // Drop the bomb at bombDropX System.out.println("Bomb dropped at: " + bombDropX); bombDropped = true; // Mark that the bomb has been dropped diff --git a/src/states/GameModel.java b/src/states/GameModel.java index 3632504fc2019a3d6334ee22f5e9033a94ac9a39..ae426e3d120a37d86b05ce5d8f4ce714a72d794c 100644 --- a/src/states/GameModel.java +++ b/src/states/GameModel.java @@ -4,7 +4,8 @@ import javafx.scene.canvas.GraphicsContext; import javafx.scene.input.KeyEvent; /** - * This class represents the current state of the game. + * @author oscarwiberg, filipyhde + * * This class represents the current state of the game. * * This implementation of a state machine keeps a reference to the current state * (see /src/states/GameState). @@ -18,9 +19,7 @@ import javafx.scene.input.KeyEvent; * passing a reference to some other gameState. * * Initial State: MenuState - * */ - public class GameModel { private GameState currentState; diff --git a/src/states/GameState.java b/src/states/GameState.java index cba0ddd627d4898fa1497189881797d744757f2b..a4adc898e974db0bde0a7ac57f6e786fd8f48932 100644 --- a/src/states/GameState.java +++ b/src/states/GameState.java @@ -1,15 +1,12 @@ package states; import javafx.scene.canvas.GraphicsContext; - import javafx.scene.input.KeyEvent; -import javafx.scene.layout.Pane; import javafx.scene.paint.Color; - - import constants.Constants; /** + * @author oscarwiberg, filipyhde * This class represents a state of the game. These states are different views * in the game, which contain their own separate logic. * @@ -29,7 +26,6 @@ import constants.Constants; * To define a valid state, that state has to be derived from this class, and * needs to override the three functions mentioned above. */ - public abstract class GameState { protected GameModel model; diff --git a/src/states/HighScore.java b/src/states/HighScore.java index 98931e969c4f6abb254898de27d6354bb9aa6c2c..e2f7ad9956145d70afa51429e003a4870aa10f3a 100644 --- a/src/states/HighScore.java +++ b/src/states/HighScore.java @@ -1,16 +1,15 @@ package states; -import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.File; - import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Scanner; +/** + * @author oscarwiberg + * Skriver och läser highscore till textfilen. Om den är tom returneras noll. + */ public class HighScore { diff --git a/src/states/MenuState.java b/src/states/MenuState.java index e32016fb176fc04943f4b6cf1ba1a8f875de2715..edd626d808c8b2b80035785629ec848074db819d 100644 --- a/src/states/MenuState.java +++ b/src/states/MenuState.java @@ -1,52 +1,46 @@ package states; import javafx.scene.canvas.GraphicsContext; - - import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.scene.text.Font; -import javafx.scene.text.Text; +import javafx.scene.transform.Rotate; import javafx.scene.image.Image; - import java.io.FileInputStream; import java.io.FileNotFoundException; - import constants.Constants; /** + * @author oscarwiberg, filipyhde * This state represents the menu of the Game The main responsibility of this * class is to allow the user to swap state to the PlayState */ public class MenuState extends GameState { - /* - * The following three variables are just used to show that a change of state - * can be made. The same variables also exist in the PlayState, can you think of - * a way to make this more general and not duplicate variables? - */ + private String informationText; private Color bgColor; private Color fontColor; - // A PlayState, so we can change to the PlayState from the menu. private PlayState playState; - private Image dinosaur; + private Image img1; + private Image img2; private boolean mode1; public MenuState(GameModel model) { super(model); - informationText = "Welcome to the Dino game!\nTo play, press 1 for mode 1 or 2 for mode 2\nEscape to exit game"; + informationText = "Welcome to the Dino game!\nTo play, press:\n1 for mode 1\n2 for mode 2\nEscape to exit game"; bgColor = Color.GREY; fontColor = Color.LIGHTBLUE; - + try { - - dinosaur = new Image(new FileInputStream("src/Images1/dinosaur.png")); + + img1 = new Image(new FileInputStream(Constants.playerImg)); + img2 = new Image(new FileInputStream(Constants.playerImg2)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + } /** @@ -56,14 +50,25 @@ public class MenuState extends GameState { public void draw(GraphicsContext g) { drawBg(g, bgColor); g.setFill(fontColor); - g.setFont(new Font(30)); // Big letters - // Print the information text, centered on the canvas - g.fillText(informationText, Constants.screenWidth/4, Constants.screenHeight / 4); - g.drawImage(dinosaur, Constants.screenWidth/2, Constants.screenHeight/2, 200, 200); - + g.setFont(new Font(30)); + g.fillText(informationText, Constants.screenWidth/3, Constants.screenHeight / 4); + drawRotatedImage(g, img1, 45, 0, 100, 450, 450); + drawRotatedImage(g, img2, -45, Constants.screenWidth - 450, 100, 450, 450); + } + + + private void drawRotatedImage(GraphicsContext g, Image image, double angle, double topLeftX, double topLeftY, double width, double height) { + g.save(); // Save the current graphics context state + rotate(g, angle, topLeftX + width / 2, topLeftY + height / 2); + g.drawImage(image, topLeftX, topLeftY, width, height); + g.restore(); // Restore the graphics context to its original state + } + + private void rotate(GraphicsContext gc, double angle, double px, double py) { + Rotate r = new Rotate(angle, px, py); + gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy()); } - @Override public void keyPressed(KeyEvent key) { System.out.println("Trycker på " + key.getText() + " i MenuState"); @@ -78,29 +83,28 @@ public class MenuState extends GameState { model.switchState(playState); } else if (key.getCode() == KeyCode.ESCAPE) { System.exit(0); - } - + } } @Override public void update() { // TODO Auto-generated method stub - + } @Override public void activate() { // TODO Auto-generated method stub - + } @Override public void deactivate() { // TODO Auto-generated method stub - + } - + } diff --git a/src/states/Object.java b/src/states/Object.java index abbe682c9abef9c9b4a641853103a471add24be8..026a78fafd809e17a43ade25e4a03f270b7ddfe4 100644 --- a/src/states/Object.java +++ b/src/states/Object.java @@ -2,12 +2,16 @@ package states; import java.io.FileInputStream; import java.io.FileNotFoundException; - import constants.Constants; import javafx.geometry.Bounds; import javafx.scene.image.Image; import javafx.scene.shape.Rectangle; +/** + * @author oscarwiberg, filipyhde + * Allt som inte är player går egentligen genom denna class för att ärva funktionalitet och variabler. + * + */ public abstract class Object { protected double posX; diff --git a/src/states/PlayState.java b/src/states/PlayState.java index 68dc3a0497f23f8100c3adb5d3386c819bcd9029..979d637a9ff0d96fd20209bb9284434022c2b99d 100644 --- a/src/states/PlayState.java +++ b/src/states/PlayState.java @@ -1,44 +1,19 @@ package states; import javafx.scene.canvas.GraphicsContext; - -import javafx.scene.image.Image; -import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; -import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; -import javafx.scene.text.Text; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; - import constants.Constants; /** - * This state represents the Playing State of the Game The main responsibility - * of this class is to; - create Game Objects - update Game Objects - draw Game - * Objects Game Objects are for instance; players, enemies, npc's, etc... - * - * The PlayState can also be thought off as a blue print where data is loaded - * into some container from a file or some other type of data storage. - * - * It can also be created by some class responsible for object creation and then - * passed to the PlayState as a parameter. This means all the PlayState has to - * do is receive a list of objects, store them in some container and then for - * every object in that container update and render that object. - * - * This way you can let the user define different Levels based on what - * parameters are passed into the PlayState. + * @author oscarwiberg, filipyhde + * hanterar självaste spelflödet. renderar alla karaktärer och objekt under spelets gång och uppdaterar alla positioner. */ public class PlayState extends GameState { - /* - * The following three variables are just used to show that a change of state - * can be made. The same variables also exist in the MenuState, can you think of - * a way to make this more general and not duplicate variables? - */ + private String informationText; private String livesleft; private String gameOverText; @@ -57,7 +32,7 @@ public class PlayState extends GameState { // private double tempy; private Random engen = new Random(); private int movingSpeed = 10; - private Bomb bomb; + private Enemy bomb; private boolean isFlyingEnemyActive = false; private String currScore; private double collisionX = -1.00; @@ -67,11 +42,6 @@ public class PlayState extends GameState { - /* Class only used for testing */ - - // TODO nästa steg, lägg in en flygande enemy för att testa glid funktionen, ändra boundsen på den glidande bilden! - // TODO kanske ta bort att skicka med image när man instansierar player - public PlayState(GameModel model, boolean mode) { super(model); informationText = "Press Escape \nTo Return To The Menu"; @@ -389,7 +359,7 @@ public class PlayState extends GameState { flyingEnemy.setX(flyingEnemy.getX() -movingSpeed); - Bomb droppedBomb = flyingEnemy.dropBomb(player); + Enemy droppedBomb = flyingEnemy.dropBomb(player); if (droppedBomb != null) { bomb = droppedBomb; diff --git a/src/states/Player.java b/src/states/Player.java index 121ed8d6a12662eddbf0e53d01f6dc2fdc4e3b7f..9b3c279de52cfb7cf34d4cae809662fbe9c205e9 100644 --- a/src/states/Player.java +++ b/src/states/Player.java @@ -5,7 +5,11 @@ import java.io.FileNotFoundException; import constants.Constants; import javafx.scene.image.Image; - +/** + * @author oscarwiberg, filipyhde + * player hanterar hur den rör sig efter vilka tangeter vi trycker på i playstate. + * Hanterar hur långt spelaren har kommit i spelet(passes), samt justerar sina liv utefter kollisioner. + */ public class Player { // TODO se över funktioner, kanske lättare att slå samman vissa @@ -162,9 +166,6 @@ public class Player { } - - - public void lockLives(boolean b) { livesLocked = b; diff --git a/src/states/PowerUp.java b/src/states/PowerUp.java index bc9271a75c30b0b4f2256297473bc0a16f654d89..f271fab6d1bccb81acda0087247acdfcd1ca1298 100644 --- a/src/states/PowerUp.java +++ b/src/states/PowerUp.java @@ -2,9 +2,14 @@ package states; import java.util.Random; +/** + * @author oscarwiberg, filipyhde + * Powerup bygger vidare på object eftersom vi fortfarande vill komma åt kollisionshanteringen + * när vi vill kolla kollision med powerup kallar vi däremot på checkcCollision, då kallar den på use om det blir en collision. + * De spawnar också in på en random y-coordinat inom det spannet som player kan nå med sitt hopp. + */ public abstract class PowerUp extends Object{ - private Boolean active = false; private int scoreSinceActive = 0; private Random random = new Random(); private int maxH = 110; diff --git a/src/states/SpeedPowerUp.java b/src/states/SpeedPowerUp.java index 64d6176f3c397863b67f342e833f930a7be58957..5d2ff7b907c8e9cfb0db17bfea41c6cbfd1ddb50 100644 --- a/src/states/SpeedPowerUp.java +++ b/src/states/SpeedPowerUp.java @@ -1,5 +1,11 @@ package states; +/** + * @author oscarwiberg, filipyhde + * Denhär klassen har en liten längre chain of events vid kollision. Vi kallar på handle i playstate, sparar hur många passes vi gjort samt nuvarande hastighet i spelet + * därfter kallar vi på kollision, om det blir kollision kallar den på use som låser liven på player och ökar spelhastigheten till 100. + * När det har gått 10 passeringar sen kollision återgår hastigheten till den som den var innan. + */ public class SpeedPowerUp extends PowerUp { private boolean active = false; @@ -8,7 +14,6 @@ public class SpeedPowerUp extends PowerUp { public SpeedPowerUp(String image, double x, double y, double h, double w) { super(image, x, y, h, w); - // TODO Auto-generated constructor stub } @Override @@ -20,9 +25,6 @@ public class SpeedPowerUp extends PowerUp { active = true; - - // TODO Auto-generated method stub - } public void handle(Player player, PlayState playState) { @@ -33,24 +35,14 @@ public class SpeedPowerUp extends PowerUp { this.checkCollision(player, playState); - - } else { - if ((player.getPasses() - start) >= 10) { playState.setSpeed(speed); player.lockLives(false); player.setPlayerY(265); active = false; - } - - } - - - } - -} +} \ No newline at end of file diff --git a/src/testing/Tester.java b/src/testing/Tester.java deleted file mode 100644 index 9fe95fcad9e613cd5ae7e48f6dcad51394eef9f5..0000000000000000000000000000000000000000 --- a/src/testing/Tester.java +++ /dev/null @@ -1,119 +0,0 @@ -package testing; - -import javafx.scene.canvas.GraphicsContext; - -import javafx.scene.image.Image; -import javafx.scene.transform.Rotate; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import constants.Constants; - - - -/** - * This class is only used for testing that PlayState works as intended. You - * will probably not have a similar class in your game. - */ -public class Tester { - // Internal class, mostly to show how it works in case you need it. - public class Point { - double x; - double y; - - public Point(double x, double y) { - this.x = x; - this.y = y; - } - } - - private Point position; - private Image banana; - private Image car; - private Image player; - private Image smile; - private int angle = 0; - - public Tester() { - position = new Point(0, 0); - - try { - banana = new Image(new FileInputStream("src/Images1/h-banana.png")); - car = new Image(new FileInputStream("src/Images1/car.png")); - smile = new Image(new FileInputStream("src/Images1/smiley.png")); - player = new Image(new FileInputStream(Constants.playerImg)); - - - } catch (FileNotFoundException e) { - System.out.println("Unable to find image-files!"); - } - } - - /** - * Sets the transform for the GraphicsContext to rotate around a pivot point. - * - * @param gc the graphics context the transform to applied to. - * @param angle the angle of rotation. - * @param px the x pivot coordinate for the rotation (in canvas coordinates). - * @param py the y pivot coordinate for the rotation (in canvas coordinates). - */ - private void rotate(GraphicsContext gc, double angle, double px, double py) { - Rotate r = new Rotate(angle, px, py); - gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy()); - } - - /** - * Draws an image on a graphics context. - * - * The image is drawn at (topLeftX, topLeftY) rotated by angle pivoted around the point: - * (topLeftX + image.getWidth() / 2, topLeftY + image.getHeight() / 2) - * - * @param g the graphics context the image is to be drawn on. - * @param angle the angle of rotation. - * @param topLeftX the top left x coordinate where the image will be plotted (in canvas coordinates). - * @param topLeftY the top left y coordinate where the image will be plotted (in canvas coordinates). - */ - private void drawRotatedImage(GraphicsContext g, Image image, double angle, double topLeftX, double topLeftY) { - g.save(); // saves the current state on stack, including the current transform - rotate(g, angle, topLeftX + image.getWidth() / 2, topLeftY + image.getHeight() / 2); - g.drawImage(image, topLeftX, topLeftY); - g.restore(); // back to original state (before rotation) - } - - /** - * Updates the position of the car and the banana. - */ - public void update() { - // We move the position for the images each "tick", or call from the timer. - // Can be adjusted to accomodate how fast you wish to move. - position.x -= 2; -// position.y -= 2; - angle -= 3; // Updates the angle of the rotating image - // angle -= 3; // Updates the angle of the rotating image - } - - public void delegate(GraphicsContext g) { - if (g != null) { - draw(g); - } - } - - private void draw(GraphicsContext g) { - // if (position.x >= SCREEN_WIDTH || position.y >= SCREEN_HEIGHT) { - if (position.x <= 0 || position.y >= Constants.screenHeight) { - // The position is exiting the screen, so we reset it - // position.x = 0.0; - position.x = 1000.0; - // position.y = 0.0; - position.y = 600.0; - } - -// drawRotatedImage(g, smile, angle, 500, 400); - g.drawImage(car, position.x, position.y, 100, 100); - g.drawImage(player, Constants.screenWidth/2-50, 600, 100, 100); - g.drawImage(banana, position.x, position.y, 100, 100); - } -} - -