Merge branch 'test' of http://124.70.85.113:3000/wsj/Game into test
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
13
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="game" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
20
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
pom.xml
@@ -54,17 +54,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.badlogicgames.gdx</groupId>
|
<groupId>com.badlogicgames.gdx</groupId>
|
||||||
<artifactId>gdx</artifactId>
|
<artifactId>gdx</artifactId>
|
||||||
<version>${gdx.version}</version>
|
<version>1.12.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.badlogicgames.gdx</groupId>
|
<groupId>com.badlogicgames.gdx</groupId>
|
||||||
<artifactId>gdx-backend-lwjgl3</artifactId>
|
<artifactId>gdx-backend-lwjgl3</artifactId>
|
||||||
<version>${gdx.version}</version>
|
<version>1.12.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.badlogicgames.gdx</groupId>
|
<groupId>com.badlogicgames.gdx</groupId>
|
||||||
<artifactId>gdx-platform</artifactId>
|
<artifactId>gdx-platform</artifactId>
|
||||||
<version>${gdx.version}</version>
|
<version>1.12.1</version>
|
||||||
<classifier>natives-desktop</classifier>
|
<classifier>natives-desktop</classifier>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package uno.mloluyu.characters;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.*;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import uno.mloluyu.util.SimpleFormatter;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
|
||||||
|
public class FighterAnimationManager {
|
||||||
|
private EnumMap<Action, Animation<TextureRegion>> animations = new EnumMap<>(Action.class);
|
||||||
|
private EnumMap<Action, Float> frameDurations = new EnumMap<>(Action.class);
|
||||||
|
private TextureAtlas atlas;
|
||||||
|
private float scaleX = 1.0f;
|
||||||
|
private float scaleY = 1.0f;
|
||||||
|
|
||||||
|
public FighterAnimationManager(TextureAtlas atlas) {
|
||||||
|
this.atlas = atlas;
|
||||||
|
for (Action action : Action.values()) {
|
||||||
|
frameDurations.put(action, 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadAnimation(Action action, String prefix, int count, boolean loop) {
|
||||||
|
Array<TextureRegion> frames = new Array<>();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
String regionName = prefix + SimpleFormatter.addLeadingZeros(i, 3);
|
||||||
|
TextureRegion region = atlas.findRegion(regionName);
|
||||||
|
if (region == null) {
|
||||||
|
throw new IllegalArgumentException("未找到区域: " + regionName);
|
||||||
|
}
|
||||||
|
frames.add(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
Animation<TextureRegion> animation = new Animation<>(frameDurations.get(action), frames);
|
||||||
|
animation.setPlayMode(loop ? Animation.PlayMode.LOOP : Animation.PlayMode.NORMAL);
|
||||||
|
animations.put(action, animation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLooping(Action action, String prefix, int count) {
|
||||||
|
loadAnimation(action, prefix, count, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadOneShot(Action action, String prefix, int count) {
|
||||||
|
loadAnimation(action, prefix, count, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrameDuration(Action action, float duration) {
|
||||||
|
frameDurations.put(action, duration);
|
||||||
|
Animation<TextureRegion> anim = animations.get(action);
|
||||||
|
if (anim != null) anim.setFrameDuration(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFinished(Action action, float stateTime) {
|
||||||
|
Animation<TextureRegion> anim = animations.get(action);
|
||||||
|
return anim != null && anim.isAnimationFinished(stateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(SpriteBatch batch, Action action, float stateTime, Rectangle hitbox, boolean isFacingRight) {
|
||||||
|
Animation<TextureRegion> anim = animations.get(action);
|
||||||
|
if (anim == null) return;
|
||||||
|
|
||||||
|
TextureRegion frame = anim.getKeyFrame(stateTime, anim.getPlayMode() == Animation.PlayMode.LOOP);
|
||||||
|
if (frame == null) return;
|
||||||
|
|
||||||
|
float frameWidth = frame.getRegionWidth() * scaleX;
|
||||||
|
float frameHeight = frame.getRegionHeight() * scaleY;
|
||||||
|
float drawX = hitbox.x + (hitbox.width - frameWidth) / 2;
|
||||||
|
float drawY = hitbox.y;
|
||||||
|
|
||||||
|
boolean wasFlippedX = frame.isFlipX();
|
||||||
|
frame.flip(!isFacingRight && !wasFlippedX, false);
|
||||||
|
frame.flip(isFacingRight && wasFlippedX, false);
|
||||||
|
|
||||||
|
batch.draw(frame, drawX, drawY, frameWidth / 2, frameHeight / 2, frameWidth, frameHeight, 1f, 1f, 0f);
|
||||||
|
frame.flip(wasFlippedX != frame.isFlipX(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
if (atlas != null) atlas.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,33 +2,52 @@ package uno.mloluyu.desktop;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.InputProcessor;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import uno.mloluyu.characters.AdvancedFighter;
|
||||||
|
import uno.mloluyu.network.NetworkManager;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.ScreenAdapter;
|
import com.badlogic.gdx.ScreenAdapter;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
|
||||||
import uno.mloluyu.characters.AdvancedFighter;
|
|
||||||
import uno.mloluyu.characters.SimpleFighter;
|
import uno.mloluyu.characters.SimpleFighter;
|
||||||
import uno.mloluyu.network.NetworkManager;
|
|
||||||
import uno.mloluyu.util.ClearScreen;
|
import uno.mloluyu.util.ClearScreen;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static uno.mloluyu.util.Font.loadChineseFont;
|
import static uno.mloluyu.util.Font.loadChineseFont;
|
||||||
|
|
||||||
public class CharacterSelectScreen extends ScreenAdapter {
|
public class CharacterSelectScreen extends ScreenAdapter implements InputProcessor {
|
||||||
private boolean multiplayerMode = false; // 默认为单人模式
|
private boolean multiplayerMode = false; // 默认为单人模式
|
||||||
|
|
||||||
private final MainGame game;
|
private final MainGame game;
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
private ShapeRenderer shapeRenderer;
|
private ShapeRenderer shapeRenderer;
|
||||||
|
private SimpleFighter selectedFighter1;
|
||||||
|
private SimpleFighter selectedFighter2;
|
||||||
|
|
||||||
|
private final List<Texture> bgs = Arrays.asList(
|
||||||
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/10b_back_blue2p.png")),
|
||||||
|
//new Texture(Gdx.files.internal("src/main/resources/selectpage/back_door.png")),
|
||||||
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/11b_back_red1p.png"))
|
||||||
|
);
|
||||||
|
private final List<Texture> charsTexts = Arrays.asList(
|
||||||
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_03.png")),
|
||||||
|
new Texture(Gdx.files.internal("src/main/resources/selectpage/character_00.png"))
|
||||||
|
);
|
||||||
private final List<String> characters = Arrays.asList("Alice", "Reimu", "暂定");
|
private final List<String> characters = Arrays.asList("Alice", "Reimu", "暂定");
|
||||||
private int selectedIndex = -1;
|
private Texture profile1p = charsTexts.get(0);
|
||||||
|
private Texture profile2p = charsTexts.get(1);
|
||||||
|
private Texture selectText;
|
||||||
|
|
||||||
|
private static int selectedIndex = 0;
|
||||||
|
private static boolean is1P = true;
|
||||||
|
|
||||||
private static final int BUTTON_WIDTH = 300;
|
private static final int BUTTON_WIDTH = 300;
|
||||||
private static final int BUTTON_HEIGHT = 80;
|
private static final int BUTTON_HEIGHT = 80;
|
||||||
@@ -38,6 +57,7 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
|
|
||||||
public CharacterSelectScreen(MainGame game) {
|
public CharacterSelectScreen(MainGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMultiplayerMode(boolean multiplayerMode) {
|
public void setMultiplayerMode(boolean multiplayerMode) {
|
||||||
@@ -59,10 +79,9 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
|
|
||||||
int mouseX = Gdx.input.getX();
|
int mouseX = Gdx.input.getX();
|
||||||
int mouseY = Gdx.graphics.getHeight() - Gdx.input.getY();
|
int mouseY = Gdx.graphics.getHeight() - Gdx.input.getY();
|
||||||
|
renderBackground();
|
||||||
renderCharacters(mouseX, mouseY);
|
renderCharacters(multiplayerMode);
|
||||||
renderButtons(mouseX, mouseY);
|
// renderTexts();
|
||||||
renderTexts();
|
|
||||||
|
|
||||||
handleInput(mouseX, mouseY);
|
handleInput(mouseX, mouseY);
|
||||||
if (multiplayerMode) {
|
if (multiplayerMode) {
|
||||||
@@ -78,121 +97,133 @@ public class CharacterSelectScreen extends ScreenAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderCharacters(int mouseX, int mouseY) {
|
private void renderBackground() {
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
|
||||||
int x = 200;
|
|
||||||
int y = 500 - i * 120;
|
|
||||||
boolean hovered = isHovered(mouseX, mouseY, x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
|
||||||
shapeRenderer.setColor(selectedIndex == i ? Color.GREEN : (hovered ? Color.LIGHT_GRAY : Color.DARK_GRAY));
|
|
||||||
shapeRenderer.rect(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
|
||||||
}
|
|
||||||
shapeRenderer.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderButtons(int mouseX, int mouseY) {
|
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
drawButton(CONFIRM_Y, mouseX, mouseY, "确认");
|
|
||||||
drawButton(BACK_Y, mouseX, mouseY, "返回");
|
|
||||||
shapeRenderer.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderTexts() {
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
font.draw(batch, "选择你的角色", 200, 650);
|
for (int i = 0; i < bgs.size(); i ++) {
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
batch.draw(bgs.get(i), 0, 528 * i, 1920, 528);
|
||||||
int x = 200 + 30;
|
|
||||||
int y = 500 - i * 120 + 50;
|
|
||||||
font.draw(batch, characters.get(i), x, y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (selectedIndex != -1) {
|
|
||||||
font.draw(batch, "已选择: " + characters.get(selectedIndex), 200, 100);
|
|
||||||
}
|
|
||||||
drawButtonText(CONFIRM_Y, "确认");
|
|
||||||
drawButtonText(BACK_Y, "返回");
|
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawButton(int y, int mouseX, int mouseY, String label) {
|
private void renderCharacters(boolean multiplayerMode) {
|
||||||
boolean hovered = isHovered(mouseX, mouseY, BUTTON_X, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
batch.begin();
|
||||||
shapeRenderer.setColor(hovered ? Color.LIGHT_GRAY : Color.DARK_GRAY);
|
batch.draw(profile1p, 0, 0, profile1p.getWidth()*3, profile1p.getHeight()*3);
|
||||||
shapeRenderer.rect(BUTTON_X, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
batch.draw(profile2p, 0, 528, profile2p.getWidth()*3, profile2p.getHeight()*3);
|
||||||
}
|
batch.end();
|
||||||
|
|
||||||
private void drawButtonText(int y, String text) {
|
|
||||||
float textX = BUTTON_X + BUTTON_WIDTH / 2f - font.getScaleX() * text.length() * 10;
|
|
||||||
float textY = y + BUTTON_HEIGHT / 2f + 20;
|
|
||||||
font.draw(batch, text, textX, textY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isHovered(int x, int y, int bx, int by, int bw, int bh) {
|
|
||||||
return x >= bx && x <= bx + bw && y >= by && y <= by + bh;
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// private void renderTexts() {
|
||||||
|
// batch.begin();
|
||||||
|
// font.draw(batch, "选择你的角色", 200, 650);
|
||||||
|
// for (int i = 0; i < characters.size(); i++) {
|
||||||
|
// int x = 200 + 30;
|
||||||
|
// int y = 500 - i * 120 + 50;
|
||||||
|
// font.draw(batch, characters.get(i), x, y);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// if (selectedIndex != -1) {
|
||||||
|
// font.draw(batch, "已选择: " + characters.get(selectedIndex), 200, 100);
|
||||||
|
// }
|
||||||
|
// drawButtonText(CONFIRM_Y, "确认");
|
||||||
|
// drawButtonText(BACK_Y, "返回");
|
||||||
|
// batch.end();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
private void handleInput(int mouseX, int mouseY) {
|
private void handleInput(int mouseX, int mouseY) {
|
||||||
if (Gdx.input.justTouched()) {
|
if (selectedFighter1 != null && selectedFighter2 != null) {
|
||||||
// 检查是否点击了角色按钮
|
if (multiplayerMode) {
|
||||||
for (int i = 0; i < characters.size(); i++) {
|
// 设置唯一玩家 ID 并发送角色选择
|
||||||
int x = 200;
|
if (NetworkManager.getInstance().getLocalPlayerId() == null) {
|
||||||
int y = 500 - i * 120;
|
String playerId = UUID.randomUUID().toString();
|
||||||
if (isHovered(mouseX, mouseY, x, y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
NetworkManager.getInstance().setLocalPlayerId(playerId);
|
||||||
selectedIndex = i;
|
Gdx.app.log("Network", "设置玩家ID: " + playerId);
|
||||||
Gdx.app.log("Character", "选择了角色: " + characters.get(i));
|
|
||||||
return; // 防止同时触发其他按钮
|
|
||||||
}
|
}
|
||||||
|
NetworkManager.getInstance().sendCharacterSelection(selectedFighter1.getName());
|
||||||
}
|
}
|
||||||
|
game.setScreen(new GameScreen(game, selectedFighter1));
|
||||||
// 点击确认按钮
|
|
||||||
if (isHovered(mouseX, mouseY, BUTTON_X, CONFIRM_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
|
||||||
if (selectedIndex != -1) {
|
|
||||||
String selectedCharacter = characters.get(selectedIndex);
|
|
||||||
Gdx.app.log("Character", "确认角色: " + selectedCharacter);
|
|
||||||
|
|
||||||
SimpleFighter fighter = null;
|
|
||||||
switch (selectedCharacter) {
|
|
||||||
case "Alice":
|
|
||||||
case "Reimu":
|
|
||||||
fighter = new AdvancedFighter(selectedCharacter);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fighter = new SimpleFighter(selectedCharacter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fighter != null) {
|
|
||||||
if (multiplayerMode) {
|
|
||||||
NetworkManager nm = NetworkManager.getInstance();
|
|
||||||
// 主机或客户端的 localPlayerId 应该已经在 NetworkSettingsScreen 设置,这里兜底
|
|
||||||
if (nm.getLocalPlayerId() == null) {
|
|
||||||
String playerId = UUID.randomUUID().toString();
|
|
||||||
nm.setLocalPlayerId(playerId);
|
|
||||||
Gdx.app.log("Network", "兜底设置玩家ID: " + playerId);
|
|
||||||
}
|
|
||||||
if (nm.isConnected()) {
|
|
||||||
nm.sendCharacterSelection(selectedCharacter);
|
|
||||||
// 发送初始位置(角色生成初始 hitbox 坐标)
|
|
||||||
nm.sendPosition(fighter.getHitbox().x, fighter.getHitbox().y);
|
|
||||||
} else {
|
|
||||||
Gdx.app.log("Network", "未连接网络,无法发送角色选择");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game.setScreen(new GameScreen(game, fighter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 点击返回按钮
|
|
||||||
if (isHovered(mouseX, mouseY, BUTTON_X, BACK_Y, BUTTON_WIDTH, BUTTON_HEIGHT)) {
|
|
||||||
Gdx.app.log("Character", "返回主菜单");
|
|
||||||
game.setScreen(new MainMenuScreen(game));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
font.dispose();
|
font.dispose();
|
||||||
shapeRenderer.dispose();
|
shapeRenderer.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int i) {
|
||||||
|
boolean value = false;
|
||||||
|
if (!multiplayerMode) {
|
||||||
|
if (i == Input.Keys.LEFT || i == Input.Keys.RIGHT) {
|
||||||
|
selectText = charsTexts.get(selectedIndex);
|
||||||
|
selectedIndex = (selectedIndex + 1) % charsTexts.size();
|
||||||
|
if (is1P) {
|
||||||
|
profile1p = selectText;
|
||||||
|
} else {
|
||||||
|
profile2p = selectText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
//占坑说是
|
||||||
|
}
|
||||||
|
if (i == Input.Keys.Z) {
|
||||||
|
if (is1P) {
|
||||||
|
selectedFighter1 = new AdvancedFighter(characters.get(selectedIndex));
|
||||||
|
} else {
|
||||||
|
selectedFighter2 = new AdvancedFighter(characters.get(selectedIndex));
|
||||||
|
}
|
||||||
|
is1P = false;
|
||||||
|
selectedIndex = 1;
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
if (i == Input.Keys.ESCAPE) {
|
||||||
|
Gdx.app.log("Character", "返回主菜单");
|
||||||
|
game.setScreen(new MainMenuScreen(game));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int i) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchCancelled(int i, int i1, int i2, int i3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int i, int i1, int i2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int i, int i1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(float v, float v1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.ScreenAdapter;
|
import com.badlogic.gdx.ScreenAdapter;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
@@ -18,17 +19,20 @@ public class MainMenuScreen extends ScreenAdapter {
|
|||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
private ShapeRenderer shapeRenderer;
|
private ShapeRenderer shapeRenderer;
|
||||||
|
private Texture texture;
|
||||||
|
|
||||||
// 按钮区域
|
// 按钮区域
|
||||||
private final int buttonWidth = 400;
|
private final int buttonWidth = 600;
|
||||||
private final int buttonHeight = 80;
|
private final int buttonHeight = 80;
|
||||||
private final int buttonX = 760;
|
private final int buttonX = 760;
|
||||||
private final int startY = 600;
|
private final int startY = 600;
|
||||||
private final int settingsY = 480;
|
private final int settingsY = 480;
|
||||||
private final int networkY = 360;
|
private final int networkY = 360;
|
||||||
|
private final int escY = 240;
|
||||||
|
|
||||||
public MainMenuScreen(MainGame game) {
|
public MainMenuScreen(MainGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
texture = new Texture(Gdx.files.internal("src\\main\\resources\\bg.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +46,7 @@ public class MainMenuScreen extends ScreenAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
Gdx.gl.glClearColor(0.75F, 1, 0.98F, 1);
|
Gdx.gl.glClearColor(0,0,0,0);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
int mouseX = Gdx.input.getX();
|
int mouseX = Gdx.input.getX();
|
||||||
@@ -53,13 +57,16 @@ public class MainMenuScreen extends ScreenAdapter {
|
|||||||
drawButtonBox(startY, "开始游戏", mouseX, mouseY);
|
drawButtonBox(startY, "开始游戏", mouseX, mouseY);
|
||||||
drawButtonBox(settingsY, "设置", mouseX, mouseY);
|
drawButtonBox(settingsY, "设置", mouseX, mouseY);
|
||||||
drawButtonBox(networkY, "联网设置", mouseX, mouseY);
|
drawButtonBox(networkY, "联网设置", mouseX, mouseY);
|
||||||
|
drawButtonBox(escY, "退出游戏", mouseX, mouseY);
|
||||||
shapeRenderer.end();
|
shapeRenderer.end();
|
||||||
|
|
||||||
// 绘制按钮文字
|
// 绘制按钮文字
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
batch.draw(texture, 0, 0, 1920, 1080);
|
||||||
drawButtonText(startY, "开始游戏");
|
drawButtonText(startY, "开始游戏");
|
||||||
drawButtonText(settingsY, "设置");
|
drawButtonText(settingsY, "设置");
|
||||||
drawButtonText(networkY, "联网设置");
|
drawButtonText(networkY, "联网设置");
|
||||||
|
drawButtonText(escY, "退出游戏");
|
||||||
batch.end();
|
batch.end();
|
||||||
|
|
||||||
// 点击事件
|
// 点击事件
|
||||||
@@ -72,6 +79,8 @@ public class MainMenuScreen extends ScreenAdapter {
|
|||||||
} else if (isTouched(mouseX, mouseY, buttonX, networkY)) {
|
} else if (isTouched(mouseX, mouseY, buttonX, networkY)) {
|
||||||
Gdx.app.log("Button", "联网设置按钮被点击!");
|
Gdx.app.log("Button", "联网设置按钮被点击!");
|
||||||
game.setScreen(new NetworkSettingsScreen(game));
|
game.setScreen(new NetworkSettingsScreen(game));
|
||||||
|
} else if (isTouched(mouseX, mouseY, buttonX, escY)) {
|
||||||
|
Gdx.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class StartScreen implements Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.gl.glClearColor(0.75F, 1, 0.98F, 1);
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
batch.begin();
|
batch.begin();
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import com.badlogic.gdx.InputAdapter;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import uno.mloluyu.characters.SimpleFighter;
|
import uno.mloluyu.characters.SimpleFighter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class FighterController extends InputAdapter {
|
public class FighterController extends InputAdapter {
|
||||||
private final SimpleFighter fighter;
|
private final SimpleFighter fighter;
|
||||||
private final Array<Integer> pressedKeys = new Array<>();
|
private final Array<Integer> pressedKeys = new Array<>();
|
||||||
|
private final Map<Integer, Float> keyPressDuration = new HashMap<>();
|
||||||
|
|
||||||
public FighterController(SimpleFighter fighter) {
|
public FighterController(SimpleFighter fighter) {
|
||||||
this.fighter = fighter;
|
this.fighter = fighter;
|
||||||
@@ -19,34 +23,44 @@ public class FighterController extends InputAdapter {
|
|||||||
public void update(float deltaTime) {
|
public void update(float deltaTime) {
|
||||||
if (fighter == null)
|
if (fighter == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int keycode : pressedKeys) {
|
for (int keycode : pressedKeys) {
|
||||||
fighter.handleInput(keycode, true); // 持续按下的键,每帧触发
|
float currentDuration = keyPressDuration.getOrDefault(keycode, 0f);
|
||||||
|
currentDuration += deltaTime;
|
||||||
|
keyPressDuration.put(keycode, currentDuration);
|
||||||
|
fighter.handleInput(keycode, true, currentDuration); // 持续按下的键,传递持续时间
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode) {
|
public boolean keyDown(int keycode) {
|
||||||
|
// System.out.println("按键按下: " + keycode);
|
||||||
if (fighter == null)
|
if (fighter == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!pressedKeys.contains(keycode, false)) {
|
if (!pressedKeys.contains(keycode, false)) {
|
||||||
pressedKeys.add(keycode);
|
pressedKeys.add(keycode);
|
||||||
|
keyPressDuration.put(keycode, 0f); // 初始化按键持续时间
|
||||||
}
|
}
|
||||||
|
|
||||||
fighter.handleInput(keycode, true); // 按下事件
|
fighter.handleInput(keycode, true, 0f); // 按下事件,初始持续时间为 0
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
public boolean keyUp(int keycode) {
|
||||||
|
// System.out.println("按键松开: " + keycode);
|
||||||
|
|
||||||
if (fighter == null)
|
if (fighter == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
float duration = keyPressDuration.getOrDefault(keycode, 0f);
|
||||||
pressedKeys.removeValue(keycode, false);
|
pressedKeys.removeValue(keycode, false);
|
||||||
|
keyPressDuration.remove(keycode);
|
||||||
|
|
||||||
fighter.handleInput(keycode, false); // 按键松开事件
|
fighter.handleInput(keycode, false, duration); // 按键松开事件,传递持续时间
|
||||||
return true;
|
return true;
|
||||||
}
|
}// 松开事件
|
||||||
|
|
||||||
public SimpleFighter getFighter() {
|
public SimpleFighter getFighter() {
|
||||||
return fighter;
|
return fighter;
|
||||||
|
|||||||
BIN
src/main/resources/bg.png
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 29 KiB |
BIN
src/main/resources/selectpage/10b_back_blue2p.png
Normal file
|
After Width: | Height: | Size: 440 KiB |
BIN
src/main/resources/selectpage/11b_back_red1p.png
Normal file
|
After Width: | Height: | Size: 440 KiB |
BIN
src/main/resources/selectpage/back_door.png
Normal file
|
After Width: | Height: | Size: 320 KiB |
BIN
src/main/resources/selectpage/character_00.png
Normal file
|
After Width: | Height: | Size: 576 KiB |
BIN
src/main/resources/selectpage/character_03.png
Normal file
|
After Width: | Height: | Size: 384 KiB |
|
Before Width: | Height: | Size: 2.3 MiB |
|
Before Width: | Height: | Size: 3.0 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
@@ -1,24 +0,0 @@
|
|||||||
uiskin.png
|
|
||||||
format: RGBA8888
|
|
||||||
filter: Nearest,Nearest
|
|
||||||
repeat: none
|
|
||||||
button-up
|
|
||||||
rotate: false
|
|
||||||
xy: 0, 0
|
|
||||||
size: 200, 60
|
|
||||||
split: 10, 10, 10, 10
|
|
||||||
orig: 200, 60
|
|
||||||
offset: 0, 0
|
|
||||||
button-down
|
|
||||||
rotate: false
|
|
||||||
xy: 0, 60
|
|
||||||
size: 200, 60
|
|
||||||
split: 10, 10, 10, 10
|
|
||||||
orig: 200, 60
|
|
||||||
offset: 0, 0
|
|
||||||
white
|
|
||||||
rotate: false
|
|
||||||
xy: 0, 120
|
|
||||||
size: 1, 1
|
|
||||||
orig: 1, 1
|
|
||||||
offset: 0, 0
|
|
||||||