Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package core;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.newdawn.slick.AppGameContainer;
- import org.newdawn.slick.BasicGame;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.Input;
- import org.newdawn.slick.SlickException;
- public class HelloWorld extends BasicGame {
- Image img;
- Image image;
- int positionX = 100;
- int positionY = 100;
- int boostJ = 0;
- int boostK = 0;
- int tailleducarre = 10;
- boolean z = false;
- boolean d = false;
- boolean q = false;
- boolean s = false;
- boolean UP = false;
- boolean DOWN = false;
- boolean LEFT = false;
- boolean RIGHT = false;
- byte direction1 = 0;
- byte direction2 = 0;
- byte Futuredirection1 = 0;
- byte Futuredirection2 = 0;
- int gamewonJ = 0;
- int gamewonK = 0;
- int Xmax = 1290;
- int Xmin = 100;
- int Ymax = 690;
- int Ymin = 100;
- int vittesse = 1;
- int changementX1 = 0;
- int changementY1 = 0;
- int changementX2 = 0;
- int changementY2 = 0;
- // initialisation des joueurs et de la grille
- Joueur j = new Joueur(positionX + tailleducarre * 5, positionY + tailleducarre * 5);
- Joueur k = new Joueur(positionX + tailleducarre * 10, positionY + tailleducarre * 10);
- Grid grid = new Grid(100);
- public HelloWorld(String gamename) {
- super(gamename);
- }
- @Override
- public void init(GameContainer gc) throws SlickException {
- img = new Image("Design.png");
- // image= new Image("croix.png");
- // chercher une case parmis la liste de case
- for (Case b : grid.listOfCase) {
- if (b.x == 20 && b.y == 30) {
- System.out.println("voici la case de coordonées : " + b.x + " " + b.y);
- }
- }
- }
- @Override
- public void update(GameContainer gc, int i) throws SlickException {
- // déplacement du joueur J en faisant varier la polarité de la direction
- boolean pressD = gc.getInput().isKeyDown(Input.KEY_D);
- if (pressD) {
- if (!d) {
- d = true;
- Futuredirection1 = 2;
- }
- } else {
- d = false;
- }
- boolean pressQ = gc.getInput().isKeyDown(Input.KEY_Q);
- if (pressQ) {
- if (!q) {
- q = true;
- Futuredirection1 = 4;
- }
- } else {
- q = false;
- }
- boolean pressZ = gc.getInput().isKeyDown(Input.KEY_Z);
- if (pressZ) {
- if (!z) {
- z = true;
- Futuredirection1 = 1;
- }
- } else {
- z = false;
- }
- boolean pressS = gc.getInput().isKeyDown(Input.KEY_S);
- if (pressS) {
- if (!s) {
- s = true;
- Futuredirection1 = 3;
- }
- } else {
- s = false;
- }
- boolean pressSPACE = gc.getInput().isKeyDown(Input.KEY_SPACE);
- if (pressSPACE) {
- }
- // déplacement du joueur K en faisant varier la polarité de la direction
- boolean pressRIGHT = gc.getInput().isKeyDown(Input.KEY_RIGHT);
- if (pressRIGHT) {
- if (!RIGHT) {
- RIGHT = true;
- Futuredirection2 = 2;
- }
- } else {
- RIGHT = false;
- }
- boolean pressLEFT = gc.getInput().isKeyDown(Input.KEY_LEFT);
- if (pressLEFT) {
- if (!LEFT) {
- LEFT = true;
- Futuredirection2 = 4;
- }
- } else {
- LEFT = false;
- }
- boolean pressUP = gc.getInput().isKeyDown(Input.KEY_UP);
- if (pressUP) {
- if (!UP) {
- UP = true;
- Futuredirection2 = 1;
- }
- } else {
- UP = false;
- }
- boolean pressDOWN = gc.getInput().isKeyDown(Input.KEY_DOWN);
- if (pressDOWN) {
- if (!DOWN) {
- DOWN = true;
- Futuredirection2 = 3;
- }
- } else {
- DOWN = false;
- }
- boolean pressCTRL = gc.getInput().isKeyDown(Input.KEY_RCONTROL);
- if (pressCTRL) {
- }
- if (Futuredirection1 != direction1 ) {
- final int coordonéX = j.x ;
- final int coordonéY = j.y;
- System.out.println(coordonéX);
- System.out.println(coordonéY);
- }
- // Directions prises par le joueur : Nord = 1 ; Est = 2 ; Sud = 3 ; Ouest = 4
- switch (direction1) {
- case 1:
- j.y = j.y - vittesse;
- break;
- case 2:
- j.x = j.x + vittesse;
- break;
- case 3:
- j.y = j.y + vittesse;
- break;
- case 4:
- j.x = j.x - vittesse;
- break;
- }
- if (Futuredirection1 != 8) {
- if (j.y % tailleducarre == 0 && j.x % tailleducarre == 0) {
- direction1 = Futuredirection1;
- Futuredirection1 = 8;
- }
- }
- switch (direction2) {
- case 1:
- k.y = k.y - vittesse;
- break;
- case 2:
- k.x = k.x + vittesse;
- break;
- case 3:
- k.y = k.y + vittesse;
- break;
- case 4:
- k.x = k.x - vittesse;
- break;
- }
- if (Futuredirection2 != 8) {
- if (k.y % tailleducarre == 0 && k.x % tailleducarre == 0) {
- direction2 = Futuredirection2;
- Futuredirection2 = 8;
- }
- }
- //limites du terrain
- //limitation pour le joueur 1
- if (j.x >= Xmax) {
- direction1 = 4;
- }
- if (j.x <= Xmin) {
- direction1 = 2;
- }
- if (j.y >= Ymax) {
- direction1 = 1;
- }
- if (j.y <= Ymin) {
- direction1 = 3;
- }
- // limitation pour le joueur 2
- if (k.x >= Xmax) {
- direction2 = 4;
- }
- if (k.x <= Xmin) {
- direction2 = 2;
- }
- if (k.y >= Ymax) {
- direction2 = 1;
- }
- if (k.y <= Ymin) {
- direction2 = 3;
- }
- if (j.y % tailleducarre == 0 && j.x % tailleducarre == 0) {
- grid.listOfDeadlyCase.add(new Case(j.x, j.y));
- }
- // fin de partie
- for (Case b : grid.listOfDeadlyCase) {
- if (b.x == j.x && b.y == j.y) {
- // fin de partie pour le joueur J
- System.out.println("le joueur K gagne la partie. GG !");
- gamewonJ = 10;
- }
- if (b.x == k.x && b.y == k.y) {
- // fin de partie pour le joueur k
- System.out.println("le joueur J gagne la partie. GG !");
- gamewonK = 10;
- }
- }
- }
- @Override
- public void render(GameContainer gc, Graphics g) throws SlickException {
- // dessin des images
- g.drawString("La grille !", 20, 20);
- img.draw(positionX, positionY, 1200, 600);
- g.drawRect(k.x, k.y, tailleducarre, tailleducarre);
- g.drawRect(j.x, j.y, tailleducarre, tailleducarre);
- g.setColor(Color.orange);
- g.drawRect(j.x, j.y, tailleducarre, tailleducarre);
- //rendue du tracé du joueur
- g.setColor(Color.orange);
- if (direction1 == 3 ) {
- for( int i =0; i<10 ; i++ ){
- g.drawGradientLine(100.0f, 100.0f+i, Color.orange, j.x, j.y+i,Color.orange);
- }
- }
- if( direction1 == 2 ) {
- for( int o = 0; o<10 ; o++) {
- g.drawGradientLine(100.0f+o, 100.0f, Color.orange, j.x+o, j.y,Color.orange);
- }
- }
- //g.drawImage(image, 100f, 100f, Color.black);
- //g.setColor( new Color( 128, 128, 128 ) );g.setColor( Color.white );new Color(128, 128, 128);g.fillRect(100, 100, 10, 10);g.drawLine(100, 150, 300, 350);g.setColor(new Color(0, 0, 0, .5f));
- // affichage de la victoire d'un joueur
- if (gamewonJ == 10) {
- g.setColor(Color.white);
- g.drawString("le joueur j gagne ", 825, 825);
- //g.clear();
- }
- if (gamewonK == 10) {
- g.drawString("le joueur k gagne ", 825, 825);
- //g.clear();
- }
- }
- public static void main(String[] args) {
- try {
- AppGameContainer appgc;
- appgc = new AppGameContainer(new HelloWorld("Simple Slick Game"));
- appgc.setDisplayMode(1920, 1080, false);
- appgc.start();
- } catch (SlickException ex) {
- Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement