1
0
Fork 0

Added files via upload

This commit is contained in:
mrdev023 2016-03-15 16:03:24 +01:00
parent 46ef2d26ee
commit 61a0c5903e
100 changed files with 2445 additions and 0 deletions

View file

@ -0,0 +1,90 @@
package Audio;
import java.util.*;
import java.util.Map.*;
import javax.print.attribute.standard.MediaSize.*;
import acm.util.*;
public class AudioManager {
private static String previousStage = "";
public static String otherNameStage = "";
private static SoundClip tmpSound,prev;
private static boolean start = true;
private static int indexSound = -1;
private static HashMap<String,SoundClip> ambientSound = new HashMap<String,SoundClip>();
private static HashMap<String,SoundClip> sound = new HashMap<String,SoundClip>();
public static void addAmbientSound(String stage,String url){
try{
tmpSound = new SoundClip(url);
tmpSound.setVolume(1.0);
ambientSound.put(stage, tmpSound);
}catch(Exception e){e.printStackTrace();}
}
public static void update(String stage){
if(!previousStage.equals(stage))indexSound = -1;
ArrayList<SoundClip> sounds = getAmbientSoundByStage(stage);
if(sounds.size() != 0){
if(indexSound != -1){
if(sounds.get(indexSound).getFrameIndex() >= sounds.get(indexSound).getFrameCount()){
prev.stop();
indexSound++;
if(indexSound>=sounds.size())indexSound=0;
sounds.get(indexSound).play();
}
}else{
if(!start){
prev.stop();
}
sounds.get(0).play();
prev = sounds.get(0);
indexSound = 0;
previousStage = stage;
}
}
start = false;
}
public static void addSound(String name,String url){
try{
tmpSound = new SoundClip(url);
tmpSound.setVolume(1.0);
sound.put(name, tmpSound);
}catch(Exception e){e.printStackTrace();}
}
public static SoundClip getSound(String name){
return sound.get(name);
}
public static void playSound(String name){
getSound(name).play();
}
public static void setVolumeSound(double vol){
for(Entry<String, SoundClip> s : sound.entrySet())s.getValue().setVolume(vol);
}
public static void setVolumeAmbientSound(double vol){
for(Entry<String, SoundClip> s : ambientSound.entrySet())s.getValue().setVolume(vol);
}
public static ArrayList<SoundClip> getAmbientSoundByStage(String stage){
ArrayList<SoundClip> sounds = new ArrayList<SoundClip>();
for(Entry<String,SoundClip> s : ambientSound.entrySet()){
if(s.getKey().equals(stage)){
sounds.add(s.getValue());
}
}
return sounds;
}
public static void stopSound(String name){
getSound(name).stop();
}
}

View file

@ -0,0 +1,107 @@
package Entity;
import java.util.ArrayList;
import java.util.Random;
import Tools.CoordD;
public class Boss extends Monster{
private ArrayList<CoordD> spotCoordDs = new ArrayList<CoordD>();
private boolean patternFini = false;
private final double maxRandRange = 1000.0;
private double actualRandRange = 1000.0;
private int inMotion = 0;
private Random randG = new Random();
private ArrayList<ShootingPattern> listShootingPattern = new ArrayList<ShootingPattern>();
private int indiceActualShootingPattern = 0;
public Boss(String name, String patternName, int HP, double moveSpeed,int scoreDead,
ArrayList<CoordD> spotCoordDs, ArrayList<ShootingPattern> listShootingPattern){
super(name, patternName, HP, moveSpeed, 300, true, 1,scoreDead);
this.spotCoordDs = spotCoordDs;
this.listShootingPattern = listShootingPattern;
}
public void deplacer(){
// si le boss est static
if(inMotion <= 0){
// on fait un test aléatoire pour savoir si il va commencer un déplacement
double testDepla = actualRandRange * Math.random();
// si oui
if(testDepla < 1.0){
// on réinitialise le test
actualRandRange = maxRandRange;
// on détermine on va
int indiceSpot = randG.nextInt(spotCoordDs.size());
//on calcule le vercteur de déplacement pour y allez
double longDeplaTT = spotCoordDs.get(indiceSpot).x - (x + (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth()); // orienté
double hautDeplaTT = spotCoordDs.get(indiceSpot).y - (y + (image.getHeight() / 2) / Jeu.Jeu.resolution.getHeight()); // orienté
double hypo = Math.sqrt((longDeplaTT * longDeplaTT) + (hautDeplaTT * hautDeplaTT));
setVectorX(longDeplaTT / hypo);
setVectorY(hautDeplaTT / hypo);
// on détermine le nombre de déplacement à faire pour rejoindre le spot
inMotion = (int)(hypo / moveSpeed);
}
//sinon
else{
// on augmente la probabilité de réussir le test
actualRandRange *= 0.99;
}
}
// sinon il poursuit juste son déplacement
else{
inMotion --;
move(getVectorX() * moveSpeed, getVectorY() * moveSpeed);
}
}
public void gestionTir(){
if(HP < listShootingPattern.get(0).hpFinish){
listShootingPattern.remove(0);
}
}
public void setAFiniSonParttern(){
patternFini = true;
current = System.currentTimeMillis();
previous = 0;
elapsed = 0;
}
public boolean getPatternFini(){
return patternFini;
}
public boolean isAlive(){
return (HP > 0) ? true : false;
}
public ArrayList<ShootingPattern> getListShootingPattern(){
return listShootingPattern;
}
public boolean isTimeOut(){
return elapsed >= listShootingPattern.get(0).duration;
}
public void resetTimer(){
elapsed -= listShootingPattern.get(0).duration;
}
public void setIndiceActualShootingPattern(int p){
indiceActualShootingPattern = p;
}
public int getIndiceActualShootingPattern(){
return indiceActualShootingPattern;
}
}

View file

@ -0,0 +1,52 @@
package Entity;
import java.awt.Dimension;
public class Bullet extends Entity{
private int damage;
public Bullet(String name, double xStart, double yStart, double xTarget, double yTarget, double moveSpeed){
super("res/textures/" + name + ".png");
xStart -= (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth();
yStart -= (image.getHeight() / 2) / Jeu.Jeu.resolution.getHeight();
xTarget -= (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth();
yTarget -= (image.getHeight() / 2) / Jeu.Jeu.resolution.getHeight();
setPosition(xStart, yStart);
double longDeplaTT = xTarget - x; // orienté
double hautDeplaTT = yTarget - y; // orienté
double hypo = Math.sqrt((longDeplaTT * longDeplaTT) + (hautDeplaTT * hautDeplaTT));
setVectorX(longDeplaTT / hypo);
setVectorY(hautDeplaTT / hypo);
super.moveSpeed = moveSpeed;
}
public Bullet(String name, double xStart, double yStart, double xTarget, double yTarget, double moveSpeed, int damage){
this(name, xStart, yStart, xTarget, yTarget, moveSpeed);
this.damage = damage;
}
// boss untargeted bullet
public Bullet(TimedBullet tB, double xS, double yS){
this(tB.name, xS, yS, xS + tB.x, yS + tB.y, tB.moveSpeed);
}
// boss targeted bullet
public Bullet(TimedBullet tB, double xS, double yS, double xT, double yT){
this(tB.name, xS, yS, xT, yT, tB.moveSpeed);
}
public int getDamage(){
return damage;
}
@Override
public void update(){
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,81 @@
package Entity;
import java.awt.Dimension;
import acm.graphics.GImage;
public abstract class Entity {
protected double x,y;
protected double vectorX = 0.0, vectorY = 0.0;
protected GImage image;
protected double moveSpeed = 5.0;
public Entity(int x,int y,String url){
this.x = x;
this.y = y;
this.image = new GImage(url, Jeu.Jeu.resolution.getWidth() * x, Jeu.Jeu.resolution.getHeight() * y);
image.setSize(image.getWidth() / 1920.0 * Jeu.Jeu.resolution.getWidth(), image.getHeight() / 1080.0 * Jeu.Jeu.resolution.getHeight());
}
public Entity(String url){
this(-200,-200,url);
}
public double getX(){
return x;
}
public double getY(){
return y;
}
public double getVectorX(){
return vectorX;
}
public double getVectorY(){
return vectorY;
}
public void setVectorX(double vectorX){
this.vectorX = vectorX;
}
public void setVectorY(double vectorY){
this.vectorY = vectorY;
}
public void setPosition(double x,double y){
image.setLocation(Jeu.Jeu.resolution.getWidth() * x, Jeu.Jeu.resolution.getHeight() * y);
this.x = x;
this.y = y;
}
public void move(double x, double y){
image.move(Jeu.Jeu.resolution.getWidth() * x, Jeu.Jeu.resolution.getHeight() * y);
this.x += x;
this.y += y;
}
public GImage getImage() {
return image;
}
public void setImage(GImage image) {
this.image = image;
}
public double getMoveSpeed(){
return moveSpeed;
}
public void setMoveSpeed(double moveSpeed){
this.moveSpeed = moveSpeed;
}
public abstract void update();
}

View file

@ -0,0 +1,175 @@
package Entity;
import java.io.*;
import java.util.*;
import Items.*;
import Tools.*;
public class Monster extends Entity{
private int fireRate; // temps entre chaque tire en ms
protected long current,previous = 0,elapsed = 0;
protected int HP;
private ArrayList<Coord> pattern = new ArrayList<Coord>();
private int indicePattern = 0;
private boolean fireModeFocus;
private float dropChance;
private int scoreDead;
public Monster(String name, String patternName, int HP, double moveSpeed, int fireRate, boolean fireModeFocus, float dropChance,int scoreDead){
super("res/textures/" + name + ".png");
this.moveSpeed = moveSpeed;
this.HP = HP;
this.fireRate = fireRate;
this.fireModeFocus = fireModeFocus;
this.dropChance = dropChance;
this.scoreDead = scoreDead;
try{
File fichier = new File("res/donnees/" + patternName + ".txt");
Scanner fEntree = new Scanner(new BufferedInputStream(new FileInputStream(fichier)));
String line, tab[];
while(fEntree.hasNext()){
line = fEntree.nextLine();
tab = line.split(" ");
pattern.add(new Coord(Integer.parseInt(tab[0]), Integer.parseInt(tab[1])));
}
fEntree.close();
}
catch(IOException e){
System.out.println("ERREUR DE LECTURE du fichier : " + patternName + ".txt");
}
current = System.currentTimeMillis();
previous = 0;
elapsed = 0;
}
public void setTimerTo0(){
current = System.currentTimeMillis();
previous = 0;
elapsed = 0;
}
public void drop(){
if(Math.random() <= dropChance){
if(Math.random()>0.5){
World.World.getItemsList().add(new PowerItems(image.getX(),image.getY()));
}else{
World.World.getItemsList().add(new SpellItems(image.getX(),image.getY()));
}
}
}
public void addBullet(double xTarget, double yTarget){
World.World.getBulletsList().add(new Bullet("tireau", x + (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth(), y + image.getHeight() / Jeu.Jeu.resolution.getHeight(), xTarget, yTarget, 0.0085));
}
public boolean isTimeOut(){
return elapsed >= fireRate;
}
public void resetTimer(){
elapsed -= fireRate;
}
public void update(){
previous = current;
current = System.currentTimeMillis();
elapsed += current - previous;
}
public ArrayList<Coord> getPattern(){
return pattern;
}
public int getIndicePattern(){
return indicePattern;
}
public int getScoreDead() {
return scoreDead;
}
public void setScoreDead(int scoreDead) {
this.scoreDead = scoreDead;
}
public boolean incrementIndicePattern(){
indicePattern++;
if(indicePattern == pattern.size()) return false;
else return true;
}
public boolean getFireModeFocus(){
return fireModeFocus;
}
public int getFireRate() {
return fireRate;
}
public void setFireRate(int fireRate) {
this.fireRate = fireRate;
}
public long getCurrent() {
return current;
}
public void setCurrent(long current) {
this.current = current;
}
public long getPrevious() {
return previous;
}
public void setPrevious(long previous) {
this.previous = previous;
}
public long getElapsed() {
return elapsed;
}
public void setElapsed(long elapsed) {
this.elapsed = elapsed;
}
public int getHP() {
return HP;
}
public void setHP(int hP) {
HP = hP;
}
public float getDropChance() {
return dropChance;
}
public void setDropChance(float dropChance) {
this.dropChance = dropChance;
}
public void setPattern(ArrayList<Coord> pattern) {
this.pattern = pattern;
}
public void setIndicePattern(int indicePattern) {
this.indicePattern = indicePattern;
}
public void setFireModeFocus(boolean fireModeFocus) {
this.fireModeFocus = fireModeFocus;
}
}

View file

@ -0,0 +1,7 @@
package Entity;
public class MonsterModel_chauve_souris_focus_bas extends Monster{
public MonsterModel_chauve_souris_focus_bas() {
super("chauve-souris", "pattern_mob_bas", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,8 @@
package Entity;
public class MonsterModel_chauve_souris_focus_bomb extends Monster{
public MonsterModel_chauve_souris_focus_bomb() {
super("chauve-souris", "pattern_mob_bomb", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,8 @@
package Entity;
public class MonsterModel_chauve_souris_focus_cross extends Monster{
public MonsterModel_chauve_souris_focus_cross() {
super("chauve-souris", "pattern_mob_cross", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,7 @@
package Entity;
public class MonsterModel_chauve_souris_focus_cube extends Monster{
public MonsterModel_chauve_souris_focus_cube() {
super("chauve-souris", "pattern_mob_cube", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,7 @@
package Entity;
public class MonsterModel_chauve_souris_focus_feint extends Monster{
public MonsterModel_chauve_souris_focus_feint() {
super("chauve-souris", "pattern_mob_feint", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,7 @@
package Entity;
public class MonsterModel_chauve_souris_focus_loop extends Monster{
public MonsterModel_chauve_souris_focus_loop() {
super("chauve-souris", "pattern_mob_loop", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,8 @@
package Entity;
public class MonsterModel_chauve_souris_focus_trace extends Monster{
public MonsterModel_chauve_souris_focus_trace() {
super("chauve-souris", "pattern_mob_trace", 3, 18.0, 1500, true,0.5f,10);
}
}

View file

@ -0,0 +1,9 @@
package Entity;
public class MonsterModel_monstre extends Monster{
public MonsterModel_monstre(){
super("monster", "pattern_1", 1, 18.0, 500, false,0.3f,20);
}
}

View file

@ -0,0 +1,8 @@
package Entity;
public class MonsterModel_squelette_focus_bomb extends Monster{
public MonsterModel_squelette_focus_bomb() {
super("squelette", "pattern_mob_bomb", 3, 18.0, 1500, true,0.7f,10);
}
}

View file

@ -0,0 +1,8 @@
package Entity;
public class MonsterModel_squelette_focus_loop extends Monster{
public MonsterModel_squelette_focus_loop() {
super("squelette", "pattern_mob_loop", 3, 18.0, 1500, true,0.7f,10);
}
}

View file

@ -0,0 +1,335 @@
package Entity;
import java.awt.*;
import java.util.ArrayList;
import acm.graphics.GImage;
import acm.util.SwingTimer;
public class Player extends Entity{
public static ArrayList<Bullet> bulletsList = new ArrayList<Bullet>();
private int fireRate = 100; // temps entre chaque tire en ms
private long current,previous = 0,elapsed = 0,elapsedDead = 0,elapsedRitual = 0;
private float ritualPercentage = 50f,power = 0.0f,spell = 0.0f,powerLevel = 0, spellLevel = 0;
private boolean isDead = false;
public boolean inBoss = false;
private double minX = Jeu.Jeu.MARGIN + 0.11, maxX = Jeu.Jeu.MARGIN + Jeu.Jeu.SIZE_OF_GAME - 0.173, minY = 0.3, maxY = 0.8;
private double xCenterSpell, yCenterSpell;
private GImage imageSpell = new GImage("res/textures/spell.png");
private double widthSpell = imageSpell.getWidth(), heightSpell = imageSpell.getHeight();
private SwingTimer timerAnimSpell = new SwingTimer(20, null);
private int nbRepAnimSpell = 0;
private boolean isInvul = false;
public Player(){
super("res/textures/joueur.png");
moveSpeed = 0.008;
setPosition(0.38, 0.8);
current = System.currentTimeMillis();
}
public ArrayList<Bullet> getBulletsList(){
return bulletsList;
}
public void addBullet(String name, double xTarget, double yTarget, int damage){
bulletsList.add(new Bullet(name, x + (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth(), y , xTarget, yTarget, 0.018, damage));
}
public boolean isTimeOut(){
return elapsed >= fireRate;
}
public void resetTimer(){
elapsed -= fireRate;
}
public void setTimerTo0(){
current = System.currentTimeMillis();
previous = 0;
elapsed = 0;
}
public boolean isDead() {
return isDead;
}
public void setDead(boolean isDead) {
this.isDead = isDead;
if(isDead){
setPosition(0.38, 0.8);
powerLevel--;
if(powerLevel <0 )powerLevel = 0;
if(powerLevel == 0){
ritualPercentage -= 10;
}
elapsedDead = 0;
}
}
public void update() {
previous = current;
current = System.currentTimeMillis();
elapsed += current - previous;
elapsedDead += current - previous;
if(!Jeu.Jeu.jeu.world.getBossSpawned())elapsedRitual += current - previous;
try{for(Bullet b : bulletsList)b.update();}catch(Exception e){}
if(ritualPercentage>100)ritualPercentage=100;
if(ritualPercentage<0)ritualPercentage=0;
if(power>100)power=100;
if(power<0)power=0;
if(spell>100)spell=100;
if(spell<0)spell=0;
if(elapsedDead <= 5000 && isDead){
isInvul = true;
}
if(elapsedDead > 5000 && isDead){
isDead = false;
isInvul = false;
elapsedDead = 0;
image.setVisible(true);
}
if(isDead){
if(System.currentTimeMillis()%500 < 250){
image.setVisible(false);
}else{
image.setVisible(true);
}
}
if(elapsedRitual>=3000 && !Jeu.Jeu.jeu.world.getBossSpawned()){
ritualPercentage -= 1;
elapsedRitual -= 3000;
}
}
public int getFireRate() {
return fireRate;
}
public void setFireRate(int fireRate) {
this.fireRate = fireRate;
}
public long getCurrent() {
return current;
}
public void setCurrent(long current) {
this.current = current;
}
public long getPrevious() {
return previous;
}
public void setPrevious(long previous) {
this.previous = previous;
}
public long getElapsed() {
return elapsed;
}
public void setElapsed(long elapsed) {
this.elapsed = elapsed;
}
public float getRitualPercentage() {
return ritualPercentage;
}
public void setRitualPercentage(float ritualPercentage) {
this.ritualPercentage = ritualPercentage;
}
public void setBulletsList(ArrayList<Bullet> bulletsList) {
this.bulletsList = bulletsList;
}
public float getPower() {
return power;
}
public void setPower(float power) {
this.power = power;
if(this.power >= 100){
this.powerLevel++;
this.power -= 100;
}
}
public double getMinX() {
return minX;
}
public void setMinX(double minX) {
this.minX = minX;
}
public double getMaxX() {
return maxX;
}
public void setMaxX(double maxX) {
this.maxX = maxX;
}
public double getMinY() {
return minY;
}
public void setMinY(double minY) {
this.minY = minY;
}
public double getMaxY() {
return maxY;
}
public void setMaxY(double maxY) {
this.maxY = maxY;
}
public void move(double x, double y){
x += this.x;
y += this.y;
if(x < minX) x = minX;
if(x > maxX) x = maxX;
if(y < minY) y = minY;
if(y > maxY) y = maxY;
image.setLocation(Jeu.Jeu.resolution.getWidth() * x, Jeu.Jeu.resolution.getHeight() * y);
this.x = x;
this.y = y;
}
public float getSpell() {
return spell;
}
public void setSpell(float spell) {
this.spell = spell;
if(this.spellLevel == 3){
if(this.spell >= 100){
this.spell = 100;
}
}
else if(this.spell >= 100){
this.spellLevel++;
this.spell -= 100;
}
}
public int getPowerLevel() {
return (int)powerLevel;
}
public void setPowerLevel(float powerLevel) {
this.powerLevel = powerLevel;
}
public int getSpellLevel() {
return (int)spellLevel;
}
public void setSpellLevel(float spellLevel) {
this.spellLevel = spellLevel;
}
public double getXCenterSpell(){
return xCenterSpell;
}
public double getYCenterSpell(){
return yCenterSpell;
}
public void setXCenterSpell(double p){
xCenterSpell = p;
}
public void setYCenterSpell(double p){
yCenterSpell = p;
}
public GImage getImageSpell(){
return imageSpell;
}
public SwingTimer getTimerAnimSpell(){
return timerAnimSpell;
}
public int getNbRepAnimSpell(){
return nbRepAnimSpell;
}
public void setNbRepAnimSpell(int p){
nbRepAnimSpell = p;
}
public double getWidthSpell(){
return widthSpell;
}
public double getHeightSpell(){
return heightSpell;
}
public long getElapsedDead() {
return elapsedDead;
}
public void setElapsedDead(long elapsedDead) {
this.elapsedDead = elapsedDead;
}
public double getxCenterSpell() {
return xCenterSpell;
}
public void setxCenterSpell(double xCenterSpell) {
this.xCenterSpell = xCenterSpell;
}
public double getyCenterSpell() {
return yCenterSpell;
}
public void setyCenterSpell(double yCenterSpell) {
this.yCenterSpell = yCenterSpell;
}
public boolean isInvul() {
return isInvul;
}
public void setInvul(boolean isInvul) {
this.isInvul = isInvul;
}
public void setImageSpell(GImage imageSpell) {
this.imageSpell = imageSpell;
}
public void setWidthSpell(double widthSpell) {
this.widthSpell = widthSpell;
}
public void setHeightSpell(double heightSpell) {
this.heightSpell = heightSpell;
}
public void setTimerAnimSpell(SwingTimer timerAnimSpell) {
this.timerAnimSpell = timerAnimSpell;
}
}

View file

@ -0,0 +1,18 @@
package Entity;
import java.util.ArrayList;
public class ShootingPattern {
protected ArrayList<TimedBullet> listTimedBullet = new ArrayList<TimedBullet>();
protected int hpFinish;
protected long duration;
public ShootingPattern(){
}
public ArrayList<TimedBullet> getListTimedBullet(){
return listTimedBullet;
}
}

View file

@ -0,0 +1,17 @@
package Entity;
public class ShootingPattern_0 extends ShootingPattern{
public ShootingPattern_0(){
super();
listTimedBullet.add(new TimedBullet("grosse boule", 0.0065, 0));
listTimedBullet.add(new TimedBullet("grosse boule", 0.0065, 1000));
listTimedBullet.add(new TimedBullet("grosse boule", 0.0065, 2000));
listTimedBullet.add(new TimedBullet("grosse boule", 0.0065, 3000));
listTimedBullet.add(new TimedBullet("grosse boule", 0.0065, 4000));
hpFinish = 0;
duration = 6000;
}
}

View file

@ -0,0 +1,16 @@
package Entity;
public class ShootingPattern_1 extends ShootingPattern{
public ShootingPattern_1(){
super();
listTimedBullet.add(new TimedBullet(0.0, 0.3, "tireau", 0.005, 0));
listTimedBullet.add(new TimedBullet(-0.03, 0.3, "tireau", 0.005, 0));
listTimedBullet.add(new TimedBullet(0.03, 0.3, "tireau", 0.005, 0));
hpFinish = 180;
duration = 800;
}
}

View file

@ -0,0 +1,27 @@
package Entity;
public class TimedBullet{
public boolean isFocusOnPlayer, isAlreadyShot;
public String name;
public double x, y, moveSpeed;
public long shotTimer;
public TimedBullet(String name, double moveSpeed, long shotTimer){
this.isFocusOnPlayer = true;
this.name = name;
this.moveSpeed = moveSpeed;
this.shotTimer = shotTimer;
isAlreadyShot = false;
}
public TimedBullet(double x, double y, String name, double moveSpeed, long shotTimer){
this.isFocusOnPlayer = false;
this.x = x;
this.y = y;
this.name = name;
this.moveSpeed = moveSpeed;
this.shotTimer = shotTimer;
isAlreadyShot = false;
}
}

View file

@ -0,0 +1,54 @@
package Entity;
import acm.graphics.GImage;
import acm.util.SwingTimer;
public class Ulti extends Entity{
public static final int TIME = 1000;
private long current, previous = 0, elapsed = 0,elapsedSacrifice = 0;
private boolean isSacrifice = false;
public Ulti(double x, double y, String url) {
super(url);
setPosition(x, y);
current = System.currentTimeMillis();
}
public void update() {
if(!Jeu.Jeu.jeu.isGameOver){
previous = current;
current = System.currentTimeMillis();
elapsed += current - previous;
if(isSacrifice)elapsedSacrifice += current - previous;
if(elapsed >= TIME){
Player.bulletsList.add(new Bullet("tir joueur", x + (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth(), y , x + (image.getWidth() / 2) / Jeu.Jeu.resolution.getWidth(), y - 0.05, 0.018, 1));
Jeu.Jeu.gc.add(Player.bulletsList.get(Player.bulletsList.size() - 1).getImage());
elapsed -= TIME;
}
if(isSacrifice && y > 0.5){
move(0, -.006);
}
}
}
public void resetTimer(){
elapsed = 0;
}
public boolean isSacrifice(){
return isSacrifice && elapsedSacrifice > 1000;
}
public void sacrifice(){
isSacrifice = true;
}
public void setTimerTo0(){
current = System.currentTimeMillis();
previous = 0;
elapsed = 0;
}
}

View file

@ -0,0 +1,100 @@
package Gui;
import acm.graphics.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
public class Boutons {
private GImage bouton; // la GImage du bouton qui est affiché sur l'écran
private Image boutonSurvole, boutonNormal; // les différentes textures du bouton
private GLabel texte; // le texte du bouton
private double posiX, posiY, tailleX, tailleY; // la position et les dimension du bouton
private boolean survole = false, affiche = false;
private Dimension dim;
public Boutons(String nomImage, int x ,int y, String texteP, String police, Color couleurTxt, Dimension dimP){ // constructeur du bouton
dim = dimP;
posiX = x;
posiY = y;
boutonNormal = new GImage("Ressources Editeur/HUD/Boutons/" + nomImage + ".png").getImage();
boutonSurvole = new GImage("Ressources Editeur/HUD/Boutons/" + nomImage + "_survolé.png").getImage();
bouton = new GImage(boutonNormal, posiX, posiY);
bouton.setSize((bouton.getWidth() * dim.getWidth() / 1920), (bouton.getHeight() * dim.getHeight() / 1080));
tailleX = (int)bouton.getWidth();
tailleY = (int)bouton.getHeight();
texte = new GLabel(texteP);
texte.setFont(police);
texte.setColor(couleurTxt);
texte.setLocation(posiX + tailleX/2 - (int)texte.getWidth()/2, posiY + tailleY/2 + (int)texte.getHeight()/2 -7);
}
public GImage getBouton(){
return bouton;
}
public Image getBoutonSurvole(){
return boutonSurvole;
}
public Image getBoutonNormal(){
return boutonNormal;
}
public boolean getSurvole(){
return survole;
}
public GLabel getTexte(){
return texte;
}
public void setSurvole(boolean p){
survole = p;
}
public void setPositionCentre(double x, double y){
posiX = x * dim.getWidth() - bouton.getWidth() / 2;
posiY = y * dim.getHeight() - bouton.getHeight() / 2;
bouton.setLocation(posiX, posiY);
texte.setLocation(posiX + tailleX/2 - (int)texte.getWidth()/2, posiY + tailleY/2 + (int)texte.getHeight()/2 -7);
}
public boolean hitBox(int x,int y){ // méthode qui renvoie vrai si la sourie est sur le bouton ( pour le clic par exemple )
if(x>=posiX && x<= posiX + tailleX && y>=posiY && y<=posiY+tailleY){
return true;
}
else{
return false;
}
}
public boolean gestionSurvole(int x, int y){
if(hitBox(x, y) && survole == false){
survole = true;
bouton.setImage(boutonSurvole);
bouton.setSize((bouton.getWidth() / 1920) * dim.getWidth(), (bouton.getHeight() / 1080) * dim.getHeight());
}
if(hitBox(x, y) == false && survole){
survole = false;
bouton.setImage(boutonNormal);
bouton.setSize((bouton.getWidth() / 1920) * dim.getWidth(), (bouton.getHeight() / 1080) * dim.getHeight());
}
if(survole) return true;
return false;
}
public boolean getAffiche(){
return affiche;
}
public void setAffiche(boolean p){
affiche = p;
}
}

View file

@ -0,0 +1,57 @@
package Items;
import Entity.*;
import acm.graphics.*;
public abstract class Items {
private double x,y;
private GImage image;
public Items(double x,double y,String url){
image = new GImage(url);
image.setLocation(x,y);
this.x = x;
this.y = y;
Jeu.Jeu.gc.add(image);
}
public void move(double x,double y){
image.move(x, y);
x = image.getX();
y = image.getY();
}
public abstract void action(Player player);
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void delete(){
Jeu.Jeu.gc.remove(image);
}
public void setY(double y) {
this.y = y;
}
public GImage getImage() {
return image;
}
public void setImage(GImage image) {
this.image = image;
}
}

View file

@ -0,0 +1,15 @@
package Items;
import Entity.*;
public class PowerItems extends Items{
public PowerItems(double x, double y) {
super(x, y, "res/textures/power.png");
}
public void action(Player player) {
player.setPower(player.getPower() + 50.0f);
}
}

View file

@ -0,0 +1,15 @@
package Items;
import Entity.*;
public class SpellItems extends Items{
public SpellItems(double x, double y) {
super(x, y, "res/textures/spell drop.png");
}
public void action(Player player) {
player.setSpell(player.getSpell() + 50);
}
}

View file

@ -0,0 +1,11 @@
package Tools;
public class Coord {
public int x, y;
public Coord(int x, int y){
this.x = x;
this.y = y;
}
}

View file

@ -0,0 +1,40 @@
package Tools;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class ImagePhysics {
public static final byte RED_COLOR = 0, GREEN_COLOR = 1, BLUE_COLOR = 2;
private BufferedImage image;
private int height,width;
public ImagePhysics(String file){
try{
this.image = ImageIO.read(new File(file));
this.width = image.getWidth();
this.height = image.getHeight();
}catch(Exception e){}
}
public int[] getDataByCoord(int x,int y){
Color color = new Color(image.getRGB(x, y));
return new int[]{color.getRed(),color.getGreen(),color.getBlue()};
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
}

View file

@ -0,0 +1,27 @@
package World;
import Entity.Monster;
/*
* définit le momant d'apparition d'un mob et le mob lui-même
*/
public class MonsterSpawnPattern {
private Monster monster;
private long spawnTimer;
public MonsterSpawnPattern(Monster monster, long spawnTimer){
this.monster = monster;
this.spawnTimer = spawnTimer;
this.monster.setTimerTo0();
}
public Monster getMonster(){
return monster;
}
public long getSpawnTimer(){
return spawnTimer;
}
}

View file

@ -0,0 +1,28 @@
package World;
import java.util.ArrayList;
public class Replique {
private String speakerName;
private String lignesReplique[] = new String[4];
public Replique(String speakerName, ArrayList<String> lignesReplique){
this.speakerName = speakerName;
this.lignesReplique[0] = "";
this.lignesReplique[1] = "";
this.lignesReplique[2] = "";
this.lignesReplique[3] = "";
for(int i=0; i<lignesReplique.size(); i++){
this.lignesReplique[i] = lignesReplique.get(i);
}
}
public String getSpeakerName(){
return speakerName;
}
public String[] getLignesReplique(){
return lignesReplique;
}
}

View file

@ -0,0 +1,45 @@
package World;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import Tools.Coord;
public class Speach {
private ArrayList<Replique> listReplique = new ArrayList<Replique>();
public Speach(String speachName){
try{
File fichier = new File("res/donnees/" + speachName + ".txt");
Scanner fEntree = new Scanner(new BufferedInputStream(new FileInputStream(fichier)));
String line, tab[];
ArrayList<String> list;
while(fEntree.hasNext()){
list = new ArrayList<String>();
list.clear();
line = fEntree.nextLine();
tab = line.split("/#/");
for(int i=1; i<tab.length; i++){
list.add(tab[i]);
}
listReplique.add(new Replique(tab[0], list));
}
fEntree.close();
}
catch(IOException e){
System.out.println("ERREUR DE LECTURE du fichier : " + speachName + ".txt");
}
}
public ArrayList<Replique> getListReplique(){
return listReplique;
}
}

View file

@ -0,0 +1,134 @@
package World;
import java.awt.event.*;
import java.util.ArrayList;
import Tools.CoordD;
import Entity.Boss;
import Entity.MonsterModel_chauve_souris_focus_bomb;
import Entity.MonsterModel_chauve_souris_focus_cross;
import Entity.MonsterModel_chauve_souris_focus_cube;
import Entity.MonsterModel_chauve_souris_focus_feint;
import Entity.MonsterModel_chauve_souris_focus_loop;
import Entity.MonsterModel_chauve_souris_focus_trace;
import Entity.MonsterModel_monstre;
import Entity.MonsterModel_squelette_focus_bomb;
import Entity.MonsterModel_squelette_focus_loop;
import Entity.ShootingPattern;
import Entity.ShootingPattern_0;
import Entity.ShootingPattern_1;
public class Stage1 extends World{
public Stage1() {
super("Stage1",new String[]{"res/audio/stage_1.wav"},"res/textures/abg.png");
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 6000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 6500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 7000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 7500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 8000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 8500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 9000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 9500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 10000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cross(), 10500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_squelette_focus_bomb(), 18000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 22000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 22500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 23000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 23500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 24000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 24500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 25000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 25500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 36000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 37000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 38000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 39000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_feint(), 44000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_feint(),46000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_squelette_focus_loop(), 52000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_squelette_focus_loop(), 52500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_squelette_focus_loop(), 53000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_squelette_focus_loop(), 53500));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 70000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 72000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 74000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 76000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 71000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 73000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 75000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 77000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 78000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 80000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 82000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_cube(), 84000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 79000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 81000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 83000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 85000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_bomb(), 95000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_trace(), 95000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_trace(), 98000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 102000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 104000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 106000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_loop(), 108000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_trace(), 128000));
monsterSpawnPattern.add(new MonsterSpawnPattern(new MonsterModel_chauve_souris_focus_trace(), 130000));
listSpeach.add(new Speach("intro"));
listSpeach.add(new Speach("fin_stage_1_0m"));
listSpeach.add(new Speach("fin_stage_1_1m"));
listSpeach.add(new Speach("fin_stage_1_2m"));
listSpeach.add(new Speach("fin_stage_1_3m"));
listSpeach.add(new Speach("fin_stage_1_4m"));
ArrayList<CoordD> spotCoordDs = new ArrayList<CoordD>();
spotCoordDs.add(new CoordD(0.1, 0.3));
spotCoordDs.add(new CoordD(0.35, 0.5));
spotCoordDs.add(new CoordD(0.2, 0.05));
ArrayList<ShootingPattern> listShootingPattern = new ArrayList<ShootingPattern>();
listShootingPattern.add(new ShootingPattern_1());
listShootingPattern.add(new ShootingPattern_0());
boss = new Boss("boss", "pattern_boss_0", 300, 0.010, 15000, spotCoordDs, listShootingPattern);
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
public void actionPerformed(ActionEvent e) {
}
public void update() {
}
}

View file

@ -0,0 +1,134 @@
package World;
import java.awt.event.*;
import java.util.*;
import Audio.*;
import Entity.*;
import Items.*;
public abstract class World {
private String stageName = "";
private String backgroundImage;
private static ArrayList<Monster> monstersList = new ArrayList<Monster>();
private static ArrayList<Bullet> bulletsList = new ArrayList<Bullet>();
private static ArrayList<Bullet> bossBulletsList = new ArrayList<Bullet>();
private static ArrayList<Items> itemsList = new ArrayList<Items>();
private static ArrayList<Ulti> ultiList = new ArrayList<Ulti>();
protected static Boss boss;
private boolean bossSpawned = false;
protected ArrayList<MonsterSpawnPattern> monsterSpawnPattern = new ArrayList<MonsterSpawnPattern>();
protected ArrayList<Speach> listSpeach = new ArrayList<Speach>();
public World(String stageName,String[] ambientSound,String backgroundUrl){
this.stageName = stageName;
for(String a : ambientSound){
AudioManager.addAmbientSound(stageName, a);
}
// this.backgroundImage = new GImage(backgroundUrl);
}
public abstract void keyPressed(KeyEvent e);
public abstract void keyReleased(KeyEvent e);
public abstract void keyTyped(KeyEvent e);
public abstract void actionPerformed(ActionEvent e);
public void updateWorld(){
try{
for(Monster m : monstersList){
m.update();
}
for(Bullet b : bulletsList){
b.update();
}
for(Bullet b : bossBulletsList){
b.update();
}
if(bossSpawned) boss.update();
}
catch(Exception e){}
}
public abstract void update();
public String getStageName() {
return stageName;
}
public void setStageName(String stageName) {
this.stageName = stageName;
}
public ArrayList<Monster> getMonstersList(){
return monstersList;
}
public static ArrayList<Bullet> getBulletsList(){
return bulletsList;
}
public static ArrayList<Bullet> getBossBulletsList(){
return bossBulletsList;
}
public String getBackgroundImage() {
return backgroundImage;
}
public void setBackgroundImage(String backgroundImage) {
this.backgroundImage = backgroundImage;
}
public ArrayList<MonsterSpawnPattern> getMonsterSpawnPattern() {
return monsterSpawnPattern;
}
public void setMonsterSpawnPattern(ArrayList<MonsterSpawnPattern> monsterSpawnPattern) {
this.monsterSpawnPattern = monsterSpawnPattern;
}
public static void setMonstersList(ArrayList<Monster> monstersList) {
World.monstersList = monstersList;
}
public static void setBulletsList(ArrayList<Bullet> bulletsList) {
World.bulletsList = bulletsList;
}
public static ArrayList<Items> getItemsList() {
return itemsList;
}
public static void setItemsList(ArrayList<Items> itemsList) {
World.itemsList = itemsList;
}
public static ArrayList<Ulti> getUltiList() {
return ultiList;
}
public static void setUltiList(ArrayList<Ulti> ultiList) {
World.ultiList = ultiList;
}
public ArrayList<Speach> getListSpeach(){
return listSpeach;
}
public Boss getBoss(){
return boss;
}
public boolean getBossSpawned(){
return bossSpawned;
}
public void setBossSpawned(boolean p){
bossSpawned = p;
}
}

View file

@ -0,0 +1,11 @@
package test;
public class Coord {
public int x, y;
public Coord(int x, int y){
this.x = x;
this.y = y;
}
}

View file

@ -0,0 +1,84 @@
package test;
/*
* Cette classe sert a récupérer les actions de la souris et a déclancher le timer qui lui correspond.
* Ce timer est ensuite utilisé dans la classe Jeu de la meme manière qu'un " public void mouseClicked(MouseEvent e) "
*/
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
import acm.util.SwingTimer;
@SuppressWarnings("serial")
public class EcranListeners extends JPanel implements MouseListener, MouseMotionListener{
public int posiSourisX, posiSourisY, noBouton;
public SwingTimer sourisClicked = new SwingTimer(0, null), sourisEntered = new SwingTimer(0, null), sourisExited = new SwingTimer(0, null), sourisPressed = new SwingTimer(0, null), sourisReleased = new SwingTimer(0, null), sourisDragged = new SwingTimer(0, null), sourisMoved = new SwingTimer(0, null);
public EcranListeners(Dimension dm){
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.setSize(dm);
this.setOpaque(false);
}
@Override
public void mouseClicked(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getButton();
sourisClicked.start();
}
@Override
public void mouseEntered(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getButton();
sourisEntered.start();
}
@Override
public void mouseExited(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getButton();
sourisExited.start();
}
@Override
public void mousePressed(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getButton();
sourisPressed.start();
}
@Override
public void mouseReleased(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getButton();
sourisReleased.start();
}
@Override
public void mouseDragged(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
noBouton = e.getModifiers();
sourisDragged.start();
}
@Override
public void mouseMoved(MouseEvent e) {
posiSourisX = e.getX();
posiSourisY = e.getY();
sourisMoved.start();
}
}

View file

@ -0,0 +1,229 @@
package test;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import Input.KeyCode;
import acm.graphics.GCanvas;
import acm.graphics.GContainer;
import acm.graphics.GDimension;
import acm.graphics.GImage;
import acm.graphics.GLabel;
import acm.graphics.GRect;
import acm.program.GraphicsProgram;
import acm.util.JTFTools;
import acm.util.SwingTimer;
public class Jeu extends JFrame implements ActionListener, KeyListener{
// systeme -----------------------------------------------------------------
Dimension resolution = Toolkit.getDefaultToolkit().getScreenSize();
private GCanvas gc = new GCanvas();
private EcranListeners pan = new EcranListeners(resolution);
// autre -------------------------------------------------------------------
private ArrayList<Coord> coords = new ArrayList<Coord>();
private int enregister = -1;
private SwingTimer refresh = new SwingTimer(25, this);
private GLabel afficheur_timer = new GLabel("", 100, 1000);
private long timeStart, timeElapsed, timePaused, timeStartPause;
private boolean paused = false;
public Jeu(){
this.setUndecorated(true);
this.setSize(this.getToolkit().getScreenSize());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.validate();
this.setVisible(true);
gc.add(pan);
this.setContentPane(gc);
this.show();
pan.sourisClicked.addActionListener(this);
pan.sourisDragged.addActionListener(this);
pan.sourisEntered.addActionListener(this);
pan.sourisExited.addActionListener(this);
pan.sourisMoved.addActionListener(this);
pan.sourisPressed.addActionListener(this);
pan.sourisReleased.addActionListener(this);
this.addKeyListener(this);
refresh.start();
timeStart = System.currentTimeMillis();
timeElapsed = timeStart;
timePaused = 0;
initJeu();
}
public void initJeu(){ // initalise le menu principale et affiche tout son contenu
gc.removeAll();
afficheur_timer = new GLabel("temps : " + (timeElapsed - timeStart - timePaused), 100, 1000);
afficheur_timer.setFont("Arial-18");
gc.add(afficheur_timer);
gc.add(pan);
}
@Override
public void keyPressed(KeyEvent e) {
// TODO keyPressed
switch(e.getKeyCode()){
case KeyCode.KEY_ESCAPE:
System.exit(0);
break;
case KeyCode.KEY_S:
if(enregister == -1)
coords.clear();
else{
try{
PrintWriter fSortie = new PrintWriter("pattern_mob.txt");
for(Coord c : coords){
fSortie.println(c.x + " " + c.y);
}
fSortie.close();
}
catch(IOException exception){
System.out.println("ERREUR D'ECRITURE du fichier");
}
}
enregister *= -1;
break;
case KeyCode.KEY_SPACE:
if(!paused){
timeStartPause = System.currentTimeMillis();
paused = true;
}
else{
paused = false;
}
break;
case KeyCode.KEY_R:
timeStart = System.currentTimeMillis();
timeElapsed = timeStart;
timePaused = 0;
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO keyReleased
}
@Override
public void keyTyped(KeyEvent e) {
// TODO keyTyped
}
// ************************************************************************************
public void actionPerformed(ActionEvent e) {
// TODO sourisPressed
if(e.getSource() == pan.sourisPressed){ // quand on appuit sur un bouton de la souris
switch(pan.noBouton){
case MouseEvent.BUTTON1:
break;
case MouseEvent.BUTTON3:
break;
}
pan.sourisPressed.stop();
}
// TODO sourisReleased
if(e.getSource() == pan.sourisReleased){
switch(pan.noBouton){
case MouseEvent.BUTTON1:
break;
case MouseEvent.BUTTON3:
break;
}
pan.sourisReleased.stop();
}
// TODO sourisMoved
if(e.getSource() == pan.sourisMoved){
pan.sourisMoved.stop();
}
// TODO sourisDragged
if(e.getSource() == pan.sourisDragged){
if((pan.noBouton & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { // si on darg la souris avec le bouton gauche
}
if((pan.noBouton & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
}
pan.sourisDragged.stop();
}
// *************************************************************
if(e.getSource() == refresh){
coords.add(new Coord(pan.posiSourisX, pan.posiSourisY));
timeElapsed = System.currentTimeMillis();
if(paused){
timePaused += timeElapsed - timeStartPause;
timeStartPause = System.currentTimeMillis();
}
afficheur_timer.setLabel("temps : " + (timeElapsed - timeStart - timePaused));
}
}
}

View file

@ -0,0 +1,8 @@
package test;
public class main{
public static void main(String[] args) {
new Jeu();
}
}