Skip to content

Commit

Permalink
Merge pull request #22 from LeleDallas/refactor/code-improvements
Browse files Browse the repository at this point in the history
refactor: code improvements
  • Loading branch information
LeleDallas authored Apr 8, 2024
2 parents 5431df3 + 7b87748 commit c4359a1
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 391 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
release-type: java
37 changes: 0 additions & 37 deletions .github/workflows/sonarcloud.yml

This file was deleted.

16 changes: 8 additions & 8 deletions BomberMan/.classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
Expand All @@ -12,14 +13,13 @@
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
10 changes: 5 additions & 5 deletions BomberMan/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
arguments=--init-script /var/folders/wr/g2gmgrxn15bc9gnhdycf5k_r0000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/wr/g2gmgrxn15bc9gnhdycf5k_r0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Users/dallas/Library/Java/JavaVirtualMachines/corretto-11.0.14.1/Contents/Home
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
override.workspace.settings=false
show.console.view=false
show.executions.view=false
7 changes: 4 additions & 3 deletions BomberMan/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.source=17
Binary file modified BomberMan/bin/main/it/bomberman/input/KeyManager.class
Binary file not shown.
Empty file modified BomberMan/gradlew
100644 → 100755
Empty file.
22 changes: 10 additions & 12 deletions BomberMan/src/main/java/it/bomberman/collisions/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import java.util.Collections;
import java.util.List;



public class Body {

public List<Shape> boundingShapes;

public Body() {
this.boundingShapes = new ArrayList<Shape>();
this.boundingShapes = new ArrayList<>();
}

public Body(Shape s) {
Expand All @@ -37,30 +40,25 @@ public boolean checkCollision(List<Shape> otherBoundingShapes) {
return false;
}

boolean out = false;
for (var s : this.boundingShapes) {
for (var otherS : otherBoundingShapes) {
for (Shape s : this.boundingShapes) {
for (Shape otherS : otherBoundingShapes) {
if (s.intersects(otherS)) {
out = true;
return true; // Collision detected, return true immediately
}
}
}
return out;
return false; // No collision detected
}

public List<Shape> getBoundingShapes() {
return Collections.unmodifiableList(this.boundingShapes);
}

public void move(int x, int y) {
for (Shape s : this.boundingShapes) {
s.move(x, y);
}
boundingShapes.forEach(s -> s.move(x, y));
}

public void render(Graphics g, Color color) {
for (Shape s : this.boundingShapes) {
s.render(g, color);
}
boundingShapes.forEach(s -> s.render(g, color));
}
}
19 changes: 6 additions & 13 deletions BomberMan/src/main/java/it/bomberman/entities/AbstractEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import it.bomberman.collisions.Body;
import it.bomberman.collisions.Vector2;

/**
* Classe che reacchiude le i dati che hanno in comune la maggior parte delle Classi che estendono Entity
*(Restano escluse Wall e Explosion)
*/
public abstract class AbstractEntity implements Entity {
protected int x;
protected int y;
protected int width;
protected int height;
protected EntityController controller;
protected Body body;

protected AbstractEntity(int x, int y, int width, int height, EntityController controller) {
this.x = x;
this.y = y;
Expand All @@ -23,17 +19,14 @@ protected AbstractEntity(int x, int y, int width, int height, EntityController c
this.controller = controller;
initBody();
}

/**
* Template method da implementare per assicurare l'inizializzazione del body
*/

protected abstract void initBody();
@Override

@Override
public Body getBody() {
return this.body;
return this.body;
}

@Override
public Vector2 getPosition() {
return Vector2.unmodifiableVector2(new Vector2(x, y));
Expand Down
20 changes: 8 additions & 12 deletions BomberMan/src/main/java/it/bomberman/entities/Bomb.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
import it.bomberman.gfx.Animation;
import it.bomberman.gfx.Assets;

//import org.dyn4j.geometry.Vector2;

public class Bomb extends AbstractEntity implements ICollidable {
public class Bomb extends AbstractEntity {

public static final long DEFAULT_TIMER_LENGTH = (long) 3e+9; // 3s espressi in nano secondi
public static final int DEFAULT_WIDTH = 100;
public static final int DEFAULT_EXPLOSION_EXTENTION = 1;
private static final int SCALE = 2;

private long startTime;
private final long timerLength = DEFAULT_TIMER_LENGTH;
private int exlposionExtention;
private int explosionExtention;
private boolean exploded = false;
private final int SCALE = 2;
private Animation animation;

protected Bomb(int x, int y, int width, int height, EntityController controller) {
Expand All @@ -30,7 +27,7 @@ protected Bomb(int x, int y, int width, int height, EntityController controller)
public Bomb(int x, int y, int explosionExtension, EntityController controller) {
this(x, y, DEFAULT_WIDTH, DEFAULT_WIDTH, controller);
this.exploded = false;
this.exlposionExtention = explosionExtension;
this.explosionExtention = explosionExtension;
this.animation = new Animation(600, Assets.bomb);
this.startTime = System.nanoTime();
}
Expand All @@ -44,23 +41,22 @@ protected void initBody() {
@Override
public void tick() {
long now = System.nanoTime();
if (now - this.startTime > this.timerLength) {
if (now - this.startTime > DEFAULT_TIMER_LENGTH) {
this.explode();
}
this.animation.tick();
}

@Override
public void render(Graphics g) {

// this.body.render(g, Color.BLUE);
g.drawImage(getCurrentAnimationFrame(), this.x-40, this.y-20, this.width * SCALE, this.height * SCALE, null);
g.drawImage(getCurrentAnimationFrame(), this.x - 40, this.y - 20, this.width * SCALE, this.height * SCALE,
null);
}

public void explode() {
this.exploded = true;

this.controller.register(new Explosion(this.x, this.y, this.exlposionExtention, this.controller));
this.controller.register(new Explosion(this.x, this.y, this.explosionExtention, this.controller));
this.dispose();
}

Expand Down
Loading

0 comments on commit c4359a1

Please sign in to comment.