forked from IF-LK-2020/zulda
sprite working
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
package main;
|
||||
|
||||
import ea.Game;
|
||||
import ea.Manager;
|
||||
|
||||
public class Main extends Game {
|
||||
|
||||
private World world;
|
||||
private Player player;
|
||||
|
||||
public static final int WIDTH = 1056;
|
||||
public static final int HEIGHT = 672;
|
||||
public static final int WIDTH = 1440;
|
||||
public static final int HEIGHT = 1056;
|
||||
|
||||
public Main() {
|
||||
super(WIDTH, HEIGHT);
|
||||
|
||||
world = new World();
|
||||
player = new Player(this);
|
||||
|
||||
world = new World(player);
|
||||
wurzel.add(world);
|
||||
|
||||
Manager manager = new Manager();
|
||||
manager.anmelden(player, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,10 +7,17 @@ public class Map extends Knoten {
|
||||
private Tile[][] map;
|
||||
|
||||
public Map() {
|
||||
map = new Tile[11][7];
|
||||
map = new Tile[15][11];
|
||||
for (int x = 0; x < map.length; x++) {
|
||||
for (int y = 0; y < map[0].length; y++) {
|
||||
map[x][y] = new Tile((x == 0 || y == 0 || x == map.length - 1 || y == map[0].length - 1) ? 1 : 0);
|
||||
int id = 0;
|
||||
if (y == 1) {
|
||||
id = 2;
|
||||
}
|
||||
if (y == 0 || y == map[0].length - 1 || x == 0 || x == map.length - 1) {
|
||||
id = 1;
|
||||
}
|
||||
map[x][y] = new Tile(id);
|
||||
map[x][y].setX(x * Tile.getSize());
|
||||
map[x][y].setY(y * Tile.getSize());
|
||||
add(map[x][y]);
|
||||
|
||||
90
workspace/Zulda/src/main/Player.java
Normal file
90
workspace/Zulda/src/main/Player.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package main;
|
||||
|
||||
import ea.ActionFigur;
|
||||
import ea.Taste;
|
||||
import ea.Ticker;
|
||||
|
||||
public class Player extends ActionFigur implements Ticker {
|
||||
|
||||
private Main main;
|
||||
private static PlayerSheetLoader loader = new PlayerSheetLoader();
|
||||
private boolean side;
|
||||
|
||||
private float velX, velY;
|
||||
private float accelleration = 0.15f;
|
||||
private float friction = 0.2f;
|
||||
|
||||
public Player(Main main) {
|
||||
super(loader.getPlayer(0), "idle_left");
|
||||
this.main = main;
|
||||
|
||||
neuerZustand(loader.getPlayer(1), "idle_right");
|
||||
neuerZustand(loader.getPlayer(2), "walk_left");
|
||||
neuerZustand(loader.getPlayer(3), "walk_right");
|
||||
neuerZustand(loader.getPlayer(4), "strike_left");
|
||||
neuerZustand(loader.getPlayer(5), "strike_right");
|
||||
neuerZustand(loader.getPlayer(6), "swipe_left");
|
||||
neuerZustand(loader.getPlayer(7), "swipe_right");
|
||||
neuerZustand(loader.getPlayer(8), "die");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!((aktuellesVerhalten() == "strike_left" || aktuellesVerhalten() == "strike_right")
|
||||
&& aktuelleFigur().aktuellesBild() < aktuelleFigur().animation().length - 1)) {
|
||||
|
||||
if (main.tasteGedrueckt(Taste.W)) {
|
||||
velY -= World.SCALE * accelleration;
|
||||
}
|
||||
if (main.tasteGedrueckt(Taste.S)) {
|
||||
velY += World.SCALE * accelleration;
|
||||
}
|
||||
if (main.tasteGedrueckt(Taste.A)) {
|
||||
velX -= World.SCALE * accelleration;
|
||||
side = false;
|
||||
}
|
||||
if (main.tasteGedrueckt(Taste.D)) {
|
||||
velX += World.SCALE * accelleration;
|
||||
side = true;
|
||||
}
|
||||
|
||||
setX(getX() + velX);
|
||||
setY(getY() + velY);
|
||||
velX *= (1f - friction);
|
||||
velY *= (1f - friction);
|
||||
|
||||
if (!((aktuellesVerhalten() == "swipe_left" || aktuellesVerhalten() == "swipe_right")
|
||||
&& aktuelleFigur().aktuellesBild() < aktuelleFigur().animation().length - 1)) {
|
||||
if (velX > 0.2f || velY > 0.2f || velX < -0.2f || velY < -0.2f) {
|
||||
if (side) {
|
||||
zustandSetzen("walk_right");
|
||||
} else {
|
||||
zustandSetzen("walk_left");
|
||||
}
|
||||
} else {
|
||||
if (side) {
|
||||
zustandSetzen("idle_right");
|
||||
} else {
|
||||
zustandSetzen("idle_left");
|
||||
}
|
||||
}
|
||||
|
||||
if (main.tasteGedrueckt(Taste.LEERTASTE)) {
|
||||
if (side) {
|
||||
zustandSetzen("swipe_right");
|
||||
} else {
|
||||
zustandSetzen("swipe_left");
|
||||
}
|
||||
}
|
||||
if (main.tasteGedrueckt(Taste.Q)) {
|
||||
if (side) {
|
||||
zustandSetzen("strike_right");
|
||||
} else {
|
||||
zustandSetzen("strike_left");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
86
workspace/Zulda/src/main/PlayerSheetLoader.java
Normal file
86
workspace/Zulda/src/main/PlayerSheetLoader.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package main;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import ea.Figur;
|
||||
import ea.internal.gra.PixelFeld;
|
||||
|
||||
public class PlayerSheetLoader {
|
||||
|
||||
private static Figur[] player;
|
||||
|
||||
private static final float SCALE_DIV = 1.5f;
|
||||
|
||||
public PlayerSheetLoader() {
|
||||
try {
|
||||
BufferedImage sheet = ImageIO.read(Tile.class.getResourceAsStream("/res/images/player_sprite_sheet.png"));
|
||||
|
||||
PixelFeld[][] sprites = new PixelFeld[9][];
|
||||
sprites[0] = new PixelFeld[5];
|
||||
sprites[1] = new PixelFeld[5];
|
||||
sprites[2] = new PixelFeld[8];
|
||||
sprites[3] = new PixelFeld[8];
|
||||
sprites[4] = new PixelFeld[7];
|
||||
sprites[5] = new PixelFeld[7];
|
||||
sprites[6] = new PixelFeld[6];
|
||||
sprites[7] = new PixelFeld[6];
|
||||
sprites[8] = new PixelFeld[7];
|
||||
|
||||
loadSprites(sprites[0], 0, 64, 32, sheet, true);
|
||||
loadSprites(sprites[1], 0, 64, 32, sheet, false);
|
||||
loadSprites(sprites[2], 1, 64, 32, sheet, true);
|
||||
loadSprites(sprites[3], 1, 64, 32, sheet, false);
|
||||
loadSprites(sprites[4], 2, 64, 32, sheet, true);
|
||||
loadSprites(sprites[5], 2, 64, 32, sheet, false);
|
||||
loadSprites(sprites[6], 3, 64, 32, sheet, true);
|
||||
loadSprites(sprites[7], 3, 64, 32, sheet, false);
|
||||
loadSprites(sprites[8], 7, 64, 32, sheet, false);
|
||||
|
||||
Figur fig;
|
||||
player = new Figur[9];
|
||||
for (int i = 0; i < player.length; i++) {
|
||||
fig = new Figur();
|
||||
fig.animationSetzen(sprites[i]);
|
||||
player[i] = fig;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Figur getPlayer(int y) {
|
||||
return player[y];
|
||||
}
|
||||
|
||||
private void loadSprites(PixelFeld[] sprites, int row, int w, int h, BufferedImage sheet, boolean reverse) {
|
||||
for (int s = 0; s < sprites.length; s++) {
|
||||
sprites[s] = new PixelFeld(w * (int) (World.SCALE / SCALE_DIV), h * (int) (World.SCALE / SCALE_DIV), 1);
|
||||
for (int x = 0; x < w; x++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
Color clr = new Color(sheet.getRGB((s * w + x), (row * h + y)), true);
|
||||
if (clr.getAlpha() > 0) {
|
||||
for (int i = 0; i < World.SCALE / SCALE_DIV; i++) {
|
||||
for (int j = 0; j < World.SCALE / SCALE_DIV; j++) {
|
||||
sprites[s].farbeSetzen(x * (int) (World.SCALE / SCALE_DIV) + i, y * (int) (World.SCALE / SCALE_DIV) + j, clr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reverse) {
|
||||
PixelFeld copy = new PixelFeld(sprites[s].breite(), sprites[s].hoehe(), 1);
|
||||
for (int x = 0; x < sprites[s].breite(); x++) {
|
||||
for (int y = 0; y < sprites[s].hoehe(); y++) {
|
||||
copy.farbeSetzen(sprites[s].breite() - x - 1, y, sprites[s].getPic()[x][y]);
|
||||
}
|
||||
}
|
||||
sprites[s] = copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,8 @@ import ea.Knoten;
|
||||
public class Tile extends Knoten {
|
||||
|
||||
public static final int GRASS = 0;
|
||||
public static final int WALL = 1;
|
||||
|
||||
private static final int SCALE = 6;
|
||||
public static final int WALL_TOP = 1;
|
||||
public static final int WALL_BOTTOM = 2;
|
||||
|
||||
private Bild img;
|
||||
|
||||
@@ -24,18 +23,14 @@ public class Tile extends Knoten {
|
||||
BufferedImage buff = ImageIO.read(Tile.class.getResourceAsStream(getPathFromId(id)));
|
||||
if (id == GRASS) {
|
||||
buff = buff.getSubimage(16 * (int) (Math.random() * 8), 0, 16, 16);
|
||||
|
||||
}
|
||||
BufferedImage after = new BufferedImage(buff.getWidth() * SCALE, buff.getHeight() * SCALE, BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage after = new BufferedImage(buff.getWidth() * World.SCALE, buff.getHeight() * World.SCALE, BufferedImage.TYPE_INT_ARGB);
|
||||
AffineTransform at = new AffineTransform();
|
||||
at.scale(SCALE, SCALE);
|
||||
at.scale(World.SCALE, World.SCALE);
|
||||
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
|
||||
after = scaleOp.filter(buff, after);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (id == WALL) {
|
||||
y = -after.getHeight() + 16 * SCALE;
|
||||
}
|
||||
img = new Bild(x, y, after);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -47,13 +42,15 @@ public class Tile extends Knoten {
|
||||
switch (id) {
|
||||
case GRASS:
|
||||
return "/res/images/tiles/grass.png";
|
||||
case WALL:
|
||||
return "/res/images/tiles/wall.png";
|
||||
case WALL_TOP:
|
||||
return "/res/images/tiles/wall_top.png";
|
||||
case WALL_BOTTOM:
|
||||
return "/res/images/tiles/wall_bottom.png";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getSize() {
|
||||
return 16 * SCALE;
|
||||
return 16 * World.SCALE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ package main;
|
||||
import ea.Knoten;
|
||||
|
||||
public class World extends Knoten {
|
||||
|
||||
public static final int SCALE = 6;
|
||||
|
||||
private Map currentMap;
|
||||
|
||||
public World() {
|
||||
public World(Player player) {
|
||||
|
||||
currentMap = new Map();
|
||||
add(currentMap);
|
||||
add(player);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
BIN
workspace/Zulda/src/res/images/player_sprite_sheet.png
Normal file
BIN
workspace/Zulda/src/res/images/player_sprite_sheet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 391 B |
BIN
workspace/Zulda/src/res/images/tiles/wall_bottom.png
Normal file
BIN
workspace/Zulda/src/res/images/tiles/wall_bottom.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 305 B |
BIN
workspace/Zulda/src/res/images/tiles/wall_top.png
Normal file
BIN
workspace/Zulda/src/res/images/tiles/wall_top.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 291 B |
Reference in New Issue
Block a user