/** * Tries to cast the spell with the given index. Checks cooldown and manacosts. * * @param index */ public void spellAttack(int index) { if (state == DynamicObjectState.Attacking) return; curAnim = idleAnim.get(heading); Vector2 spVelo = new Vector2(); Vector2 startPos = new Vector2(); if (heading == Heading.Right) { spVelo.x = spSpeed; startPos = new Vector2(collisionRect.x + collisionRect.width, collisionRect.y); } else if (heading == Heading.Left) { spVelo.x = -spSpeed; startPos = new Vector2(collisionRect.x - 32, collisionRect.y); } else if (heading == Heading.Up) { spVelo.y = -spSpeed; startPos = new Vector2(collisionRect.x, collisionRect.y - 32); } else { spVelo.y = spSpeed; startPos = new Vector2(collisionRect.x, collisionRect.y + (float) collisionRect.getHeight()); } Spell curSpell = spellManager.getSpell(index); if (!curSpell.isOnCooldown() && mana.getCurrentMana() >= curSpell.getManaCost()) { mana.reduceMana(curSpell.getManaCost()); manager.spawnSpell(curSpell.getProjectile(startPos, heading)); spellManager.activate(index); if (isInNetwork && controllerActive) { NetworkManager.sendSpellMessage(this, index); } } }
public void actionPerformed(ActionEvent a) { Object source = a.getSource(); if (scene == OVERWORLD) { if (source == moveTimer) { if (moveUp && !moveDown) player.moveUp(); else if (!moveUp && moveDown) player.moveDown(); if (moveLeft && !moveRight) player.moveLeft(); else if (!moveLeft && moveRight) player.moveRight(); } if (source == itemsButton) itemsButton.setText("ITEMS!"); else if (source == equipButton) equipButton.setText("EQUIPMENT!"); else if (source == skillsButton) skillsButton.setText("SKILLS"); else if (source == settingsButton) settingsButton.setText("SETTINGS"); else if (source == statusButton) statusButton.setText("STATUS"); else if (source == dataButton) dataButton.setText("DATA"); } if (scene == BATTLE) { if (source == moveTimer) { // Spell Movement for (int spellNum = 0; spellNum < spellsThrown.size(); spellNum++) { Spell spell = spellsThrown.get(spellNum); spell.move(); if (spell.spellHit()) { enemies.get(spell.getTarget()).takeDamage(spell.getDamage()); enemies.get(spell.getTarget()).statusPresent(spell.getEffect()); spellsThrown.remove(spellNum); checkEnemyPresence(); } } for (int enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) { Enemy enemy = enemies.get(enemyLoop); for (int spellNum = 0; spellNum < enemy.spellsThrown.size(); spellNum++) { Spell spell = enemy.spellsThrown.get(spellNum); spell.move(); if (spell.spellHit()) { player.takeDamage(spell.getDamage()); enemy.spellsThrown.remove(spellNum); checkAllyPresence(); } } } } if (source == staminaTimer) { // Stamina Regeneration player.staminaGain(16); // Enemy Attacks int enemyLoop; for (enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) { enemies.get(enemyLoop).attack(player.centerX(), player.centerY(), 12); } } } repaint(); // To check collision if (scene == OVERWORLD) { for (int loop = 0; loop < enemies.size(); loop++) { Enemy enemy = enemies.get(loop); if (enemy.hitbox().intersects(player.hitbox())) { player.combatChange(true); enemy.combatChange(true); battleBegin(); } } } }