This commit is contained in:
Makussu 2024-05-26 19:49:32 +02:00
parent d0bf6c6066
commit 491b138a33
3 changed files with 31 additions and 6 deletions

View File

@ -20,6 +20,20 @@ public class Character {
this.collidable = false; this.collidable = false;
} }
Character (PApplet window, String type, int color, boolean collidable) {
this.window = window;
this.type = type;
this.color = color;
this.collidable = collidable;
}
Character (Character another) {
this.window = another.window;
this.type = another.type;
this.collidable = another.collidable;
this.color = another.color;
}
public Character(PApplet window) { public Character(PApplet window) {
this.window = window; this.window = window;
} }

View File

@ -6,7 +6,7 @@ public class Enemy extends Character implements Health {
Enemy(PApplet window) { Enemy(PApplet window) {
super(window); super(window);
this.type = "A"; this.type = "Z";
this.health = maxHealth; this.health = maxHealth;
this.collidable = true; this.collidable = true;
this.color = window.color(200, 0, 0); this.color = window.color(200, 0, 0);

View File

@ -1,4 +1,5 @@
import processing.core.PApplet; import processing.core.PApplet;
import processing.core.PFont;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
@ -7,6 +8,10 @@ import java.util.ArrayList;
public class Fenster extends PApplet { public class Fenster extends PApplet {
Cell[][] tileMap; Cell[][] tileMap;
Character spot = new Character(this, "."); Character spot = new Character(this, ".");
Character empty = new Character(this, " ");
Character tree = new Character(this, "A", color(10, 200, 10), true);
Character wall = new Character(this, "#", color(132,86,60), true);
Player player = new Player(this); Player player = new Player(this);
Character old_player_cell; Character old_player_cell;
int old_player_x; int old_player_x;
@ -19,11 +24,19 @@ public class Fenster extends PApplet {
tileMap = new Cell[100][100]; tileMap = new Cell[100][100];
for(int i = 0; i < tileMap.length; i++) { for(int i = 0; i < tileMap.length; i++) {
for(int j = 0; j < tileMap[0].length; j++) { for(int j = 0; j < tileMap[0].length; j++) {
tileMap[i][j] = new Cell(j, i, 40.0f, new Character(this, "."));//put whatever number you want in tileMap[i][j] = new Cell(j, i, 40.0f, new Character(spot));//put whatever number you want in
//here and it will insert it instead of 0's //here and it will insert it instead of 0's
} }
} }
tileMap[20][14].character = new Character(tree);
tileMap[25][0].character = new Character(wall);
tileMap[25][1].character = new Character(wall);
tileMap[25][2].character = new Character(wall);
tileMap[25][3].character = new Character(wall);
tileMap[25][4].character = new Character(wall);
tileMap[25][5].character = new Character(wall);
tileMap[10][10].character = new Enemy(this); tileMap[10][10].character = new Enemy(this);
//this.text("lol", 0, 0); //this.text("lol", 0, 0);
@ -32,6 +45,8 @@ public class Fenster extends PApplet {
@Override @Override
public void setup() { public void setup() {
PFont font = createFont("UbuntuMono Nerd Font Mono Bold", 18);
this.textFont(font);
this.textSize(20); this.textSize(20);
this.textAlign(CENTER, CENTER); this.textAlign(CENTER, CENTER);
} }
@ -63,7 +78,6 @@ public class Fenster extends PApplet {
public void keyPressed(processing.event.KeyEvent event) { public void keyPressed(processing.event.KeyEvent event) {
this.keyPressed(); this.keyPressed();
if (keyCode == this.UP) { if (keyCode == this.UP) {
println("pressed");
Cell newTile = tileMap[player.y -1][player.x]; Cell newTile = tileMap[player.y -1][player.x];
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.y = player.y - 1; player.y = player.y - 1;
@ -74,7 +88,6 @@ public class Fenster extends PApplet {
} }
if (keyCode == this.LEFT) { if (keyCode == this.LEFT) {
Cell newTile = tileMap[player.y][player.x - 1]; Cell newTile = tileMap[player.y][player.x - 1];
println("pressed");
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.x = player.x - 1; player.x = player.x - 1;
tileMap[old_player_y][old_player_x].character = old_player_cell; tileMap[old_player_y][old_player_x].character = old_player_cell;
@ -84,7 +97,6 @@ public class Fenster extends PApplet {
} }
if (keyCode == this.DOWN) { if (keyCode == this.DOWN) {
Cell newTile = tileMap[player.y +1][player.x]; Cell newTile = tileMap[player.y +1][player.x];
println("pressed");
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.y = player.y + 1; player.y = player.y + 1;
tileMap[old_player_y][old_player_x].character = old_player_cell; tileMap[old_player_y][old_player_x].character = old_player_cell;
@ -94,7 +106,6 @@ public class Fenster extends PApplet {
} }
if (keyCode == this.RIGHT) { if (keyCode == this.RIGHT) {
Cell newTile = tileMap[player.y][player.x + 1]; Cell newTile = tileMap[player.y][player.x + 1];
println("pressed");
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.x = player.x + 1; player.x = player.x + 1;
tileMap[old_player_y][old_player_x].character = old_player_cell; tileMap[old_player_y][old_player_x].character = old_player_cell;