Removed collisionmask for large pellets

This commit is contained in:
Urban Modig
2025-08-28 17:39:49 +02:00
parent 76cb35c955
commit 09e0396cc3
4 changed files with 29 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import se.urmo.game.main.GamePanel; import se.urmo.game.main.GamePanel;
import se.urmo.game.util.Direction; import se.urmo.game.util.Direction;
import se.urmo.game.map.GameMap; import se.urmo.game.map.GameMap;
import se.urmo.game.util.Pair;
import java.awt.Point; import java.awt.Point;
import java.util.Collections; import java.util.Collections;
@ -31,7 +32,8 @@ public class CollisionChecker {
); );
}; };
log.debug("{} boundaries for {} are {}", direction, position, boundaries); List<Pair> bs = boundaries.stream().map(p -> new Pair(p.x, p.y, GameMap.screenToRow(p.y), GameMap.screenToCol(p.x))).toList();
log.debug("{} boundaries for {} are {}", direction, position, bs);
List<Point> normalized = boundaries.stream() List<Point> normalized = boundaries.stream()
.map(p -> normalizePosition(direction, p, agent_width, agent_height)) .map(p -> normalizePosition(direction, p, agent_width, agent_height))

View File

@ -77,13 +77,12 @@ public class PacMan {
PACMAN_SIZE, PACMAN_SIZE,
PACMAN_SIZE, null); PACMAN_SIZE, null);
g.drawImage(COLLISION_BOX, position.x - COLLISION_BOX_OFFSET, position.y - COLLISION_BOX_OFFSET, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE, null); g.drawImage(COLLISION_BOX, position.x - COLLISION_BOX_OFFSET, position.y - COLLISION_BOX_OFFSET, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE, null);
g.setColor(Color.BLUE); //g.setColor(Color.BLUE);
//g.fillRect(position.x-1, position.y-1, 3, 3); //g.fillRect(position.x-1, position.y-1, 3, 3);
} }
public void update() { public void update() {
updateAnimationTick(); updateAnimationTick();
//if(direction == Direction.NONE) return;
if(moving) { if(moving) {
Point newPosition = switch (direction) { Point newPosition = switch (direction) {
case RIGHT -> new Point(position.x + speed, position.y); case RIGHT -> new Point(position.x + speed, position.y);

View File

@ -15,7 +15,7 @@ public class MapTile {
public MapTile(BufferedImage image, TileType tileType) { public MapTile(BufferedImage image, TileType tileType) {
this.tileType = tileType; this.tileType = tileType;
this.image = image; this.image = image;
this.collisionMask = tileType.getValue() != 0 ? createCollisionMask(image) : null; this.collisionMask = tileType.isSolid() ? createCollisionMask(image) : null;
} }
private boolean[][] createCollisionMask(BufferedImage img) { private boolean[][] createCollisionMask(BufferedImage img) {

View File

@ -0,0 +1,24 @@
package se.urmo.game.util;
public class Pair{
private final int x;
private final int y;
int row;
int col;
public Pair(int x, int y, int row, int col){
this.x = x;
this.y = y;
this.row = row;
this.col = col;
}
@Override
public String toString() {
return "Pair{" +
"x=" + x +
", y=" + y +
", row=" + row +
", col=" + col +
'}';
}
}