diff --git a/.idea/libraries/core.xml b/.idea/libraries/core.xml index 77d8491..f35f12c 100644 --- a/.idea/libraries/core.xml +++ b/.idea/libraries/core.xml @@ -1,7 +1,7 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/dungeon/Graphic.java b/src/dungeon/Graphic.java new file mode 100644 index 0000000..3dc8992 --- /dev/null +++ b/src/dungeon/Graphic.java @@ -0,0 +1,5 @@ +package dungeon; + +public class Graphic { + // work in progress +} diff --git a/src/dungeon/ItemCollection.java b/src/dungeon/ItemCollection.java index 9ad0f56..1d133b1 100644 --- a/src/dungeon/ItemCollection.java +++ b/src/dungeon/ItemCollection.java @@ -5,7 +5,7 @@ public class ItemCollection { - private Vector contenuto; + private final Vector contenuto; public ItemCollection(Vector contenuto) { this.contenuto = contenuto; @@ -19,14 +19,14 @@ public void addItem(Item item){ contenuto.add(item); } - public int elementi(){ + public int elementi() { return contenuto.size(); } public String elementiContenuti(){ var sg = new StringJoiner(","); - for(int i = 0; i < contenuto.size(); i++){ - sg.add(contenuto.get(i).getNome()); + for (Item item : contenuto) { + sg.add(item.getNome()); } return sg.toString(); } diff --git a/src/dungeon/App.java b/src/dungeon/MainGame.java similarity index 56% rename from src/dungeon/App.java rename to src/dungeon/MainGame.java index a831458..b6f89b9 100644 --- a/src/dungeon/App.java +++ b/src/dungeon/MainGame.java @@ -3,11 +3,8 @@ import processing.core.PApplet; import processing.event.KeyEvent; -public class App extends PApplet { - - private Player player; - - public App() { +public class MainGame extends PApplet { + public MainGame() { } @@ -18,8 +15,8 @@ public void settings() { @Override public void setup() { - player = new Player("Hero",getGraphics()); - player.setPos(10,10); + Player.getPlayerInstance("Giovanni", getGraphics()); + Player.setPos(10,10); } @@ -28,7 +25,7 @@ public void draw() { background(55); update(); - player.draw(); + Player.draw(); } @@ -36,10 +33,10 @@ public void draw() { @Override public void keyPressed(KeyEvent event) { switch (event.getKeyCode()) { - case 65 -> player.move(-1, 0); - case 68 -> player.move(1, 0); - case 87 -> player.move(0,-1); - case 83 -> player.move(0,1); + case 65 -> Player.move(-1, 0); + case 68 -> Player.move(1, 0); + case 87 -> Player.move(0,-1); + case 83 -> Player.move(0,1); } } @@ -49,6 +46,6 @@ private void update() { } public static void main(String[] args) { - PApplet.main("dungeon.App"); + PApplet.main("dungeon.MainGame"); } } diff --git a/src/dungeon/Player.java b/src/dungeon/Player.java index 28eae0b..f51667d 100644 --- a/src/dungeon/Player.java +++ b/src/dungeon/Player.java @@ -1,32 +1,45 @@ package dungeon; import processing.core.PGraphics; +import processing.core.PVector; public class Player { - private final String name; - private final PGraphics gfx; - private int x; - private int y; - - public Player(String name, PGraphics gfx) { - this.name = name; - this.gfx = gfx; - x = 0; - y = 0; + private static Player playerInstance = null; + + private static String name; + + private static PGraphics gfx; + + private static PVector direction; + + private Player(String name, PGraphics gfx) { + Player.name = name; + Player.gfx = gfx; + direction = new PVector(0, 0); } - public void setPos(int x, int y) { - this.x = x; - this.y = y; + public static void getPlayerInstance(String playerName, PGraphics gfx) { + if (isNull()) { + playerInstance = new Player(playerName, gfx); // C'รจ una warning un po' bislacca + } } - public void draw() { + public static void setPos(int x, int y) { + direction.x = x; + direction.y = y; + } + + public static void draw() { gfx.fill(255,0,0); - gfx.rect(x*16,y*16,16,16); + gfx.rect(direction.x*16,direction.y*16,16,16); + } + + public static void move(int dx, int dy) { + direction.x += dx; + direction.y += dy; } - public void move(int dx, int dy) { - x += dx; - y += dy; + private static boolean isNull() { + return playerInstance == null; } } diff --git a/src/dungeon/PlayerController.java b/src/dungeon/PlayerController.java new file mode 100644 index 0000000..777e864 --- /dev/null +++ b/src/dungeon/PlayerController.java @@ -0,0 +1,5 @@ +package dungeon; + +public class PlayerController { + // work in progress... +}