tree
This commit is contained in:
parent
d0bf6c6066
commit
491b138a33
@ -20,6 +20,20 @@ public class Character {
|
||||
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) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ public class Enemy extends Character implements Health {
|
||||
|
||||
Enemy(PApplet window) {
|
||||
super(window);
|
||||
this.type = "A";
|
||||
this.type = "Z";
|
||||
this.health = maxHealth;
|
||||
this.collidable = true;
|
||||
this.color = window.color(200, 0, 0);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import processing.core.PApplet;
|
||||
import processing.core.PFont;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
@ -7,6 +8,10 @@ import java.util.ArrayList;
|
||||
public class Fenster extends PApplet {
|
||||
Cell[][] tileMap;
|
||||
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);
|
||||
Character old_player_cell;
|
||||
int old_player_x;
|
||||
@ -19,11 +24,19 @@ public class Fenster extends PApplet {
|
||||
tileMap = new Cell[100][100];
|
||||
for(int i = 0; i < tileMap.length; i++) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
//this.text("lol", 0, 0);
|
||||
@ -32,6 +45,8 @@ public class Fenster extends PApplet {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
PFont font = createFont("UbuntuMono Nerd Font Mono Bold", 18);
|
||||
this.textFont(font);
|
||||
this.textSize(20);
|
||||
this.textAlign(CENTER, CENTER);
|
||||
}
|
||||
@ -63,7 +78,6 @@ public class Fenster extends PApplet {
|
||||
public void keyPressed(processing.event.KeyEvent event) {
|
||||
this.keyPressed();
|
||||
if (keyCode == this.UP) {
|
||||
println("pressed");
|
||||
Cell newTile = tileMap[player.y -1][player.x];
|
||||
if (!newTile.character.collidable) {
|
||||
player.y = player.y - 1;
|
||||
@ -74,7 +88,6 @@ public class Fenster extends PApplet {
|
||||
}
|
||||
if (keyCode == this.LEFT) {
|
||||
Cell newTile = tileMap[player.y][player.x - 1];
|
||||
println("pressed");
|
||||
if (!newTile.character.collidable) {
|
||||
player.x = player.x - 1;
|
||||
tileMap[old_player_y][old_player_x].character = old_player_cell;
|
||||
@ -84,7 +97,6 @@ public class Fenster extends PApplet {
|
||||
}
|
||||
if (keyCode == this.DOWN) {
|
||||
Cell newTile = tileMap[player.y +1][player.x];
|
||||
println("pressed");
|
||||
if (!newTile.character.collidable) {
|
||||
player.y = player.y + 1;
|
||||
tileMap[old_player_y][old_player_x].character = old_player_cell;
|
||||
@ -94,7 +106,6 @@ public class Fenster extends PApplet {
|
||||
}
|
||||
if (keyCode == this.RIGHT) {
|
||||
Cell newTile = tileMap[player.y][player.x + 1];
|
||||
println("pressed");
|
||||
if (!newTile.character.collidable) {
|
||||
player.x = player.x + 1;
|
||||
tileMap[old_player_y][old_player_x].character = old_player_cell;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user