From 28b9404fe972b379d9a3ac846233211fc452b003 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 30 Jun 2021 13:32:05 +0200 Subject: [PATCH 1/2] added default texture --- Zoelda/src/main/SheetLoader.java | 54 +++++++++++---------- Zoelda/src/main/entities/LivingEntity.java | 20 +++++++- Zoelda/src/main/entities/Snake.java | 7 ++- Zoelda/src/main/entities/Spider.java | 7 +-- Zoelda/src/main/entities/player/Player.java | 5 +- Zoelda/src/main/worlds/TestWorld.java | 6 +-- 6 files changed, 58 insertions(+), 41 deletions(-) diff --git a/Zoelda/src/main/SheetLoader.java b/Zoelda/src/main/SheetLoader.java index 17acd13..0dfb025 100644 --- a/Zoelda/src/main/SheetLoader.java +++ b/Zoelda/src/main/SheetLoader.java @@ -12,44 +12,46 @@ import ea.internal.gra.PixelFeld; public class SheetLoader { private Figur[] figures; + private BufferedImage sheet; /** * Macht aus einem Spritesheet Figuren. - * @param path - Der pfad zum sheet - * @param width - die Breite von einem Bild - * @param height - die Höhe von einem Bild (nicht das ganze sheet) + * + * @param path - Der pfad zum sheet + * @param width - die Breite von einem Bild + * @param height - die Höhe von einem Bild (nicht das ganze sheet) * @param lengths - die Anzahl der Frames der verschiedenen Animationen */ - public SheetLoader(String path, int width, int height, int[] frames) { - + public SheetLoader(String path) { try { // Bild laden - BufferedImage sheet = ImageIO.read(Tile.class.getResourceAsStream(path)); - - // Anzahl der Animationen - int rows = frames.length; - - // Sprites anordnen *magie* - PixelFeld[][] sprites = new PixelFeld[rows][]; - for (int i = 0; i < frames.length; i++) { - sprites[i] = new PixelFeld[frames[i]]; - } - for (int i = 0; i < sprites.length; i++) { - loadSprites(sprites[i], i, width, height, sheet); - } - Figur fig; - figures = new Figur[rows]; - for (int i = 0; i < figures.length; i++) { - fig = new Figur(); - fig.animationSetzen(sprites[i]); - figures[i] = fig; - } - + sheet = ImageIO.read(Tile.class.getResourceAsStream(path)); } catch (IOException e) { e.printStackTrace(); } } + public void generateFigures(int width, int height, int[] frames) { + // Anzahl der Animationen + int rows = frames.length; + + // Sprites anordnen *magie* + PixelFeld[][] sprites = new PixelFeld[rows][]; + for (int i = 0; i < frames.length; i++) { + sprites[i] = new PixelFeld[frames[i]]; + } + for (int i = 0; i < sprites.length; i++) { + loadSprites(sprites[i], i, width, height, sheet); + } + Figur fig; + figures = new Figur[rows]; + for (int i = 0; i < figures.length; i++) { + fig = new Figur(); + fig.animationSetzen(sprites[i]); + figures[i] = fig; + } + } + public Figur getFigur(int y) { return figures[y]; } diff --git a/Zoelda/src/main/entities/LivingEntity.java b/Zoelda/src/main/entities/LivingEntity.java index 7e86c60..686a428 100644 --- a/Zoelda/src/main/entities/LivingEntity.java +++ b/Zoelda/src/main/entities/LivingEntity.java @@ -1,7 +1,10 @@ package main.entities; +import java.awt.Color; + import ea.ActionFigur; import ea.Figur; +import ea.internal.gra.PixelFeld; import main.worlds.World; /* @@ -16,12 +19,25 @@ public abstract class LivingEntity extends Entity { protected float hp = 1f; //hp des Entitys protected boolean mirrored; + private static Figur noTexture = new Figur(); + + static { + PixelFeld[] img = new PixelFeld[1]; + img[0] = new PixelFeld(16, 16, 1); + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + img[0].farbeSetzen(x, y, Color.MAGENTA); + } + } + noTexture.animationSetzen(img); + } + /** * @param figur - erstes (standart) Sprite * @param name - name des Zustands */ - public LivingEntity(Figur figur, String name) { - actionFigur = new ActionFigur(figur, name) { + public LivingEntity() { + actionFigur = new ActionFigur(noTexture, "undefined") { // DEBUG: render boxes // @Override diff --git a/Zoelda/src/main/entities/Snake.java b/Zoelda/src/main/entities/Snake.java index b6150d7..cb6230d 100644 --- a/Zoelda/src/main/entities/Snake.java +++ b/Zoelda/src/main/entities/Snake.java @@ -7,15 +7,13 @@ import main.entities.player.Player; public class Snake extends LivingEntity { - private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png", 32, 32, - new int[] { 10, 10, 10, 10, 13, 8 }); + private static SheetLoader loader = new SheetLoader("/res/images/snake_spritesheet_calciumtrice.png"); private float damage = 0.1f; private boolean attackOnce; public Snake() { - super(loader.getFigur(0), "idle"); - + loader.generateFigures(32, 32, new int[] { 10, 10, 10, 10, 13, 8 }); posX = 9f; posY = 9f; accelleration = 0.006f; @@ -24,6 +22,7 @@ public class Snake extends LivingEntity { height = 0.8f; mirrored = true; + actionFigur.neuerZustand(loader.getFigur(0), "idle"); actionFigur.neuerZustand(loader.getFigur(1), "lost_sight"); actionFigur.neuerZustand(loader.getFigur(2), "walk"); actionFigur.neuerZustand(loader.getFigur(3), "attack"); diff --git a/Zoelda/src/main/entities/Spider.java b/Zoelda/src/main/entities/Spider.java index 4cd2782..786d644 100644 --- a/Zoelda/src/main/entities/Spider.java +++ b/Zoelda/src/main/entities/Spider.java @@ -7,10 +7,10 @@ import main.entities.player.Player; public class Spider extends LivingEntity { - private static SheetLoader loader = new SheetLoader("/res/images/spider_sprite_sheet.png", 32, 32, new int[] { 5, 3, 6, 9, 9, 8 }); + private static SheetLoader loader = new SheetLoader("/res/images/spider_sprite_sheet.png"); public Spider() { - super(loader.getFigur(0), "idle"); + loader.generateFigures(32, 32, new int[] { 5, 3, 6, 9, 9, 8 }); width = 0.7f; height = 0.8f; @@ -19,7 +19,8 @@ public class Spider extends LivingEntity { posX = 4f; posY = 4f; mirrored = true; - + + actionFigur.neuerZustand(loader.getFigur(0), "idle"); actionFigur.neuerZustand(loader.getFigur(1), "lost_sight"); actionFigur.neuerZustand(loader.getFigur(2), "walk"); actionFigur.neuerZustand(loader.getFigur(3), "attack"); diff --git a/Zoelda/src/main/entities/player/Player.java b/Zoelda/src/main/entities/player/Player.java index 5820567..bd4eff1 100644 --- a/Zoelda/src/main/entities/player/Player.java +++ b/Zoelda/src/main/entities/player/Player.java @@ -11,13 +11,12 @@ import main.entities.LivingEntity; public class Player extends LivingEntity { - private static SheetLoader loader = new SheetLoader("/res/images/player_sprite_sheet.png", 64, 32, - new int[] { 5, 8, 7, 6, 2, 5, 4, 7 }); + private static SheetLoader loader = new SheetLoader("/res/images/player_sprite_sheet.png"); private boolean onlyAttackOnceTrigger; private float range = 1.2f; // die reichweite der Attacke public Player() { - super(loader.getFigur(0), "idle"); + loader.generateFigures(64, 32, new int[] { 5, 8, 7, 6, 2, 5, 4, 7 }); // Entity-Eigenschaften werden festgelegt width = 0.7f; diff --git a/Zoelda/src/main/worlds/TestWorld.java b/Zoelda/src/main/worlds/TestWorld.java index 41e0542..9b4f459 100644 --- a/Zoelda/src/main/worlds/TestWorld.java +++ b/Zoelda/src/main/worlds/TestWorld.java @@ -6,11 +6,11 @@ import main.maps.Map; public class TestWorld extends World { public TestWorld() { - super(5); + super(4); - Map m2 = maps[7].clone(); + Map m2 = maps[3].clone(); getCurrentMap().connectDoors(getCurrentMap().leftDoor, m2.leftDoor); - + getCurrentMap().addLivingEntity(new Snake()); } From ec74176426b799471f428ddcfbdf49cebe449bb4 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 30 Jun 2021 13:32:26 +0200 Subject: [PATCH 2/2] Disco sprite sheet added --- Zoelda/src/main/Tile.java | 3 +++ Zoelda/src/res/images/disco_sprite_sheet.png | Bin 0 -> 3268 bytes 2 files changed, 3 insertions(+) create mode 100644 Zoelda/src/res/images/disco_sprite_sheet.png diff --git a/Zoelda/src/main/Tile.java b/Zoelda/src/main/Tile.java index 6e1ab05..87f8fe5 100644 --- a/Zoelda/src/main/Tile.java +++ b/Zoelda/src/main/Tile.java @@ -25,6 +25,7 @@ public class Tile extends Knoten { public static final int STONE_FLOOR_SHADOW_LEFT = 6; public static final int DOOR_LEFT_BOTTOM = 7; public static final int DOOR_LEFT_TOP = 8; + public static final int DISCO = 9; private Bild img; // Bild, das gerendert wird private int id; // Die id dises Tiles// @@ -98,6 +99,8 @@ public class Tile extends Knoten { return "/res/images/tiles/door_left_bottom.png"; case DOOR_LEFT_TOP: return "/res/images/tiles/door_left_top.png"; + case DISCO: + return "/res/images/tiles/disco_sprite_sheet.png"; } return null; } diff --git a/Zoelda/src/res/images/disco_sprite_sheet.png b/Zoelda/src/res/images/disco_sprite_sheet.png new file mode 100644 index 0000000000000000000000000000000000000000..2f04b2547b5d1ae1553f6161bc6b1a18a9f1954a GIT binary patch literal 3268 zcmV;#3_J6QP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D3|UD;K~!i%&02|W z9LWu(M#tzJo%YzqW?`@M|6k+;yX$PM(K)uR(Va)WBAeCSIu@G%0Uins`4##4RTaCN z$QK)lFY^9cK8t)39f7~g`B?VXWwIfE zEXzMd@tX|3$=WwrJ(3M&6c`)h?~59VREs@2Q~|(GH$}tGat8sBu`AQI0E{1v1h|IN z9ogTI$+~=9(x~8lm4$s-+n3d;?79FxK*n$LCGa0IgaF96kg;oU#g`wt8fXGEe0(giKgbo=VnzOKB-}nG zmQjwgJ~-0Sj9+V6=B>ycXD0}uoG*t{tMz@q@yP-Cw|Dj3UbR0K?yiiTqmWCx(6 zqEZY=)LxV{nCaYn3=E7+Kr%gn zrW2vT1V9N%h;620_v40x=NH*@JArDtIUc5i2LVr-KJt_5A@8<}<4+Ozi>?d-c);%t{pi zX;<#y00eBvRUs9&fg~3I&;j6hpbW%5m3a!d)bbA!9q^GP#MR;dEnbOJT%xT~R0G18cR! zW5@#;9D5b8N)#F>!v%1TUGSt57V#6~$H>7H?4OyFjYuq^UaXLocFwimm;5DX$$KCIylZOk-inj!kJS0q~ zF*m)?)cI2*OI$@^ATnCbI;luQ)m0tMXF&%KzIa*Yj zj@w4*r3RV~xasMJVY;UdPylb3QSENS^q`s;n4UG*ZP9UTJ_-Q1_4`f7TLR;OXBUrq znmtTsZ0`QrbWCv5Ndip3{E23#jFtwVtrq|l0(b}?v;$_O z5IwV=R>-jBMRv-F*l>Uv=9Fiof{CnM6_UR)KI}F=MC`N~jFgvyT0;Y?fC300Os}3bnhXcdO$X1_ zU5z4NL~T8DO+z-FJYJaTwFa8r(vV)j7&4ijjj`AZr^>?3v8@W|Yxk66BE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