Real startscreen

This commit is contained in:
Makussu 2024-06-07 17:30:22 +02:00
parent 8e1f740c95
commit 7fdb3880cb
12 changed files with 133 additions and 54 deletions

View File

@ -11,12 +11,9 @@ public class AniMove extends Animation {
if (frame_count < numPoints) { if (frame_count < numPoints) {
animating = true; animating = true;
PVector point = move(from_x,from_y, to_x, to_y); PVector point = move(from_x,from_y, to_x, to_y);
player.real_x = point.x; player.pos.set(point);
player.real_y = point.y;
System.out.println(player.real_x);
} else { } else {
player.real_x = from_x; player.pos.set(from_x, from_y);
player.real_y = from_y;
animating = false; animating = false;
} }
return animating; return animating;

View File

@ -8,7 +8,7 @@ public class AniShrink extends Animation {
if (frame_count < numPoints) { if (frame_count < numPoints) {
animating = true; animating = true;
player.textsize = shrink(from_size, to_size); player.textsize = shrink(from_size, to_size);
System.out.println(player.real_x); System.out.println(player.pos.x);
} else { } else {
player.textsize = to_size; player.textsize = to_size;
animating = false; animating = false;

View File

@ -22,12 +22,11 @@ public class AuraFight extends Bubble{
void drawPlayer() { void drawPlayer() {
if (!pos_set) { if (!pos_set) {
player.real_x = player_x; player.pos.set(player_x, player_y);
player.real_y = player_y;
pos_set = true; pos_set = true;
} }
player.textsize = 150; player.textsize = 150;
player.draw(0, 0); player.draw();
window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth); window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth);
} }

View File

@ -3,13 +3,13 @@
*/ */
public class Cell { public class Cell {
float width; float width;
float x, y; int x, y;
Character character; Character character;
Cell(float x, float y, float width, Character character) { Cell(int x, int y, float width, Character character) {
this.width = width;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.width = width;
this.character = character; this.character = character;
} }
public boolean hasChar() { public boolean hasChar() {
@ -21,7 +21,8 @@ public class Cell {
public void draw() { public void draw() {
if (this.hasChar()) { if (this.hasChar()) {
character.draw(x, y); character.pos.set_on_grid(x, y);
character.draw();
} }
} }
} }

View File

@ -8,8 +8,7 @@ public class Character implements Drawable {
String type; String type;
int color; int color;
boolean collidable; boolean collidable;
float x, y; Position pos;
float real_x, real_y;
int experience = 0; int experience = 0;
int level = 1; int level = 1;
float damage_mult = (float) (1 + level * 0.4); float damage_mult = (float) (1 + level * 0.4);
@ -20,6 +19,7 @@ public class Character implements Drawable {
this.type = type; this.type = type;
this.collidable = true; this.collidable = true;
this.color = 0; this.color = 0;
this.pos = new Position(window);
} }
Character (Fenster window, String type, int color) { Character (Fenster window, String type, int color) {
@ -34,6 +34,7 @@ public class Character implements Drawable {
this.type = type; this.type = type;
this.color = color; this.color = color;
this.collidable = collidable; this.collidable = collidable;
this.pos = new Position(window);
} }
Character (Character another) { Character (Character another) {
@ -41,19 +42,20 @@ public class Character implements Drawable {
this.type = another.type; this.type = another.type;
this.collidable = another.collidable; this.collidable = another.collidable;
this.color = another.color; this.color = another.color;
this.pos = new Position(window);
} }
public Character(Fenster window) { public Character(Fenster window) {
this.window = window; this.window = window;
this.pos = new Position(window);
} }
public void draw(float x, float y) { public void draw() {
if (window.inGame) { if (window.inGame) {
this.real_x = x * window.tilewidth / 2; pos.sync_grid();
this.real_y = y * window.tilewidth / 2;
} }
window.fill(color); window.fill(color);
window.textSize(textsize); window.textSize(textsize);
window.text(type, real_x, real_y); window.text(type, pos.get().x, pos.get().y);
} }
} }

View File

@ -1,3 +1,3 @@
public interface Drawable { public interface Drawable {
public void draw(float x, float y); public void draw();
} }

View File

@ -31,13 +31,11 @@ public class Enemy extends Fightable implements Health, Interactable {
} }
} }
public void draw(float x, float y) { public void draw() {
this.x = x;
this.y = y;
window.fill(color); window.fill(color);
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); window.text(type, pos.get().x, pos.get().y);
if (window.inFight) { if (window.inFight) {
window.ui.healthBar(x * window.tilewidth/2, y * window.tilewidth/2 - 15, health, maxHealth); window.ui.healthBar(pos.get().x, pos.get().y - 15, health, maxHealth);
} }
} }

View File

@ -21,10 +21,13 @@ public class Fenster extends PApplet {
boolean inMenu = false; boolean inMenu = false;
boolean inDialog = false; boolean inDialog = false;
boolean starting = true; boolean starting = true;
boolean gametitel = true;
Fight myfight; Fight myfight;
AniShrink startingAnimation = new AniShrink(this, player); AniShrink startingAnimation = new AniShrink(this, player);
Bubble startingDialog = new Bubble(this, Arrays.asList("Das bist du...", "In einer gefährlichen Welt", "Wirst du überleben?")); Bubble startingDialog = new Bubble(this, Arrays.asList("Das bist du...", "In einer gefährlichen Welt", "Wirst du überleben?"));
int gametitel_gamma = 255;
boolean gametitel_fade = false;
UI ui = new UI(this); UI ui = new UI(this);
@Override @Override
@ -58,14 +61,13 @@ public class Fenster extends PApplet {
public void draw() { public void draw() {
background(255); background(255);
if (starting) { if (starting) {
if (startingDialog.opened) { if (startingDialog.opened) {
startingDialog.draw(200, 200, 40); startingDialog.draw(200, 200, 40);
System.out.println(startingDialog.opened); player.pos.set(400, 400);
player.real_x = 400;
player.real_y = 400;
player.textsize = 200; player.textsize = 200;
player.draw(0, 0); player.draw();
} else { } else {
if (!startingAnimation.animate(200, 20)) { if (!startingAnimation.animate(200, 20)) {
starting = false; starting = false;
@ -73,22 +75,44 @@ public class Fenster extends PApplet {
} else { } else {
tiles.draw(); tiles.draw();
System.out.println("startscreen"); System.out.println("startscreen");
player.draw(0, 0); player.draw();
} }
} }
} }
if (gametitel) {
System.out.println(gametitel_gamma);
fill(255, gametitel_gamma);
rect(0, 0, 800, 800);
textSize(15);
fill(0, gametitel_gamma);
text(" ('-. _ .-') ('-. (`\\ .-') /` _ .-') _ .-') _ \n" +
" ( OO ).-. ( \\( -O ) ( OO ).-. `.( OO ),' ( \\( -O ) ( ( OO) ) \n" +
" / . --. / ,--. ,--. ,------. / . --. /,--./ .--. .-'),-----. ,------. ,--. \\ .'_ \n" +
" | \\-. \\ | | | | | /`. ' | \\-. \\ | | | ( OO' .-. '| /`. ' | |.-') ,`'--..._) \n" +
".-'-' | | | | | .-') | / | |.-'-' | || | | |, / | | | || / | | | | OO )| | \\ ' \n" +
" \\| |_.' | | |_|( OO )| |_.' | \\| |_.' || |.'.| |_)\\_) | |\\| || |_.' | | |`-' || | ' | \n" +
" | .-. | | | | `-' /| . '.' | .-. || | \\ | | | || . '.'(| '---.'| | / : \n" +
" | | | |(' '-'(_.-' | |\\ \\ | | | || ,'. | `' '-' '| |\\ \\ | | | '--' / \n" +
" `--' `--' `-----' `--' '--' `--' `--''--' '--' `-----' `--' '--' `------' `-------'", 400, 200);
if (gametitel_fade) {
gametitel_gamma = gametitel_gamma - 5;
}
if (gametitel_gamma < 1) {
gametitel = false;
}
}
if (inGame) { if (inGame) {
player.textsize = 20; player.textsize = 20;
tiles.draw(); tiles.draw();
// Handle the Cell which the player was on last round // Handle the Cell which the player was on last round
if (tiles.get(player.x, player.y) != player) { if (tiles.get(player.pos.grid_x, player.pos.grid_y) != player) {
old_player_cell = tiles.get(player.x, player.y); old_player_cell = tiles.get(player.pos.grid_x, player.pos.grid_y);
old_player_x = player.x; old_player_x = player.pos.grid_x;
old_player_y = player.y; old_player_y = player.pos.grid_y;
} }
tiles.set(player.x, player.y, player); tiles.set(player.pos.grid_x, player.pos.grid_y, player);
ui.draw(); ui.draw();
@ -102,16 +126,21 @@ public class Fenster extends PApplet {
} }
public void keyPressed(processing.event.KeyEvent event) { public void keyPressed(processing.event.KeyEvent event) {
if (starting) { if (gametitel) {
if (keyCode == 32) {
gametitel_fade = true;
}
}
if (starting && !gametitel) {
if (keyCode == 32) { if (keyCode == 32) {
startingDialog.toggle(); startingDialog.toggle();
} }
} }
if (inGame) { if (inGame) {
if (keyCode == this.UP) { if (keyCode == this.UP) {
Cell newTile = tiles.get_cell(player.x, player.y - 1); Cell newTile = tiles.get_cell(player.pos.grid_x, player.pos.grid_y - 1);
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.y = player.y - 1; player.pos.grid_y_change(-1);
tiles.set(old_player_x, old_player_y, old_player_cell); tiles.set(old_player_x, old_player_y, old_player_cell);
} else if (newTile.character instanceof Interactable) { } else if (newTile.character instanceof Interactable) {
if (newTile.character instanceof Enemy) { if (newTile.character instanceof Enemy) {
@ -122,27 +151,27 @@ public class Fenster extends PApplet {
} }
} }
if (keyCode == this.LEFT) { if (keyCode == this.LEFT) {
Cell newTile = tiles.get_cell(player.x - 1, player.y); Cell newTile = tiles.get_cell(player.pos.grid_x - 1, player.pos.grid_y);
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.x = player.x - 1; player.pos.grid_x_change(-1);
tiles.set(old_player_x, old_player_y, old_player_cell); tiles.set(old_player_x, old_player_y, old_player_cell);
} else if (newTile.character instanceof Interactable) { } else if (newTile.character instanceof Interactable) {
((Interactable) newTile.character).interact(); ((Interactable) newTile.character).interact();
} }
} }
if (keyCode == this.DOWN) { if (keyCode == this.DOWN) {
Cell newTile = tiles.get_cell(player.x, player.y + 1); Cell newTile = tiles.get_cell(player.pos.grid_x, player.pos.grid_y + 1);
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.y = player.y + 1; player.pos.grid_y_change(1);
tiles.set(old_player_x, old_player_y, old_player_cell); tiles.set(old_player_x, old_player_y, old_player_cell);
} else if (newTile.character instanceof Interactable) { } else if (newTile.character instanceof Interactable) {
((Interactable) newTile.character).interact(); ((Interactable) newTile.character).interact();
} }
} }
if (keyCode == this.RIGHT) { if (keyCode == this.RIGHT) {
Cell newTile = tiles.get_cell(player.x + 1, player.y); Cell newTile = tiles.get_cell(player.pos.grid_x + 1, player.pos.grid_y);
if (!newTile.character.collidable) { if (!newTile.character.collidable) {
player.x = player.x + 1; player.pos.grid_x_change(1);
tiles.set(old_player_x, old_player_y, old_player_cell); tiles.set(old_player_x, old_player_y, old_player_cell);
} else if (newTile.character instanceof Interactable) { } else if (newTile.character instanceof Interactable) {
((Interactable) newTile.character).interact(); ((Interactable) newTile.character).interact();

View File

@ -26,12 +26,11 @@ public class Fight extends Bubble {
void drawPlayer() { void drawPlayer() {
if (!pos_set) { if (!pos_set) {
player.real_x = player_x; player.pos.set(player_x, player_y);
player.real_y = player_y;
pos_set = true; pos_set = true;
} }
player.textsize = 150; player.textsize = 150;
player.draw(0, 0); player.draw();
window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth); window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth);
} }

View File

@ -7,7 +7,6 @@ import java.util.List;
* This is the main player of the game we can move around with and interact. * This is the main player of the game we can move around with and interact.
*/ */
public class Player extends Fightable implements Health { public class Player extends Fightable implements Health {
int x, y;
int health; int health;
int maxHealth = 20; int maxHealth = 20;
@ -17,8 +16,7 @@ public class Player extends Fightable implements Health {
Player(Fenster window) { Player(Fenster window) {
super(window); super(window);
this.type = "@"; this.type = "@";
this.x = 20; pos.set_on_grid(20, 20);
this.y = 20;
this.health = maxHealth; this.health = maxHealth;
this.skills.add(new Tritt(window, (Fightable) window.player)); this.skills.add(new Tritt(window, (Fightable) window.player));

55
src/Position.java Normal file
View File

@ -0,0 +1,55 @@
import processing.core.PVector;
public class Position {
Fenster window;
float x, y;
int grid_x, grid_y;
Position(Fenster window) {
this.window = window;
}
public PVector get() {
return new PVector(x, y);
}
public PVector get_grid() {
return new PVector(grid_x, grid_y);
}
public void set(float x, float y) {
this.x = x;
this.y = y;
}
public void set(PVector point) {
this.x = point.x;
this.y = point.y;
}
public void set_on_grid(int x, int y) {
this.grid_x = x;
this.grid_y = y;
sync_grid();
}
public void set_grid_x(int x) {
set_on_grid(x, grid_y);
}
public void set_grid_y(int y) {
set_on_grid(grid_x, y);
}
public void grid_x_change(int x) {
set_grid_x(grid_x + x);
}
public void grid_y_change(int y) {
set_grid_y(grid_y + y);
}
public void sync_grid() {
x = grid_x * window.tilewidth / 2;
y = grid_y * window.tilewidth / 2;
}
}

View File

@ -23,13 +23,14 @@ public class Talkable extends Character implements Interactable{
this.bubble.toggle(); this.bubble.toggle();
} }
public void draw(float x, float y) { public void draw() {
window.fill(color); window.fill(color);
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); window.text(type, this.pos.get().x, this.pos.get().y);
this.bubble.draw(x, y, 20); this.bubble.draw(this.pos.get_grid().x, this.pos.get_grid().y, 20);
if (Math.abs(window.player.x - x) > 1 || Math.abs(window.player.y - y) > 1) { System.out.println(window.player.pos.get_grid().x - this.pos.get_grid().x);
if (Math.abs(window.player.pos.get_grid().x - this.pos.get_grid().x) > 1 || Math.abs(window.player.pos.get_grid().y - this.pos.get_grid().y) > 1) {
this.bubble.close(); this.bubble.close();
} }
} }