start screen with animations

This commit is contained in:
Makussu 2024-06-07 14:44:10 +02:00
parent 6fd9d22304
commit 1d9e03af7a
11 changed files with 192 additions and 79 deletions

38
src/AniMove.java Normal file
View File

@ -0,0 +1,38 @@
import processing.core.PVector;
public class AniMove extends Animation {
public AniMove(Fenster window, Character player) {
super(window, player);
this.window = window;
this.player = player;
}
public boolean animate(float from_x, float from_y, float to_x, float to_y) {
if (frame_count < numPoints) {
animating = true;
PVector point = move(from_x,from_y, to_x, to_y);
player.real_x = point.x;
player.real_y = point.y;
System.out.println(player.real_x);
} else {
player.real_x = from_x;
player.real_y = from_y;
animating = false;
}
return animating;
}
public PVector move(float from_x, float from_y, float to_x, float to_y) {
PVector point = new PVector(from_x, from_y);
float interpolationAmount = window.map(frame_count, 0, numPoints - 1, 0, 1);
float interpolatedX = window.lerp(from_x, to_x, interpolationAmount);
float interpolatedY = window.lerp(from_y, to_y, interpolationAmount);
point = new PVector(interpolatedX, interpolatedY);
frame_count++;
return point;
}
}

26
src/AniShrink.java Normal file
View File

@ -0,0 +1,26 @@
public class AniShrink extends Animation {
int numPoints = 100;
public AniShrink(Fenster window, Character player) {
super(window, player);
}
public boolean animate(int from_size, int to_size){
if (frame_count < numPoints) {
animating = true;
player.textsize = shrink(from_size, to_size);
System.out.println(player.real_x);
} else {
player.textsize = to_size;
animating = false;
}
return animating;
}
private int shrink(int from_size, int to_size){
float interpolationAmount = window.map(frame_count, 0, numPoints - 1, 0, 1);
int interpolated = (int) window.lerp(from_size, to_size, interpolationAmount);
frame_count++;
return interpolated;
}
}

View File

@ -6,11 +6,12 @@ import java.util.List;
/** /**
* The speech bubble that can be shown by all Talkable characters * The speech bubble that can be shown by all Talkable characters
*/ */
public class Bubble implements Drawable { public class Bubble {
Fenster window; Fenster window;
List<String> text; List<String> text;
boolean opened; boolean opened;
int index = 0; int index = 0;
float real_x, real_y;
Bubble(Fenster window, List<String> text) { Bubble(Fenster window, List<String> text) {
this.window = window; this.window = window;
@ -45,12 +46,21 @@ public class Bubble implements Drawable {
this.text = text; this.text = text;
} }
public void draw(float x, float y) { public void draw(float x, float y, int textsize) {
if (window.inGame) {
this.real_x = x * window.tilewidth / 2;
this.real_y = y * window.tilewidth / 2;
} else {
this.real_x = x;
this.real_y = y;
}
if (opened) { if (opened) {
window.fill(255); window.fill(255);
window.rect(x * window.tilewidth/2, y * window.tilewidth/2, 300, 50); window.rect(x * window.tilewidth/2, y * window.tilewidth/2, 300, 50);
window.fill(0); window.fill(0);
window.text(text.get(index), x * window.tilewidth/2, y * window.tilewidth/2, 300, 50); window.textSize(textsize);
window.textAlign(window.CENTER);
window.text(text.get(index), real_x, real_y, window.textWidth(text.get(index)), 50);
} }
} }
} }

View File

@ -10,6 +10,7 @@ public class Character implements Drawable {
boolean collidable; boolean collidable;
float x, y; float x, y;
float real_x, real_y; float real_x, real_y;
int textsize = 20;
Character (Fenster window, String type) { Character (Fenster window, String type) {
this.window = window; this.window = window;
@ -44,10 +45,12 @@ public class Character implements Drawable {
} }
public void draw(float x, float y) { public void draw(float x, float y) {
this.real_x = x * window.tilewidth/2; if (window.inGame) {
this.real_y = y * window.tilewidth/2; this.real_x = x * window.tilewidth / 2;
this.real_y = y * window.tilewidth / 2;
}
window.fill(color); window.fill(color);
window.textSize(20); window.textSize(textsize);
window.text(type, real_x, real_y); window.text(type, real_x, real_y);
} }
} }

View File

@ -3,6 +3,7 @@ import processing.core.PFont;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
public class Fenster extends PApplet { public class Fenster extends PApplet {
@ -16,11 +17,14 @@ public class Fenster extends PApplet {
// STATES // STATES
boolean inFight = false; boolean inFight = false;
boolean inGame = true; boolean inGame = false;
boolean inMenu = false; boolean inMenu = false;
boolean inDialog = false; boolean inDialog = false;
boolean starting = true;
Fight myfight; Fight myfight;
AniShrink startingAnimation = new AniShrink(this, player);
Bubble startingDialog = new Bubble(this, Arrays.asList("Das bist du...", "In einer gefährlichen Welt", "Wirst du überleben?"));
UI ui = new UI(this); UI ui = new UI(this);
@Override @Override
@ -30,7 +34,7 @@ public class Fenster extends PApplet {
tiles.settings(); tiles.settings();
myfight = new Fight(this, player, (Enemy) tiles.get(10, 10));
//this.text("lol", 0, 0); //this.text("lol", 0, 0);
@ -44,33 +48,65 @@ public class Fenster extends PApplet {
this.textSize(20); this.textSize(20);
this.textAlign(CENTER, CENTER); this.textAlign(CENTER, CENTER);
myfight = new Fight(this, player, (Enemy) tiles.get(10, 10));
// start the first dialog
startingDialog.open();
} }
@Override @Override
public void draw() { public void draw() {
background(255); background(255);
tiles.draw(); if (starting) {
// Handle the Cell which the player was on last round if (startingDialog.opened) {
if (tiles.get(player.x, player.y) != player) { startingDialog.draw(200, 200, 40);
old_player_cell = tiles.get(player.x, player.y); System.out.println(startingDialog.opened);
old_player_x = player.x; player.real_x = 400;
old_player_y = player.y; player.real_y = 400;
player.textsize = 200;
player.draw(0, 0);
} else {
if (!startingAnimation.animate(200, 20)) {
starting = false;
inGame = true;
} else {
tiles.draw();
System.out.println("startscreen");
player.draw(0, 0);
}
}
} }
if (inGame) {
player.textsize = 20;
tiles.set(player.x, player.y, player); tiles.draw();
// Handle the Cell which the player was on last round
if (tiles.get(player.x, player.y) != player) {
old_player_cell = tiles.get(player.x, player.y);
old_player_x = player.x;
old_player_y = player.y;
}
tiles.set(player.x, player.y, player);
ui.draw(); ui.draw();
}
if (inFight) { if (inFight) {
tiles.draw();
myfight.draw(); myfight.draw();
} }
//println(player.x + " " + player.y); //println(player.x + " " + player.y);
} }
public void keyPressed(processing.event.KeyEvent event) { public void keyPressed(processing.event.KeyEvent event) {
if (starting) {
if (keyCode == 32) {
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.x, player.y - 1);

View File

@ -1,3 +1,5 @@
import processing.core.PApplet;
import java.util.List; import java.util.List;
public class Fight extends Bubble { public class Fight extends Bubble {
@ -10,20 +12,26 @@ public class Fight extends Bubble {
float enemy_x = 600; float enemy_x = 600;
float enemy_y = 300; float enemy_y = 300;
boolean pos_set = false;
Skill running_move; Skill running_move;
Fight(Fenster window, Player player, Enemy enemy) { Fight(Fenster window, Player player, Enemy enemy) {
super(window); super(window);
System.out.println(player);
this.player = player; this.player = player;
this.enemy = enemy; this.enemy = enemy;
this.opened = true; this.opened = true;
} }
void drawPlayer() { void drawPlayer() {
window.textSize(150); if (!pos_set) {
window.fill(0); player.real_x = player_x;
window.text(player.type, player_x, player_y); player.real_y = player_y;
pos_set = true;
}
player.textsize = 150;
player.draw(0, 0);
window.ui.healthBar(player_x, player_y-60, player.health, player.maxHealth); window.ui.healthBar(player_x, player_y-60, player.health, player.maxHealth);
} }
@ -37,8 +45,9 @@ public class Fight extends Bubble {
} }
public void attack() { public void attack() {
running_move = player.skills.get(0);
player.skills.get(0).use(enemy); running_move = player.skill;
running_move.use(enemy);
} }
@ -54,6 +63,7 @@ public class Fight extends Bubble {
window.fill(0); window.fill(0);
} }
if (running_move != null) { if (running_move != null) {
//System.out.println("move is running");
running_move.draw(); running_move.draw();
} }
if (enemy.health <= 0) { if (enemy.health <= 0) {

View File

@ -11,15 +11,16 @@ public class Player extends Fightable implements Health {
int health; int health;
int maxHealth = 20; int maxHealth = 20;
List<Skill> skills = new ArrayList<Skill>(); List<Skill> skills = new ArrayList<Skill>();
Skill skill = new Tritt(window, this);
Player(Fenster window) { Player(Fenster window) {
super(window); super(window);
this.type = "@"; this.type = "@";
this.x = 4; this.x = 20;
this.y = 4; this.y = 20;
this.health = maxHealth; this.health = maxHealth;
this.skills.add(new Tritt(window, this)); this.skills.add(new Tritt(window, (Fightable) window.player));
} }
public void damage(int damage) { public void damage(int damage) {

25
src/Save.java Normal file
View File

@ -0,0 +1,25 @@
import java.io.*;
public class Save {
private static Save INSTANCE;
private String file = "./save";
private Save() {}
public static Save getInstance() {
if(INSTANCE == null) {
INSTANCE = new Save();
}
return INSTANCE;
}
public void save() {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), "utf-8"))) {
writer.write("something");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,7 +1,7 @@
public class Skill { public class Skill {
Fenster window; Fenster window;
Fightable user; Character user;
Fightable target; Character target;
static int power = 5; static int power = 5;
int numPoints = 10; int numPoints = 10;

View File

@ -27,7 +27,7 @@ public class Talkable extends Character implements Interactable{
window.fill(color); window.fill(color);
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); window.text(type, x * window.tilewidth/2, y * window.tilewidth/2);
this.bubble.draw(x, y); this.bubble.draw(x, y, 20);
if (Math.abs(window.player.x - x) > 1 || Math.abs(window.player.y - y) > 1) { if (Math.abs(window.player.x - x) > 1 || Math.abs(window.player.y - y) > 1) {
this.bubble.close(); this.bubble.close();

View File

@ -1,69 +1,33 @@
public class Tritt extends Skill { public class Tritt extends Skill {
Fenster window;
Fightable user;
Fightable target;
boolean animating = false; boolean animating = false;
Animation animation;
Tritt(Fenster window, Fightable user) { Tritt(Fenster window, Fightable user) {
super(window, user); super(window, user);
System.out.println(user); System.out.println(user);
} }
public void use(Fightable target){ public void use(Fightable target){
System.out.println("using tritt");
target.damage(power); target.damage(power);
this.target = target; this.target = target;
animate();
}; };
public void animate(){ public void animate(){
animating = true;
// it should be user, but that doesnt work, so pick the player from window
animation = new AniMove(window, window.player);
}; };
int i = 0;
boolean ani_hit = false;
void animating_attack() {
float startanimate_x;
float startanimate_y;
float stopanimate_x;
float stopanimate_y;
if (i == 10 && ani_hit == false) {
ani_hit = true;
i = 0;
}
if (!ani_hit) {
startanimate_x = 600;
startanimate_y = 300;
stopanimate_x = 200;
stopanimate_y = 500;
} else {
startanimate_x = 200;
startanimate_y = 500;
stopanimate_x = 600;
stopanimate_y = 300;
}
if (i < 10) {
float interpolationAmount = window.map(i, 0, numPoints - 1, 0, 1);
float interpolatedX = window.lerp(startanimate_x, stopanimate_x, interpolationAmount);
float interpolatedY = window.lerp(startanimate_y, stopanimate_y, interpolationAmount);
user.real_x = interpolatedX;
user.real_y = interpolatedY;
i++;
}
}
void animation_cleanup() {
if (!ani_hit && user.real_x == 600 && user.real_y == 300) {
animating = false;
i = 0;
ani_hit = false;
user.real_x = 600;
user.real_y = 300;
}
}
public boolean draw() { public boolean draw() {
System.out.println(2); System.out.println("before drawing");
animating_attack(); if (animating) {
System.out.println("animating tritt");
if (!animation.animate(200, 500, 600, 300)) {
animating = false;
}
}
return true; return true;
} }
} }