animationen für pacman

master
leventius imperatus 2020-06-08 17:07:17 +02:00
parent eb3bce08f5
commit eb8bb01e17
15 changed files with 101 additions and 8 deletions

27
assets/Maps/Flocke.txt Normal file
View File

@ -0,0 +1,27 @@
###########################
############# #############
############ ############
########### # ###########
####0 ## ### ## 1####
#### ## ### # ### ## ####
#### ## #.## ##.# ## ####
#### ### ### ####
####### # #,# #,# # #######
######. ### ### .######
#### #### ## ## #### ####
### ##,# #,## ###
## # #### #.# #### # ##
#L ### # ### R#
## # #### #P# #### # ##
### ##,# #,## ###
#### #### ## ## #### ####
######. ### ### .######
####### # #,# #,# # #######
#### ### ### ####
#### ## #.## ##.# ## ####
#### ## ### # ### ## ####
####2 ## ### ## 3####
########### # ###########
############ ############
############# #############
###########################

BIN
assets/Pacman_Down1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

BIN
assets/Pacman_Down3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

BIN
assets/Pacman_Left1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

BIN
assets/Pacman_Left3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
assets/Pacman_Right1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

BIN
assets/Pacman_Right3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

BIN
assets/Pacman_Up1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

BIN
assets/Pacman_Up3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

BIN
assets/Pacman_full.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

Binary file not shown.

View File

@ -154,6 +154,7 @@ public class Game {
while (true) { // Hauptschleife
for (int i = 0; i < ghosts.length; i++) {
if (ghosts[i].getIsDead()) {
if (ghosts[i].getDeathTimer() != 0) {

View File

@ -35,6 +35,8 @@ public class Player extends Picture implements KeyListener { // extends Picture
public boolean pressed_down;
public boolean hui; // Boolean zur Abfrage, ob gerade ein Brick im Weg ist, um den aktuellen
private int movingTicks;
// Richtungsbefehl durchzuführen.
public Player() { // Erstellen des Konstruktors
@ -77,8 +79,8 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_up = false;
pressed_down = false;
// und Pac-Man schaut jetzt nach links
this.changeSauce("Pacman_Left");
} else { // ansonsten:
// soll Pac-Man sich sobald er kann nach links bewegen
@ -115,7 +117,10 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_right = false;
pressed_up = false;
pressed_down = false;
this.changeSauce("Pacman_Right");
} else {
pressed_left = false;
pressed_right = true;
@ -146,7 +151,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_right = false;
pressed_up = false;
pressed_down = false;
this.changeSauce("Pacman_Up");
} else {
pressed_left = false;
pressed_right = false;
@ -177,7 +182,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_right = false;
pressed_up = false;
pressed_down = false;
this.changeSauce("Pacman_Down");
} else {
pressed_left = false;
pressed_right = false;
@ -216,15 +221,19 @@ public class Player extends Picture implements KeyListener { // extends Picture
if (coordinate == 'x') { // Auslesen der 'x' - Koordinate:
if (left && dt != 0) {
xPos -= speed * dt;
animate("Left");
} else if (right && dt != 0) {
xPos += speed * dt;
animate("Right");
}
return (int) xPos;
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
if (down && dt != 0) {
yPos += speed * dt;
animate("Down");
} else if (up && dt != 0) {
yPos -= speed * dt;
animate("Up");
}
return (int) yPos;
} else {
@ -243,4 +252,60 @@ public class Player extends Picture implements KeyListener { // extends Picture
}
private void animate(String Dir) {
this.movingTicks++;
int aniFrames;
aniFrames = ((this.movingTicks + 1) % 125 / 25);
if (Dir == "Left") {
if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Left1");
} else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Left");
} else if (aniFrames == 3) {
this.changeSauce("Pacman_Left3");
}
}if (Dir == "Right") {
if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Right1");
} else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Right");
} else if (aniFrames == 3) {
this.changeSauce("Pacman_Right3");
}
}if (Dir == "Up") {
if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Up1");
} else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Up");
} else if (aniFrames == 3) {
this.changeSauce("Pacman_Up3");
}
}if (Dir == "Down") {
if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Down1");
} else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Down");
} else if (aniFrames == 3) {
this.changeSauce("Pacman_Down3");
}
}
}
}