Я не уверен, что не так с моим кодом, я не могу понять, проблема ли это в коллизии или в проблеме врага. В любом случае я проверил отладку, и здоровье врага становится равным единице, а не 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, но не нашел решения.
Я не уверен, что не так с моим кодом, я не могу понять, проблема ли это в коллизии или в проблеме врага. В любом случае я проверил отладку, и здоровье врага становится равным единице, а не 0, и не вызывает мою анимацию смерти. Основной код эскиза: [code]// 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);
// 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); } }
// 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 }
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; } } }
void setVelocity(PVector commonVelocity) { vel = commonVelocity; }
void removeFromGame() { enemies.remove(this); println("being removed"); } } [/code] Я пробовал изменить столкновение снарядов в основном коде, а затем попробовал изменить некоторые вещи в классе врага, но ничего из того, что я пробовал, не помогло. Я ввел отладочную команду println, чтобы узнать, в чем проблема. Я выяснил, что здоровье врага остановилось на 1, но не нашел решения.
Я не уверен, что не так с моим кодом, я не могу понять, проблема ли это в коллизии или в проблеме врага. В любом случае я проверил отладку, и здоровье врага становится равным единице, а не 0, и не вызывает мою анимацию смерти.
Основной код эскиза:...
Я пытаюсь автоматически экспортировать данные о здоровье из моего iPhone/Apple Watch. Я знаю, что можно экспортировать данные вручную, открыв приложение Health на вашем iPhone> нажав на значок пользователя> «Данные о здоровье экспорта». Тем не...
Я новичок в Pint. Я имею дело с производными единицами, такими как Сименс, Джоуль, Фарад и т. д.
В частности, я хотел бы хранить созданные величины в их единицах без какого-либо префикса, без преобразования в базовые единицы. Например, 1 миллисименс...
Во -первых, мне нужно, чтобы главный герой этой видеоигры поднимался на 4 единицы высоты в ответ, когда я толкаю ключ прыжка. Это в функции дисплея:
if((saltar)&&(saltarContadorAltura=0.0f))
{
incy = 1.0f;...
Во -первых, мне нужно, чтобы главный герой (как спрайт) этой видеоигры поднимался на 4 единицы высоты в ответ, когда я толкаю ключ прыжка. Именно в функции дисплея (функция OpenGL Java выполняется повторение в цикле)
@Override
public void...