commit d0bf6c6066802d0f7d6bfd0258f4587dfccd7b00 Author: Makussu Date: Sun May 26 17:24:02 2024 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5af9c98 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c1036bd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ascii2.iml b/ascii2.iml new file mode 100644 index 0000000..af93f41 --- /dev/null +++ b/ascii2.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cell.java b/src/Cell.java new file mode 100644 index 0000000..1c251be --- /dev/null +++ b/src/Cell.java @@ -0,0 +1,24 @@ +public class Cell { + float width; + float x, y; + Character character; + + Cell(float x, float y, float width, Character character) { + this.width = width; + this.x = x * width/2; + this.y = y * width/2; + this.character = character; + } + public boolean hasChar() { + if (this.character != null) { + return true; + } + return false; + } + + public void draw() { + if (this.hasChar()) { + character.draw(this.x, this.y); + } + } +} diff --git a/src/Character.java b/src/Character.java new file mode 100644 index 0000000..5f1961b --- /dev/null +++ b/src/Character.java @@ -0,0 +1,31 @@ +import processing.core.PApplet; + +public class Character { + PApplet window; + String type; + int color; + boolean collidable; + + Character (PApplet window, String type) { + this.window = window; + this.type = type; + this.collidable = false; + this.color = 0; + } + + Character (PApplet window, String type, int color) { + this.window = window; + this.type = type; + this.color = color; + this.collidable = false; + } + + public Character(PApplet window) { + this.window = window; + } + + public void draw(float x, float y) { + window.fill(color); + window.text(type, x, y); + } +} diff --git a/src/Enemy.java b/src/Enemy.java new file mode 100644 index 0000000..09501d6 --- /dev/null +++ b/src/Enemy.java @@ -0,0 +1,29 @@ +import processing.core.PApplet; + +public class Enemy extends Character implements Health { + int health; + int maxHealth = 20; + + Enemy(PApplet window) { + super(window); + this.type = "A"; + this.health = maxHealth; + this.collidable = true; + this.color = window.color(200, 0, 0); + } + + public void damage(int damage) { + health = health - damage; + if (health <= 0) { + window.println("dead"); + this.color = window.color(100); + } + } + + public void heal(int healing) { + health = health + healing; + if (health > maxHealth) { + health = maxHealth; + } + } +} diff --git a/src/Fenster.java b/src/Fenster.java new file mode 100644 index 0000000..de3e4e1 --- /dev/null +++ b/src/Fenster.java @@ -0,0 +1,108 @@ +import processing.core.PApplet; + +import java.awt.event.KeyEvent; +import java.util.ArrayList; + + +public class Fenster extends PApplet { + Cell[][] tileMap; + Character spot = new Character(this, "."); + Player player = new Player(this); + Character old_player_cell; + int old_player_x; + int old_player_y; + + UI ui = new UI(this); + @Override + public void settings() { + size(800, 800); + 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 + //here and it will insert it instead of 0's + } + } + + tileMap[10][10].character = new Enemy(this); + + //this.text("lol", 0, 0); + //this.rect(4.0f, 4.0f, 4.0f, 4.0f); + } + + @Override + public void setup() { + this.textSize(20); + this.textAlign(CENTER, CENTER); + } + + @Override + public void draw() { + background(255); + + // Handle the Cell which the player was on last round + if (tileMap[player.y][player.x].character != player) { + old_player_cell = tileMap[player.y][player.x].character; + old_player_x = player.x; + old_player_y = player.y; + } + tileMap[player.y][player.x].character = player; + + for(int i = 0; i < tileMap.length; i++) { + for(int j = 0; j < tileMap[0].length; j++) { + tileMap[i][j].draw();//put whatever number you want in + //here and it will insert it instead of 0's + } + } + + + ui.draw(); + //println(player.x + " " + player.y); + } + + 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; + tileMap[old_player_y][old_player_x].character = old_player_cell; + } else if (newTile.character instanceof Enemy) { + player.damageEnemy(5, (Enemy) newTile.character); + } + } + 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; + } else if (newTile.character instanceof Enemy) { + player.damageEnemy(5, (Enemy) newTile.character); + } + } + 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; + } else if (newTile.character instanceof Enemy) { + player.damageEnemy(5, (Enemy) newTile.character); + } + } + 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; + } else if (newTile.character instanceof Enemy) { + player.damageEnemy(5, (Enemy) newTile.character); + } + } + + + } +} \ No newline at end of file diff --git a/src/Health.java b/src/Health.java new file mode 100644 index 0000000..f454fb6 --- /dev/null +++ b/src/Health.java @@ -0,0 +1,7 @@ +public interface Health { + + + public void damage(int damage); + + public void heal(int healing); +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..3cddefb --- /dev/null +++ b/src/Main.java @@ -0,0 +1,9 @@ +import processing.core.PApplet; + +// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, +// then press Enter. You can now see whitespace characters in your code. +public class Main { + public static void main(String[] args) { + PApplet.main("Fenster"); + } +} \ No newline at end of file diff --git a/src/Player.java b/src/Player.java new file mode 100644 index 0000000..7f09372 --- /dev/null +++ b/src/Player.java @@ -0,0 +1,33 @@ +import processing.core.PApplet; + +public class Player extends Character implements Health { + int x, y; + int health; + int maxHealth = 20; + + Player(PApplet window) { + super(window); + this.type = "@"; + this.x = 4; + this.y = 4; + this.health = maxHealth; + } + + public void damageEnemy(int damage, Enemy enemy) { + enemy.damage(damage); + } + + public void damage(int damage) { + health = health - damage; + if (health <= 0) { + window.println("dead"); + } + } + + public void heal(int healing) { + health = health + healing; + if (health > maxHealth) { + health = maxHealth; + } + } +} diff --git a/src/UI.java b/src/UI.java new file mode 100644 index 0000000..f1a24ab --- /dev/null +++ b/src/UI.java @@ -0,0 +1,18 @@ +import processing.core.PApplet; + +public class UI { + PApplet window; + + UI(PApplet window) { + this.window = window; + } + + private void bottomBar(float x, float y) { + window.rectMode(window.CENTER); + window.rect(x, 775, 300, 50); + } + + public void draw() { + bottomBar(400, 700); + } +}