Commit 1d0f0b51 authored by Myriam Begel's avatar Myriam Begel

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

parents ec23bb9e e2ecc781
......@@ -38,7 +38,7 @@ public abstract class Entity implements Serializable{
private Zone visibility;
private Zone collisionBox;
private TilePropertyVector tpv;
private int speed=1;
private int speed=5;
private ActionVector actionVector=new ActionVector();
//The following 3 fields are used by the method getEntityDisplayer
......@@ -249,7 +249,7 @@ public abstract class Entity implements Serializable{
;i++){
list.forEach(x->x.translate(unary));
try{
list.forEach(x->x.hasToExist(map,tpv));
list.forEach(x->x.hasToExist(map,tpv));
}catch(Exception e){/*
System.out.println("Ended with i=" + i);*/
break;
......
package core.relayer;
import core.event.Event;
import core.event.MoveEvent;
import core.event.TypeE;
import core.zone.Direction;
import core.zone.Translation;
import gameloop.DummyLocalGameLoop;
import gameloop.DummyServerLoop;
import core.gamestate.Entity;
/*Thread launch when an entity's moves for the first time that send one movement per frame
* depending only on the entity direction*/
public class MoveRelayer extends Thread{
public class MoveThread extends Thread{
private Direction direction = Direction.NONE;
private boolean cont = true;
private Entity entity;
private Relayer myRelayer;
public MoveRelayer(Entity entity){
this.entity = entity;
public MoveThread(Relayer relayer){
this.myRelayer = relayer;
}
public void run(){
......@@ -45,19 +40,7 @@ public class MoveRelayer extends Thread{
}
private void move(){
if(direction == Direction.NONE)
return;
Event event = null;
if(!direction.composed())
event = new MoveEvent(entity.getID(), Translation.construct(direction,entity.getSpeed()));
else{
Event e1=new MoveEvent(entity.getID(), Translation.construct(direction.first(),Math.max(1,(int)(entity.getSpeed()/1.41))));
Event e2=new MoveEvent(entity.getID(), Translation.construct(direction.second(),Math.max(1,(int)(entity.getSpeed()/1.41))));
event=e1.simultaneousMerge(e2);
}
event.setEntity(entity);
event.setType(TypeE.MOVE);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
myRelayer.move(direction);
}
......
package core.relayer;
import core.event.*;
import core.event.MoveEvent;
import core.gamestate.Action;
import core.gamestate.Entity;
import core.zone.Direction;
......@@ -23,13 +21,11 @@ public class Relayer {
private final int ID;
private Entity entity;
private GameContent gameContent;
private MoveRelayer moveRelayer;
public Relayer(int ID,Entity entity, GameContent gameContent){
this.ID=ID;
this.entity=Objects.requireNonNull(entity);
this.gameContent = gameContent;
moveRelayer = new MoveRelayer(entity);
}
public final int getID(){
......@@ -37,16 +33,21 @@ public class Relayer {
}
public void move(Direction direction) {
if(!(moveRelayer.isAlive())){
/*starts a thread to move*/
moveRelayer = new MoveRelayer(entity);
moveRelayer.start();
}
if(direction==Direction.NONE){
stopMove();
return;
}
Event event = null;
if(!direction.composed())
event = new MoveEvent(entity.getID(), Translation.construct(direction,entity.getSpeed()));
else{
Event e1=new MoveEvent(entity.getID(), Translation.construct(direction.first(),Math.max(1,(int)(entity.getSpeed()/1.41))));
Event e2=new MoveEvent(entity.getID(), Translation.construct(direction.second(),Math.max(1,(int)(entity.getSpeed()/1.41))));
event=e1.simultaneousMerge(e2);
}
moveRelayer.setDirection(direction);
event.setEntity(entity);
event.setType(TypeE.MOVE);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
}
public void stopMove(){
......
......@@ -83,6 +83,8 @@ public class Translation implements Cloneable, Serializable {
* @return the unaryTileTranslation with the same direction this translation.
*/
public Translation getOrientedUnary() {
if(Point.between(posX,-Tile.TileScaleX,Tile.TileScaleX) || Point.between(posY,-Tile.TileScaleY,Tile.TileScaleY))
return this;
return posX!=0?(posX<=0?unaryTileUp:unaryTileDown):(posY<=0?unaryTileLeft:unaryTileRight);
}
......
package graphics;
/**
* Created by etouss on 26/10/2015.
*/
public interface Affichable {
void affiche(Display d, int x,int y);
}
package graphics;
import map_generation.tiles.Tile;
public abstract class Display {
public Display()
{
}
//public abstract void clean_screen(); // to clean the screen
public abstract void set_local_display(int x, int y, Character graph); // to set the display in one tile
}
\ No newline at end of file
package graphics.graphical_display;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* Created by etouss on 26/10/2015.
* Modified by Thomas on 3/11/2015.
*/
public class Graphical_Display extends JFrame {
// The width and height of the window on the user's screen
public int winWidth;
public int winHeight;
public Graphical_Display(){
initUI();
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add(new Graphical_Panel(), BorderLayout.CENTER);
}
public void initUI() {
// Getting the size of the user's computer screen and setting winWidth and winHeight accordingly
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = ge.getMaximumWindowBounds();
winWidth = (int)bounds.getWidth();
winHeight = (int)bounds.getHeight();
// Setting the JFrame properties
setTitle("Notre jeu");
setSize(winWidth, winHeight);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setLayout(new BorderLayout());
}
private class InputKeyboardListener implements KeyListener {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
}
}
\ No newline at end of file
package graphics.graphical_display;
import graphics.graphical_display.Graphical_Display;
import javax.swing.*;
/**
* Created by etouss on 26/10/2015.
*/
public class Graphical_Main {
public static void main (String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
Graphical_Display mainFrame = new Graphical_Display();
mainFrame.setVisible(true);
}
});
}
}
package graphics.graphical_display;
import graphics.terminalUI.Sprite_Terminal.TerminalSprite;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
/**
* Created by etouss on 26/10/2015.
* Modified by Thomas on 3/11/2015.
*/
public class Graphical_Panel extends JPanel {
private BufferedImage img = null;
// private Image ii2im;
// private ImageIcon ii;
public Graphical_Panel(){
super();
// Why? (what does it do?)
this.setFocusable(true);
// Loading an image
try {
img = ImageIO.read(getClass().getResource("/assets/dungeon_set_1/floor/0000_floor_default.bmp"));
} catch (IOException e) {
e.printStackTrace();
}
// ii = new ImageIcon(getClass().getResource("/0000_floor_default.bmp"));
// ii2im = ii.getImage();
/*try {
img = ImageIO.read(new FileInputStream("assets/dungeon_set_1/floor/0000_floor_default.bmp"));
} catch (IOException e) {
e.printStackTrace();
}*/
}
@Override
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
public void paintComponent(Graphics g, TerminalSprite sp) {
super.paintComponent(g);
this.requestFocusInWindow();
g.drawImage(img, 0, 0, 100, 100, 0, 0, img.getWidth(), img.getHeight(), null);
}
}
package graphics.graphical_sprite;
/**
* Created by zobi on 26/10/15.
*/
public class RealFloorSprite extends RealSprite {
public RealFloorSprite() {
super("/home/zobi/Documents/cours/M1/genie_logiciel/the_dungeon_project/assets/dungeon_set_1/floor/0006_floor_default.bmp");
}
}
package graphics.graphical_sprite;
/**
* Created by zobi on 26/10/15.
*/
public class RealSprite{
String path;
public RealSprite(String path){
this.path = path;
}
}
\ No newline at end of file
package graphics.guiSkeleton.DummyForTest;
/**
* Created by dupriez on 23/11/15.
*/
public enum DotyColour{
BLUE,
GREEN,
RED
}
package graphics.guiSkeleton.DummyForTest;
/**
* Created by dupriez on 14/11/15.
*
* This interface must be satisfied by objects that want to be warned when the content of GameContent changes.
* Part of the observer pattern.
*/
public interface DummyGameContentMapChangeListener {
/**
* What to do when the map of the dummyGameContent changes.
*/
void mapChange();
}
......@@ -220,6 +220,9 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener
if (e == Input.DOWN_ARROW) {
MyInputInterpreter.setMoveYBottom(true);
}
if (e == Input.SPACE) {
MyInputInterpreter.setSpellCast(1);
}
}
@Override
......
package graphics.guiSkeleton;
import core.relayer.Relayer;
import core.zone.Direction;
import core.relayer.*;
/**
* Created by ghocquet
......@@ -10,8 +9,8 @@ import core.zone.Direction;
public class InputInterpreter {
private Relayer MyRelayer;
private Direction direction;
private MoveThread moveThread;
/****************************
* Constuctor InputInterpretor
......@@ -19,15 +18,24 @@ public class InputInterpreter {
public InputInterpreter(Relayer r) {
MyRelayer = r;
direction=Direction.NONE;
moveThread = new MoveThread(MyRelayer);
}
private void move(){
MyRelayer.move(direction);
if(!(moveThread.isAlive())){
/*starts a thread to move*/
moveThread.start();
}
moveThread.setDirection(direction);
if(direction == Direction.NONE)
return;
}
/**
* Changes the orientation on x of the Entity
* @param b the new orientation on x
* @param bool the new orientation on x
*/
public void setMoveXRight(boolean bool) {
if(bool)
......@@ -38,7 +46,7 @@ public class InputInterpreter {
}
/**
* Changes the orientation on x of the Entity
* @param x the new orientation on x
* @param bool the new orientation on x
*/
public void setMoveXLeft(boolean bool) {
if(bool)
......@@ -55,7 +63,7 @@ public class InputInterpreter {
direction=direction.remove(Direction.UP);
move();
}
public void setMoveYBottom(boolean bool) {
if(bool)
direction=direction.add(Direction.DOWN);
......@@ -64,4 +72,8 @@ public class InputInterpreter {
move();
}
public void setSpellCast(int num_spell) {
//System.out.println("SPELLL !!");
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment