Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/libraries/core.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/dungeon/Graphic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dungeon;

public class Graphic {
// work in progress
}
8 changes: 4 additions & 4 deletions src/dungeon/ItemCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ItemCollection {

private Vector<Item> contenuto;
private final Vector<Item> contenuto;

public ItemCollection(Vector<Item> contenuto) {
this.contenuto = contenuto;
Expand All @@ -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();
}
Expand Down
23 changes: 10 additions & 13 deletions src/dungeon/App.java → src/dungeon/MainGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

}

Expand All @@ -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);

}

Expand All @@ -28,18 +25,18 @@ public void draw() {
background(55);
update();

player.draw();
Player.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);
}

}
Expand All @@ -49,6 +46,6 @@ private void update() {
}

public static void main(String[] args) {
PApplet.main("dungeon.App");
PApplet.main("dungeon.MainGame");
}
}
49 changes: 31 additions & 18 deletions src/dungeon/Player.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions src/dungeon/PlayerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dungeon;

public class PlayerController {
// work in progress...
}