mirror of
https://inf.pirckheimer-gymnasium.de/kebab/kebab
synced 2026-08-26 16:31:23 +00:00
Re-implement Statistics saving; Improve GameScene
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
kebabPrice=5
|
||||||
|
kebabSold=28
|
||||||
|
money=123
|
||||||
|
totalEarned=0
|
||||||
|
upgradeLevel=0
|
||||||
|
waitingCustomers=0
|
||||||
|
workers=0
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.pirckheimer-gymnasium</groupId>
|
<groupId>de.pirckheimer-gymnasium</groupId>
|
||||||
<artifactId>engine-pi</artifactId>
|
<artifactId>engine-pi</artifactId>
|
||||||
<version>0.50.0</version>
|
<version>0.52.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package project;
|
package project;
|
||||||
|
|
||||||
import project.scenes.LoadingScene;
|
import project.scenes.GameScene;
|
||||||
|
import project.utils.Statistics;
|
||||||
import pi.Controller;
|
import pi.Controller;
|
||||||
|
import pi.config.ConfigLoader;
|
||||||
|
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
@@ -9,10 +11,18 @@ import java.awt.Toolkit;
|
|||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
|
public static ConfigLoader config;
|
||||||
|
|
||||||
|
static {
|
||||||
|
config = new ConfigLoader("kebab.properties", new Statistics());
|
||||||
|
config.load();
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
Controller.instantMode(false);
|
Controller.instantMode(false);
|
||||||
Controller.start(new LoadingScene(), 1000, 600);
|
//Controller.start(new LoadingScene(), 1000, 600);
|
||||||
|
Controller.start(new GameScene(), 1000, 600);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||||
|
|||||||
@@ -7,18 +7,26 @@ import pi.Text;
|
|||||||
import pi.actor.Actor;
|
import pi.actor.Actor;
|
||||||
import pi.actor.Animation;
|
import pi.actor.Animation;
|
||||||
import pi.actor.Image;
|
import pi.actor.Image;
|
||||||
|
import pi.config.ConfigLoader;
|
||||||
import pi.event.FrameListener;
|
import pi.event.FrameListener;
|
||||||
|
import pi.event.MouseButton;
|
||||||
|
import pi.event.MouseClickListener;
|
||||||
import pi.graphics.geom.Vector;
|
import pi.graphics.geom.Vector;
|
||||||
|
import project.Main;
|
||||||
|
import project.utils.Statistics;
|
||||||
|
|
||||||
import static pi.Controller.fonts;
|
import static pi.Controller.fonts;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
|
|
||||||
public class GameScene extends Scene implements FrameListener
|
public class GameScene extends Scene implements FrameListener, MouseClickListener
|
||||||
{
|
{
|
||||||
Rectangle bg;
|
Rectangle bg;
|
||||||
|
Image tatli;
|
||||||
Text[] texts;
|
Text[] texts;
|
||||||
|
Image[] ingredients;
|
||||||
Actor[] customers;
|
Actor[] customers;
|
||||||
|
public static ConfigLoader loader;
|
||||||
|
|
||||||
public GameScene() {
|
public GameScene() {
|
||||||
// the background music, color, stats (some meta information)
|
// the background music, color, stats (some meta information)
|
||||||
@@ -31,26 +39,62 @@ public class GameScene extends Scene implements FrameListener
|
|||||||
texts = createTexts(this);
|
texts = createTexts(this);
|
||||||
camera().meter(10);
|
camera().meter(10);
|
||||||
|
|
||||||
|
tatli = new Image("images/kebab-pack/tatli-ekmek-256x256.png");
|
||||||
|
tatli.size(2.56*13, 2.56*13);
|
||||||
|
tatli.center(-33, -23);
|
||||||
|
|
||||||
// create customers
|
// create customers
|
||||||
customers = new Actor[1];
|
customers = new Actor[2];
|
||||||
customers[0] = Animation.createFromAnimatedGif("images/kebab-pack/customer-mr-eggman.gif", 1.48*25, 1.25*25);
|
customers[0] = Animation.createFromAnimatedGif("images/kebab-pack/customer-sonic-on-white.gif", 1.48*25, 1.25*25);
|
||||||
customers[0].center(-60,0);
|
customers[0].center(-60,0);
|
||||||
customers[0].applyImpulse(new Vector(1, 0).multiply(100000));
|
customers[0].applyImpulse(new Vector(1, 0).multiply(100000));
|
||||||
|
customers[1] = Animation.createFromAnimatedGif("images/kebab-pack/customer-mr-eggman.gif", 1.48*20, 1.48*20);
|
||||||
|
customers[1].center(-180,0);
|
||||||
|
customers[1].applyImpulse(new Vector(1, 0).multiply(100000));
|
||||||
|
|
||||||
|
ingredients = createIngredients();
|
||||||
|
|
||||||
// add all actors
|
// add all actors
|
||||||
add(bg);
|
add(bg);
|
||||||
add(customers);
|
add(customers);
|
||||||
|
add(ingredients);
|
||||||
|
add(tatli);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFrame(double pastTime)
|
public void onFrame(double pastTime)
|
||||||
{
|
{
|
||||||
if(visibleArea().xRight() < customers[0].anchor().add(new Vector(-20, 0)).x()) {
|
for(Actor c : customers) {
|
||||||
customers[0].center(-60,0);
|
if(visibleArea().xRight() < c.anchor().add(new Vector(-20, 0)).x()) {
|
||||||
|
c.center(-60,0);
|
||||||
|
Statistics s = Main.config.getGroup(Statistics.class);;
|
||||||
|
s.kebabSold(s.kebabSold()+1);
|
||||||
|
Main.config.save();
|
||||||
|
|
||||||
|
setKebabSold(texts, s.kebabSold());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMouseDown(Vector position, MouseButton button)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Static helper methods
|
// Static helper methods
|
||||||
|
public static Image[] createIngredients() {
|
||||||
|
Image[] ingredients = new Image[5];
|
||||||
|
|
||||||
|
ingredients[0] = new Image("images/kebab-pack/onion-256x256.png");
|
||||||
|
ingredients[1] = new Image("images/kebab-pack/meat-256x256.png");
|
||||||
|
ingredients[2] = new Image("images/kebab-pack/bread-256x256.png");
|
||||||
|
ingredients[3] = new Image("images/kebab-pack/lettuce-96x96.png");
|
||||||
|
ingredients[4] = new Image("images/kebab-pack/kebab-128x128.png");
|
||||||
|
|
||||||
|
return ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
public static void addStatsCollectionOutline(Scene scene) {
|
public static void addStatsCollectionOutline(Scene scene) {
|
||||||
Image moneyButton = new Image("images/pixui-pack/Buttons/Button_White_Outline (9).png");
|
Image moneyButton = new Image("images/pixui-pack/Buttons/Button_White_Outline (9).png");
|
||||||
moneyButton.center(-10, 25);
|
moneyButton.center(-10, 25);
|
||||||
@@ -78,19 +122,21 @@ public class GameScene extends Scene implements FrameListener
|
|||||||
Text[] texts = new Text[10];
|
Text[] texts = new Text[10];
|
||||||
Font font = fonts.get("fonts/BitcountGridDouble-Regular.ttf");
|
Font font = fonts.get("fonts/BitcountGridDouble-Regular.ttf");
|
||||||
|
|
||||||
Text money = new Text("0");
|
Statistics s = Main.config.getGroup(Statistics.class);
|
||||||
|
|
||||||
|
Text money = new Text(s.money());
|
||||||
money.color("#000000");
|
money.color("#000000");
|
||||||
money.font(font);
|
money.font(font);
|
||||||
money.height(2.5);
|
money.height(2.5);
|
||||||
money.center(-9, 25);
|
money.center(-9, 25);
|
||||||
texts[0] = money;
|
texts[0] = money;
|
||||||
Text kebabSold = new Text("0");
|
Text kebabSold = new Text(s.kebabSold());
|
||||||
kebabSold.color("#000000");
|
kebabSold.color("#000000");
|
||||||
kebabSold.font(font);
|
kebabSold.font(font);
|
||||||
kebabSold.height(2.5);
|
kebabSold.height(2.5);
|
||||||
kebabSold.center(1, 25);
|
kebabSold.center(1, 25);
|
||||||
texts[1] = kebabSold;
|
texts[1] = kebabSold;
|
||||||
Text waitingCustomers = new Text("0");
|
Text waitingCustomers = new Text(s.waitingCustomers());
|
||||||
waitingCustomers.color("#000000");
|
waitingCustomers.color("#000000");
|
||||||
waitingCustomers.font(font);
|
waitingCustomers.font(font);
|
||||||
waitingCustomers.height(2.5);
|
waitingCustomers.height(2.5);
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package project.utils;
|
||||||
|
|
||||||
|
import pi.config.ConfigGroup;
|
||||||
|
|
||||||
|
public class Statistics extends ConfigGroup {
|
||||||
|
private int money = 0;
|
||||||
|
private int kebabPrice = 5;
|
||||||
|
private int upgradeLevel = 0;
|
||||||
|
private int kebabSold = 0;
|
||||||
|
private int workers = 0;
|
||||||
|
private int waitingCustomers = 0;
|
||||||
|
private int totalEarned = 0;
|
||||||
|
|
||||||
|
public Statistics() {
|
||||||
|
money(0);
|
||||||
|
kebabPrice(5);
|
||||||
|
upgradeLevel(0);
|
||||||
|
kebabSold(0);
|
||||||
|
workers(0);
|
||||||
|
waitingCustomers(0);
|
||||||
|
totalEarned(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- money ---
|
||||||
|
public int money(){
|
||||||
|
return money;
|
||||||
|
}
|
||||||
|
public Statistics money(int money) {
|
||||||
|
set("money", money);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- kebabPrice ---
|
||||||
|
public int kebabPrice() {
|
||||||
|
return kebabPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics kebabPrice(int kebabPrice) {
|
||||||
|
set("kebabPrice", kebabPrice);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- upgradeLevel ---
|
||||||
|
public int upgradeLevel() {
|
||||||
|
return upgradeLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics upgradeLevel(int upgradeLevel) {
|
||||||
|
set("upgradeLevel", upgradeLevel);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- kebabSold ---
|
||||||
|
public int kebabSold() {
|
||||||
|
return kebabSold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics kebabSold(int kebabSold) {
|
||||||
|
set("kebabSold", kebabSold);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- workers ---
|
||||||
|
public int workers() {
|
||||||
|
return workers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics workers(int workers) {
|
||||||
|
set("workers", workers);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- waitingCustomers ---
|
||||||
|
public int waitingCustomers() {
|
||||||
|
return waitingCustomers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics waitingCustomers(int waitingCustomers) {
|
||||||
|
set("waitingCustomers", waitingCustomers);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- totalEarned ---
|
||||||
|
public int totalEarned() {
|
||||||
|
return totalEarned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statistics totalEarned(int totalEarned) {
|
||||||
|
set("totalEarned", totalEarned);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user