├── RPGGame-main.zip ├── bin ├── Game │ ├── Game.class │ ├── Utils.class │ ├── World.class │ ├── Display.class │ ├── Handler.class │ ├── Launcher.class │ ├── UIManager.class │ ├── UIObject.class │ ├── GameCamera.class │ ├── KeyManager.class │ ├── ClickListener.class │ ├── MouseManager.class │ └── UIImageButton.class ├── Assets │ ├── Bar.class │ ├── Text.class │ ├── Tile.class │ ├── Tree.class │ ├── Arrow.class │ ├── Assets.class │ ├── Entity.class │ ├── Level.class │ ├── Monster.class │ ├── Player.class │ ├── XPBar.class │ ├── CoinAndXP.class │ ├── Creature.class │ ├── HealthBar.class │ ├── Description.class │ ├── InGamePlayer.class │ ├── MonsterBar.class │ ├── Transition$1.class │ ├── Transition.class │ ├── EntityManager.class │ ├── AttackBarManager.class │ ├── EntityManager$1.class │ └── AttackBarManager$1.class ├── textures │ ├── Bar.png │ ├── Player.png │ ├── Monsters.png │ └── LedgeTiles2.png ├── States │ ├── State.class │ ├── GameState.class │ ├── MenuState.class │ ├── BattleState.class │ ├── MenuState$1.class │ ├── BattleState$1.class │ ├── BattleState$2.class │ ├── BattleState$3.class │ └── BattleState$4.class └── ImageStuff │ ├── Animation.class │ ├── ImageLoader.class │ └── SpriteSheet.class ├── res ├── textures │ ├── Bar.png │ ├── Player.png │ ├── Tiles.png │ ├── Trees.png │ ├── Monsters.png │ └── LedgeTiles2.png └── worlds │ └── world1.txt ├── src ├── Game │ ├── ClickListener.java │ ├── Launcher.java │ ├── Handler.java │ ├── Utils.java │ ├── UIImageButton.java │ ├── UIManager.java │ ├── Display.java │ ├── GameCamera.java │ ├── UIObject.java │ ├── MouseManager.java │ ├── KeyManager.java │ ├── World.java │ └── Game.java ├── ImageStuff │ ├── SpriteSheet.java │ ├── ImageLoader.java │ └── Animation.java ├── States │ ├── State.java │ ├── MenuState.java │ ├── GameState.java │ └── BattleState.java ├── Assets │ ├── Level.java │ ├── InGamePlayer.java │ ├── Tree.java │ ├── Transition.java │ ├── XPBar.java │ ├── CoinAndXP.java │ ├── Description.java │ ├── EntityManager.java │ ├── Entity.java │ ├── Arrow.java │ ├── Tile.java │ ├── Bar.java │ ├── HealthBar.java │ ├── Creature.java │ ├── Player.java │ ├── Monster.java │ ├── MonsterBar.java │ ├── Text.java │ ├── AttackBarManager.java │ └── Assets.java └── world1.txt └── README.md /RPGGame-main.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/RPGGame-main.zip -------------------------------------------------------------------------------- /bin/Game/Game.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/Game.class -------------------------------------------------------------------------------- /bin/Assets/Bar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Bar.class -------------------------------------------------------------------------------- /bin/Assets/Text.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Text.class -------------------------------------------------------------------------------- /bin/Assets/Tile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Tile.class -------------------------------------------------------------------------------- /bin/Assets/Tree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Tree.class -------------------------------------------------------------------------------- /bin/Game/Utils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/Utils.class -------------------------------------------------------------------------------- /bin/Game/World.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/World.class -------------------------------------------------------------------------------- /bin/textures/Bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/textures/Bar.png -------------------------------------------------------------------------------- /res/textures/Bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/Bar.png -------------------------------------------------------------------------------- /bin/Assets/Arrow.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Arrow.class -------------------------------------------------------------------------------- /bin/Assets/Assets.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Assets.class -------------------------------------------------------------------------------- /bin/Assets/Entity.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Entity.class -------------------------------------------------------------------------------- /bin/Assets/Level.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Level.class -------------------------------------------------------------------------------- /bin/Assets/Monster.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Monster.class -------------------------------------------------------------------------------- /bin/Assets/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Player.class -------------------------------------------------------------------------------- /bin/Assets/XPBar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/XPBar.class -------------------------------------------------------------------------------- /bin/Game/Display.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/Display.class -------------------------------------------------------------------------------- /bin/Game/Handler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/Handler.class -------------------------------------------------------------------------------- /bin/Game/Launcher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/Launcher.class -------------------------------------------------------------------------------- /bin/Game/UIManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/UIManager.class -------------------------------------------------------------------------------- /bin/Game/UIObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/UIObject.class -------------------------------------------------------------------------------- /bin/States/State.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/State.class -------------------------------------------------------------------------------- /bin/textures/Player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/textures/Player.png -------------------------------------------------------------------------------- /res/textures/Player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/Player.png -------------------------------------------------------------------------------- /res/textures/Tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/Tiles.png -------------------------------------------------------------------------------- /res/textures/Trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/Trees.png -------------------------------------------------------------------------------- /bin/Assets/CoinAndXP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/CoinAndXP.class -------------------------------------------------------------------------------- /bin/Assets/Creature.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Creature.class -------------------------------------------------------------------------------- /bin/Assets/HealthBar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/HealthBar.class -------------------------------------------------------------------------------- /bin/Game/GameCamera.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/GameCamera.class -------------------------------------------------------------------------------- /bin/Game/KeyManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/KeyManager.class -------------------------------------------------------------------------------- /bin/States/GameState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/GameState.class -------------------------------------------------------------------------------- /bin/States/MenuState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/MenuState.class -------------------------------------------------------------------------------- /bin/textures/Monsters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/textures/Monsters.png -------------------------------------------------------------------------------- /res/textures/Monsters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/Monsters.png -------------------------------------------------------------------------------- /bin/Assets/Description.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Description.class -------------------------------------------------------------------------------- /bin/Assets/InGamePlayer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/InGamePlayer.class -------------------------------------------------------------------------------- /bin/Assets/MonsterBar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/MonsterBar.class -------------------------------------------------------------------------------- /bin/Assets/Transition$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Transition$1.class -------------------------------------------------------------------------------- /bin/Assets/Transition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/Transition.class -------------------------------------------------------------------------------- /bin/Game/ClickListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/ClickListener.class -------------------------------------------------------------------------------- /bin/Game/MouseManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/MouseManager.class -------------------------------------------------------------------------------- /bin/Game/UIImageButton.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Game/UIImageButton.class -------------------------------------------------------------------------------- /bin/States/BattleState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/BattleState.class -------------------------------------------------------------------------------- /bin/States/MenuState$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/MenuState$1.class -------------------------------------------------------------------------------- /bin/textures/LedgeTiles2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/textures/LedgeTiles2.png -------------------------------------------------------------------------------- /res/textures/LedgeTiles2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/res/textures/LedgeTiles2.png -------------------------------------------------------------------------------- /bin/Assets/EntityManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/EntityManager.class -------------------------------------------------------------------------------- /bin/ImageStuff/Animation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/ImageStuff/Animation.class -------------------------------------------------------------------------------- /bin/States/BattleState$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/BattleState$1.class -------------------------------------------------------------------------------- /bin/States/BattleState$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/BattleState$2.class -------------------------------------------------------------------------------- /bin/States/BattleState$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/BattleState$3.class -------------------------------------------------------------------------------- /bin/States/BattleState$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/States/BattleState$4.class -------------------------------------------------------------------------------- /bin/Assets/AttackBarManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/AttackBarManager.class -------------------------------------------------------------------------------- /bin/Assets/EntityManager$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/EntityManager$1.class -------------------------------------------------------------------------------- /bin/ImageStuff/ImageLoader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/ImageStuff/ImageLoader.class -------------------------------------------------------------------------------- /bin/ImageStuff/SpriteSheet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/ImageStuff/SpriteSheet.class -------------------------------------------------------------------------------- /bin/Assets/AttackBarManager$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuelvin/eclipse-rpg-game/HEAD/bin/Assets/AttackBarManager$1.class -------------------------------------------------------------------------------- /src/Game/ClickListener.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | public interface ClickListener { 4 | 5 | public void onClick(); 6 | } 7 | -------------------------------------------------------------------------------- /src/Game/Launcher.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | public class Launcher{ 4 | public static void main(String[] args) { 5 | Game game = new Game("Title", 800, 800); 6 | game.start(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eclipse-rpg-game 2 | 3 | Tile-based RPG game with a turn-based battling system; created 100% using the Eclipse IDE and Java. 4 | 5 | -- 6 | 7 | Developed from Dec. 2017 to Jun. 2018 8 | 9 | Added to Github May 2022 10 | 11 | -- 12 | 13 | HOW TO PLAY 14 | 15 | Arrow keys or WASD to move. 16 | 17 | Space to attack/defend during the player and enemy turn. 18 | -------------------------------------------------------------------------------- /src/ImageStuff/SpriteSheet.java: -------------------------------------------------------------------------------- 1 | package ImageStuff; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | public class SpriteSheet { 6 | private BufferedImage sheet; 7 | 8 | public SpriteSheet(BufferedImage sheet) { 9 | this.sheet = sheet; 10 | } 11 | 12 | public BufferedImage crop(int x, int y, int width, int height) { 13 | //returns new image of the x and y area specified 14 | return sheet.getSubimage(x, y, width, height); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/ImageStuff/ImageLoader.java: -------------------------------------------------------------------------------- 1 | package ImageStuff; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.IOException; 5 | 6 | import javax.imageio.ImageIO; 7 | 8 | public class ImageLoader { 9 | 10 | public static BufferedImage loadImage(String path) { 11 | try { 12 | //load in image 13 | return ImageIO.read(ImageLoader.class.getResource(path)); 14 | } catch (IOException e) { 15 | e.printStackTrace(); 16 | System.exit(1); 17 | } 18 | return null; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/States/State.java: -------------------------------------------------------------------------------- 1 | package States; 2 | 3 | import java.awt.Graphics; 4 | 5 | import Game.Handler; 6 | 7 | public abstract class State { 8 | 9 | private static State currentState = null; 10 | 11 | public static void setState(State state) { 12 | currentState = state; 13 | } 14 | 15 | public static State getState() { 16 | return currentState; 17 | } 18 | 19 | protected Handler handler; 20 | 21 | public State(Handler handler) { 22 | this.handler = handler; 23 | } 24 | 25 | public abstract void tick(); 26 | 27 | public abstract void render(Graphics g); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Assets/Level.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | 5 | public class Level { 6 | 7 | private int level; 8 | private int x; 9 | private int y; 10 | private Text levelText; 11 | private int type; 12 | 13 | public Level(int type, int level, int x, int y) { 14 | this.type = type; 15 | this.level = level; 16 | this.x = x; 17 | this.y = y; 18 | levelText = new Text(level + "", x + 368, y + 22, 4, 1); 19 | } 20 | 21 | public void tick() { 22 | 23 | } 24 | 25 | public void render(Graphics g) { 26 | g.drawImage(Assets.monsterLevel, x + 304, y + 14, 92, 40, null); 27 | levelText.render(g); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/Assets/InGamePlayer.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | 6 | import Game.Handler; 7 | 8 | public class InGamePlayer { 9 | 10 | Description description; 11 | Handler handler; 12 | 13 | public InGamePlayer(Handler handler) { 14 | this.handler = handler; 15 | description = new Description(1, Player.name, Player.health, Player.baseHealth, Player.level, 392, 396, handler); 16 | } 17 | 18 | public void tick() { 19 | description.tick(); 20 | } 21 | 22 | public void render(Graphics g) { 23 | description.render(g); 24 | Color c = new Color(184, 184, 184); 25 | g.setColor(c); 26 | //g.fillRect(396, 516, 400, 12); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Game/Handler.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | public class Handler { 4 | 5 | private Game game; 6 | private World world; 7 | 8 | public Handler(Game game) { 9 | this.game = game; 10 | } 11 | 12 | public GameCamera getGameCamera() { 13 | return game.getGameCamera(); 14 | } 15 | 16 | public KeyManager getKeymanager() { 17 | return game.getKeyManager(); 18 | } 19 | 20 | public MouseManager getMouseManager() { 21 | return game.getMouseManager(); 22 | } 23 | 24 | public int getWidth() { 25 | return game.getWidth(); 26 | } 27 | 28 | public int getHeight() { 29 | return game.getHeight(); 30 | } 31 | 32 | public Game getGame() { 33 | return game; 34 | } 35 | 36 | public void setGame(Game game) { 37 | this.game = game; 38 | } 39 | 40 | public World getWorld() { 41 | return world; 42 | } 43 | 44 | public void setWorld(World world) { 45 | this.world = world; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/Game/Utils.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | public class Utils { 8 | 9 | public static String loadFileAsString(String path) { 10 | StringBuilder builder = new StringBuilder(); 11 | 12 | try { 13 | BufferedReader br = new BufferedReader(new FileReader(path)); 14 | System.out.println("BR: " + br); 15 | String line; 16 | while((line = br.readLine()) != null){ 17 | builder.append(line + "\n"); 18 | } 19 | 20 | br.close(); 21 | }catch(IOException e) { 22 | e.printStackTrace(); 23 | } 24 | return builder.toString(); 25 | } 26 | 27 | public static int parseInt(String number) { 28 | try { 29 | return Integer.parseInt(number); 30 | }catch(NumberFormatException e) { 31 | e.printStackTrace(); 32 | return 0; 33 | } 34 | } 35 | 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/ImageStuff/Animation.java: -------------------------------------------------------------------------------- 1 | package ImageStuff; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | public class Animation { 6 | 7 | private int speed, index; 8 | private long lastTime, timer; 9 | private BufferedImage[] frames; 10 | 11 | public Animation(int speed, BufferedImage[] frames) { 12 | this.speed = speed; 13 | this.frames = frames; 14 | index = 0; 15 | lastTime = System.currentTimeMillis(); 16 | } 17 | 18 | public void tick() { 19 | timer += System.currentTimeMillis() - lastTime; 20 | lastTime = System.currentTimeMillis(); 21 | 22 | if(timer > speed) { 23 | index++; 24 | timer = 0; 25 | if(index >= frames.length) { 26 | index = 0; 27 | } 28 | } 29 | } 30 | 31 | public int getIndex() { 32 | return index; 33 | } 34 | 35 | public void setIndex(int index) { 36 | this.index = index; 37 | } 38 | public BufferedImage getCurrentFrame() { 39 | return frames[index]; 40 | } 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/States/MenuState.java: -------------------------------------------------------------------------------- 1 | package States; 2 | 3 | import java.awt.Color; 4 | 5 | import java.awt.Graphics; 6 | 7 | import Game.ClickListener; 8 | import Game.Handler; 9 | import Game.UIImageButton; 10 | import Game.UIManager; 11 | import Assets.Assets; 12 | 13 | public class MenuState extends State{ 14 | 15 | private UIManager uiManager; 16 | 17 | public MenuState(Handler handler) { 18 | super(handler); 19 | uiManager = new UIManager(handler); 20 | handler.getMouseManager().setUIManager(uiManager); 21 | 22 | uiManager.addObject(new UIImageButton(200, 200, 128, 64, Assets.buttonStart, new ClickListener() { 23 | 24 | @Override 25 | public void onClick() { 26 | handler.getMouseManager().setUIManager(null); 27 | State.setState(handler.getGame().gameState); 28 | } 29 | })); 30 | } 31 | 32 | @Override 33 | public void tick() { 34 | uiManager.tick(); 35 | } 36 | 37 | @Override 38 | public void render(Graphics g) { 39 | uiManager.render(g); 40 | } 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/Game/UIImageButton.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.event.MouseListener; 5 | import java.awt.event.MouseMotionListener; 6 | import java.awt.image.BufferedImage; 7 | 8 | import States.BattleState; 9 | 10 | public class UIImageButton extends UIObject{ 11 | 12 | private BufferedImage[] images; 13 | private ClickListener clicker; 14 | 15 | public UIImageButton(float x, float y, int width, int height, BufferedImage[] images, ClickListener clicker) { 16 | super(x, y, width, height); 17 | this.images = images; 18 | this.clicker = clicker; 19 | } 20 | 21 | @Override 22 | public void tick() {} 23 | 24 | @Override 25 | public void render(Graphics g) { 26 | if(hovering) { 27 | g.drawImage(images[1], (int) x, (int) y, width, height, null); 28 | } else { 29 | g.drawImage(images[0], (int) x, (int) y, width, height, null); 30 | } 31 | } 32 | 33 | @Override 34 | public void onClick() { 35 | clicker.onClick(); 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/Assets/Tree.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Color; 4 | 5 | import java.awt.Graphics; 6 | 7 | import Game.Game; 8 | import Game.Handler; 9 | import Assets.Tile; 10 | 11 | public class Tree extends Entity{ 12 | private int type; 13 | public Tree(Handler handler, float x, float y, int type) { 14 | super(handler, x, y, Tile.TILEWIDTH * 3, Tile.TILEHEIGHT * 3); 15 | this.type = type; 16 | bounds.width = this.width / 2 + 30; 17 | bounds.height = this.height / 6 + 1; 18 | bounds.x = Tile.TILEWIDTH * 2 - bounds.width; 19 | bounds.y = Tile.TILEHEIGHT * 2; 20 | 21 | } 22 | 23 | @Override 24 | public void tick() { 25 | 26 | } 27 | 28 | @Override 29 | public void render(Graphics g) { 30 | g.drawImage(Assets.trees[type], (int) (x - handler.getGameCamera().getxOffset()), (int) (y - handler.getGameCamera().getyOffset()), width, height, null); 31 | 32 | if(Game.showHitboxes) { 33 | g.setColor(Color.red); 34 | g.drawRect((int) (x + bounds.x - handler.getGameCamera().getxOffset()), (int) (y + bounds.y - handler.getGameCamera().getyOffset()), bounds.width, bounds.height); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/Assets/Transition.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.util.Timer; 6 | import java.util.TimerTask; 7 | 8 | public class Transition { 9 | private int i = 0; 10 | private int milliSecondsPassed; 11 | private Timer timer; 12 | private TimerTask task; 13 | public static boolean canStart; 14 | 15 | 16 | public Transition() { 17 | canStart = false; 18 | milliSecondsPassed = 0; 19 | timer = new Timer(); 20 | task = new TimerTask() { 21 | public void run() { 22 | milliSecondsPassed++; 23 | //System.out.println(milliSecondsPassed); 24 | } 25 | }; 26 | timer.scheduleAtFixedRate(task, 1, 1); 27 | } 28 | 29 | public void render(Graphics g) { 30 | //System.out.println(milliSecondsPassed); 31 | if(milliSecondsPassed > 400) { 32 | g.setColor(Color.white); 33 | g.fillRect(0, 0, 800, 800); 34 | } 35 | if(milliSecondsPassed > 475) { 36 | g.dispose(); 37 | milliSecondsPassed = 0; 38 | i++; 39 | } 40 | if(i == 3) { 41 | i = 0; 42 | timer.cancel(); 43 | task.cancel(); 44 | canStart = true; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Assets/XPBar.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | import java.awt.Color; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | 8 | import States.GameState; 9 | 10 | public class XPBar { 11 | 12 | private int x; 13 | private int y; 14 | private Text healthText; 15 | 16 | public XPBar(int x, int y) { 17 | this.x = x; 18 | this.y = y; 19 | healthText = new Text(Player.health + "/" + Player.baseHealth, x + 152, y + 80, 4, 1); 20 | } 21 | 22 | public void tick() { 23 | } 24 | 25 | public void render(Graphics g) { 26 | drawXPBar(g); 27 | } 28 | 29 | private void drawXPBar(Graphics g) { 30 | Graphics2D g2d = (Graphics2D) g; 31 | int cc = 90; 32 | Color c = new Color(cc, cc, cc); 33 | g.setColor(c); 34 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); 35 | g.fillRect(112, 44, 276, 20); 36 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); 37 | 38 | c = new Color(0, 0, 255); 39 | g.setColor(c); 40 | for(int i = 0; i < GameState.xp * 10; i++) { 41 | g.fillRect(x + 88 + i , y + 44, 2, 20); 42 | } 43 | 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Game/UIManager.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.event.MouseEvent; 5 | import java.util.ArrayList; 6 | 7 | public class UIManager { 8 | 9 | private Handler handler; 10 | private ArrayList objects; 11 | 12 | public UIManager(Handler handler) { 13 | this.setHandler(handler); 14 | objects = new ArrayList(); 15 | } 16 | 17 | public void tick() { 18 | for(UIObject o : objects) { 19 | o.tick(); 20 | } 21 | } 22 | 23 | public void render(Graphics g) { 24 | for(UIObject o : objects) { 25 | o.render(g); 26 | } 27 | } 28 | 29 | public void onMouseMove(MouseEvent e) { 30 | for(UIObject o : objects) { 31 | o.onMouseMove(e); 32 | } 33 | } 34 | 35 | public void onMouseRelease(MouseEvent e) { 36 | for(UIObject o : objects) { 37 | o.onMouseRelease(e); 38 | } 39 | } 40 | 41 | public void addObject(UIObject o) { 42 | objects.add(o); 43 | } 44 | 45 | public void removeObject(UIObject o) { 46 | objects.remove(o); 47 | } 48 | 49 | public Handler getHandler() { 50 | return handler; 51 | } 52 | 53 | public void setHandler(Handler handler) { 54 | this.handler = handler; 55 | } 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/Game/Display.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | import java.awt.Canvas; 3 | import java.awt.Dimension; 4 | 5 | import javax.swing.JFrame; 6 | 7 | public class Display { 8 | 9 | private JFrame frame; 10 | private Canvas canvas; 11 | 12 | private String title; 13 | private int width; 14 | private int height; 15 | 16 | public Display(String title, int width, int height) { 17 | this.title = title; 18 | this.width = width; 19 | this.height = height; 20 | 21 | createDisplay(); 22 | } 23 | 24 | private void createDisplay() { 25 | frame = new JFrame(title); 26 | frame.setSize(width, height); 27 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 28 | frame.setResizable(false); 29 | frame.setLocationRelativeTo(null); 30 | frame.setVisible(true); 31 | 32 | 33 | canvas = new Canvas(); 34 | canvas.setPreferredSize(new Dimension(width, height)); 35 | canvas.setMaximumSize(new Dimension(width, height)); 36 | canvas.setMinimumSize(new Dimension(width, height)); 37 | canvas.setFocusable(false); 38 | 39 | frame.add(canvas); 40 | frame.pack(); 41 | } 42 | 43 | public Canvas getCanvas() { 44 | return canvas; 45 | } 46 | 47 | public JFrame getFrame() { 48 | return frame; 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/States/GameState.java: -------------------------------------------------------------------------------- 1 | package States; 2 | 3 | import java.awt.Color; 4 | import java.awt.Graphics; 5 | import java.awt.image.BufferedImage; 6 | import java.util.Timer; 7 | import java.util.TimerTask; 8 | 9 | import Assets.Assets; 10 | import Assets.Description; 11 | import Assets.Player; 12 | import Assets.Text; 13 | import Game.Handler; 14 | import Game.World; 15 | 16 | public class GameState extends State{ 17 | 18 | private Player player; 19 | private World world; 20 | public static boolean flag; 21 | private Description playerDescription; 22 | public static int coins = 0; 23 | public static int xp = 0; 24 | private Text coinsText; 25 | 26 | public GameState(Handler handler) { 27 | super(handler); //calls constructor of "State" class 28 | world = new World(handler, "res/worlds/world1.txt"); 29 | handler.setWorld(world); 30 | playerDescription = new Description(2, Player.name, Player.health, Player.baseHealth, Player.level, handler); 31 | 32 | } 33 | 34 | 35 | 36 | @Override 37 | public void tick() { 38 | world.tick(); 39 | 40 | } 41 | 42 | @Override 43 | public void render(Graphics g) { 44 | world.render(g); 45 | playerDescription.render(g); 46 | coinsText = new Text(coins + "", 50, 126, 4, 4); 47 | coinsText.render(g); 48 | 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/Game/GameCamera.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import Assets.Entity; 4 | import Assets.Tile; 5 | 6 | public class GameCamera { 7 | 8 | private Handler handler; 9 | private float xOffset, yOffset; 10 | 11 | public GameCamera(Handler handler, float xOffset, float yOffset) { 12 | this.handler = handler; 13 | this.xOffset = xOffset; 14 | this.yOffset = yOffset; 15 | } 16 | 17 | public void checkBlankSpace() { 18 | if(xOffset < 0) { 19 | xOffset = 0; 20 | } else if(xOffset > handler.getWorld().getWidth() * Tile.TILEWIDTH - handler.getWidth()) { 21 | xOffset = handler.getWorld().getWidth() * Tile.TILEWIDTH - handler.getWidth(); 22 | } 23 | 24 | if(yOffset < 0) { 25 | yOffset = 0; 26 | } else if(yOffset > handler.getWorld().getHeight() * Tile.TILEHEIGHT - handler.getHeight()) { 27 | yOffset = handler.getWorld().getHeight() * Tile.TILEHEIGHT - handler.getHeight(); 28 | } 29 | } 30 | 31 | public void centerOnEntity(Entity e) { 32 | xOffset = e.getX() - handler.getWidth() / 2 + e.getWidth() / 2; 33 | yOffset = e.getY() - handler.getHeight() / 2 + e.getHeight() / 2; 34 | checkBlankSpace(); 35 | } 36 | 37 | public void move(float xAmount, float yAmount) { 38 | xOffset += xAmount; 39 | yOffset += yAmount; 40 | } 41 | 42 | public float getxOffset() { 43 | return xOffset; 44 | } 45 | 46 | public void setxOffset(float xOffset) { 47 | this.xOffset = xOffset; 48 | } 49 | 50 | public float getyOffset() { 51 | return yOffset; 52 | } 53 | 54 | public void setyOffset(float yOffset) { 55 | this.yOffset = yOffset; 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/Assets/CoinAndXP.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | import java.awt.Graphics; 5 | import java.awt.Graphics2D; 6 | import java.util.ArrayList; 7 | 8 | public class CoinAndXP { 9 | 10 | private int x; 11 | private int y; 12 | private int type; 13 | private int type2; 14 | private float xVel; 15 | private float yVel; 16 | private float opacity = 1; 17 | 18 | private float randSpeed; 19 | 20 | public CoinAndXP(int x, int y) { 21 | this.x = 500; 22 | this.y = 200; 23 | type = (int)Math.round(Math.random()); 24 | type2 = (int)Math.round(Math.random()); 25 | if(type2 == 0){ 26 | xVel = (int)(Math.random() * 3 + 1); 27 | } else { 28 | xVel = (int)(Math.random() * 3 + 1) * -1; 29 | } 30 | randSpeed = (int)(Math.random() * 99 + 1) / 100; 31 | yVel = 10; 32 | } 33 | 34 | public void tick() { 35 | x += xVel; 36 | y -= yVel; 37 | if(type2 == 0) { 38 | xVel += randSpeed; 39 | } else { 40 | xVel -= randSpeed * -1; 41 | } 42 | yVel -= 0.4f; 43 | } 44 | 45 | public void render(Graphics g) { 46 | Graphics2D g2d = (Graphics2D) g; 47 | if(opacity >= 0.017) { 48 | opacity -= 0.017; 49 | } else { 50 | opacity = 0; 51 | } 52 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); 53 | 54 | if(type == 0) { 55 | g.drawImage(Assets.coin, x, y, 8 * 4, 8 * 4, null); 56 | } else { 57 | g.drawImage(Assets.xp, x, y, 10 * 4, 8 * 4, null); 58 | } 59 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/Assets/Description.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | 5 | import Game.Handler; 6 | 7 | public class Description { 8 | private Text nameText; 9 | private String name; 10 | private int level; 11 | private int x; 12 | private int y; 13 | private Level levelDescription; 14 | private HealthBar healthBar; 15 | private XPBar xpBar; 16 | private int baseHealth; 17 | private int health; 18 | private int type; 19 | private Handler handler; 20 | 21 | public Description(int type, String name, int health, int baseHealth, int level, int x, int y, Handler handler) { 22 | nameText = new Text(name, x - 4, y + 22, 4, -1); 23 | this.handler = handler; 24 | this.type = type; 25 | this.name = name; 26 | this.level = level; 27 | this.x = x; 28 | this.y = y; 29 | this.health = health; 30 | this.baseHealth = baseHealth; 31 | levelDescription = new Level(type, level, x, y); 32 | healthBar = new HealthBar(type, x, y, handler); 33 | xpBar = new XPBar(x, y); 34 | } 35 | 36 | public Description(int type, String name, int health, int baseHealth, int level, Handler handler) { 37 | this(type, name, health, baseHealth, level, 0, 0, handler); 38 | } 39 | 40 | public void tick() { 41 | healthBar.tick(); 42 | } 43 | 44 | public void render(Graphics g) { 45 | if(type == 0 || type == 1) { 46 | g.drawImage(Assets.enemyDescription, x, y, 102 * 4, 33 * 4, null); 47 | levelDescription.render(g); 48 | nameText.render(g); 49 | healthBar.render(g); 50 | } else if(type == 2) { 51 | xpBar.render(g); 52 | healthBar.render(g); 53 | g.drawImage(Assets.playerDescription, 0, 0, 105 * 4, 38 * 4, null); 54 | } 55 | } 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/Assets/EntityManager.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | import java.util.ArrayList; 5 | import java.util.Comparator; 6 | 7 | import Game.Handler; 8 | 9 | public class EntityManager { 10 | 11 | private Handler handler; 12 | private Player player; 13 | private ArrayList entities; 14 | private Comparator renderSorter = new Comparator() { 15 | 16 | @Override 17 | public int compare(Entity a, Entity b) { 18 | if(a.getY() + a.getHeight() < b.getY() + b.getHeight()) { 19 | return -1; 20 | } 21 | return 1; 22 | } 23 | 24 | }; 25 | 26 | public EntityManager(Handler handler, Player player) { 27 | this.handler = handler; 28 | this.player = player; 29 | entities = new ArrayList(); 30 | addEntity(player); 31 | } 32 | 33 | public void tick() { 34 | for(int i = 0; i < entities.size(); i++) { 35 | Entity e = entities.get(i); 36 | e.tick(); 37 | } 38 | } 39 | 40 | public void render(Graphics g) { 41 | for(Entity e : entities) { 42 | e.render(g); 43 | } 44 | entities.sort(renderSorter); 45 | } 46 | 47 | public void addEntity(Entity e) { 48 | entities.add(e); 49 | } 50 | 51 | public void removeEntity(Entity e) { 52 | entities.remove(e); 53 | } 54 | 55 | 56 | 57 | 58 | public Handler getHandler() { 59 | return handler; 60 | } 61 | 62 | public void setHandler(Handler handler) { 63 | this.handler = handler; 64 | } 65 | 66 | public Player getPlayer() { 67 | return player; 68 | } 69 | 70 | public void setPlayer(Player player) { 71 | this.player = player; 72 | } 73 | 74 | public ArrayList getEntities() { 75 | return entities; 76 | } 77 | 78 | public void setEntities(ArrayList entities) { 79 | this.entities = entities; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/Assets/Entity.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Rectangle; 5 | 6 | import Game.Handler; 7 | 8 | public abstract class Entity { 9 | 10 | protected Handler handler; 11 | protected float x, y; 12 | protected int width, height; 13 | protected Rectangle bounds; 14 | 15 | 16 | public Entity(Handler handler, float x, float y, int width, int height) { 17 | this.handler = handler; 18 | this.x = x; 19 | this.y = y; 20 | this.width = width; 21 | this.height = height; 22 | 23 | bounds = new Rectangle(0, 0, width, height); 24 | } 25 | 26 | public abstract void tick(); 27 | 28 | public abstract void render(Graphics g); 29 | 30 | public boolean checkEntityCollisions(float xOffset, float yOffset) { 31 | for(Entity e : handler.getWorld().getEntityManager().getEntities()) { 32 | if(e.equals(this)) { 33 | continue; 34 | } 35 | if(e.getCollisionBounds(0f, 0f).intersects(getCollisionBounds(xOffset, yOffset))) { 36 | Creature.collided = true; 37 | return true; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | public Rectangle getCollisionBounds(float xOffset, float yOffset) { 44 | return new Rectangle((int)(x + bounds.x + xOffset), (int)(y + bounds.y + yOffset), bounds.width, bounds.height); 45 | } 46 | 47 | public float getX() { 48 | return x; 49 | } 50 | 51 | public void setX(float x) { 52 | this.x = x; 53 | } 54 | 55 | public float getY() { 56 | return y; 57 | } 58 | 59 | public void setY(float y) { 60 | this.y = y; 61 | } 62 | 63 | public int getWidth() { 64 | return width; 65 | } 66 | 67 | public void setWidth(int width) { 68 | this.width = width; 69 | } 70 | 71 | public int getHeight() { 72 | return height; 73 | } 74 | 75 | public void setHeight(int height) { 76 | this.height = height; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/Game/UIObject.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Rectangle; 5 | import java.awt.event.MouseEvent; 6 | 7 | import States.BattleState; 8 | 9 | public abstract class UIObject { 10 | 11 | protected float x, y; 12 | protected int width, height; 13 | protected Rectangle bounds; 14 | protected boolean hovering = false; 15 | protected boolean moved; 16 | 17 | public UIObject(float x, float y, int width, int height) { 18 | this.x = x; 19 | this.y = y; 20 | this.width = width; 21 | this.height = height; 22 | bounds = new Rectangle((int) x, (int) y, width, height); 23 | } 24 | 25 | public abstract void tick(); 26 | 27 | public abstract void render(Graphics g); 28 | 29 | public abstract void onClick(); 30 | 31 | public void onMouseMove(MouseEvent e) { 32 | moved = true; 33 | if (bounds.contains(e.getX(), e.getY())) { 34 | hovering = true; 35 | } else { 36 | moved = false; 37 | hovering = false; 38 | } 39 | } 40 | 41 | public void onMouseRelease(MouseEvent e) { 42 | if ((hovering || moved) && e.getButton() == MouseEvent.BUTTON1) { 43 | onClick(); 44 | } 45 | } 46 | 47 | public float getX() { 48 | return x; 49 | } 50 | 51 | public void setX(float x) { 52 | this.x = x; 53 | } 54 | 55 | public float getY() { 56 | return y; 57 | } 58 | 59 | public void setY(float y) { 60 | this.y = y; 61 | } 62 | 63 | public int getWidth() { 64 | return width; 65 | } 66 | 67 | public void setWidth(int width) { 68 | this.width = width; 69 | } 70 | 71 | public int getHieght() { 72 | return height; 73 | } 74 | 75 | public void setHieght(int hieght) { 76 | this.height = hieght; 77 | } 78 | 79 | public boolean isHovering() { 80 | return hovering; 81 | } 82 | 83 | public void setHovering(boolean hovering) { 84 | this.hovering = hovering; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/Assets/Arrow.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.Rectangle; 5 | import java.awt.event.MouseEvent; 6 | import java.awt.event.MouseListener; 7 | import java.awt.event.MouseMotionListener; 8 | import java.awt.image.BufferedImage; 9 | 10 | import Game.ClickListener; 11 | import Game.UIImageButton; 12 | import Game.UIObject; 13 | import States.BattleState; 14 | 15 | public class Arrow extends UIObject{ 16 | private int i = 0; 17 | private float arrowX = 0; 18 | private ClickListener clicker; 19 | protected float x, y; 20 | protected int width, height; 21 | protected Rectangle bounds; 22 | protected boolean hovering = false; 23 | protected boolean moved; 24 | protected BufferedImage[] images; 25 | 26 | public Arrow(float x, float y, int width, int height, BufferedImage[] images, ClickListener clicker) { 27 | super(x, y, width, height); 28 | this.x = x; 29 | this.y = y; 30 | this.width = width; 31 | this.height = height; 32 | this.clicker = clicker; 33 | this.images = images; 34 | bounds = new Rectangle((int)x, (int)y, width, height); 35 | 36 | } 37 | 38 | public void tick() { 39 | i++; 40 | if(i <= 15) { 41 | arrowX += 0.2f; 42 | } else if(i <= 30) { 43 | arrowX -= 0.2f; 44 | } else { 45 | i = 0; 46 | } 47 | } 48 | 49 | public void render(Graphics g) { 50 | g.drawImage(Assets.arrow[0], (int)(x + arrowX), (int)y, width, height, null); 51 | } 52 | 53 | @Override 54 | public void onClick() { 55 | clicker.onClick(); 56 | } 57 | 58 | public void onMouseMove(MouseEvent e) { 59 | moved = true; 60 | if(bounds.contains(e.getX(), e.getY())) { 61 | hovering = true; 62 | } else { 63 | moved = false; 64 | hovering = false; 65 | } 66 | } 67 | 68 | public void onMouseRelease(MouseEvent e) { 69 | if((hovering || moved) && e.getButton() == MouseEvent.BUTTON1) { 70 | onClick(); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/Game/MouseManager.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.event.MouseEvent; 4 | import java.awt.event.MouseListener; 5 | import java.awt.event.MouseMotionListener; 6 | 7 | public class MouseManager implements MouseListener, MouseMotionListener{ 8 | 9 | private boolean leftPressed, rightPressed; 10 | private int mouseX, mouseY; 11 | private UIManager uiManager; 12 | 13 | public void setUIManager(UIManager uiManager) { 14 | this.uiManager = uiManager; 15 | } 16 | 17 | public boolean isLeftPressed() { 18 | return leftPressed; 19 | } 20 | 21 | public boolean isRightPressed() { 22 | return rightPressed; 23 | } 24 | 25 | public int getMouseX() { 26 | return mouseX; 27 | } 28 | 29 | public int getMouseY() { 30 | return mouseY; 31 | } 32 | 33 | 34 | @Override 35 | public void mouseDragged(MouseEvent e) { 36 | // TODO Auto-generated method stub 37 | 38 | } 39 | 40 | @Override 41 | public void mouseMoved(MouseEvent e) { 42 | mouseX = e.getX(); 43 | mouseY = e.getY(); 44 | 45 | if(uiManager != null) { 46 | uiManager.onMouseMove(e); 47 | } 48 | } 49 | 50 | @Override 51 | public void mouseClicked(MouseEvent e) { 52 | // TODO Auto-generated method stub 53 | 54 | } 55 | 56 | @Override 57 | public void mouseEntered(MouseEvent e) { 58 | // TODO Auto-generated method stub 59 | 60 | } 61 | 62 | @Override 63 | public void mouseExited(MouseEvent e) { 64 | // TODO Auto-generated method stub 65 | 66 | } 67 | 68 | @Override 69 | public void mousePressed(MouseEvent e) { 70 | if(e.getButton() == MouseEvent.BUTTON1) { //if left mouse button is pressed 71 | leftPressed = true; 72 | } else if(e.getButton() == MouseEvent.BUTTON3) { //right click 73 | rightPressed = true; 74 | } 75 | 76 | if(uiManager != null) { 77 | uiManager.onMouseRelease(e); 78 | } 79 | 80 | } 81 | 82 | @Override 83 | public void mouseReleased(MouseEvent e) { 84 | if(e.getButton() == MouseEvent.BUTTON1) { //if left mouse button is pressed 85 | leftPressed = false; 86 | } else if(e.getButton() == MouseEvent.BUTTON3) { //right click 87 | rightPressed = false; 88 | } 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/Assets/Tile.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | import java.awt.image.BufferedImage; 5 | 6 | import Game.Game; 7 | import Game.Handler; 8 | import Assets.Assets; 9 | 10 | public class Tile { 11 | 12 | public static Tile[] tiles = new Tile[256]; 13 | public static Tile grassTile = new Tile(Assets.grass, 0, false, false); 14 | public static Tile rockTile = new Tile(Assets.rock, 1, false, false); 15 | 16 | public static Tile ledgeTopLeft = new Tile(Assets.ledgeTopLeft, 3, true, true); 17 | public static Tile ledgeTopMiddle = new Tile(Assets.ledgeTopMiddle, 4, true, false); 18 | public static Tile ledgeTopRight = new Tile(Assets.ledgeTopRight, 5, true, true); 19 | 20 | public static Tile ledgeTile = new Tile(Assets.ledgeMiddleLeft, 6, true, false); 21 | public static Tile ledgeMiddleMiddle = new Tile(Assets.ledgeMiddleMiddle, 7, true, false); 22 | public static Tile middleRightLedge = new Tile(Assets.ledgeMiddleRight, 8, true, false); 23 | 24 | public static Tile leftCornerLedge = new Tile(Assets.leftCornerLedge, 9, true, true); 25 | public static Tile bottomMiddleLedge = new Tile(Assets.bottomMiddleLedge, 10, true, false); 26 | public static Tile bottomRightLedge = new Tile(Assets.bottomRightLedge, 11, true, true); 27 | 28 | public static Tile ledgeCornerTopRight = new Tile(Assets.ledgeCornerTopRight, 14, true, false); 29 | public static Tile ledgeCornerTopLeft = new Tile(Assets.ledgeCornerTopLeft, 15, true, false); 30 | 31 | public static Tile ledgeMiddle = new Tile(Assets.ledge, 12, true, false); 32 | public static Tile grassLedge = new Tile(Assets.grassLedge, 13, true, false); 33 | 34 | public static Tile bush = new Tile(Assets.bush, 2, false, false); 35 | 36 | public static final int TILEWIDTH = 64, TILEHEIGHT = 64; 37 | 38 | protected BufferedImage texture; 39 | protected final int id; 40 | protected boolean isSolid; 41 | protected boolean isFront; 42 | 43 | public Tile(BufferedImage texture, int id, boolean isSolid, boolean isFront) { 44 | this.texture = texture; 45 | this.id = id; 46 | tiles[id] = this; 47 | this.isSolid = isSolid; 48 | this.isFront = isFront; 49 | } 50 | 51 | public void tick() { 52 | 53 | } 54 | 55 | public void render(Graphics g, int x, int y) { 56 | g.drawImage(texture, x, y, TILEWIDTH, TILEHEIGHT, null); 57 | } 58 | 59 | public boolean isSolid() { 60 | return isSolid; 61 | } 62 | 63 | public boolean front() { 64 | return isFront; 65 | } 66 | 67 | public int getId() { 68 | return id; 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/Game/KeyManager.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.event.KeyEvent; 4 | import java.awt.event.KeyListener; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import Assets.Creature; 10 | import Assets.Player; 11 | 12 | public class KeyManager implements KeyListener{ 13 | 14 | private boolean[] keys; 15 | public boolean up, down, left, right; 16 | public boolean Up, Down, Left, Right; 17 | public boolean q, space; 18 | private int current = -1; 19 | private int backup = -1; 20 | private int keysPressed = 0; 21 | public static boolean isMoving = false; 22 | private boolean flag = false; 23 | 24 | public KeyManager() { 25 | keys = new boolean[256]; 26 | } 27 | 28 | public void tick() { 29 | up = keys[KeyEvent.VK_W]; 30 | down = keys[KeyEvent.VK_S]; 31 | left = keys[KeyEvent.VK_A]; 32 | right = keys[KeyEvent.VK_D]; 33 | Up = keys[KeyEvent.VK_UP]; 34 | Down = keys[KeyEvent.VK_DOWN]; 35 | Left = keys[KeyEvent.VK_LEFT]; 36 | Right = keys[KeyEvent.VK_RIGHT]; 37 | q = keys[KeyEvent.VK_Q]; 38 | space = keys[KeyEvent.VK_SPACE]; 39 | } 40 | 41 | @Override 42 | public void keyPressed(KeyEvent e) { 43 | if(current != e.getKeyCode() && current != -1) { //has current, move current to backup 44 | backup = current; 45 | keys[backup] = false; 46 | } 47 | current = e.getKeyCode(); 48 | keys[current] = true; 49 | } 50 | 51 | @Override 52 | public void keyReleased(KeyEvent e) { 53 | if(backup != -1) { //if you are pressing more than one key 54 | 55 | if(e.getKeyCode() != backup) { //release current, backup becomes current 56 | keys[current] = false; 57 | keys[backup] = true; 58 | current = backup; 59 | } 60 | backup = -1; 61 | } else { 62 | int keyCode = e.getKeyCode(); 63 | if(keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) { 64 | //while(!checkGridMovementX()) { 65 | keys[keyCode] = true; 66 | //System.out.println("Player's current xPosition: " + Creature.xPosition); 67 | //if(Creature.collided) { 68 | // break; 69 | // } 70 | //} 71 | } else if(keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) { 72 | //while(!checkGridMovementY()) { 73 | keys[keyCode] = true; 74 | //System.out.println("Player's current yPosition: " + Creature.yPosition); 75 | //if(Creature.collided) { 76 | //break; 77 | //} 78 | //} 79 | } 80 | keys[keyCode] = false; 81 | current = -1; 82 | } 83 | } 84 | 85 | @Override 86 | public void keyTyped(KeyEvent e) { 87 | 88 | } 89 | 90 | /*protected boolean checkGridMovementX() { 91 | if(Creature.xPosition % 64 == 0) { 92 | return true; 93 | } 94 | Creature.xPosition += Creature.DEFAULT_SPEED; 95 | return false; 96 | } 97 | */ 98 | 99 | /*protected boolean checkGridMovementY() { 100 | if(Creature.yPosition % 64 == 0) { 101 | return true; 102 | } 103 | Creature.yPosition += Creature.DEFAULT_SPEED; 104 | return false; 105 | } */ 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/Assets/Bar.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | 4 | import java.awt.Color; 5 | 6 | import java.awt.Graphics; 7 | import java.util.ArrayList; 8 | import Game.Handler; 9 | import States.BattleState; 10 | 11 | public class Bar { 12 | public static int randomX = (int)(Math.random() * 540 + 150); 13 | public static int randomX2 = (int)(Math.random() * 540 + 150); 14 | public static int height = 670; 15 | public static int barsLeft; 16 | public static int barsShown; 17 | private int v = 0; 18 | private int x = 0; 19 | private int barWidth; 20 | private int barHeight; 21 | private ArrayList monsterBars; 22 | public static int monsterBarWidth = 40; 23 | public static boolean[] ids = new boolean[100]; 24 | 25 | public Bar(Handler handler) { 26 | barWidth = 1; 27 | barHeight = 50; 28 | monsterBars = new ArrayList<>(); 29 | } 30 | 31 | private boolean render; 32 | public void tick() { 33 | if(BattleState.playerAttack) { 34 | render = false; 35 | } else if(!BattleState.playerAttack && !render){ 36 | render = true; 37 | monsterBars.clear(); 38 | barsLeft = 0; 39 | barsShown = 0; 40 | for(int i = 0; i < 3; i++) { 41 | barsLeft++; 42 | monsterBars.add(new MonsterBar(60, 85, 1.5f, 2.7f, 1000, 2500, i)); 43 | randomX2 = (int)(Math.random() * (600 - monsterBarWidth - 2) + 100); 44 | } 45 | } 46 | } 47 | 48 | public void render(Graphics g) { 49 | if(Monster.deathState < 2) { 50 | if(BattleState.playerAttack) { 51 | playerBarRender(g); 52 | Color c = new Color(0, 0, 0); 53 | g.setColor(c); 54 | g.drawImage(Assets.critBar, randomX - 6, height, 12, 50, null); 55 | } else { 56 | enemyBarRender(g); 57 | } 58 | g.drawImage(Assets.bar, 100, height - 1, 150 * 4, 13 * 4, null); 59 | x = 0; 60 | v = 0; 61 | 62 | if(!BattleState.playerAttack) { 63 | MonsterBar.touchingBar = false; 64 | for(MonsterBar e: monsterBars) { 65 | e.render(g); 66 | } 67 | if(!MonsterBar.touchingBar) { 68 | AttackBarManager.id = 0; 69 | } 70 | } 71 | } 72 | } 73 | 74 | private void enemyBarRender(Graphics g) { 75 | Color c = new Color(255, 0, 0); 76 | g.setColor(c); 77 | g.fillRect(100, height, 600, barHeight); 78 | } 79 | 80 | private void playerBarRender(Graphics g) { 81 | for(int i = 0; i < 10; i++) { 82 | drawBar(g, v, 255, 0); 83 | v += 10; 84 | x++; 85 | } 86 | for(int i = 0; i < 52; i++) { 87 | drawBar(g, v, 255, 0); 88 | v += 3; 89 | x++; 90 | } 91 | v = 0; 92 | for(int i = 0; i < 155; i++) { 93 | drawBar(g, 255, 255 - v, 0); 94 | v += 1; 95 | x++; 96 | } 97 | for(int i = 0; i < 50; i++) { 98 | drawBar(g, 255, 255 - v, 0); 99 | v += 2; 100 | x++; 101 | } 102 | int j = Math.max(800 - (randomX - x), 200 - (randomX - x)); 103 | for(int i = 0; i < j; i++) { 104 | drawBar(g, 255, 0, 0); 105 | x++; 106 | } 107 | } 108 | 109 | private void drawBar(Graphics g, int r, int gr, int b) { 110 | Color c = new Color(r, gr, b); 111 | g.setColor(c); 112 | g.fillRect(randomX - x, height, barWidth, barHeight); 113 | g.fillRect(randomX + x, height, barWidth, barHeight); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/Assets/HealthBar.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | import States.GameState; 5 | 6 | import java.awt.Color; 7 | import java.awt.Graphics; 8 | import java.awt.Graphics2D; 9 | 10 | import Game.Game; 11 | import Game.Handler; 12 | import States.BattleState; 13 | import States.State; 14 | 15 | public class HealthBar { 16 | 17 | private int x; 18 | private int y; 19 | private Text healthText; 20 | private float healthBarWidth = 300; 21 | private float inGameHPWidth = 346; 22 | private int type; 23 | private Handler handler; 24 | private Transition transition; 25 | 26 | public HealthBar(int type, int x, int y, Handler handler) { 27 | this.handler = handler; 28 | this.type = type; 29 | this.x = x; 30 | this.y = y; 31 | healthText = new Text(Player.health + "/" + Player.baseHealth, x + 152, y + 80, 4, 1); 32 | transition = new Transition(); 33 | } 34 | 35 | private boolean f; 36 | private int i = 0; 37 | public void tick() { 38 | if(type == 0) { 39 | if(Monster.health <= 0) { 40 | Monster.health = 0; 41 | if(!f) { 42 | f = true; 43 | Monster.deathState = 1; 44 | } 45 | } 46 | healthText.setHealth(Monster.health, Monster.baseHealth); 47 | } else if(type == 1){ 48 | if(Player.health <= 0) { 49 | BattleState.encounterFlag = true; 50 | Player.health = 0; 51 | handler.getMouseManager().setUIManager(null); 52 | Transition.canStart = false; 53 | Game.flag2 = false; 54 | i++; 55 | BattleState.switchGameStates = true; 56 | 57 | if(i > 100) { 58 | State.setState(handler.getGame().gameState); 59 | Player.health = 100; 60 | GameState.coins = 0; 61 | GameState.xp = 0; 62 | handler.getGameCamera().setxOffset(0); 63 | handler.getGameCamera().setyOffset(0); 64 | handler.getWorld().getEntityManager().getPlayer().setX(24 * Tile.TILEWIDTH + 10); 65 | handler.getWorld().getEntityManager().getPlayer().setY(48 * Tile.TILEHEIGHT + 16); 66 | Player.dir = 1; 67 | Creature.xPosition = 0; 68 | Creature.yPosition = 0; 69 | } 70 | 71 | } 72 | healthText.setHealth(Player.health, Player.baseHealth); 73 | } 74 | } 75 | 76 | 77 | public void render(Graphics g) { 78 | if(type == 0 || type == 1) { 79 | drawHealthBar(g); 80 | } else if(type == 2) { 81 | drawHealthBar2(g); 82 | } 83 | } 84 | 85 | private int combinedDamage; 86 | private int baseHealth; 87 | private void drawHealthBar(Graphics g) { 88 | if(type == 0) { 89 | combinedDamage = Monster.baseHealth - Monster.health; 90 | baseHealth = Monster.baseHealth; 91 | } else if(type == 1) { 92 | combinedDamage = Player.baseHealth - Player.health; 93 | baseHealth = Player.baseHealth; 94 | } 95 | 96 | Color c = new Color(0, 255, 0); 97 | g.setColor(c); 98 | 99 | for(int i = 0; i < healthBarWidth - (healthBarWidth / baseHealth * combinedDamage); i++) { 100 | g.fillRect(x + 74 + i , y + 72, 1, 40); 101 | } 102 | 103 | g.drawImage(Assets.enemyHealthBar, x + 70, y + 72, 77 * 4, 10 * 4, null); 104 | 105 | healthText.render(g); 106 | } 107 | 108 | private void drawHealthBar2(Graphics g) { 109 | Graphics2D g2d = (Graphics2D) g; 110 | int cc = 110; 111 | Color c = new Color(cc, cc, cc); 112 | g.setColor(c); 113 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); 114 | g.fillRect(74, 4, 345, 40); 115 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); 116 | 117 | c = new Color(0, 245, 0); 118 | g.setColor(c); 119 | for(int i = 0; i < inGameHPWidth - (inGameHPWidth / 100 * (Player.baseHealth - Player.health)); i++) { 120 | g.fillRect(x + 70 + i , y, 1, 44); 121 | } 122 | } 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/Game/World.java: -------------------------------------------------------------------------------- 1 | package Game; 2 | 3 | import java.awt.Graphics; 4 | 5 | 6 | import Assets.EntityManager; 7 | import Assets.Player; 8 | import Assets.Tree; 9 | import Assets.Tile; 10 | 11 | public class World { 12 | 13 | private Handler handler; 14 | private int width, height; 15 | private int spawnX, spawnY; 16 | private int[][] tiles; 17 | private int half = Tile.TILEWIDTH / 2; 18 | 19 | private EntityManager entityManager; 20 | 21 | 22 | public World(Handler handler, String path) { 23 | this.handler = handler; 24 | entityManager = new EntityManager(handler, new Player(handler, 100, 100)); 25 | 26 | loadWorld(path); 27 | 28 | entityManager.getPlayer().setX(spawnX * Tile.TILEWIDTH + 10); 29 | entityManager.getPlayer().setY(spawnY * Tile.TILEHEIGHT + 16); 30 | 31 | for(int i = 0; i < width; i++) { 32 | for(int j = 0; j < height; j++) { 33 | if(tiles[j][i] >= 96 && tiles[j][i] < 100) { 34 | entityManager.addEntity(new Tree(handler, (int) (j * Tile.TILEWIDTH), (int) (i * Tile.TILEWIDTH) - (int)(Tile.TILEWIDTH * 1.5), 99 - tiles[j][i])); 35 | } 36 | } 37 | } 38 | } 39 | 40 | public EntityManager getEntityManager() { 41 | return entityManager; 42 | } 43 | 44 | public void tick() { 45 | entityManager.tick(); 46 | } 47 | 48 | public void render(Graphics g) { 49 | int xStart = (int) Math.max(0, handler.getGameCamera().getxOffset() / Tile.TILEWIDTH); 50 | int xEnd = (int) Math.min(width, (handler.getGameCamera().getxOffset() + handler.getWidth()) / Tile.TILEWIDTH + 1); 51 | int yStart = (int) Math.max(0, handler.getGameCamera().getyOffset() / Tile.TILEHEIGHT); 52 | int yEnd = (int) Math.min(height, (handler.getGameCamera().getyOffset() + handler.getHeight()) / Tile.TILEHEIGHT + 1); 53 | 54 | for(int i = yStart; i < yEnd; i++) { 55 | for(int j = xStart; j < xEnd; j++) { 56 | getTile(j, i).render(g, (int) (j * Tile.TILEWIDTH - handler.getGameCamera().getxOffset()), (int) (i * Tile.TILEHEIGHT - handler.getGameCamera().getyOffset())); 57 | if(getTile(j, i).front()) { 58 | getTile(-1, -1).render(g, (int) (j * Tile.TILEWIDTH - handler.getGameCamera().getxOffset()), (int) (i * Tile.TILEHEIGHT - handler.getGameCamera().getyOffset())); 59 | } 60 | } 61 | } 62 | 63 | entityManager.render(g); 64 | 65 | for(int i = yStart; i < yEnd; i++) { 66 | for(int j = xStart; j < xEnd; j++) { 67 | if(getTile(j, i).front()) { 68 | getTile(j, i).render(g, (int) (j * Tile.TILEWIDTH - handler.getGameCamera().getxOffset()), (int) (i * Tile.TILEHEIGHT - handler.getGameCamera().getyOffset())); 69 | } 70 | } 71 | } 72 | } 73 | 74 | public Tile getTile(int x, int y) { 75 | if(x < 0 || y < 0 || x >= width || y >= height) { 76 | return Tile.grassTile; 77 | } 78 | 79 | Tile t = Tile.tiles[tiles[x][y]]; 80 | if(t == null) { 81 | return Tile.grassTile; 82 | } 83 | return t; 84 | } 85 | 86 | private void loadWorld(String path) { 87 | System.out.println(path); 88 | String file = Utils.loadFileAsString(path); 89 | System.out.println(file); 90 | String[] tokens = file.split("\\s+"); 91 | width = Utils.parseInt(tokens[0]); 92 | height = Utils.parseInt(tokens[1]); 93 | spawnX = Utils.parseInt(tokens[2]); 94 | spawnY = Utils.parseInt(tokens[3]); 95 | 96 | tiles = new int[width][height]; 97 | for(int y = 0; y < height; y++) { 98 | for(int x = 0; x < width; x++) { 99 | tiles[x][y] = Utils.parseInt(tokens[(x + y * width) + 4]); 100 | } 101 | } 102 | 103 | } 104 | 105 | public int getWidth() { 106 | return width; 107 | } 108 | 109 | public int getHeight() { 110 | return height; 111 | } 112 | 113 | public int getSpawnX() { 114 | return spawnX; 115 | } 116 | 117 | public int getSpawnY() { 118 | return spawnY; 119 | } 120 | 121 | public void setSpawnX(int spawnX) { 122 | this.spawnX = spawnX; 123 | } 124 | 125 | public void setSpawnY(int spawnY) { 126 | this.spawnY = spawnY; 127 | } 128 | } 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /src/Assets/Creature.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import Game.Handler; 4 | 5 | import Game.KeyManager; 6 | import Assets.Tile; 7 | 8 | public abstract class Creature extends Entity{ 9 | 10 | public static final int DEFAULT_HEALTH = 10; 11 | public static final float DEFAULT_SPEED = 4.0f; 12 | public static final int DEFAULT_CREATURE_WIDTH = 64; 13 | public static final int DEFAULT_CREATURE_HEIGHT = 64; 14 | public static final int PLAYER_WIDTH = 48; 15 | public static final int PLAYER_HEIGHT = 80; 16 | 17 | protected int health; 18 | protected float speed; 19 | public static float xMove, yMove; 20 | public static float xPosition, yPosition; 21 | public static boolean collided = false; 22 | 23 | public Creature(Handler handler, float x, float y, int width, int height) { 24 | super(handler, x, y, width, height); 25 | health = DEFAULT_HEALTH; 26 | speed = DEFAULT_SPEED; 27 | xMove = 0; 28 | yMove = 0; 29 | 30 | } 31 | 32 | public void move() { 33 | if(xMove != 0 && !checkEntityCollisions(xMove, 0f)) { 34 | moveX(); 35 | } 36 | if(yMove != 0 && !checkEntityCollisions(0f, yMove)) { 37 | moveY(); 38 | } 39 | } 40 | 41 | public void moveX() { 42 | if(xMove > 0) { 43 | collided = false; 44 | int tx = (int) (x + xMove + bounds.x + bounds.width) / Tile.TILEWIDTH; 45 | if(!collisionWithTile(tx, (int) (y + bounds.y) / Tile.TILEHEIGHT) && !collisionWithTile(tx, (int) (y + bounds.y + bounds.height) / Tile.TILEHEIGHT)){ 46 | x += xMove; 47 | xPosition += xMove; 48 | //System.out.println("x added to xMove:" + x + " xPosition=" + xPosition); 49 | } else { 50 | x = tx * Tile.TILEWIDTH + bounds.x - bounds.width - 1; 51 | } 52 | } else if(xMove < 0) { 53 | collided = false; 54 | int tx = (int) (x + xMove + bounds.x) / Tile.TILEWIDTH; 55 | if(!collisionWithTile(tx, (int) (y + bounds.y) / Tile.TILEHEIGHT) && !collisionWithTile(tx, (int) (y + bounds.y + bounds.height) / Tile.TILEHEIGHT)){ 56 | x += xMove; 57 | xPosition += xMove; 58 | //System.out.println("x added to xMove:" + x + " xPosition=" + xPosition); 59 | } else { 60 | x = tx * Tile.TILEWIDTH + Tile.TILEWIDTH - bounds.x; 61 | } 62 | } 63 | } 64 | 65 | public void moveY() { 66 | if(yMove < 0) { 67 | collided = false; 68 | int ty = (int) (y + yMove + bounds.y) / Tile.TILEHEIGHT; 69 | if(!collisionWithTile((int) (x + bounds.x) / Tile.TILEWIDTH, ty) && !collisionWithTile((int) (x + bounds.x + bounds.width) / Tile.TILEWIDTH, ty)) { 70 | y += yMove; 71 | yPosition += yMove; 72 | //System.out.println("y added to yMove:" + y + " yPosition=" + yPosition); 73 | } else { 74 | collided = true; 75 | y = ty * Tile.TILEHEIGHT + Tile.TILEHEIGHT - bounds.y; 76 | } 77 | } else if(yMove > 0) { 78 | collided = false; 79 | int ty = (int) (y + yMove + bounds.y + bounds.height) / Tile.TILEHEIGHT; 80 | if(!collisionWithTile((int) (x + bounds.x) / Tile.TILEWIDTH, ty) && !collisionWithTile((int) (x + bounds.x + bounds.width) / Tile.TILEWIDTH, ty)) { 81 | y += yMove; 82 | yPosition += yMove; 83 | //System.out.println("y added to yMove:" + y + " yPosition=" + yPosition); 84 | } else { 85 | y = ty * Tile.TILEHEIGHT - bounds.y - bounds.height - 1; 86 | collided = true; 87 | } 88 | 89 | } 90 | } 91 | 92 | protected boolean collisionWithTile(int x, int y) { 93 | if(handler.getWorld().getTile(x, y).isSolid()) { 94 | collided = true; 95 | } 96 | return handler.getWorld().getTile(x, y).isSolid(); 97 | } 98 | 99 | 100 | // public float getxMove() { 101 | // return xMove; 102 | // } 103 | // 104 | // public void setxMove(float xMove) { 105 | // this.xMove = xMove; 106 | // } 107 | // 108 | // public float getyMove() { 109 | // return yMove; 110 | // } 111 | // 112 | // public void setyMove(float yMove) { 113 | // this.yMove = yMove; 114 | // } 115 | 116 | public int getHealth() { 117 | return health; 118 | } 119 | 120 | public void setHealth(int health) { 121 | this.health = health; 122 | } 123 | 124 | public float getSpeed() { 125 | return speed; 126 | } 127 | 128 | public void setSpeed(float speed) { 129 | this.speed = speed; 130 | } 131 | 132 | 133 | 134 | 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/Assets/Player.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Color; 4 | 5 | import java.awt.Graphics; 6 | import java.awt.image.BufferedImage; 7 | 8 | import Game.Game; 9 | import Game.Handler; 10 | import Game.World; 11 | import ImageStuff.Animation; 12 | import States.BattleState; 13 | import States.GameState; 14 | import States.State; 15 | import Assets.Tile; 16 | 17 | public class Player extends Creature { 18 | 19 | private Animation animDown, animUp, animLeft, animRight; 20 | public static int dir = 1; 21 | public static float xPosition; 22 | public static float yPosition; 23 | public static int health; 24 | public static int baseHealth; 25 | public static int level; 26 | public static String name; 27 | 28 | private boolean flag; 29 | private boolean flag2; 30 | private boolean flag3; 31 | private int a; 32 | private int b; 33 | 34 | public Player(Handler handler, float x, float y) { 35 | super(handler, x, y, Creature.PLAYER_WIDTH, Creature.PLAYER_HEIGHT); 36 | 37 | bounds.x = 0; 38 | bounds.height = 35; 39 | bounds.y = PLAYER_HEIGHT - bounds.height - 1; 40 | bounds.width = 43; 41 | 42 | health = 100; 43 | baseHealth = 100; 44 | level = 1; 45 | name = "Fuelvin"; 46 | 47 | animDown = new Animation(120, Assets.player_down); 48 | animUp = new Animation(120, Assets.player_up); 49 | animLeft = new Animation(120, Assets.player_left); 50 | animRight = new Animation(120, Assets.player_right); 51 | 52 | } 53 | 54 | @Override 55 | public void tick() { 56 | if (!Game.flag2) { 57 | animDown.tick(); 58 | animUp.tick(); 59 | animRight.tick(); 60 | animLeft.tick(); 61 | getInput(); 62 | move(); 63 | checkEncounter(); 64 | } 65 | handler.getGameCamera().centerOnEntity(this); 66 | } 67 | 68 | private void getInput() { 69 | xMove = 0; 70 | yMove = 0; 71 | 72 | if (handler.getMouseManager().isRightPressed() && !flag) { 73 | flag = true; 74 | if (this.speed == 16.0f) { 75 | this.speed = 4.0f; 76 | } else { 77 | this.speed = 16.0f; 78 | } 79 | } else if (!handler.getMouseManager().isRightPressed() && flag) { 80 | flag = false; 81 | } 82 | 83 | if (handler.getKeymanager().q && !flag2) { 84 | flag2 = true; 85 | Game.showHitboxes = !Game.showHitboxes; 86 | } else if (!handler.getKeymanager().q && flag2) { 87 | flag2 = false; 88 | } 89 | 90 | if (handler.getKeymanager().up || handler.getKeymanager().Up) { 91 | yMove = -speed; 92 | dir = 1; 93 | return; 94 | } 95 | if (handler.getKeymanager().down || handler.getKeymanager().Down) { 96 | yMove = speed; 97 | dir = 0; 98 | return; 99 | } 100 | if (handler.getKeymanager().left || handler.getKeymanager().Left) { 101 | xMove = -speed; 102 | dir = 2; 103 | return; 104 | } 105 | if (handler.getKeymanager().right || handler.getKeymanager().Right) { 106 | xMove = speed; 107 | dir = 3; 108 | return; 109 | } 110 | 111 | } 112 | 113 | @Override 114 | public void render(Graphics g) { 115 | g.drawImage(getCurrentAnimationFrame(), (int) (x - handler.getGameCamera().getxOffset()), 116 | (int) (y - handler.getGameCamera().getyOffset()), width, height, null); 117 | if (Game.showHitboxes) { 118 | g.setColor(Color.red); 119 | g.drawRect((int) (x + bounds.x - handler.getGameCamera().getxOffset()), 120 | (int) (y + bounds.y - handler.getGameCamera().getyOffset()), bounds.width, bounds.height); 121 | } 122 | } 123 | 124 | private BufferedImage getCurrentAnimationFrame() { 125 | if (xMove < 0) { 126 | return animLeft.getCurrentFrame(); 127 | } else if (xMove > 0) { 128 | return animRight.getCurrentFrame(); 129 | } else if (yMove < 0) { 130 | return animUp.getCurrentFrame(); 131 | } else if (yMove > 0) { 132 | return animDown.getCurrentFrame(); 133 | } else { 134 | if (dir == 0) { 135 | animDown.setIndex(0); 136 | return animDown.getCurrentFrame(); 137 | } else if (dir == 1) { 138 | animUp.setIndex(0); 139 | return animUp.getCurrentFrame(); 140 | } else if (dir == 2) { 141 | animLeft.setIndex(0); 142 | return animLeft.getCurrentFrame(); 143 | } else { 144 | animRight.setIndex(1); 145 | return animRight.getCurrentFrame(); 146 | } 147 | } 148 | } 149 | 150 | private void checkEncounter() { 151 | World w = handler.getWorld(); 152 | if ((w.getTile(w.getSpawnX() + ((int) Creature.xPosition) / 64, 153 | w.getSpawnY() + ((int) Creature.yPosition) / 64) == Tile.bush) && !BattleState.encounterFlag 154 | && Math.random() >= 0.99) { 155 | a = w.getSpawnX() + ((int) Creature.xPosition) / 64; 156 | b = w.getSpawnY() + ((int) Creature.yPosition) / 64; 157 | if (!flag3) { 158 | flag3 = true; 159 | Game.flag = true; 160 | } 161 | } else if (BattleState.encounterFlag) { 162 | if (a != w.getSpawnX() + ((int) Creature.xPosition) / 64 163 | || b != w.getSpawnY() + ((int) Creature.yPosition) / 64) { 164 | BattleState.encounterFlag = false; 165 | flag3 = false; 166 | } 167 | } 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /src/Assets/Monster.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | import java.awt.Composite; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.image.BufferedImage; 8 | import java.util.ArrayList; 9 | 10 | import Game.Handler; 11 | import States.BattleState; 12 | import States.GameState; 13 | 14 | public class Monster { 15 | 16 | protected BufferedImage img; 17 | private int width; 18 | private int height; 19 | public static int baseHealth; 20 | public static int health; 21 | public static int deathState; 22 | private long lastTime, timer; 23 | private int money; 24 | private int xp; 25 | private Handler handler; 26 | 27 | private Text defeatText; 28 | private Text text; 29 | private Text rewardsText; 30 | private Text rewardsText2; 31 | private Description monsterDescription; 32 | private ArrayList coinAndXP; 33 | 34 | private int x; 35 | private int y; 36 | 37 | public Monster(String name, BufferedImage img, int width, int height, int x, int y, int health, int attack, int level, Handler handler) { 38 | this.img = img; 39 | this.width = width; 40 | this.height = height; 41 | this.health = health; 42 | this.baseHealth = health; 43 | this.money = (level * 4) + (int)(Math.random() * (level * 3) + 1); 44 | this.xp = (level * 4) + (int)(Math.random() * (level * 3) + 1); 45 | deathState = 0; 46 | this.x = x; 47 | this.y = y; 48 | lastTime = System.currentTimeMillis(); 49 | coinAndXP = new ArrayList<>(); 50 | monsterDescription = new Description(0, name, health, baseHealth, level, 8, 10, handler); 51 | text = new Text("You encounter a " + name + "!", 68, 604, 4, 0); 52 | defeatText = new Text("You defeated the " + name + "!", 56, 654, 4, 0); 53 | rewardsText = new Text("You gain " + money + " coins!", 0, 654, 4, 0); 54 | rewardsText2 = new Text("You gain " + xp + " xp!", 0, 654, 4, 5); 55 | f = false; 56 | f2 = false; 57 | } 58 | 59 | 60 | public void tick() { 61 | timer += System.currentTimeMillis() - lastTime; 62 | lastTime = System.currentTimeMillis(); 63 | monsterDescription.tick(); 64 | if(deathState == 1 && time > 10) { 65 | for(int i = 0; i < coinAndXP.size(); i++) { 66 | coinAndXP.get(i).tick(); 67 | } 68 | } 69 | 70 | moveEffect(); 71 | } 72 | 73 | 74 | private int amount = 0; 75 | private float opacity = 1; 76 | private int time = 0; 77 | private int time2 = 0; 78 | private int maxAmount = 15; 79 | private boolean f; 80 | private boolean f2; 81 | public void render(Graphics g) { 82 | Graphics2D g2d = (Graphics2D)g; 83 | Composite ogComposite = g2d.getComposite(); 84 | 85 | if(!BattleState.showBars) { 86 | text.render(g); 87 | } 88 | if(deathState == 1 || deathState == 2) { 89 | time++; 90 | time2++; 91 | if(amount < maxAmount) { 92 | if(time2 > (50 / maxAmount)) { 93 | time2 = 0; 94 | coinAndXP.add(new CoinAndXP(x, y)); 95 | amount++; 96 | } 97 | } 98 | for(int i = 0; i < coinAndXP.size(); i++) { 99 | coinAndXP.get(i).render(g); 100 | } 101 | 102 | if(time > 100) { 103 | reward(g); 104 | } 105 | } else if(deathState == 3) { 106 | if(!f) { 107 | GameState.coins += money; 108 | f = true; 109 | } 110 | rewardsText.render(g); 111 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0)); 112 | //BattleState.switchGameStates = true; 113 | } else if(deathState == 4) { 114 | if(!f2) { 115 | GameState.xp += xp; 116 | f2 = true; 117 | } 118 | rewardsText2.render(g); 119 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0)); 120 | } 121 | 122 | g.drawImage(img, x, y, width, height, null); 123 | g2d.setComposite(ogComposite); 124 | monsterDescription.render(g); 125 | 126 | } 127 | 128 | private void reward(Graphics g) { 129 | Graphics2D g2d = (Graphics2D) g; 130 | deathState = 2; 131 | defeatText.render(g); 132 | //rewardsText.render(g); 133 | if(opacity <= 0.04) { 134 | opacity = 0; 135 | } else { 136 | opacity -= 0.04; 137 | } 138 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); 139 | } 140 | 141 | public int getHealth() { 142 | return health; 143 | } 144 | 145 | 146 | 147 | int i = 0; 148 | private void moveEffect() { 149 | if(AttackBarManager.slash) { 150 | if(!AttackBarManager.critical) { 151 | if(i < 4) { 152 | if(timer > 60 && timer < 120) { 153 | y = 156; 154 | x = 444; 155 | } else if(timer > 120 && timer < 180) { 156 | y = 158; 157 | x = 435; 158 | } else if(timer > 180) { 159 | i++; 160 | x = 440; 161 | y = 160; 162 | timer = 0; 163 | } 164 | } 165 | } else { 166 | if(i < 5) { 167 | if(timer > 50 && timer < 100) { 168 | y = 150; 169 | x = 448; 170 | } else if(timer > 100 && timer < 150) { 171 | y = 152; 172 | x = 432; 173 | } else if(timer > 150) { 174 | i++; 175 | x = 440; 176 | y = 160; 177 | timer = 0; 178 | } 179 | } 180 | } 181 | } else { 182 | i = 0; 183 | } 184 | } 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | } 193 | -------------------------------------------------------------------------------- /src/Assets/MonsterBar.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | import java.awt.BasicStroke; 5 | import java.awt.Color; 6 | import java.awt.Graphics; 7 | import java.awt.Graphics2D; 8 | import java.awt.Stroke; 9 | 10 | import States.BattleState; 11 | 12 | public class MonsterBar { 13 | 14 | private float width; 15 | private float speed; 16 | private float x; 17 | private float y; 18 | private int id; 19 | private long lastTime, timer; 20 | private boolean flag = true; 21 | public static final int MONSTER_BAR_HEIGHT = 48; 22 | private int randomTimer; 23 | private boolean destroyed; 24 | public static boolean touchingBar; 25 | private Text redDamageText; 26 | 27 | public MonsterBar(float minWidth, float maxWidth, float minSpeed, float maxSpeed, int minTimer, int maxTimer, int id) { 28 | this.width = (float)(minWidth + (Math.random() * (maxWidth - minWidth))); 29 | this.speed = (float)(minSpeed + (Math.random() * (maxSpeed - minSpeed))); 30 | this.x = 700; 31 | this.y = 671; 32 | this.id = id; 33 | randomTimer = (int)(minTimer * (id + 1) + (Math.random() * (maxTimer - minTimer))); 34 | redDamageText = new Text("-20", 90, 640, 4, 3); 35 | } 36 | 37 | 38 | private boolean f3; 39 | public void tick() { 40 | if(timer > randomTimer) { 41 | if(!f3) { 42 | f3 = true; 43 | Bar.barsShown++; 44 | } 45 | } 46 | } 47 | 48 | public static boolean justDestroyed; 49 | private boolean touchedEnd; 50 | private int i = 0; 51 | private boolean f; 52 | private boolean f2; 53 | private boolean pressed; 54 | private boolean draw; 55 | private float opacity; 56 | public void render(Graphics g) { 57 | //System.out.println(touchingBar); 58 | if(!destroyed) { 59 | if(flag) { 60 | flag = false; 61 | lastTime = System.currentTimeMillis(); 62 | } 63 | if(timer > randomTimer) { 64 | if(!((AttackBarManager.xVel >= x && AttackBarManager.xVel <= x + width) && AttackBarManager.pressed)) { 65 | if(AttackBarManager.xVel >= x && AttackBarManager.xVel <= x + width) { 66 | touchingBar = true; 67 | Bar.ids[id] = true; 68 | } else { 69 | Bar.ids[id] = false; 70 | } 71 | 72 | if(!AttackBarManager.hitPause) { 73 | x -= speed; 74 | if(x < 100) { 75 | destroyed = true; 76 | touchedEnd = true; 77 | } 78 | } 79 | drawSquare(g); 80 | } else { 81 | touchingBar = true; 82 | Bar.ids[id] = true; 83 | if(AttackBarManager.maxId == this.id) { 84 | if(AttackBarManager.canCheckId) { 85 | pressed = true; 86 | } 87 | } else { 88 | drawSquare(g); 89 | } 90 | } 91 | } else { 92 | if(AttackBarManager.hitPause) { 93 | lastTime = System.currentTimeMillis(); 94 | timer += System.currentTimeMillis() - lastTime; 95 | } else { 96 | timer += System.currentTimeMillis() - lastTime; 97 | lastTime = System.currentTimeMillis(); 98 | } 99 | } 100 | 101 | } else if(touchedEnd) { 102 | if(i < 50) { 103 | redDamageText.render(g); 104 | i++; 105 | redDamageText.setY(640 - i / 2); 106 | if(!f) { 107 | f = true; 108 | Player.health -= 20; 109 | } 110 | } else { 111 | f = false; 112 | Bar.barsLeft--; 113 | if(Bar.barsLeft == 0) { 114 | BattleState.playerAttack = true; 115 | BattleState.showBars = false; 116 | AttackBarManager.xVel = 104; 117 | AttackBarManager.milliSecondsPassed = 0; 118 | } 119 | touchedEnd = false; 120 | } 121 | } 122 | 123 | checkPressed(g); 124 | 125 | 126 | } 127 | 128 | private void checkPressed(Graphics g) { 129 | 130 | Graphics2D g2d = (Graphics2D) g; 131 | if(pressed) { 132 | if(draw) { 133 | drawSquare(g); 134 | } 135 | 136 | if(!f2) { 137 | opacity = 1; 138 | draw = true; 139 | i = 0; 140 | f2 = true; 141 | redDamageText = new Text("Blocked!", (int)this.x, 635, 4, -1); 142 | //width -= tempWidth / 10; 143 | destroyed = true; 144 | justDestroyed = true; 145 | AttackBarManager.id = 0; 146 | AttackBarManager.maxId = -1; 147 | Bar.ids[id] = false; 148 | } 149 | if(i < 30) { 150 | draw = false; 151 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); 152 | redDamageText.render(g); 153 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); 154 | i++; 155 | redDamageText.setY(635 - i / 2); 156 | opacity -= 0.0333f; 157 | } else { 158 | Bar.barsLeft--; 159 | f2 = false; 160 | pressed = false; 161 | i = 0; 162 | } 163 | 164 | } 165 | } 166 | 167 | private void drawSquare(Graphics g) { 168 | Graphics2D g2 = (Graphics2D) g; 169 | 170 | g.setColor(Color.orange); 171 | g.fillRect((int)x, (int)y, (int)width, MONSTER_BAR_HEIGHT); 172 | 173 | Stroke oldS = g2.getStroke(); 174 | Stroke s = new BasicStroke(2); 175 | g2.setStroke(s); 176 | g2.setColor(Color.black); 177 | g2.drawRect((int)x, (int)y, (int)width, MONSTER_BAR_HEIGHT); 178 | g2.setStroke(oldS); 179 | } 180 | 181 | public int getId() { 182 | return this.id; 183 | } 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | } 207 | -------------------------------------------------------------------------------- /src/Game/Game.java: -------------------------------------------------------------------------------- 1 | package Game; //Adding res to build path: Project, properties, add class folder, select folder. 2 | 3 | import java.awt.Graphics; 4 | 5 | import java.awt.image.BufferStrategy; 6 | import Assets.Assets; 7 | import Assets.Transition; 8 | import States.BattleState; 9 | import States.GameState; 10 | import States.MenuState; 11 | import States.State; 12 | 13 | public class Game implements Runnable{ 14 | 15 | private Display display; 16 | 17 | private int width; 18 | private int height; 19 | public String title; 20 | public boolean running = false; 21 | 22 | public static boolean showHitboxes = false; 23 | public static boolean flag = false; 24 | public static boolean flag2 = false; 25 | public static boolean battling = false; 26 | 27 | private Thread thread; //own separate game loop 28 | 29 | private BufferStrategy bs; 30 | private Graphics g; 31 | 32 | //States 33 | public State gameState; 34 | public State menuState; 35 | public State battleState; 36 | 37 | //Input 38 | private KeyManager keyManager; 39 | private MouseManager mouseManager; 40 | 41 | private GameCamera gameCamera; 42 | 43 | private Handler handler; 44 | private Transition transition; 45 | 46 | private int fps; 47 | private double timePerTick; 48 | 49 | double delta; 50 | long now; 51 | long lastTime; 52 | long timer; 53 | int ticks; 54 | 55 | public Game(String title, int width, int height) { 56 | this.width = width; 57 | this.height = height; 58 | this.title = title; 59 | keyManager = new KeyManager(); 60 | mouseManager = new MouseManager(); 61 | } 62 | 63 | private void init() { 64 | display = new Display("RPG Game", width, height); 65 | display.getFrame().addKeyListener(keyManager); 66 | display.getFrame().addMouseListener(mouseManager); 67 | display.getFrame().addMouseMotionListener(mouseManager); 68 | display.getCanvas().addMouseListener(mouseManager); 69 | display.getCanvas().addMouseMotionListener(mouseManager); 70 | Assets.init(); 71 | 72 | handler = new Handler(this); 73 | gameCamera = new GameCamera(handler, 0, 0); 74 | 75 | gameState = new GameState(handler); 76 | menuState = new MenuState(handler); 77 | //battleState = new BattleState(handler); 78 | State.setState(gameState); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 79 | } 80 | 81 | private void tick() { //updates all variables 82 | keyManager.tick(); 83 | 84 | if(State.getState() != null) { 85 | State.getState().tick(); 86 | } 87 | 88 | if(flag) { 89 | flag = false; 90 | transition = new Transition(); 91 | flag2 = true; 92 | } 93 | if(Transition.canStart) { 94 | Transition.canStart = false; 95 | battling = true; 96 | battleState = new BattleState(handler); 97 | State.setState(handler.getGame().battleState); 98 | } 99 | } 100 | 101 | 102 | 103 | private void render() { //renders all objects 104 | bs = display.getCanvas().getBufferStrategy(); 105 | if(bs == null) { 106 | display.getCanvas().createBufferStrategy(3); 107 | return; 108 | } 109 | g = bs.getDrawGraphics(); 110 | 111 | //Clears certain portion of screen (in this case the whole screen) 112 | g.clearRect(0, 0, width, height); 113 | 114 | //Draws stuff in the screen- 115 | 116 | if(State.getState() != null) { 117 | State.getState().render(g); 118 | } 119 | 120 | if(flag2) { 121 | transition.render(g); 122 | } 123 | 124 | //End drawings- 125 | bs.show(); 126 | g.dispose(); 127 | } 128 | 129 | 130 | //starting the thread runs this method 131 | public void run() { 132 | init(); 133 | fps = 60; 134 | timePerTick = 1000000000 / fps; //1 billion bcus 1 billion nanoseconds in one second 135 | delta = 0; 136 | lastTime = System.nanoTime(); 137 | timer = 0; 138 | ticks = 0; 139 | 140 | while(running) { 141 | now = System.nanoTime(); 142 | delta += (now - lastTime) / timePerTick; 143 | //System.out.println(delta); 144 | timer += now - lastTime; 145 | lastTime = now; 146 | if(delta >= 1) { 147 | tick(); 148 | render(); 149 | ticks++; 150 | delta--; 151 | } 152 | if(timer >= 1000000000) { //if timer exceeds one second 153 | System.out.println("FPS: " + ticks); 154 | ticks = 0; 155 | timer = 0; 156 | } 157 | } 158 | 159 | stop(); 160 | } 161 | 162 | public KeyManager getKeyManager() { 163 | return keyManager; 164 | } 165 | 166 | public MouseManager getMouseManager() { 167 | return mouseManager; 168 | } 169 | 170 | public GameCamera getGameCamera() { 171 | return gameCamera; 172 | } 173 | 174 | public int getWidth() { 175 | return width; 176 | } 177 | 178 | public int getHeight() { 179 | return height; 180 | } 181 | 182 | public synchronized void start() { 183 | 184 | if(running == true) { 185 | return; //checks if already running 186 | } 187 | running = true; 188 | 189 | //runs this class on a new thread 190 | thread = new Thread(this); 191 | 192 | //calls the run method 193 | thread.start(); 194 | } 195 | 196 | public synchronized void stop() { 197 | if(running == false) { 198 | return; 199 | } 200 | running = false; 201 | 202 | try { 203 | thread.join(); 204 | } catch (InterruptedException e) { 205 | e.printStackTrace(); 206 | } 207 | } 208 | 209 | 210 | 211 | } 212 | -------------------------------------------------------------------------------- /src/Assets/Text.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.Graphics; 4 | 5 | public class Text { 6 | private String s; 7 | private int x; 8 | private int y; 9 | private int multiplier; 10 | private int type; 11 | private int start; 12 | private int letterCount; 13 | private boolean show; 14 | 15 | public Text(String s, int x, int y, int multiplier, int type) { 16 | this.s = s; 17 | this.x = x; 18 | this.y = y; 19 | this.multiplier = multiplier; 20 | this.type = type; 21 | } 22 | 23 | private int count; 24 | public void render(Graphics g) { 25 | if(type == -1) { 26 | start = x; 27 | for(int i = 0; i < s.length(); i++) { 28 | if(s.charAt(i) == ' ') { 29 | count -= multiplier; 30 | start += 5 * multiplier + count; 31 | g.drawImage(Assets.miniAlphabet[26], start, y, 3 * multiplier, 6 * multiplier, null); 32 | } else if(s.toLowerCase().charAt(i) == 'm' || s.toLowerCase().charAt(i) == 'w'){ 33 | count += multiplier; 34 | start += 5 * multiplier; 35 | g.drawImage(Assets.miniAlphabet[(s.toLowerCase().charAt(i) - 97)], start, y, 5 * multiplier, 6 * multiplier, null); 36 | } else if(s.charAt(i) == '!') { 37 | start += 5 * multiplier + count; 38 | g.drawImage(Assets.miniAlphabet[27], start, y, 3 * multiplier, 6 * multiplier, null); 39 | } else { 40 | start += 5 * multiplier + count; 41 | g.drawImage(Assets.miniAlphabet[(s.toLowerCase().charAt(i) - 97)], start, y, 4 * multiplier, 6 * multiplier, null); 42 | count = 0; 43 | } 44 | } 45 | } else if(type == 0) { 46 | String delims = "[ ]+"; 47 | String[] tokens = s.split(delims); 48 | int shift = 0; 49 | int xShift = 0; 50 | letterCount = 0; 51 | for(int i = 0; i < tokens.length; i++) { 52 | if(tokens[i].length() + letterCount > 29) { 53 | f = true; 54 | letterCount = 0; 55 | shift += 60; 56 | } 57 | xShift = 400 - ((maxLetters - 1) * multiplier * 3); 58 | alphabetRender(g, tokens[i], i, xShift, y + shift, 0); 59 | } 60 | show = true; 61 | f = true; 62 | 63 | } else if(type == 1) { 64 | for(int i = 0; i < s.length(); i++) { 65 | if(s.charAt(i) == '/') { 66 | g.drawImage(Assets.numbers[10], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 67 | } else { 68 | if(s.charAt(i) != '-') { 69 | g.drawImage(Assets.numbers[s.charAt(i) - 48], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 70 | } 71 | } 72 | } 73 | } else if(type == 2) { 74 | for(int i = 0; i < s.length(); i++) { 75 | g.drawImage(Assets.damageNumbers[s.charAt(i) - 48], x + i * 7 * multiplier, y, 7 * multiplier, 8 * multiplier, null); 76 | } 77 | } else if(type == 3) { 78 | for(int i = 0; i < s.length(); i++) { 79 | if(s.charAt(i) == '-') { 80 | g.drawImage(Assets.redNumbers[0], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 81 | } else { 82 | g.drawImage(Assets.redNumbers[(s.charAt(i) - 48) + 1], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 83 | } 84 | } 85 | } else if(type == 4) { 86 | for(int i = 0; i < s.length(); i++) { 87 | g.drawImage(Assets.moneyNumbers[(s.charAt(i) - 48)], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 88 | } 89 | } else if(type == 5) { 90 | String delims = "[ ]+"; 91 | String[] tokens = s.split(delims); 92 | int shift = 0; 93 | int xShift = 0; 94 | letterCount = 0; 95 | for(int i = 0; i < tokens.length; i++) { 96 | if(tokens[i].length() + letterCount > 28) { 97 | f = true; 98 | letterCount = 0; 99 | shift += 60; 100 | } 101 | xShift = 400 - ((maxLetters - 1) * multiplier * 3); 102 | alphabetRender(g, tokens[i], i, xShift, y + shift, 1); 103 | } 104 | show = true; 105 | f = true; 106 | 107 | } 108 | } 109 | 110 | public void setHealth(int health, int baseHealth) { 111 | s = health + "/" + baseHealth; 112 | } 113 | 114 | public void setY(int y) { 115 | this.y = y; 116 | } 117 | 118 | private int maxLetters; 119 | private boolean f; 120 | private void alphabetRender(Graphics g, String s, int j, int x, int y, int type) { 121 | if(!f) { 122 | maxLetters++; 123 | } 124 | for(int i = 0; i < s.length(); i++) { 125 | if(!f) { 126 | maxLetters++; 127 | } 128 | if(show) { 129 | if(s.charAt(i) == ' ') { 130 | g.drawImage(Assets.alphabet[26], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 131 | } else if(s.charAt(i) == '!') { 132 | g.drawImage(Assets.alphabet[27], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 133 | } else { 134 | if(s.charAt(i) == '/') { 135 | g.drawImage(Assets.numbers[10], x + i * 5 * multiplier, y, 4 * multiplier, 6 * multiplier, null); 136 | } else if(s.charAt(i) != '-' && (s.charAt(i) == '1' || s.charAt(i) == '2' || s.charAt(i) == '3' || s.charAt(i) == '4' || s.charAt(i) == '5' || s.charAt(i) == '6' || s.charAt(i) == '7' || s.charAt(i) == '8' || s.charAt(i) == '9' || s.charAt(i) == '0')) { 137 | if(type == 0) { 138 | g.drawImage(Assets.moneyNumbers[s.charAt(i) - 48], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 139 | } else if(type == 1) { 140 | g.drawImage(Assets.xpNumbers[s.charAt(i) - 48], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 141 | } 142 | } else { 143 | g.drawImage(Assets.alphabet[(s.toLowerCase().charAt(i) - 97)], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 144 | } 145 | } 146 | } 147 | letterCount++; 148 | } 149 | g.drawImage(Assets.alphabet[26], x + letterCount * 6 * multiplier, y, 5 * multiplier, 8 * multiplier, null); 150 | letterCount++; 151 | } 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/States/BattleState.java: -------------------------------------------------------------------------------- 1 | package States; 2 | 3 | import java.awt.Color; 4 | 5 | import java.awt.Graphics; 6 | import java.util.ArrayList; 7 | 8 | import Assets.Arrow; 9 | import Assets.Assets; 10 | import Assets.AttackBarManager; 11 | import Assets.Bar; 12 | import Assets.InGamePlayer; 13 | import Assets.Monster; 14 | import Assets.Transition; 15 | import Game.Handler; 16 | import Game.UIImageButton; 17 | import Game.UIManager; 18 | import Game.UIObject; 19 | import Game.ClickListener; 20 | import Game.Game; 21 | 22 | public class BattleState extends State{ 23 | Handler handler; 24 | Bar bar; 25 | ArrayList monsters = new ArrayList<>(); 26 | Monster monster; 27 | InGamePlayer inGamePlayer; 28 | AttackBarManager attackBarManager; 29 | private UIManager uiManager; 30 | private UIManager arrowManager; 31 | public static boolean encounterFlag; 32 | public static boolean showBars; 33 | public static boolean playerAttack; 34 | public static boolean changedTurn; 35 | public static boolean switchGameStates; 36 | 37 | public BattleState(Handler handler) { 38 | super(handler); 39 | showBars = false; 40 | playerAttack = true; 41 | this.handler = handler; 42 | bar = new Bar(handler); 43 | 44 | monsters.add(new Monster("Green Slime", Assets.monsters[0], 38 * 4, 27 * 4, 440, 160, 50, 20, 1, handler)); 45 | //monsters.add(new Monster("Angry Radish", Assets.monsters[1], 23 * 4, 41 * 4, 480, 110, 1, 20, 1)); 46 | 47 | monster = monsters.get(0); 48 | inGamePlayer = new InGamePlayer(handler); 49 | attackBarManager = new AttackBarManager(handler); 50 | switchGameStates = false; 51 | initializeUI(); 52 | } 53 | 54 | private boolean f; 55 | @Override 56 | public void tick() { 57 | if(showBars) { 58 | bar.tick(); 59 | attackBarManager.tick(); 60 | } 61 | uiManager.tick(); 62 | monster.tick(); 63 | inGamePlayer.tick(); 64 | 65 | if(Monster.deathState != 0) { 66 | if(!f) { 67 | f = true; 68 | handler.getMouseManager().setUIManager(arrowManager); 69 | } 70 | arrowManager.tick(); 71 | if(switchGameStates) { 72 | switchGameStates = false; 73 | switchToGameState(); 74 | destroy(); 75 | } 76 | } 77 | 78 | 79 | } 80 | 81 | @Override 82 | public void render(Graphics g) { 83 | drawBackground(g); 84 | monster.render(g); 85 | inGamePlayer.render(g); 86 | 87 | if(showBars) { 88 | bar.render(g); 89 | attackBarManager.render(g); 90 | if(Monster.deathState < 2) { 91 | drawSquares(g); 92 | } 93 | } else { 94 | uiManager.render(g); 95 | } 96 | 97 | if(Monster.deathState <= 4 && Monster.deathState >= 2) { 98 | arrowManager.render(g); 99 | } 100 | 101 | if(Monster.deathState == 5) { 102 | switchToGameState(); 103 | Monster.deathState = 0; 104 | } 105 | 106 | } 107 | 108 | private void switchToGameState() { 109 | encounterFlag = true; 110 | handler.getMouseManager().setUIManager(null); 111 | Transition.canStart = false; 112 | Game.flag2 = false; 113 | State.setState(handler.getGame().gameState); 114 | BattleState.switchGameStates = true; 115 | destroy(); 116 | } 117 | 118 | private void initializeUI() { 119 | uiManager = new UIManager(handler); 120 | arrowManager = new UIManager(handler); 121 | handler.getMouseManager().setUIManager(uiManager); 122 | 123 | uiManager.addObject(new UIImageButton(50, 680, 49 * 4, 17 * 4, Assets.attackButton, new ClickListener() { 124 | @Override 125 | public void onClick() { 126 | showBars = true; 127 | } 128 | })); 129 | 130 | uiManager.addObject(new UIImageButton(300, 680, 49 * 4, 17 * 4, Assets.statsButton, new ClickListener() { 131 | @Override 132 | public void onClick() { 133 | if(!showBars) { 134 | 135 | } 136 | } 137 | })); 138 | 139 | uiManager.addObject(new UIImageButton(550, 680, 49 * 4, 17 * 4, Assets.escapeButton, new ClickListener() { 140 | @Override 141 | public void onClick() { 142 | if(!showBars) { 143 | switchToGameState(); 144 | destroy(); 145 | } 146 | } 147 | })); 148 | 149 | arrowManager.addObject(new Arrow(715, 728, 12 * 2, 12 * 2, Assets.arrow, new ClickListener() { 150 | @Override 151 | public void onClick() { 152 | if(Monster.deathState <= 4 && Monster.deathState >= 2) { 153 | Monster.deathState++; 154 | } 155 | } 156 | 157 | })); 158 | 159 | 160 | } 161 | 162 | private void drawBackground(Graphics g) { 163 | Color c = new Color(0, 203, 3); 164 | g.setColor(c); 165 | g.fillRect(0, 0, 800, 800); 166 | g.drawImage(Assets.barGrass, -75, 524, 110 * 8, 85 * 4, null); 167 | 168 | //c = new Color(147, 147, 147); 169 | //g.setColor(c); 170 | //g.fillRect(25, 550, 750, 230); 171 | g.drawImage(Assets.greySquare, 28, 558, 185 * 4, 55 * 4, null); 172 | g.drawImage(Assets.grassPlatform, 356, 180, 86 * 4, 37 * 4, null); 173 | } 174 | 175 | private void drawSquares(Graphics g) { 176 | Color d = new Color(184, 184, 184); 177 | g.setColor(d); 178 | g.fillRect(32, Bar.height, 68, 50); 179 | d = new Color(73, 73, 73); 180 | g.setColor(d); 181 | g.fillRect(28, Bar.height, 4, 50); 182 | d = new Color(5, 169, 6); 183 | g.setColor(d); 184 | g.fillRect(0, Bar.height, 28, 50); 185 | 186 | d = new Color(184, 184, 184); 187 | g.setColor(d); 188 | g.fillRect(700, Bar.height, 64, 50); 189 | d = new Color(73, 73, 73); 190 | g.setColor(d); 191 | g.fillRect(764, Bar.height, 4, 50); 192 | d = new Color(5, 169, 6); 193 | g.setColor(d); 194 | g.fillRect(768, Bar.height, 28, 50); 195 | 196 | d = new Color(0, 124, 1); 197 | g.setColor(d); 198 | g.fillRect(796, Bar.height, 4, 50); 199 | 200 | } 201 | 202 | public void destroy() { 203 | attackBarManager.destroy(); 204 | } 205 | 206 | 207 | 208 | } 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /src/world1.txt: -------------------------------------------------------------------------------- 1 | 50 50 2 | 24 48 3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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7 7 7 7 7 7 7 7 50 | 0 0 0 0 0 0 0 0 0 0 0 3 15 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 51 | 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 52 | 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /res/worlds/world1.txt: -------------------------------------------------------------------------------- 1 | 50 50 2 | 24 48 3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 6 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 48 | 0 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 49 | 0 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 50 | 0 0 0 0 0 0 0 0 0 0 0 3 15 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 51 | 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 52 | 0 0 0 0 0 0 0 0 0 0 0 6 7 7 7 7 7 7 7 7 7 7 8 0 0 0 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/Assets/AttackBarManager.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.AlphaComposite; 4 | 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.util.Timer; 8 | import java.util.TimerTask; 9 | 10 | import Game.Handler; 11 | import ImageStuff.Animation; 12 | import States.BattleState; 13 | 14 | public class AttackBarManager { 15 | private int y; 16 | public static float xVel; 17 | private static final float STARTING_X = 104; 18 | public boolean flag; 19 | public static boolean pressed; 20 | private boolean canPress; 21 | public static boolean hitPause; 22 | private int baseDamage; 23 | private int damage; 24 | public static int id = 0; 25 | 26 | private Handler handler; 27 | 28 | public static int milliSecondsPassed = 0; 29 | private int milliSecondsPassed2 = 0; 30 | private Timer timer; 31 | 32 | private Text damageText; 33 | private Text turn; 34 | private Text turn2; 35 | private Text redDamageText; 36 | 37 | private Animation slashAnimation; 38 | private Animation attackBar; 39 | 40 | TimerTask task; 41 | 42 | 43 | public AttackBarManager(Handler handler) { 44 | timer = new Timer(); 45 | task = new TimerTask() { 46 | public void run() { 47 | if(BattleState.showBars && milliSecondsPassed < 2600) 48 | milliSecondsPassed++; 49 | milliSecondsPassed2++; 50 | } 51 | }; 52 | 53 | this.handler = handler; 54 | xVel = STARTING_X; 55 | baseDamage = 20; 56 | damage = baseDamage; 57 | milliSecondsPassed = 0; 58 | y = Bar.height - 8; 59 | canPress = true; 60 | turn = new Text("Your turn", 0, 600, 4, 0); 61 | turn2 = new Text("Enemy turn", 0, 600, 4, 0); 62 | slash = false; 63 | pressed = false; 64 | slashAnimation = new Animation(35, Assets.slashAnimation); 65 | attackBar = new Animation(90, Assets.attackBar); 66 | timer.scheduleAtFixedRate(task, 1, 1); 67 | } 68 | 69 | public void tick() { 70 | if(slash && slashAnimation.getIndex() < 8) { 71 | slashAnimation.tick(); 72 | } 73 | if(f) { 74 | attackBar.tick(); 75 | } 76 | if(milliSecondsPassed > 700) { 77 | move(); 78 | } 79 | 80 | if(BattleState.switchGameStates) { 81 | destroy(); 82 | } 83 | } 84 | 85 | private boolean f; 86 | private boolean f2; 87 | public static boolean slash; 88 | private boolean slashFlag; 89 | public static boolean critical; 90 | 91 | public void render(Graphics g) { 92 | if(Monster.deathState < 2) { 93 | g.drawImage(Assets.attackBar[0], (int)(xVel) - 4, y, 4 * 2, 34 * 2, null); 94 | if(BattleState.playerAttack) { 95 | if(!f2) { 96 | f2 = true; 97 | milliSecondsPassed = 0; 98 | } 99 | playerAttack(g); 100 | } else { 101 | enemyAttack(g); 102 | } 103 | } 104 | 105 | 106 | } 107 | 108 | public int getDamage() { 109 | return damage; 110 | } 111 | 112 | private float opacity = 1; 113 | private void playerAttack(Graphics g) { 114 | if(Monster.deathState < 2) { 115 | turn.render(g); 116 | } 117 | if(pressed) { 118 | if(!f) { 119 | initializeOnPress(); 120 | } 121 | if(milliSecondsPassed > 600) { 122 | if(!slashFlag) { 123 | Monster.health -= damage; 124 | if(critical) { 125 | damageText = new Text(damage + "", 503 - (String.valueOf(damage).length()) * 14, 80, 8, 2); 126 | } else { 127 | damageText = new Text(damage + "", 529 - (String.valueOf(damage).length()) * 14, 100, 4, 2); 128 | } 129 | slashFlag = true; 130 | slash = true; 131 | } 132 | if(milliSecondsPassed < 1600) { 133 | damageText.render(g); 134 | } 135 | } 136 | if(milliSecondsPassed > 2200 && Monster.deathState == 0) { 137 | initializeWhenPlayerTurnEnd(); 138 | } else { 139 | g.drawImage(attackBar.getCurrentFrame(), (int)(xVel) - 4, y, 8, 68, null); 140 | } 141 | } 142 | 143 | if(slash && slashAnimation.getIndex() < 8) { 144 | g.drawImage(slashAnimation.getCurrentFrame(), 510, 170, 30, 100, null); 145 | } 146 | 147 | } 148 | 149 | private void initializeOnPress() { 150 | critical = false; 151 | attackBar.setIndex(0); 152 | damage = baseDamage - (int)(Math.abs(Bar.randomX - xVel) / (300 / baseDamage)); 153 | if(Math.abs(Bar.randomX - xVel) <= 8) { 154 | damage *= 1.5; 155 | critical = true; 156 | } else if(damage <= 0) { 157 | damage = 0; 158 | } 159 | 160 | slashAnimation.setIndex(0); 161 | f = true; 162 | 163 | milliSecondsPassed = 0; 164 | } 165 | 166 | private void initializeWhenPlayerTurnEnd() { 167 | f = false; 168 | f2 = false; 169 | milliSecondsPassed = 0; 170 | xVel = 104; 171 | flag = false; 172 | pressed = false; 173 | canPress = true; 174 | slashFlag = false; 175 | slash = false; 176 | BattleState.playerAttack = false; 177 | Bar.randomX = (int)(Math.random() * 540 + 150); 178 | } 179 | 180 | 181 | private int i = 0; 182 | private int max; 183 | public static int maxId; 184 | private boolean renderRedText; 185 | public static boolean canCheckId; 186 | 187 | private void enemyAttack(Graphics g) { 188 | if(Monster.deathState < 2) { 189 | turn2.render(g); 190 | } 191 | if(pressed) { 192 | if(!f) { 193 | initializeOnPress2(); 194 | } 195 | 196 | if(i < 30 && renderRedText) { 197 | renderRedText(g); 198 | } 199 | 200 | if(milliSecondsPassed > 500) { 201 | resetAfterTouchBar(); 202 | } 203 | g.drawImage(attackBar.getCurrentFrame(), (int)(xVel) - 4, y, 8, 68, null); 204 | } 205 | 206 | if(Bar.barsLeft == 0) { 207 | if(!f2) { 208 | milliSecondsPassed2 = 0; 209 | f2 = true; 210 | } 211 | if(milliSecondsPassed2 > 800) { 212 | switchToPlayerTurn(); 213 | } 214 | } 215 | } 216 | 217 | 218 | 219 | 220 | 221 | 222 | private void initializeOnPress2() { 223 | f = true; 224 | opacity = 1; 225 | max = -1; 226 | attackBar.setIndex(0); 227 | milliSecondsPassed = 0; 228 | hitPause = true; 229 | 230 | if(!MonsterBar.touchingBar) { 231 | renderRedText = true; 232 | Player.health -= 10; 233 | redDamageText = new Text("-10", (int)AttackBarManager.xVel - 35, 635, 4, 3); 234 | i = 0; 235 | } else { 236 | for(int i = 0; i < Bar.ids.length; i++) { 237 | if(Bar.ids[i] == true) { 238 | max = Math.max(max, i); 239 | } 240 | } 241 | maxId = max; 242 | canCheckId = true; 243 | } 244 | } 245 | 246 | private void resetAfterTouchBar() { 247 | canCheckId = false; 248 | renderRedText = false; 249 | f = false; 250 | milliSecondsPassed = 300; 251 | pressed = false; 252 | canPress = true; 253 | id = 0; 254 | } 255 | 256 | private void renderRedText(Graphics g) { 257 | Graphics2D g2d = (Graphics2D) g; 258 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); 259 | redDamageText.render(g); 260 | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)); 261 | opacity -= 0.0333f; 262 | i++; 263 | redDamageText.setY(635 - i / 2); 264 | } 265 | 266 | private void switchToPlayerTurn() { 267 | milliSecondsPassed = 0; 268 | BattleState.playerAttack = true; 269 | BattleState.showBars = false; 270 | xVel = STARTING_X; 271 | f = false; 272 | flag = false; 273 | f2 = false; 274 | } 275 | 276 | public void destroy() { 277 | timer.cancel(); 278 | task.cancel(); 279 | } 280 | 281 | private void move() { 282 | if(canPress && (handler.getKeymanager().q || handler.getKeymanager().space)) { 283 | pressed = true; 284 | } else if(!canPress){ 285 | pressed = false; 286 | } 287 | 288 | if(!pressed) { 289 | hitPause = false; 290 | if(!flag) { 291 | xVel+=15; 292 | if(xVel >= 680) { 293 | flag = true; 294 | } 295 | } else { 296 | xVel-=15; 297 | if(xVel <= 110) { 298 | flag = false; 299 | } 300 | } 301 | } 302 | } 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | } 321 | -------------------------------------------------------------------------------- /src/Assets/Assets.java: -------------------------------------------------------------------------------- 1 | package Assets; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | import ImageStuff.ImageLoader; 6 | import ImageStuff.SpriteSheet; 7 | 8 | public class Assets { 9 | 10 | private static final int width = 16; //Size of each tile in sprite sheet 11 | private static final int height = 16; 12 | 13 | private static final int pWidth = 12; 14 | private static final int pHeight = 20; 15 | 16 | public static BufferedImage grass, rock, ledgeMiddleLeft, tree, bush, leftCornerLedge, ledge, bottomMiddleLedge, bottomRightLedge, 17 | ledgeMiddleRight, ledgeTopLeft, ledgeTopMiddle, ledgeTopRight, ledgeMiddleMiddle, grassLedge, ledgeCornerTopRight, ledgeCornerTopLeft, bar, 18 | critBar, barGrass, grassPlatform, enemyDescription, enemyHealthBar, slash, monsterLevel, monsterBar, playerDescription, 19 | greySquare, barOutline, coin, xp; //images from sprite sheet 20 | public static BufferedImage[] player_down, player_up, player_left, player_right; 21 | public static BufferedImage[] buttonStart, trees, attackButton, escapeButton, alphabet, numbers, slashAnimation, attackBar, damageNumbers, 22 | miniAlphabet, statsButton, redNumbers, arrow, moneyNumbers, xpNumbers, monsters; 23 | 24 | public static void init() { 25 | SpriteSheet sheet = new SpriteSheet(ImageLoader.loadImage("/textures/Tiles.png")); 26 | SpriteSheet playerSheet = new SpriteSheet(ImageLoader.loadImage("/textures/Player.png")); 27 | SpriteSheet ledgeSheet = new SpriteSheet(ImageLoader.loadImage("/textures/LedgeTiles2.png")); 28 | SpriteSheet treeSheet = new SpriteSheet(ImageLoader.loadImage("/textures/Trees.png")); 29 | SpriteSheet barSheet = new SpriteSheet(ImageLoader.loadImage("/textures/Bar.png")); 30 | SpriteSheet monsterSheet = new SpriteSheet(ImageLoader.loadImage("/textures/Monsters.png")); 31 | 32 | buttonStart = new BufferedImage[2]; 33 | buttonStart[0] = sheet.crop(0, height, width * 2, height); 34 | buttonStart[1] = sheet.crop(0, height * 2, width * 2, height); 35 | 36 | attackButton = new BufferedImage[2]; 37 | attackButton[0] = sheet.crop(40, 0, 49, 17); 38 | attackButton[1] = sheet.crop(89, 0, 49, 17); 39 | 40 | statsButton = new BufferedImage[2]; 41 | statsButton[0] = sheet.crop(40, 17, 49, 17); 42 | statsButton[1] = sheet.crop(89, 17, 49, 17); 43 | 44 | 45 | 46 | escapeButton = new BufferedImage[2]; 47 | escapeButton[0] = sheet.crop(40, 34, 49, 17); 48 | escapeButton[1] = sheet.crop(89, 34, 49, 17); 49 | 50 | attackBar = new BufferedImage[2]; 51 | attackBar[0] = sheet.crop(32, 0, 4, 34); 52 | attackBar[1] = sheet.crop(36, 0, 4, 34); 53 | 54 | arrow = new BufferedImage[2]; 55 | arrow[0] = barSheet.crop(235, 76, 12, 12); 56 | arrow[1] = barSheet.crop(235, 76, 12, 12); 57 | 58 | trees = new BufferedImage[4]; 59 | trees[0] = treeSheet.crop(0, 0, width * 3, height * 3); 60 | trees[1] = treeSheet.crop(width * 3, 0, width * 3, height * 3); 61 | trees[2] = treeSheet.crop(0, height * 3 + 10, width * 3, height * 3); 62 | trees[3] = treeSheet.crop(width * 3, height * 3 + 10, width * 3, height * 3); 63 | 64 | monsters = new BufferedImage[1]; 65 | monsters[0] = monsterSheet.crop(0, 0, 38, 27); 66 | //monsters[1] = monsterSheet.crop(0, 27, 23, 41); 67 | 68 | player_down = new BufferedImage[4]; 69 | player_up = new BufferedImage[4]; 70 | player_left = new BufferedImage[4]; 71 | player_right = new BufferedImage[4]; 72 | 73 | player_down[0] = playerSheet.crop(0, 0, pWidth, pHeight); 74 | player_down[1] = playerSheet.crop(pWidth, 0, pWidth, pHeight); 75 | player_down[2] = playerSheet.crop(pWidth * 2, 0, pWidth, pHeight); 76 | player_down[3] = playerSheet.crop(pWidth * 3, 0, pWidth, pHeight); 77 | 78 | player_up[0] = playerSheet.crop(0, pHeight * 2, pWidth, pHeight); 79 | player_up[1] = playerSheet.crop(pWidth, pHeight * 2, pWidth, pHeight); 80 | player_up[2] = playerSheet.crop(pWidth * 2, pHeight * 2, pWidth, pHeight); 81 | player_up[3] = playerSheet.crop(pWidth * 3, pHeight * 2, pWidth, pHeight); 82 | 83 | player_left[0] = playerSheet.crop(0, pHeight, pWidth, pHeight); 84 | player_left[1] = playerSheet.crop(pWidth, pHeight, pWidth, pHeight); 85 | player_left[2] = playerSheet.crop(pWidth * 2, pHeight, pWidth, pHeight); 86 | player_left[3] = playerSheet.crop(pWidth * 3, pHeight, pWidth, pHeight); 87 | 88 | player_right[0] = playerSheet.crop(0, pHeight * 3, pWidth, pHeight); 89 | player_right[1] = playerSheet.crop(pWidth, pHeight * 3, pWidth, pHeight); 90 | player_right[2] = playerSheet.crop(pWidth * 2, pHeight * 3, pWidth, pHeight); 91 | player_right[3] = playerSheet.crop(pWidth * 3, pHeight * 3, pWidth, pHeight); 92 | 93 | slashAnimation = new BufferedImage[9]; 94 | 95 | for(int i = 0; i < 9; i++) { 96 | slashAnimation[i] = barSheet.crop(187 + i * 6, 52, 6, 25); 97 | } 98 | 99 | alphabet = new BufferedImage[28]; 100 | for(int i = 0; i < 28; i++) { 101 | alphabet[i] = barSheet.crop(101 + i * 6, 32, 5, 8); 102 | } 103 | 104 | miniAlphabet = new BufferedImage[28]; 105 | int count = 0; 106 | for(int i = 0; i < 28; i++) { 107 | if(i == 12) { 108 | count++; 109 | miniAlphabet[i] = barSheet.crop(101 + i * 5, 25, 5, 6); 110 | } else if(i == 22) { 111 | count++; 112 | miniAlphabet[i] = barSheet.crop(101 + i * 5 + 1, 25, 5, 6); 113 | } else if(i == 27) { 114 | miniAlphabet[i] = barSheet.crop(101 + i * 5, 25, 3, 6); 115 | } else { 116 | miniAlphabet[i] = barSheet.crop(101 + i * 5 + count, 25, 4, 6); 117 | } 118 | } 119 | 120 | numbers = new BufferedImage[11]; 121 | for(int i = 0; i < 10; i++) { 122 | numbers[i] = barSheet.crop(246 + i * 5, 25, 4, 6); 123 | } 124 | numbers[10] = barSheet.crop(296, 25, 4, 6); 125 | 126 | damageNumbers = new BufferedImage[10]; 127 | for(int i = 0; i < 10; i++) { 128 | damageNumbers[i] = barSheet.crop(187 + i * 7, 40, 7, 8); 129 | } 130 | 131 | redNumbers = new BufferedImage[11]; 132 | for(int i = 0; i < 11; i++) { 133 | redNumbers[i] = barSheet.crop(234 + i * 5, 49, 4, 6); 134 | } 135 | 136 | moneyNumbers = new BufferedImage[11]; 137 | for(int i = 0; i < 11; i++) { 138 | moneyNumbers[i] = barSheet.crop(235 + i * 6, 58, 5, 8); 139 | } 140 | 141 | xpNumbers = new BufferedImage[11]; 142 | for(int i = 0; i < 11; i++) { 143 | xpNumbers[i] = barSheet.crop(235 + i * 6, 67, 5, 8); 144 | } 145 | 146 | grass = sheet.crop(width, 0, width, height); 147 | ledgeMiddleLeft = ledgeSheet.crop(0, height, width, height); 148 | ledgeMiddleRight = ledgeSheet.crop(width * 2, height, width, height); 149 | bush = sheet.crop(0, height * 3, width, height); 150 | leftCornerLedge = ledgeSheet.crop(0, height * 2, width, height); 151 | ledge = ledgeSheet.crop(0, height * 3, width, height); 152 | grassLedge = ledgeSheet.crop(0, height * 4, width, height); 153 | bottomMiddleLedge = ledgeSheet.crop(width, height * 2, width, height); 154 | bottomRightLedge = ledgeSheet.crop(width * 2, height * 2, width, height); 155 | ledgeTopLeft = ledgeSheet.crop(0, 0, width, height); 156 | ledgeTopMiddle = ledgeSheet.crop(width, 0, width, height); 157 | ledgeTopRight = ledgeSheet.crop(width * 2, 0, width, height); 158 | ledgeMiddleMiddle = ledgeSheet.crop(width, height, width, height); 159 | ledgeCornerTopRight = ledgeSheet.crop(width * 3, 0, width, height); 160 | ledgeCornerTopLeft = ledgeSheet.crop(width * 4, 0, width, height); 161 | 162 | //bar = barSheet.crop(0, 0, 300, 25); 163 | critBar = barSheet.crop(299, 0, 6, 25); 164 | barGrass = barSheet.crop(7, 25, 94, 85); 165 | grassPlatform = barSheet.crop(101, 40, 86, 37); 166 | enemyDescription = barSheet.crop(102, 77, 102, 33); 167 | enemyHealthBar = barSheet.crop(204, 88, 77, 10); 168 | slash = barSheet.crop(187, 57, 6, 20); 169 | monsterLevel = barSheet.crop(204, 77, 23, 10); 170 | monsterBar = barSheet.crop(0, 110, 20, 26); 171 | playerDescription = barSheet.crop(0, 110, 105, 38); 172 | greySquare = barSheet.crop(105, 110, 185, 55); 173 | bar = barSheet.crop(105, 165, 150, 13); 174 | coin = barSheet.crop(204, 98, 8, 8); 175 | xp = barSheet.crop(212, 98, 10, 8); 176 | 177 | 178 | 179 | } 180 | 181 | 182 | 183 | 184 | 185 | } 186 | --------------------------------------------------------------------------------