Skip to content

Commit da86020

Browse files
author
github-actions
committed
style: apply google format
1 parent 98cec7a commit da86020

22 files changed

+519
-519
lines changed

examples/java/Tiled/Bamboo.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
public class Bamboo extends Enemy {
22

3-
protected double speed = 2.5;
3+
protected double speed = 2.5;
44

5-
public Bamboo(double mapX, double mapY) {
6-
super(mapX, mapY);
5+
public Bamboo(double mapX, double mapY) {
6+
super(mapX, mapY);
77

8-
this.addAnimation("walk-down", "assets/Bamboo.png", 4, 32, 32, 0, true);
9-
this.addAnimation("walk-up", "assets/Bamboo.png", 4, 32, 32, 1, true);
10-
this.addAnimation("walk-left", "assets/Bamboo.png", 4, 32, 32, 2, true);
11-
this.addAnimation("walk-right", "assets/Bamboo.png", 4, 32, 32, 3, true);
8+
this.addAnimation("walk-down", "assets/Bamboo.png", 4, 32, 32, 0, true);
9+
this.addAnimation("walk-up", "assets/Bamboo.png", 4, 32, 32, 1, true);
10+
this.addAnimation("walk-left", "assets/Bamboo.png", 4, 32, 32, 2, true);
11+
this.addAnimation("walk-right", "assets/Bamboo.png", 4, 32, 32, 3, true);
12+
}
1213

14+
public void run() {
15+
state = "walk";
16+
17+
this.changeMapX(this.speed);
18+
19+
if (this.speed > 0) {
20+
dir = "right";
21+
} else {
22+
dir = "left";
23+
}
24+
this.changeMapY(0);
25+
if (this.isTouchingSprite(Wall.class)) {
26+
state = "idle";
27+
this.changeMapX(-this.speed);
28+
this.speed *= -1;
29+
this.changeMapY(0);
1330
}
1431

15-
public void run() {
16-
state = "walk";
17-
18-
this.changeMapX(this.speed);
19-
20-
if (this.speed > 0) {
21-
dir = "right";
22-
} else {
23-
dir = "left";
24-
}
25-
this.changeMapY(0);
26-
if (this.isTouchingSprite(Wall.class)) {
27-
state = "idle";
28-
this.changeMapX(-this.speed);
29-
this.speed *= -1;
30-
this.changeMapY(0);
31-
}
32-
33-
if (this.isTouchingSprite(Fireball.class)) {
34-
this.remove();
35-
}
36-
37-
if (state.equals("idle")) {
38-
this.setAnimationFrame(0);
39-
}
40-
41-
this.playAnimation("walk-" + dir);
32+
if (this.isTouchingSprite(Fireball.class)) {
33+
this.remove();
4234
}
43-
}
35+
36+
if (state.equals("idle")) {
37+
this.setAnimationFrame(0);
38+
}
39+
40+
this.playAnimation("walk-" + dir);
41+
}
42+
}

examples/java/Tiled/Enemy.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
public class Enemy extends AnimatedSprite {
44

5-
protected String state = "idle";
6-
protected String dir = "down";
7-
protected double mapX = 0;
8-
protected double mapY = 0;
5+
protected String state = "idle";
6+
protected String dir = "down";
7+
protected double mapX = 0;
8+
protected double mapY = 0;
99

10-
public Enemy(double mapX, double mapY) {
11-
this.mapX = mapX;
12-
this.mapY = mapY;
13-
}
10+
public Enemy(double mapX, double mapY) {
11+
this.mapX = mapX;
12+
this.mapY = mapY;
13+
}
1414

15-
public void setMapX(double mapX) {
16-
this.mapX = mapX;
17-
this.setX(this.mapX - GameState.get().camX);
18-
}
15+
public void setMapX(double mapX) {
16+
this.mapX = mapX;
17+
this.setX(this.mapX - GameState.get().camX);
18+
}
1919

20-
public void changeMapX(double dx) {
21-
this.setMapX(this.mapX + dx);
22-
}
20+
public void changeMapX(double dx) {
21+
this.setMapX(this.mapX + dx);
22+
}
2323

24-
public void setMapY(double mapY) {
25-
this.mapY = mapY;
26-
this.setY(this.mapY - GameState.get().camY);
27-
}
24+
public void setMapY(double mapY) {
25+
this.mapY = mapY;
26+
this.setY(this.mapY - GameState.get().camY);
27+
}
2828

29-
public void changeMapY(double dy) {
30-
this.setMapY(this.mapY + dy);
31-
}
32-
}
29+
public void changeMapY(double dy) {
30+
this.setMapY(this.mapY + dy);
31+
}
32+
}

examples/java/Tiled/Fireball.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import org.openpatch.scratch.extensions.animation.*;
22

33
public class Fireball extends AnimatedSprite {
4-
private double mapX;
5-
private double mapY;
6-
private String dir;
7-
private double speed = 3;
8-
9-
public Fireball(double mapX, double mapY, String dir) {
10-
this.mapX = mapX;
11-
this.mapY = mapY;
12-
this.dir = dir;
13-
14-
this.addAnimation("default", "assets/Fireball.png", 4, 32, 32);
4+
private double mapX;
5+
private double mapY;
6+
private String dir;
7+
private double speed = 3;
8+
9+
public Fireball(double mapX, double mapY, String dir) {
10+
this.mapX = mapX;
11+
this.mapY = mapY;
12+
this.dir = dir;
13+
14+
this.addAnimation("default", "assets/Fireball.png", 4, 32, 32);
15+
}
16+
17+
public void run() {
18+
if (this.getTimer().afterMillis(1000)) {
19+
this.remove();
1520
}
16-
17-
public void run() {
18-
if (this.getTimer().afterMillis(1000)) {
19-
this.remove();
20-
}
21-
22-
if (dir == "left") {
23-
this.mapX -= speed;
24-
} else if (dir == "right") {
25-
this.mapX += speed;
26-
} else if (dir == "up") {
27-
this.mapY += speed;
28-
} else if (dir == "down") {
29-
this.mapY -= speed;
30-
}
31-
32-
this.setX(this.mapX - GameState.get().camX);
33-
this.setY(this.mapY - GameState.get().camY);
34-
this.playAnimation("default");
21+
22+
if (dir == "left") {
23+
this.mapX -= speed;
24+
} else if (dir == "right") {
25+
this.mapX += speed;
26+
} else if (dir == "up") {
27+
this.mapY += speed;
28+
} else if (dir == "down") {
29+
this.mapY -= speed;
3530
}
36-
}
31+
32+
this.setX(this.mapX - GameState.get().camX);
33+
this.setY(this.mapY - GameState.get().camY);
34+
this.playAnimation("default");
35+
}
36+
}

examples/java/Tiled/GameState.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
import org.openpatch.scratch.extensions.fs.File;
33

44
public class GameState {
5-
public List<String> items = new ArrayList<>();
6-
public double camX = Double.MAX_VALUE;
7-
public double camY = Double.MAX_VALUE;
8-
public String map = "Level1";
9-
public String locale = "de";
10-
private static GameState instance;
5+
public List<String> items = new ArrayList<>();
6+
public double camX = Double.MAX_VALUE;
7+
public double camY = Double.MAX_VALUE;
8+
public String map = "Level1";
9+
public String locale = "de";
10+
private static GameState instance;
1111

12-
public static void save() {
13-
File.save("save.json", GameState.get());
14-
}
12+
public static void save() {
13+
File.save("save.json", GameState.get());
14+
}
1515

16-
public static void load() {
17-
instance = File.load("save.json", GameState.class);
18-
}
16+
public static void load() {
17+
instance = File.load("save.json", GameState.class);
18+
}
1919

20-
public static GameState get() {
21-
if (instance == null) {
22-
instance = new GameState();
23-
}
24-
return instance;
20+
public static GameState get() {
21+
if (instance == null) {
22+
instance = new GameState();
2523
}
26-
}
24+
return instance;
25+
}
26+
}

examples/java/Tiled/I18n.java

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
1-
import java.util.HashMap;
21
import java.text.MessageFormat;
2+
import java.util.HashMap;
33

44
public class I18n {
5-
private static String[] allowedLocales = {"en", "de"};
6-
private static String locale = allowedLocales[0];
7-
private static HashMap<String, HashMap<String, String>> messages;
8-
9-
public static void setup() {
10-
messages = new HashMap<>();
11-
12-
for (var allowedLocale : allowedLocales) {
13-
messages.put(allowedLocale, new HashMap<>());
14-
}
15-
16-
// see MessageFormat on how to write patterns: https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html
17-
var en = messages.get("en");
18-
en.put("item-found", "You have found an item: {0}!");
19-
en.put("scroll-water", "Scroll of Water");
20-
en.put("scroll-fire", "Scroll of Fire");
21-
en.put("tutorial-item-pickup", "Press E to pick up an item!");
22-
en.put("tutorial-scroll-fire", "Press G to throw a fire ball!");
23-
en.put("need-scroll-water", "I probably need the water scroll. Maybe it is here somewhere!");
24-
25-
26-
var de = messages.get("de");
27-
de.put("item-found", "Du hast einen Gegenstand gefunden: {0}!");
28-
de.put("scroll-water", "Schriftrolle des Wassers");
29-
de.put("scroll-fire", "Schriftrolle des Feuers");
30-
de.put("tutorial-scroll-fire", "Drücke G, um einen Feuerball zu werfen!");
31-
de.put("tutorial-item-pickup", "Drücke E, um das Item aufzuheben!");
32-
de.put("need-scroll-water", "Ich brauche Wahrscheinlich die Schriftrolle des Wassers. Vielleicht ist sie hier irgendwo?");
33-
}
34-
35-
public static void select(String locale) {
36-
for (var allowedLocale : allowedLocales) {
37-
if (allowedLocale.equals(locale)) {
38-
I18n.locale = locale;
39-
return;
40-
}
41-
}
5+
private static String[] allowedLocales = {"en", "de"};
6+
private static String locale = allowedLocales[0];
7+
private static HashMap<String, HashMap<String, String>> messages;
8+
9+
public static void setup() {
10+
messages = new HashMap<>();
11+
12+
for (var allowedLocale : allowedLocales) {
13+
messages.put(allowedLocale, new HashMap<>());
4214
}
43-
44-
public static String get(String key, String ...args) {
45-
var message = messages.get(locale).getOrDefault(key, "NOT_FOUND");
46-
return MessageFormat.format(message, args);
15+
16+
// see MessageFormat on how to write patterns:
17+
// https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html
18+
var en = messages.get("en");
19+
en.put("item-found", "You have found an item: {0}!");
20+
en.put("scroll-water", "Scroll of Water");
21+
en.put("scroll-fire", "Scroll of Fire");
22+
en.put("tutorial-item-pickup", "Press E to pick up an item!");
23+
en.put("tutorial-scroll-fire", "Press G to throw a fire ball!");
24+
en.put("need-scroll-water", "I probably need the water scroll. Maybe it is here somewhere!");
25+
26+
var de = messages.get("de");
27+
de.put("item-found", "Du hast einen Gegenstand gefunden: {0}!");
28+
de.put("scroll-water", "Schriftrolle des Wassers");
29+
de.put("scroll-fire", "Schriftrolle des Feuers");
30+
de.put("tutorial-scroll-fire", "Drücke G, um einen Feuerball zu werfen!");
31+
de.put("tutorial-item-pickup", "Drücke E, um das Item aufzuheben!");
32+
de.put(
33+
"need-scroll-water",
34+
"Ich brauche Wahrscheinlich die Schriftrolle des Wassers. Vielleicht ist sie hier"
35+
+ " irgendwo?");
36+
}
37+
38+
public static void select(String locale) {
39+
for (var allowedLocale : allowedLocales) {
40+
if (allowedLocale.equals(locale)) {
41+
I18n.locale = locale;
42+
return;
43+
}
4744
}
48-
}
45+
}
46+
47+
public static String get(String key, String... args) {
48+
var message = messages.get(locale).getOrDefault(key, "NOT_FOUND");
49+
return MessageFormat.format(message, args);
50+
}
51+
}

0 commit comments

Comments
 (0)