Skip to content
This repository was archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from Pixselve/mainmenulink
Browse files Browse the repository at this point in the history
World reparent.
  • Loading branch information
Pixselve authored Jan 5, 2021
2 parents d7a4011 + f3320a5 commit 8986439
Show file tree
Hide file tree
Showing 33 changed files with 911 additions and 936 deletions.
Binary file added images/leveleditor_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/leveleditor_button_hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/titlegame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 5 additions & 14 deletions src/warcraftTD/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package warcraftTD;

import warcraftTD.hud.MainMenu;
import warcraftTD.utils.Level;
import warcraftTD.utils.Sound;


import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;

Expand All @@ -17,26 +21,13 @@ public static void main(String[] args) throws UnsupportedAudioFileException, IOE
int startY = 10;

MainMenu menu = new MainMenu(width, height);
menu.start();
menu.run();

//WorldEditor we = new WorldEditor(width, height);

//we.run();

try {
Sound gameMusic = new Sound("music/glorious.wav", true);
gameMusic.play(0.25);
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace();
}

World w = new World(width, height, nbSquareX, nbSquareY, startX, startY);

//Level level = new Level(new File("levels/level.tdl"));
//World world = level.getWorld();

// Lancement de la boucle principale du jeu
world.run();
}
}

800 changes: 116 additions & 684 deletions src/warcraftTD/World.java

Large diffs are not rendered by default.

226 changes: 49 additions & 177 deletions src/warcraftTD/WorldEditor.java

Large diffs are not rendered by default.

633 changes: 633 additions & 0 deletions src/warcraftTD/WorldGame.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/warcraftTD/hud/Interface.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void removeNotif(NotifText text) {
this.garbage.add(text);
}

public abstract void makeAction(String action, Element from);
public abstract void makeAction(String action, Element from) throws IOException, LineUnavailableException, UnsupportedAudioFileException;

public void updateInterface(double mouseX, double mouseY, double delta_time) {
Iterator<Element> i = this.listElements.iterator();
Expand Down
6 changes: 5 additions & 1 deletion src/warcraftTD/hud/InterfaceEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public InterfaceEditor(WorldEditor world) throws UnsupportedAudioFileException,
this.getListElements().add(this.waveBtn);
this.saveBtn = new Button(new Position(0.21, 0.08), 0.08, 0.11, "images/save_button_editor.png", "images/save_button_editor_hover.png", "save", this);
this.getListElements().add(this.saveBtn);
this.exitBtn = new Button(new Position(0.085, 0.08), 0.15,0.1,"images/mm_button_quit.png","images/mm_button_quit_hover.png","quit", this);
this.exitBtn = new Button(new Position(0.085, 0.08), 0.15,0.1,"images/mm_button_quit.png","images/mm_button_quit_hover.png","exit", this);
this.getListElements().add(this.exitBtn);

this.settingsBox = new HorizontalGroupBox(new Position(0.88,0.5), 0.32,1.08,this, "images/PanelSettings.png");
Expand Down Expand Up @@ -343,6 +343,10 @@ public void makeAction(String action, Element from) {
this.toggleBottomToolbar(true);
this.world.setNeedReleaseMouse(true);
break;
case "exit":
this.world.setEnd(true);
this.world.setNeedReleaseMouse(true);
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.hud;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.towers.*;
import warcraftTD.utils.Position;
import warcraftTD.utils.Sound;
Expand All @@ -10,16 +10,16 @@
import java.awt.*;
import java.io.IOException;

public class InterfaceJeu extends Interface{
private final World world;
public class InterfaceGame extends Interface{
private final WorldGame world;
private final Button shop_btn;
private final ProgressBar waveEnnemyBar;
private final HorizontalGroupBox shopBox;
private final Text fps_text;
private final Text building_text;
private final boolean dev_mode = true;

public World getWorld() {
public WorldGame getWorld() {
return this.world;
}

Expand All @@ -43,7 +43,7 @@ public World getWorld() {
private Text upgradeAttackSpeedPrice;
private Text upgradeSpecialPrice;

public InterfaceJeu(World parent) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
public InterfaceGame(WorldGame parent) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
super();
this.world = parent;
this.shop_btn = new Button(new Position(0.9, 0.1), 0.1, 0.13, "images/shop_button.png", "images/shop_button_hover.png", "Shopping", this);
Expand Down
48 changes: 45 additions & 3 deletions src/warcraftTD/hud/MainMenu.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package warcraftTD.hud;

import warcraftTD.World;
import warcraftTD.WorldEditor;
import warcraftTD.WorldGame;
import warcraftTD.libs.StdDraw;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Level;
import warcraftTD.utils.Position;

import javax.sound.sampled.LineUnavailableException;
Expand All @@ -10,7 +14,6 @@
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;

import java.awt.*;
import java.io.IOException;

public class MainMenu extends Interface {
Expand All @@ -19,11 +22,19 @@ public class MainMenu extends Interface {
private double delta_time;
private boolean needReleaseMouse;
private Animation background;
private World nextWorld;
private Image title;

public void setNeedReleaseMouse(boolean needReleaseMouse) {
this.needReleaseMouse = needReleaseMouse;
}

public MainMenu(int width, int height) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
StdDraw.setCanvasSize(width, height);
StdDraw.enableDoubleBuffering();

this.nextWorld = null;

loadBackground("images/mainMenuBackground/capybara/capybara_");
this.groupBox = new HorizontalGroupBox(new Position(0.5,0.5), 0.4,0.6,this, "");
this.getListElements().add(this.groupBox);
Expand All @@ -37,8 +48,14 @@ public MainMenu(int width, int height) throws UnsupportedAudioFileException, IOE
btn = new Button(new Position(0.5,0.1),0.2,0.1,"images/mm_button_quit.png","images/mm_button_quit_hover.png","quit", this);
this.groupBox.addHUDElement(btn);

this.title = new Image(new Position(0.5,0.85), 0.8,0.25,this, "images/titlegame.png");
this.getListElements().add(this.title);

this.groupBox.ShowBox(0.5,0.0);

btn = new Button(new Position(0.105,0.055),0.2,0.1,"images/leveleditor_button.png","images/leveleditor_button_hover.png","leveleditor", this);
this.getListElements().add(btn);

btn = new Button(new Position(0.9,0.05),0.06,0.08,"images/Capybara_Button.png","images/Capybara_Button_hover.png","switchCapybara", this);
this.getListElements().add(btn);
btn = new Button(new Position(0.965,0.05),0.06,0.08,"images/Cat_Button.png","images/Cat_Button_hover.png","switchCat", this);
Expand All @@ -65,7 +82,7 @@ public void updateInterface(double mouseX, double mouseY, double delta_time) {
}

@Override
public void makeAction(String action, Element from) {
public void makeAction(String action, Element from) throws IOException, LineUnavailableException, UnsupportedAudioFileException {
switch (action) {
case "quit":
System.exit(0);
Expand All @@ -80,26 +97,51 @@ public void makeAction(String action, Element from) {
int result = fileChooser.showOpenDialog(StdDraw.getFrame());
if (result == JFileChooser.APPROVE_OPTION) {
File selectedLvl = fileChooser.getSelectedFile();
Level level = new Level(selectedLvl);
nextWorld = level.getWorld(this);
this.quit = true;
}
break;
case "lvl1":
this.needReleaseMouse = true;
File lvl1 = new File("levels/level1.tdl");
Level level = new Level(lvl1);
nextWorld = level.getWorld(this);
this.quit = true;
break;
case "lvl2":
this.needReleaseMouse = true;
File lvl2 = new File("levels/level2.tdl");
Level level2 = new Level(lvl2);
nextWorld = level2.getWorld(this);
this.quit = true;
break;
case "switchCapybara":
this.needReleaseMouse = true;
loadBackground("images/mainMenuBackground/capybara/capybara_");
break;
case "switchCat":
this.needReleaseMouse = true;
loadBackground("images/mainMenuBackground/kitten/The most dangerous kitten in the world_");
break;
case "leveleditor":
nextWorld = new WorldEditor(1200,800,this);
this.quit = true;
break;
}
}

public void run() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
this.quit = false;
this.nextWorld = null;
while(nextWorld==null){
this.startLoop();
}
this.nextWorld.setNeedReleaseMouse(true);
this.nextWorld.run();
}

public void start() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
public void startLoop() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
while(!quit){
long time_nano = System.nanoTime();

Expand Down
2 changes: 1 addition & 1 deletion src/warcraftTD/hud/ProgressBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setProgressPercent(double progressPercent) {
}
}

public void ProgressBar(InterfaceJeu parent) {
public void ProgressBar(InterfaceGame parent) {
this.setParent(parent);
}

Expand Down
6 changes: 3 additions & 3 deletions src/warcraftTD/hud/TowerBuyButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
public class TowerBuyButton extends Button {
private Class towerClass;

public TowerBuyButton(Position pos, double width, double height, String sprite, String sprite_hover, String action, InterfaceJeu parent, Class towerClass) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
public TowerBuyButton(Position pos, double width, double height, String sprite, String sprite_hover, String action, InterfaceGame parent, Class towerClass) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
super(pos, width, height, sprite, sprite_hover, action, parent);
this.towerClass = towerClass;
}

@Override
public void update(double MouseX, double MouseY, double delta_time) {
if (this.isVisible()) {
this.setEnabled(((InterfaceJeu)this.getParent()).getWorld().getPlayer_wallet().getMoney() >= ((InterfaceJeu)this.getParent()).getWorld().getPrice_tower().get(this.towerClass));
this.setEnabled(((InterfaceGame)this.getParent()).getWorld().getPlayer_wallet().getMoney() >= ((InterfaceGame)this.getParent()).getWorld().getPrice_tower().get(this.towerClass));

super.update(MouseX, MouseY, delta_time);
}
Expand All @@ -27,7 +27,7 @@ public void update(double MouseX, double MouseY, double delta_time) {
@Override
public String onClick(double MouseX, double MouseY) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
if (this.isVisible() && this.isEnabled() && this.isClickable() && this.getHitBox().isHit(MouseX, MouseY)) {
((InterfaceJeu)this.getParent()).startBuilding(this.towerClass);
((InterfaceGame)this.getParent()).startBuilding(this.towerClass);
this.getClickSound().play(0.6);
return "cancel";
}
Expand Down
4 changes: 2 additions & 2 deletions src/warcraftTD/monsters/BaseMonster.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Position;

Expand All @@ -10,7 +10,7 @@ public abstract class BaseMonster extends Monster {
private final Animation walkingAnimation;
private final Animation dieAnimation;

public BaseMonster(Position position, World world, int health, int goldWhenDead, double speed, Animation walkingAnimation, Animation dieAnimation) {
public BaseMonster(Position position, WorldGame world, int health, int goldWhenDead, double speed, Animation walkingAnimation, Animation dieAnimation) {
super(position, world, health, goldWhenDead, speed);
this.walkingAnimation = walkingAnimation;
this.dieAnimation = dieAnimation;
Expand Down
6 changes: 3 additions & 3 deletions src/warcraftTD/monsters/Monster.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.libs.StdDraw;
import warcraftTD.utils.Position;
import warcraftTD.utils.Vector;
Expand Down Expand Up @@ -40,7 +40,7 @@ public void setReadyToBeRemoved(boolean readyToBeRemoved) {
private boolean isReadyToBeRemoved;
private int goldWhenDead;

public Monster(Position p, World world, int health, int goldWhenDead, double speed) {
public Monster(Position p, WorldGame world, int health, int goldWhenDead, double speed) {
this.position = p;
this.path = new LinkedList<>(world.getPaths());
this.path = this.path.stream().map(position -> new Position(position.getX() / world.getNbSquareX() + (world.getSquareWidth() / 2), position.getY() / world.getNbSquareY() + (world.getSquareHeight() / 2))).collect(Collectors.toList());
Expand Down Expand Up @@ -138,7 +138,7 @@ private void updateEffectsDuration(double deltaTime) {

}

public void takeDamage(int damage, World world, Color colordamage) {
public void takeDamage(int damage, WorldGame world, Color colordamage) {
world.getHUD().addNotifText(this.position, new Font("Arial", Font.BOLD, 20), -0.1, "" + damage, colordamage);
this.health -= damage;
}
Expand Down
4 changes: 2 additions & 2 deletions src/warcraftTD/monsters/Wave.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters;

import warcraftTD.World;
import warcraftTD.WorldGame;

import java.util.LinkedList;

Expand Down Expand Up @@ -34,7 +34,7 @@ public void addMonster(Monster monster, double timeLeftBeforeSpawning) {
this.monsterQueue.addFirst(new QueueInstance(monster, timeLeftBeforeSpawning));
}

public void spawn(World world, double deltaTime) {
public void spawn(WorldGame world, double deltaTime) {
if (this.monsterQueue.size() > 0) {
this.monsterQueue.getFirst().decrementTime(deltaTime);
if (this.monsterQueue.getFirst().getTimeLeftBeforeSpawning() <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/warcraftTD/monsters/entities/ScienceKnight.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters.entities;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.monsters.BaseMonster;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Position;
Expand All @@ -10,7 +10,7 @@ public class ScienceKnight extends BaseMonster {
public static double scaledWidth = 0.1;


public ScienceKnight(Position position, World world) {
public ScienceKnight(Position position, WorldGame world) {
super(position, world, 10, 10, 0.2,
new Animation(new String[]{
"images/enemies/4/4_enemies_1_walk_000.png",
Expand Down
1 change: 0 additions & 1 deletion src/warcraftTD/monsters/entities/Scorpion.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package warcraftTD.monsters.entities;

import warcraftTD.World;
import warcraftTD.monsters.BaseMonster;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Position;
Expand Down
4 changes: 2 additions & 2 deletions src/warcraftTD/monsters/entities/StoneChild.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters.entities;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.monsters.BaseMonster;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Position;
Expand All @@ -10,7 +10,7 @@ public class StoneChild extends BaseMonster {
public static double scaledWidth = 0.09;


public StoneChild(Position position, World world) {
public StoneChild(Position position, WorldGame world) {
super(position, world, 15, 15, 0.09,
new Animation(new String[]{
"images/enemies/8/8_enemies_1_walk_000.png",
Expand Down
4 changes: 2 additions & 2 deletions src/warcraftTD/monsters/entities/StoneGiant.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package warcraftTD.monsters.entities;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.monsters.BaseMonster;
import warcraftTD.utils.Animation;
import warcraftTD.utils.Position;
Expand All @@ -9,7 +9,7 @@ public class StoneGiant extends BaseMonster {
public static double scaledHeight = 0.3;
public static double scaledWidth = 0.25;

public StoneGiant(Position position, World world) {
public StoneGiant(Position position, WorldGame world) {
super(position, world, 100, 100, 0.05,
new Animation(new String[]{
"images/enemies/10/10_enemies_1_walk_000.png",
Expand Down
5 changes: 2 additions & 3 deletions src/warcraftTD/towers/Arrow.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package warcraftTD.towers;

import warcraftTD.World;
import warcraftTD.WorldGame;
import warcraftTD.utils.Position;
import warcraftTD.utils.Vector;

import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;

public class Arrow extends Tower {

public Arrow(Position p, double width, double height, World world) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
public Arrow(Position p, double width, double height, WorldGame world) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
super(p, width, height, world, "music/arrow.wav");

this.setSprite("images/tower_arrow.png");
Expand Down
Loading

0 comments on commit 8986439

Please sign in to comment.