Hitboxen verbessert

This commit is contained in:
Andreas Greiner 2021-06-27 20:52:27 +02:00
parent 5653c137f8
commit 56d563ecd5
17 changed files with 27 additions and 30 deletions

View File

@ -101,6 +101,8 @@ public class GamePlayManager {
player.lives--;
gameObjectManager.getLivesLabel().setLifeCount(player.lives);
gameObjectManager.getBubbles().clear();
gameObjectManager.getHarpoons().forEach(h -> h.stopSound());
gameObjectManager.getHarpoons().clear();
specialBubblePresent = false;
spawnBubbles = true;
gameObjectManager.getGameOverlay().flashScreen(Color.red, 100);
@ -238,7 +240,7 @@ public class GamePlayManager {
collidableGameObjects.add(gameObjectManager.getPlayerObject());
collidableGameObjects.addAll(gameObjectManager.getHarpoons());
if(randomNumber<60){
if(randomNumber<10){
RoundBubble roundBubble = new RoundBubble(gameView, collidableGameObjects);
roundBubble.setGamePlayManager(this);
gameObjectManager.getBubbles().add(roundBubble);
@ -279,7 +281,7 @@ public class GamePlayManager {
public boolean shootHarpoon(Position startPosition){
if(gameView.timerExpired("ShootHarpoon","GamePlayManager") && gameObjectManager.getHarpoons().size()<2){
Harpoon harpoon = new Harpoon(gameView,new ArrayList<>());
harpoon.getPosition().setTo(startPosition.x+16, startPosition.y-15);
harpoon.getPosition().setTo(startPosition.x+6, startPosition.y-15);
harpoon.setGamePlayManager(this);
gameObjectManager.getHarpoons().add(harpoon);
gameObjectManager.getBubbles().forEach(b -> b.addCollidableGameObject(Collections.singletonList(harpoon)));

View File

@ -37,6 +37,7 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb
*/
public Bubble(GameView gameView, ArrayList<CollidableGameObject> objectsToCollideWith){
super(gameView,objectsToCollideWith);
random = new Random();
rotation = 90;
size = 10;
width = (int) (12 * size);
@ -44,8 +45,7 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb
speedInPixel = 1;
spawnID = UUID.randomUUID().getLeastSignificantBits();
random = new Random();
position.setTo(random.nextInt(GameView.WIDTH-width),-width);
position.setTo(HelperValues.FRAME_BORDER_WIDTH + random.nextInt((int)(GameView.WIDTH-width - (2*HelperValues.FRAME_BORDER_WIDTH))), -width);
spawning = true;
spawnSpeed = 500;
gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed);
@ -110,16 +110,16 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb
// Wall bounce
if((newLocation.getX() >= GameView.WIDTH - width - HelperValues.FRAME_BORDER_WIDTH) || newLocation.getX() <= HelperValues.FRAME_BORDER_WIDTH){
velocity = new Point2D.Double(velocity.getX() * -1.0, velocity.getY());
if(this instanceof SpecialBubble){
switchSpecialBubbleState((SpecialBubble) this);
}
}
// Floor bounce
if(newLocation.getY() >= HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width){
velocity = new Point2D.Double(velocity.getX(), velocity.getY() * -0.95);
newLocation = new Point2D.Double(newLocation.getX(), HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width);
if(this instanceof SpecialBubble){
switchSpecialBubbleState((SpecialBubble) this);
SpecialBubble specialBubble = (SpecialBubble) this;
specialBubble.freezeState = !specialBubble.freezeState;
gameView.playSound("specialBounce.wav",false);
}
}
@ -127,11 +127,6 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb
}
}
private void switchSpecialBubbleState(SpecialBubble specialBubble){
specialBubble.freezeState = !specialBubble.freezeState;
gameView.playSound("specialBounce.wav",false);
}
/**
* Get the score to add when bursting the bubble.
*

View File

@ -2,6 +2,7 @@ package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.*;
import de.thdeg.greiner.superpangworld.graphics.helper.HelperValues;
import java.awt.*;
import java.util.ArrayList;
@ -51,7 +52,7 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
boolean right = true;
String rope = "";
for(int i=0;i<100;i++){
for(int i = 0; i< HelperValues.FRAME_WINDOW_HEIGHT; i++){
rope += " ".repeat(pre) + "k" + " ".repeat(post)+"\n";
if(right){
pre++;

View File

@ -29,8 +29,8 @@ public class HexagonalBubble extends Bubble {
width = (int) (128 * size);
height = (int) (128 * size);
this.hitBox.width = width;
this.hitBox.height = height;
this.hitBox.width = (int)(width - (width*0.1) );
this.hitBox.height = (int)(width - (width*0.1) );
}
public HexagonalBubble(GameView gameView, ArrayList<CollidableGameObject> objectsToCollideWith, double size, double speedInPixel, Position position, boolean spawning, Point2D velocity){
@ -39,14 +39,14 @@ public class HexagonalBubble extends Bubble {
width = (int) (128 * size);
height = (int) (128 * size);
this.hitBox.width = width;
this.hitBox.height = height;
this.hitBox.width = (int)(width - (width*0.1) );
this.hitBox.height = (int)(width - (width*0.1) );
}
@Override
protected void updateHitBoxPosition() {
hitBox.x = (int) position.x;
hitBox.y = (int) position.y;
hitBox.x = (int) (position.x + (width*0.05));
hitBox.y = (int) (position.y + (width*0.05));
}
@Override
@ -55,19 +55,16 @@ public class HexagonalBubble extends Bubble {
}
@Override
public void updateStatus() {
}
public void updateStatus() {}
@Override
public void updatePosition() {
super.updatePosition();
rotation = (rotation + 1) % 360;
rotation = (rotation + 2) % 360;
}
@Override
public int getBurstScore() {
// 1 0.5 0.25 0.125
switch((int)(size*1000)){
case 1000:
return 200;

View File

@ -3,6 +3,7 @@ package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject;
import java.awt.*;
import java.util.Objects;
/**
@ -33,8 +34,8 @@ public class PlayerObject extends CollidableGameObject implements Cloneable {
height = (int) (41 * size);
speedInPixel = 2;
this.hitBox.width = width;
this.hitBox.height = height;
this.hitBox.width = width - 20;
this.hitBox.height = height - 10;
movingRight = false;
movingLeft = false;
@ -44,8 +45,8 @@ public class PlayerObject extends CollidableGameObject implements Cloneable {
@Override
protected void updateHitBoxPosition() {
hitBox.x = (int) (position.x );
hitBox.y = (int) (position.y);
hitBox.x = (int) (position.x + 10);
hitBox.y = (int) (position.y + 10);
}
@Override

View File

@ -5,6 +5,7 @@ import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject;
import de.thdeg.greiner.superpangworld.graphics.base.Position;
import java.awt.*;
import java.awt.geom.Point2D;
import java.util.ArrayList;
@ -101,7 +102,6 @@ public class RoundBubble extends Bubble {
gamePlayManager.addBubbles(bubbleLeft, bubbleRight);
}else if(timeFreeze){
gamePlayManager.freezeMovement(1000);
System.out.println("FREEZING");
}
}

View File

@ -5,6 +5,7 @@ import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject;
import de.thdeg.greiner.superpangworld.graphics.base.Position;
import java.awt.*;
import java.util.ArrayList;
/**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 336 B