Здоровье врага уменьшается до единицы, но не до нуля, поэтому анимация смерти не срабатывает.JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Здоровье врага уменьшается до единицы, но не до нуля, поэтому анимация смерти не срабатывает.

Сообщение Anonymous »

Я не уверен, что не так с моим кодом, я не могу понять, проблема ли это в коллизии или в проблеме врага. В любом случае я проверил отладку, и здоровье врага становится равным единице, а не 0, и не вызывает мою анимацию смерти.
Основной код эскиза:

Код: Выделить всё

// Gloabal key control
boolean up, down, left, right;
PVector upAcc = new PVector(0, -1);
PVector downAcc = new PVector(0, 1);
PVector leftAcc = new PVector(-1, 0);
PVector rightAcc = new PVector(1, 0);

// game state
final int START_SCREEN = 0;
final int CUTSCENE = 1;
final int GAMEPLAY = 2;
final int INSTRUCTIONS = 3;
final int VICTORY = 4;
final int CONTROLS = 5;

// back button
int backBtnX = 40;
int backBtnY = 430;
int backBtnW = 90;
int backBtnH = 30;
String backBtnLabel = "Back";

int state = START_SCREEN;
PFont font;
PImage startScreenImg, secondaryScreenImg;

int currentWave = 0;
boolean bossSpawned = false;
int wave = 0;
boolean waveComplete = false;

float lastShotTime = 0;

ArrayList enemies = new ArrayList(); // create array list for basic enemy
Player player;
BossEnemy boss;
Cutscene cutscene;
StartScreen startScreen;

void setup() {
size(500, 500);

startScreenImg = loadImage("start_screen.png");
secondaryScreenImg = loadImage("secondary_screen.png");
startScreen = new StartScreen(startScreenImg, "Outlaw Striker");
cutscene = new Cutscene("Wave " + wave, 200);
player = new Player(new PVector(width / 2, height / 4), 25, 30, 30); // Player at center, and bottom of screen
spawnEnemies(wave);

boss = null;

spawnEnemies(currentWave);
waveComplete = false;
bossSpawned = false;

// Add some enemies to the list
for (int i = 0; i < 5; i++) {
PVector pos = new PVector(random(width), random(height));
enemies.add(new ChickEnemy(pos, 1, 50, 50)); // health, width, height
println("spanwed chickenemy with health 5 at posistion: " + pos);
}

font = createFont("Bleeding_Cowboys.ttf", 40);
}

void draw() {
background(249, 179, 132);

if (state == START_SCREEN) { // start screen
startScreen.startDraw();
}

if (state == CUTSCENE) {
cutscene.update(); // update, display cutscene

if (!cutscene.isCutsceneActive()) {
wave += 1;
state = 2; // move to gameplay state when cutscene ends
spawnEnemies(wave);
}
}

if (state == GAMEPLAY) {
player.update();
player.drawMe();
player.checkProjectileCollisionsBasE(enemies);
player.checkPlayerEnemyCollisions(enemies);
player.displayHealth();
player.checkFiring();

checkWaveCompletion();

// stop after 3 waves
if (wave >= 3 && !bossSpawned && enemies.isEmpty()) {
bossSpawned = true;
boss = new BossEnemy(new PVector(width / 2, 100), 15, 100, 100);

fill(225);
cutscene = new Cutscene("There can only be one sheriff in this town...", 200);
cutscene.start();
state = 1;
}

if (boss != null) {
boss.update();
boss.drawMe();
boss.displayHealth();
}

// Display and update each enemy
for (int i = enemies.size() - 1; i >= 0; i--) {
ChickEnemy enemy = enemies.get(i);
enemy.update();
enemy.drawMe();
}

// handle player projectile
for (int i = player.pProjectiles.size() - 1; i >= 0; i--) {
Projectile p = player.pProjectiles.get(i);
p.update();
p.drawProjectile();

// Check if the projectile is off-screen
if (p.isOffScreen()) {
player.pProjectiles.remove(i);  // Remove the projectile if it's off-screen
}
}

// handle boss projectile
if (boss != null){
for (int i = boss.bProjectiles.size() - 1; i >= 0; i--) {
Projectile p = boss.bProjectiles.get(i);
p.update();
p.drawProjectile();

// Check if the projectile is off-screen
if (p.isOffScreen()) {
boss.bProjectiles.remove(i);  // Remove the projectile if it's off-screen
}
}
}

checkProjectileCollisions();

// display wave info
fill(255, 0, 0);  // Red color for health text
textSize(20);   // Set font size
textAlign(LEFT, TOP);
text("Wave: " + wave, 10, 40);  // Display health in top-left corner
}

if (player.health = 500) {
player.fireProjectile();
lastShotTime = millis();
}
}

void keyReleased() {
if (keyCode == LEFT) left = false;
if (keyCode == UP) up = false;
if (keyCode == DOWN) down = false;
if (keyCode == RIGHT) right = false;
}

void mousePressed() {
// check back button
if ((state == INSTRUCTIONS || state == CONTROLS) &&
mouseX >= backBtnX && mouseX = backBtnY && mouseY = 0; i--) {
Projectile p = player.pProjectiles.get(i);

// If the projectile is from the player, check for collisions with enemies
// Check collision with basic enemies
for (int j = enemies.size() - 1; j >= 0; j--) {
ChickEnemy enemy = enemies.get(j);
if (p.hit(enemy)) {
enemy.health -= 1;
if (enemy.health = frameDelay) {
frameTimer = 0;
currentFrame++;
if (currentFrame >= 4) {
currentFrame = 0;
}
}
}

}

@Override
void drawMe() {
PImage currentSprite;

if (isDead) {
currentSprite = deathFrames[currentFrame];
} else {
if (vel.x > 0) {
currentSprite = rightFrames[currentFrame];
} else if (vel.x < 0) {
currentSprite = leftFrames[currentFrame];
} else {
currentSprite = rightFrames[currentFrame];
}
}

image(currentSprite, pos.x - charWidth / 2, pos.y - charHeight / 2, charWidth, charHeight);

}

void kill() {
isDead = true;
health = 0;
vel = new PVector(0, 0);
deathTimer = 0;
currentFrame = 0;
println("Chicx killed, starting death animation");
}

void handleWalls() {
if (pos.x \= width) {
vel.x \*= -1;
}

if (pos.y = height) {
vel.y *= -1;
}

}

void setVelocity(PVector commonVelocity) {
vel = commonVelocity;
}

void removeFromGame() {
enemies.remove(this);
println("being removed");
}
}
Я пробовал изменить столкновение снарядов в основном коде, а затем попробовал изменить некоторые вещи в классе врага, но ничего из того, что я пробовал, не помогло. Я ввел отладочную команду println, чтобы узнать, в чем проблема. Я выяснил, что здоровье врага остановилось на 1, но не нашел решения.


Подробнее здесь: https://stackoverflow.com/questions/792 ... snt-go-off
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»