init
This commit is contained in:
commit
d0bf6c6066
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -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
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
5
.idea/misc.xml
generated
Normal file
5
.idea/misc.xml
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/ascii2.iml" filepath="$PROJECT_DIR$/ascii2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
20
ascii2.iml
Normal file
20
ascii2.iml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module-library">
|
||||||
|
<library>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$USER_HOME$/Downloads/processing-4.3/core/library/core.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</orderEntry>
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
24
src/Cell.java
Normal file
24
src/Cell.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/Character.java
Normal file
31
src/Character.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Enemy.java
Normal file
29
src/Enemy.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
108
src/Fenster.java
Normal file
108
src/Fenster.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/Health.java
Normal file
7
src/Health.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
public interface Health {
|
||||||
|
|
||||||
|
|
||||||
|
public void damage(int damage);
|
||||||
|
|
||||||
|
public void heal(int healing);
|
||||||
|
}
|
||||||
9
src/Main.java
Normal file
9
src/Main.java
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/Player.java
Normal file
33
src/Player.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/UI.java
Normal file
18
src/UI.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user