Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/main/java/ru/nsu/fit/dib/projectdib/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.app.scene.Viewport;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.FXGLForKtKt;
import com.almasb.fxgl.dsl.components.HealthIntComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.components.CollidableComponent;
import com.almasb.fxgl.input.UserAction;
import com.almasb.fxgl.input.virtual.VirtualButton;
import com.almasb.fxgl.io.FileSystemService;
import com.almasb.fxgl.pathfinding.CellState;
import com.almasb.fxgl.pathfinding.astar.AStarGrid;
import com.almasb.fxgl.physics.CollisionHandler;
import java.awt.Dimension;
import java.awt.Toolkit;
Expand Down Expand Up @@ -143,6 +148,29 @@ protected void onActionBegin() {
setSkipOther(true);
});
}
if(!isSkipOther()){
getGameWorld().getEntitiesByType(EntityType.GUN)
.stream()
.filter(gun -> gun.hasComponent(CollidableComponent.class) && gun.isColliding(player))
.forEach(gun -> {
spawn(player.getComponent(PlayerMovingComponent.class).getSpecification().getMainWeapon(), player.getCenter().subtract(new Point2D(80,100)));
player.getComponent(PlayerMovingComponent.class).getSpecification().setMainWeapon("gun");
gun.removeFromWorld();
setSkipOther(true);
});
}
if(!isSkipOther()){
getGameWorld().getEntitiesByType(EntityType.SHOTGUN)
.stream()
.filter(shotgun -> shotgun.hasComponent(CollidableComponent.class) && shotgun.isColliding(player))
.forEach(shotgun -> {
spawn(player.getComponent(PlayerMovingComponent.class).getSpecification().getMainWeapon(), player.getCenter().subtract(new Point2D(80,100)));
player.getComponent(PlayerMovingComponent.class).getSpecification().setMainWeapon("shotgun");
shotgun.removeFromWorld();
setSkipOther(true);
});
}

setSkipOther(false);
}
}, KeyCode.F, VirtualButton.X);
Expand Down Expand Up @@ -225,28 +253,5 @@ protected void initGame() {
viewport.setZoom(1.2);
viewport.setLazy(true);



/*
FXGL.setLevelFromMap("tmx/level2.tmx");
Spawn.spawnInitialObjects();
spawn("enemy", 48, 240);
this.player = spawn("player", getAppWidth() / 2, getAppHeight() / 2);
viewport.bindToEntity(player, getAppWidth() / 2, getAppHeight() / 2);
AStarGrid grid = AStarGrid.fromWorld(FXGL.getGameWorld(), FXGLForKtKt.getAppWidth(), getAppHeight(), 25, 25,
(type) -> {
if (type == EntityType.WALL || type == EntityType.CLOSED_DOOR) {
return CellState.NOT_WALKABLE;
}

return CellState.WALKABLE;
});
set("grid", grid);

spawn("ak", 600, 600);
//this.player = spawn("player", 60, 60);
viewport.bindToEntity(player, getAppWidth() / 2, getAppHeight() / 2);
viewport.setLazy(true); */
}

}
2 changes: 2 additions & 0 deletions src/main/java/ru/nsu/fit/dib/projectdib/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Config {
public static String WINDOW_MODE;
public static final javafx.util.Duration SHOOT_DELAY_ARROW = Duration.seconds(0.3);
public static final javafx.util.Duration SHOOT_DELAY_AK = Duration.seconds(0.1);
public static final javafx.util.Duration SHOOT_DELAY_GUN = Duration.seconds(1);
public static final javafx.util.Duration SHOOT_DELAY_SHOTGUN = Duration.seconds(1);



Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ru/nsu/fit/dib/projectdib/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum EntityType {
CHEST("chest"),
BOW("bow"),
AK("ak"),
GUN("gun"),
SHOTGUN("shotgun"),
EXPLOSION("explosion");

private final String name;
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/ru/nsu/fit/dib/projectdib/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Entity newPlayer(SpawnData data) {
WallMapper wallMapper = new WallMapper(64, 16, arr);*/

//////////////
HeroSpecs specs = new HeroSpecs("1", "bow", "ak", 250.0, "player.png");
//HeroSpecs specs = new HeroSpecs("1", "shotgun", "ak",10, 250.0, "player.png");

return entityBuilder()
.from(data)
Expand All @@ -89,7 +89,7 @@ public Entity newPlayer(SpawnData data) {
.bbox(new HitBox(new Point2D(25, 110), BoundingShape.box(160, 160)))
.anchorFromCenter()
.with(physics)
.with(new PlayerMovingComponent(specs))
.with(new PlayerMovingComponent(data.get("specification")))
.with(new CellMoveComponent(25, 25, 250))
.with(new AStarMoveComponent(new LazyValue<>(() -> geto("grid"))))
//.with(new ChunkLoaderComponent(new ChunkLoader(wallMapper)))
Expand Down Expand Up @@ -213,7 +213,7 @@ public Entity newCoin(SpawnData data) {
@Spawns("projectile")
public Entity newProjectile(SpawnData data) {
Entity player = FXGLForKtKt.getGameWorld().getSingleton(EntityType.PLAYER);
Point2D direction = getInput().getMousePositionWorld().subtract(player.getCenter().subtract(new Point2D(60,90)));
Point2D direction = getInput().getMousePositionWorld().subtract(new Point2D(data.get("vert_deflection"),data.get("vert_deflection"))).subtract(player.getCenter().subtract(new Point2D(60,90)));
Projectiles projectile = data.get("typeProj");
return entityBuilder()
.from(data)
Expand All @@ -224,7 +224,6 @@ public Entity newProjectile(SpawnData data) {
.collidable()
.build();
}

@Spawns("bow")
public Entity newBow(SpawnData data) {
return entityBuilder(data)
Expand All @@ -247,6 +246,27 @@ public Entity newAK(SpawnData data) {
.build();
}

@Spawns("gun")
public Entity newGun(SpawnData data) {
return entityBuilder(data)
.from(data)
.type(EntityType.GUN)
.viewWithBBox(texture("gun.png", 25, 20))
.bbox(new HitBox(BoundingShape.box(25,20)))
.with(new CollidableComponent(true))
.build();
}
@Spawns("shotgun")
public Entity newShotgun(SpawnData data) {
return entityBuilder(data)
.from(data)
.type(EntityType.SHOTGUN)
.viewWithBBox(texture("shotgun.png", 80, 50))
.bbox(new HitBox(BoundingShape.box(80,50)))
.with(new CollidableComponent(true))
.build();
}

/**
* Entity Enemy.
*
Expand Down
172 changes: 143 additions & 29 deletions src/main/java/ru/nsu/fit/dib/projectdib/data/HeroSpecs.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,148 @@
package ru.nsu.fit.dib.projectdib.data;

import javax.swing.text.html.parser.Entity;
import java.util.ArrayList;
import java.util.List;

public class HeroSpecs {
private String name;
private String mainWeapon;
private String secondWeapon;
private double speed = 250;
private String playerImage;

public HeroSpecs(String name, String firstWeapon, String secondWeapon, Double speed, String playerImage){
this.name = name;
this.mainWeapon = firstWeapon;
this.secondWeapon = secondWeapon;
this.speed = speed;
this.playerImage = playerImage;
}

public String getPlayerImage() {return playerImage;}
public Double getSpeed() {return speed;}
public String getMainWeapon() {
return mainWeapon;
}
public String getSecondWeapon() {
return secondWeapon;
}

public void setMainWeapon(String newWeapon) {
mainWeapon = newWeapon;
}
public void setSecondWeapon(String newWeapon) {
secondWeapon = newWeapon;
}
private String name;
private String mainWeapon;
private String secondWeapon;
private double speed = 250;
private String playerImage;
private List<Entity> inventory;

private int healthPoints;
private double strength;
private double dexterity;
private double physique;
private double intelligence;
private double wisdom;
private double charisma;

public HeroSpecs(
String name,
String firstWeapon,
String secondWeapon,
int hp,
Double speed,
String playerImage,
double strength,
double dexterity,
double physique,
double intelligence,
double wisdom,
double charisma) {
this.name = name;
this.mainWeapon = firstWeapon;
this.secondWeapon = secondWeapon;
this.healthPoints = hp;
this.speed = speed;
this.playerImage = playerImage;
this.strength = strength;
this.dexterity = dexterity;
this.physique = physique;
this.intelligence = intelligence;
this.wisdom = wisdom;
this.charisma = charisma;
}

public HeroSpecs(
String name,
String firstWeapon,
String secondWeapon,
int hp,
Double speed,
String playerImage) {
this.name = name;
this.mainWeapon = firstWeapon;
this.secondWeapon = secondWeapon;
this.healthPoints = hp;
this.speed = speed;
this.playerImage = playerImage;
}

public String getPlayerImage() {
return playerImage;
}

public Double getSpeed() {
return speed;
}

public String getMainWeapon() {
return mainWeapon;
}

public String getSecondWeapon() {
return secondWeapon;
}

public int getHealthPoints() {
return healthPoints;
}

public double getStrength() {
return strength;
}

public double getDexterity() {
return dexterity;
}

public double getPhysique() {
return physique;
}

public double getIntelligence() {
return intelligence;
}

public double getWisdom() {
return wisdom;
}

public double getCharisma() {
return charisma;
}

public void setHealthPoints(int healthPoints) {
this.healthPoints = healthPoints;
}

public void setStrength(double strength) {
this.strength = strength;
}

public void setDexterity(double dexterity) {
this.dexterity = dexterity;
}

public void setPhysique(double physique) {
this.physique = physique;
}

public void setIntelligence(double intelligence) {
this.intelligence = intelligence;
}

public void setWisdom(double wisdom) {
this.wisdom = wisdom;
}

public void setCharisma(double charisma) {
this.charisma = charisma;
}

public List<Entity> getInventory() {
return new ArrayList<>(inventory);
}

public void setMainWeapon(String newWeapon) {
mainWeapon = newWeapon;
}

public void setSecondWeapon(String newWeapon) {
secondWeapon = newWeapon;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

public enum Projectiles {
ARROW("arrow", 250),
BULLET("bullet", 500);
BULLET("bullet", 400);



private final String name;
private final Integer speed;


Projectiles(String name, Integer speed) {
this.name = name;
this.speed = speed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,43 @@ public void shoot() {
case("bow"):
if (!shootTimer.elapsed(Config.SHOOT_DELAY_ARROW)) return;
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.ARROW));
.put("typeProj", Projectiles.ARROW)
.put("vert_deflection", 0.0));
shootTimer.capture();
break;
case("ak"):
if(!shootTimer.elapsed(Config.SHOOT_DELAY_AK)) return;;
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET));
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", 0.0));
shootTimer.capture();
break;
/*default:
currentWeapon = "bow";
case("gun"):
if(!shootTimer.elapsed(Config.SHOOT_DELAY_GUN)) return;;
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", 0.0));
shootTimer.capture();
break;
case("shotgun"):
if(!shootTimer.elapsed(Config.SHOOT_DELAY_SHOTGUN)) return;;
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", 0.0));
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", 25.0));
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", 50.0));
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", -25.0));
FXGL.spawn("projectile", new SpawnData(getEntity().getPosition().getX()+20,getEntity().getPosition().getY()+30)
.put("typeProj", Projectiles.BULLET)
.put("vert_deflection", -50.0));
shootTimer.capture();
break;
*/
}


Expand Down
Loading