Zombie spawn and more tiles

This commit is contained in:
Makussu 2024-06-08 11:50:03 +02:00
parent 020846cf73
commit e2365edb51
3 changed files with 42 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import processing.core.PApplet;
*/ */
public class Enemy extends Fightable implements Health, Interactable { public class Enemy extends Fightable implements Health, Interactable {
int health; int health;
int maxHealth = 100; int maxHealth = 20;
Enemy(Fenster window) { Enemy(Fenster window) {
super(window); super(window);

View File

@ -88,6 +88,12 @@ public class Fenster extends PApplet {
public void draw() { public void draw() {
System.out.println(frameRate); System.out.println(frameRate);
if(player.pos.get().x > width) {
translate(-800, 0);
}
if(player.pos.get().y > height) {
translate(0, -800);
}
if(!startScreen.draw()) { if(!startScreen.draw()) {

View File

@ -1,6 +1,7 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* This keeps and creates the tiles and information around them. Basically the level builder. * This keeps and creates the tiles and information around them. Basically the level builder.
@ -11,15 +12,25 @@ public class Tiles implements Drawable {
float tilewidth; float tilewidth;
Talkable old_dude; Talkable old_dude;
Random rand = new Random();
Character spot;
Character empty;
Character tree;
Character wall;
int num_enemies = 1;
Tiles(Fenster window, float tilewidth) { Tiles(Fenster window, float tilewidth) {
this.window = window; this.window = window;
this.tilewidth = tilewidth; this.tilewidth = tilewidth;
spot = new Character(window, ".", 0, false);
empty = new Character(window, " ");
tree = new Character(window, "A", window.color(10, 200, 10), true);
wall = new Character(window, "#", window.color(132,86,60), true);
} }
void settings() { void settings() {
Character spot = new Character(window, ".", 0, false);
Character empty = new Character(window, " ");
Character tree = new Character(window, "A", window.color(10, 200, 10), true);
Character wall = new Character(window, "#", window.color(132,86,60), true);
old_dude = new Talkable(window, "T", window.color(20,20,200), true, new Bubble(window, Arrays.asList("Hey Junge!", "Was machst du hier unten?", "Lass mich dich heilen..."))); old_dude = new Talkable(window, "T", window.color(20,20,200), true, new Bubble(window, Arrays.asList("Hey Junge!", "Was machst du hier unten?", "Lass mich dich heilen...")));
tileMap = new Cell[100][100]; tileMap = new Cell[100][100];
@ -60,6 +71,7 @@ public class Tiles implements Drawable {
public void draw() { public void draw() {
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++) {
enemy_death_check(tileMap[i][j]);
tileMap[i][j].draw(); tileMap[i][j].draw();
} }
} }
@ -67,6 +79,8 @@ public class Tiles implements Drawable {
for (Cell i : talkables) { for (Cell i : talkables) {
i.draw(); i.draw();
} }
spawn_zombie();
} }
public ArrayList<Cell> get(Character type) { public ArrayList<Cell> get(Character type) {
@ -80,6 +94,23 @@ public class Tiles implements Drawable {
} }
return returns; return returns;
} }
void enemy_death_check(Cell cell) {
if (cell.character instanceof Enemy) {
if ( ((Enemy) cell.character).health < 1) {
cell.character = new Character(spot);
num_enemies--;
}
}
}
void spawn_zombie() {
if(num_enemies < 3) {
tileMap[rand.nextInt(100)][rand.nextInt(100)].character = new Enemy(window);
num_enemies++;
}
}
public Character get(int x,int y) { public Character get(int x,int y) {
return tileMap[y][x].character; return tileMap[y][x].character;
} }