Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change player type #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
target
*.log
shooter.iml
`
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved

# Assets
src/main/resources/**/*.png
src/main/resources/**/*.ogg
src/main/resources/**/*.fnt

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишнее

# XML Files
nbactions.xml
nb-configuration.xml

19 changes: 19 additions & 0 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
<netbeans.hint.jdkPlatform>JDK_11.0.2</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
49 changes: 49 additions & 0 deletions nbactions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишнее

<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath aunmag.shooter.game.client.App mvn clean compile &amp;&amp; mvn compile exec:java</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>"/home/fedot/Рабочий стол/Files/shooter"</exec.workingdir>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath aunmag.shooter.game.client.App mvn clean compile &amp;&amp; mvn compile exec:java</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
<exec.workingdir>"/home/fedot/Рабочий стол/Files/shooter"</exec.workingdir>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath aunmag.shooter.game.client.App mvn clean compile &amp;&amp; mvn compile exec:java</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>"/home/fedot/Рабочий стол/Files/shooter"</exec.workingdir>
</properties>
</action>
</actions>
5 changes: 4 additions & 1 deletion src/main/java/aunmag/shooter/game/ai/Ai.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aunmag.shooter.game.ai;

import java.util.Arrays;
import aunmag.shooter.core.math.CollisionCC;
import aunmag.shooter.core.utilities.Operative;
import aunmag.shooter.core.utilities.TimeFlow;
Expand Down Expand Up @@ -67,7 +68,9 @@ private void searchTarget() {
memoryTarget.forget();

for (Actor actor: subject.world.getActors().all) {
if (actor.isAlive() && actor.type == ActorType.human) {
if (actor.isAlive()
&& Arrays.asList(
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
ActorType.playableTypes).contains(actor.type)) {
memoryTarget.setActor(actor);
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/aunmag/shooter/game/client/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import org.lwjgl.glfw.GLFW

class Player(world: World) {

val actor = Actor(ActorType.human, world, 0f, 0f, -UtilsMath.PIx0_5.toFloat())
private val blackout = Blackout(actor)
var actor = Actor(ActorType.human, world, 0f, 0f,
-UtilsMath.PIx0_5.toFloat())
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
private var blackout = Blackout(actor)

init {
actor.weapon = Weapon(world, WeaponType.pm)
actor.weapon = Weapon(world, actor.type.primaryWeaponType)
world.actors.all.add(actor)
App.getCamera().mount.holder = actor.body.position
}
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/aunmag/shooter/game/client/states/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@ import aunmag.shooter.core.input.Input
import aunmag.shooter.core.utilities.UtilsGraphics
import aunmag.shooter.game.client.App
import aunmag.shooter.game.client.Player
import aunmag.shooter.game.environment.actor.Actor
import aunmag.shooter.game.environment.weapon.Weapon
import aunmag.shooter.game.client.graphics.CameraShaker
import aunmag.shooter.game.client.graphics.Crosshair
import aunmag.shooter.game.environment.World
import aunmag.shooter.game.client.states.ScenarioStatus;
import aunmag.shooter.game.scenarios.ScenarioEncircling
import aunmag.shooter.game.scenarios.Scenario
import aunmag.shooter.game.ux.Hud
import org.lwjgl.glfw.GLFW

class Game {

val world = World()
val player = Player(world)
private val scenario = ScenarioEncircling(world)
private val crosshair = Crosshair(player.actor) // TODO: Change implementation
private val hud = Hud()
val world: World = World()
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
val player: Player = Player(world)
val crosshair: Crosshair = Crosshair(player.actor) // TODO: Change implementation
private val scenario: Scenario = ScenarioEncircling(world)
private val hud: Hud = Hud()

init {
// When creating an instance:
// Change player's type to the selected one
player.actor.setType(ScenarioStatus.scenarioEncircling.actorType);
// Change player's weapon to the primary weapon of current player's type
player.actor.setWeapon(
Weapon(player.actor.world,
player.actor.type.primaryWeaponType
)
);
}

fun resume() {
world.playSounds()
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/aunmag/shooter/game/client/states/Pause.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import org.joml.Vector4f

class Pause {

val buttonContinue = Button(4, 7, 4, 1, "Continue", Button.ACTION_BACK)
val buttonContinue = Button(4, 6, 4, 1, "Continue", Button.ACTION_BACK)
private val theme = UtilsAudio.getOrCreateSoundOgg("sounds/music/menu")

val settingsPage: SettingsPage = SettingsPage()

init {
theme.setIsLooped(true)
buttonContinue.isEnabled = false
Expand All @@ -43,7 +45,9 @@ class Pause {

page.add(version)
page.add(buttonContinue)
page.add(Button(4, 8, 4, 1, "New game") { App.main.newGame() })
page.add(Button(4, 7, 4, 1, "New game") { App.main.newGame() })
page.add(Button(4, 8, 4, 1, "Settings",
settingsPage.createPageSettings()::open))
page.add(Button(4, 9, 4, 1, "Help", createPageHelp()::open))
page.add(Button(4, 10, 4, 1, "Exit", createPageExit()::open))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package aunmag.shooter.game.client.states;

import aunmag.shooter.game.environment.actor.ActorType;

public class ScenarioStatus {
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
// Selected player type in the current scenario
public ActorType actorType = ActorType.human;

/* Statuses for each scenario */

// Scenario Encircling
public static final ScenarioStatus scenarioEncircling =
new ScenarioStatus();
}
113 changes: 113 additions & 0 deletions src/main/java/aunmag/shooter/game/client/states/SettingsPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package aunmag.shooter.game.client.states;

import aunmag.shooter.core.gui.font.FontStyle;
import aunmag.shooter.core.structures.Texture;
import aunmag.shooter.core.gui.Button;
import aunmag.shooter.core.gui.Label;
import aunmag.shooter.core.gui.Page;
import aunmag.shooter.game.client.App;
import aunmag.shooter.game.environment.actor.ActorType;

public class SettingsPage {
// ScenarioEncircling actorType select buttons
private final Button[] actorSelectButtons = {
new Button(5, 2, 1, 1, "Classic", () -> {
changeActorTypeOrAccept(0,
ScenarioStatus.scenarioEncircling,
ActorType.human);
}),
new Button(7, 2, 1, 1, "Cowboy", () -> {
changeActorTypeOrAccept(1,
ScenarioStatus.scenarioEncircling,
ActorType.humanCowboy);
}),
};

public SettingsPage() {
// The first type is initially selected
actorSelectButtons[0].setEnabled(false);
}

public Page createPageSettings() {
Texture wallpaper = Texture.getOrCreate(
"images/wallpapers/main_menu", Texture.Type.WALLPAPER
);
Page page = new Page(wallpaper);
FontStyle style = FontStyle.LABEL_LIGHT;

page.add(new Label(5, 1, 2, 1, "Settings"));
page.add(new Label(3, 2, 1, 1, "Select Player", style));
for (Button button : actorSelectButtons) {
page.add(button);
}

page.add(new Button(4, 10, 4, 1, "Back", Button.ACTION_BACK));

return page;
}

// Either change the actor or opens a confirmation page
public void changeActorTypeOrAccept(
// `actorSelectButtons` index of button, that will be unavaliable
int indexOfUnavaliableButton,
ScenarioStatus scenarioStatus,
ActorType newActorType
) {
if (App.main.getGame() != null) {
createActorChangeConfirmingPage(
indexOfUnavaliableButton,
scenarioStatus,
newActorType
).open();
} else {
changeActorType(scenarioStatus, newActorType);
setUnavaliableButton(indexOfUnavaliableButton);
}
}

public Page createActorChangeConfirmingPage(
int indexOfUnavaliableButton,
ScenarioStatus scenarioStatus,
ActorType newType
) {
Texture wallpaper = Texture.getOrCreate(
"images/wallpapers/main_menu", Texture.Type.WALLPAPER
);
Page page = new Page(wallpaper);
page.add(new Label(5, 1, 1, 1,
"When you change the character, the current game will be lost"));
page.add(new Label(5, 2, 1, 1, "Continue?"));

page.add(new Button(4, 4, 2, 1, "Yes", () -> {
App.main.endGame();
changeActorType(scenarioStatus, newType);
setUnavaliableButton(indexOfUnavaliableButton);
Button.ACTION_BACK.run();
}));
page.add(new Button(6, 4, 2, 1, "No", Button.ACTION_BACK));

return page;
}

private void changeActorType(
ScenarioStatus scenarioStatus,
ActorType newType
) {
scenarioStatus.actorType = newType;
if (App.main.getGame() != null) {
App.main.getGame().getPlayer().getActor().setType(newType);
}
}

// Sets the button pressed in `actorSelectButtons`
public void setUnavaliableButton(int index) {
for (int i = 0; i < actorSelectButtons.length; i++) {
Button curButton = actorSelectButtons[i];
if (index != i) {
curButton.setEnabled(true);
} else {
curButton.setEnabled(false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class Actor extends Operative {

private static final int[] samples = new int[6];

public ActorType type;
public final World world;
public final ActorType type;
public final BodyCircle body;
public final Kinetics kinetics;
private float health = 1.0f;
Expand Down Expand Up @@ -301,6 +301,10 @@ public void setWeapon(Weapon weapon) {
this.weapon = weapon;
}

public void setType(ActorType type) {
FedotSoldier marked this conversation as resolved.
Show resolved Hide resolved
this.type = type;
}

/* Getters */

public float getHealth() {
Expand Down
Loading