java-ascii-game/src/Talkable.java

39 lines
984 B
Java

import processing.core.PApplet;
/**
* A Character we can talk to.
*/
public class Talkable extends Character implements Interactable{
Bubble bubble;
Talkable (Fenster window, String type, int color, boolean collidable, Bubble bubble) {
super(window, type, color, collidable);
this.bubble = bubble;
}
Talkable(Talkable another) {
super(another);
}
public Talkable(Fenster window) {
super(window);
}
public void interact() {
if(!this.bubble.toggle()) {
window.player.heal(20);
}
}
public void draw() {
window.fill(color);
window.text(type, this.pos.get().x, this.pos.get().y);
this.bubble.draw(this.pos.get_grid().x, this.pos.get_grid().y, 20);
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();
}
}
}