Code Sketch


Bixuu MythicDragonsRiseOfAncientsEvent05
By: Mhalsakant School
Category: Programming
import java.awt.{BorderLayout, Color, Dimension, Font, Graphics, Graphics2D, GradientPaint, Polygon, RenderingHints}
import java.awt.event.{ActionEvent, ActionListener, KeyAdapter, KeyEvent, MouseAdapter, MouseEvent, WindowAdapter, WindowEvent}
import javax.swing.{BorderFactory, JButton, JComboBox, JFrame, JLabel, JPanel, JTextField, SwingConstants, Timer, WindowConstants}
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object MythicDragonsRiseOfAncientsEvent05 {
  def realmName(index: Int): String = index match {
    case 0 => "EMBERWOOD WILDS"
    case 1 => "MOONSTONE HIGHLANDS"
    case 2 => "TEMPEST NEST"
    case _ => "ANCIENT SANCTUM"
  }

  def realmStory(index: Int): String = index match {
    case 0 => "Find the first runes among the roots of the old dragon forest."
    case 1 => "Cross the moonlit cliffs and recover the frost runes."
    case 2 => "Explore the storm islands and awaken the sky dragon egg."
    case _ => "Enter the Ancient Sanctum and face the final guardian."
  }

  def main(args: Array[String]): Unit = {
    javax.swing.SwingUtilities.invokeLater(new Runnable {
      override def run(): Unit = createWindow()
    })
  }

  def createWindow(): Unit = {
    val frame = new JFrame("TITANVERSE: AGE OF LEGENDS - MYTHIC DRAGONS")
    val cardLayout = new java.awt.CardLayout()
    val root = new JPanel(cardLayout)
    var activeGame: GamePanel = null

    val loginPanel = new JPanel(new BorderLayout(16, 16))
    loginPanel.setBackground(new Color(12, 20, 29))
    loginPanel.setBorder(BorderFactory.createEmptyBorder(28, 38, 28, 38))

    val title = new JLabel("MYTHIC DRAGONS", SwingConstants.CENTER)
    title.setForeground(new Color(255, 214, 132))
    title.setFont(new Font("SansSerif", Font.BOLD, 36))
    val subtitle = new JLabel("RISE OF THE ANCIENTS  |  TITANVERSE EVENT 05", SwingConstants.CENTER)
    subtitle.setForeground(new Color(177, 218, 206))
    subtitle.setFont(new Font("SansSerif", Font.BOLD, 15))

    val story = new JLabel("Awaken ancient dragons, collect runes and restore the lost Dragon Dominion.", SwingConstants.CENTER)
    story.setForeground(new Color(226, 235, 226))
    story.setFont(new Font("SansSerif", Font.PLAIN, 15))

    val nameField = new JTextField(18)
    nameField.setFont(new Font("SansSerif", Font.PLAIN, 18))
    nameField.setHorizontalAlignment(SwingConstants.CENTER)
    nameField.setToolTipText("Enter your explorer name")

    val heroChoice = new JComboBox[String]()
    heroChoice.addItem("EMBER RANGER")
    heroChoice.addItem("FROST MAGE")
    heroChoice.addItem("STORM KNIGHT")
    heroChoice.addItem("DRAGON KEEPER")
    heroChoice.setFont(new Font("SansSerif", Font.BOLD, 15))

    val enterButton = new JButton("ENTER THE DRAGON REALM")
    styleButton(enterButton, new Color(155, 91, 38))
    val loginStatus = new JLabel("Enter your name and choose your hero.", SwingConstants.CENTER)
    loginStatus.setForeground(new Color(255, 220, 157))
    loginStatus.setFont(new Font("SansSerif", Font.PLAIN, 14))

    val form = new JPanel(new java.awt.GridLayout(6, 1, 8, 8))
    form.setOpaque(false)
    val nameLabel = new JLabel("EXPLORER NAME", SwingConstants.CENTER)
    nameLabel.setForeground(new Color(226, 235, 226))
    nameLabel.setFont(new Font("SansSerif", Font.BOLD, 14))
    val heroLabel = new JLabel("CHOOSE YOUR HERO", SwingConstants.CENTER)
    heroLabel.setForeground(new Color(226, 235, 226))
    heroLabel.setFont(new Font("SansSerif", Font.BOLD, 14))
    form.add(nameLabel)
    form.add(nameField)
    form.add(heroLabel)
    form.add(heroChoice)
    form.add(enterButton)
    form.add(loginStatus)

    val headingPanel = new JPanel(new java.awt.GridLayout(3, 1, 8, 8))
    headingPanel.setOpaque(false)
    headingPanel.add(title)
    headingPanel.add(subtitle)
    headingPanel.add(story)
    loginPanel.add(headingPanel, BorderLayout.NORTH)
    loginPanel.add(form, BorderLayout.CENTER)

    val footer = new JLabel("4 REALMS  ?  12 ANCIENT RUNES  ?  4 DRAGON EGGS  ?  1 LEGENDARY GUARDIAN", SwingConstants.CENTER)
    footer.setForeground(new Color(147, 190, 168))
    footer.setFont(new Font("SansSerif", Font.BOLD, 12))
    loginPanel.add(footer, BorderLayout.SOUTH)

    root.add(loginPanel, "login")

    def openGame(): Unit = {
      val playerName = nameField.getText.trim
      if (playerName.isEmpty) {
        loginStatus.setText("Please enter your explorer name first.")
      } else {
        if (activeGame != null) {
          activeGame.stopGame()
          root.remove(activeGame)
        }
        val heroName = heroChoice.getSelectedItem.toString
        activeGame = new GamePanel(playerName, heroName, () => {
          if (activeGame != null) activeGame.stopGame()
          cardLayout.show(root, "login")
          nameField.requestFocusInWindow()
        })
        root.add(activeGame, "game")
        cardLayout.show(root, "game")
        activeGame.requestGameFocus()
      }
    }

    enterButton.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = openGame()
    })
    nameField.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = openGame()
    })

    frame.setContentPane(root)
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
    frame.setSize(1080, 740)
    frame.setMinimumSize(new Dimension(900, 650))
    frame.setLocationRelativeTo(null)
    frame.addWindowListener(new WindowAdapter {
      override def windowClosing(e: WindowEvent): Unit = {
        if (activeGame != null) activeGame.stopGame()
      }
    })
    frame.setVisible(true)
  }

  def styleButton(button: JButton, background: Color): Unit = {
    button.setFont(new Font("SansSerif", Font.BOLD, 12))
    button.setForeground(Color.WHITE)
    button.setBackground(background)
    button.setFocusPainted(false)
    button.setBorder(BorderFactory.createCompoundBorder(
      BorderFactory.createLineBorder(new Color(226, 190, 120), 1),
      BorderFactory.createEmptyBorder(9, 10, 9, 10)
    ))
  }

  class Rune(var x: Int, var y: Int, var collected: Boolean)
  class DragonEgg(var x: Int, var y: Int, var collected: Boolean, var color: Color)
  class ShadowWisp(var x: Double, var y: Double, var frozenFrames: Int)

  class GamePanel(playerName: String, heroName: String, onBack: () => Unit) extends JPanel(new BorderLayout(6, 6)) {
    var realm = 0
    var playerX = 90.0
    var playerY = 320.0
    var playerHealth = 100
    var energy = 100
    var coins = 0
    var totalRunes = 0
    var localRunes = 0
    var eggsCollected = 0
    var companionAwake = false
    var paused = false
    var won = false
    var gameOver = false
    var shieldFrames = 0
    var dashFrames = 0
    var bossHealth = 4
    var message = "Explore the realm. Collect 3 runes and find the Dragon Egg."
    var targetX = -1.0
    var targetY = -1.0

    val pressedKeys = scala.collection.mutable.Set[Int]()
    val runes = ArrayBuffer[Rune]()
    val wisps = ArrayBuffer[ShadowWisp]()
    val eggs = ArrayBuffer[DragonEgg]()
    val random = new Random()
    val statsLabel = new JLabel("", SwingConstants.CENTER)
    statsLabel.setForeground(new Color(247, 232, 197))
    statsLabel.setFont(new Font("SansSerif", Font.BOLD, 13))
    val questLabel = new JLabel("", SwingConstants.CENTER)
    questLabel.setForeground(new Color(207, 235, 215))
    questLabel.setFont(new Font("SansSerif", Font.PLAIN, 13))

    val canvas = new WorldCanvas()
    val timer = new Timer(34, new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = updateGame()
    })

    setBackground(new Color(10, 18, 23))
    setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7))

    val hud = new JPanel(new java.awt.GridLayout(2, 1, 2, 2))
    hud.setBackground(new Color(20, 34, 38))
    hud.setBorder(BorderFactory.createEmptyBorder(7, 5, 7, 5))
    hud.add(statsLabel)
    hud.add(questLabel)
    add(hud, BorderLayout.NORTH)

    canvas.setPreferredSize(new Dimension(1000, 555))
    canvas.setFocusable(true)
    add(canvas, BorderLayout.CENTER)

    val controls = new JPanel(new java.awt.GridLayout(1, 7, 5, 5))
    controls.setBackground(new Color(13, 23, 28))
    val fireButton = makeControl("EMBER PULSE", new Color(151, 72, 39)) { usePower(0) }
    val frostButton = makeControl("FROST WAVE", new Color(53, 104, 145)) { usePower(1) }
    val dashButton = makeControl("DRAGON DASH", new Color(105, 82, 48)) { doDash() }
    val shieldButton = makeControl("AURA SHIELD", new Color(69, 104, 82)) { useShield() }
    val interactButton = makeControl("INTERACT", new Color(105, 83, 132)) { interact() }
    val pauseButton = makeControl("PAUSE", new Color(69, 77, 91)) { togglePause() }
    val backButton = makeControl("BACK TO LOGIN", new Color(85, 58, 65)) { onBack() }
    controls.add(fireButton)
    controls.add(frostButton)
    controls.add(dashButton)
    controls.add(shieldButton)
    controls.add(interactButton)
    controls.add(pauseButton)
    controls.add(backButton)
    add(controls, BorderLayout.SOUTH)

    loadRealm()
    timer.start()

    def makeControl(text: String, color: Color)(action: => Unit): JButton = {
      val button = new JButton(text)
      styleButton(button, color)
      button.addActionListener(new ActionListener {
        override def actionPerformed(e: ActionEvent): Unit = {
          action
          canvas.requestFocusInWindow()
        }
      })
      button
    }

    def stopGame(): Unit = timer.stop()

    def requestGameFocus(): Unit = {
      javax.swing.SwingUtilities.invokeLater(new Runnable {
        override def run(): Unit = canvas.requestFocusInWindow()
      })
    }

    def loadRealm(): Unit = {
      runes.clear()
      wisps.clear()
      eggs.clear()
      localRunes = 0
      playerX = 90.0
      playerY = 320.0
      runes += new Rune(215, 160, false)
      runes += new Rune(455, 420, false)
      runes += new Rune(700, 170, false)
      eggs += new DragonEgg(580, 330, false, new Color(255, 179, 85))
      var j = 0
      while (j < 3) {
        wisps += new ShadowWisp(360.0 + j * 170.0, 130.0 + random.nextInt(300), 0)
        j += 1
      }
      message = realmStory(realm)
      updateHud()
      canvas.repaint()
    }

    def updateHud(): Unit = {
      val dragonText = if (companionAwake) "DRAGON COMPANION: AWAKENED" else "DRAGON EGGS: " + eggsCollected + "/4"
      statsLabel.setText("EXPLORER: " + playerName + "  |  HERO: " + heroName + "  |  REALM " + (realm + 1) + "/4  |  HP " + playerHealth + "  |  ENERGY " + energy + "  |  COINS " + coins)
      val goalText = if (realm == 3 && localRunes >= 3) "FINAL GUARDIAN: " + bossHealth + " SHIELDS" else "RUNES " + localRunes + "/3  |  TOTAL " + totalRunes + "/12"
      questLabel.setText(realmName(realm) + "  ?  " + goalText + "  ?  " + dragonText + "  ?  " + message)
    }

    def distance(ax: Double, ay: Double, bx: Double, by: Double): Double = {
      val dx = ax - bx
      val dy = ay - by
      math.sqrt(dx * dx + dy * dy)
    }

    def updateGame(): Unit = {
      if (!paused && !won && !gameOver) {
        var dx = 0.0
        var dy = 0.0
        if (pressedKeys.contains(KeyEvent.VK_W) || pressedKeys.contains(KeyEvent.VK_UP)) dy -= 1.0
        if (pressedKeys.contains(KeyEvent.VK_S) || pressedKeys.contains(KeyEvent.VK_DOWN)) dy += 1.0
        if (pressedKeys.contains(KeyEvent.VK_A) || pressedKeys.contains(KeyEvent.VK_LEFT)) dx -= 1.0
        if (pressedKeys.contains(KeyEvent.VK_D) || pressedKeys.contains(KeyEvent.VK_RIGHT)) dx += 1.0
        if (targetX >= 0.0 && dx == 0.0 && dy == 0.0) {
          val tx = targetX - playerX
          val ty = targetY - playerY
          val d = math.sqrt(tx * tx + ty * ty)
          if (d > 8.0) {
            dx = tx / d
            dy = ty / d
          } else {
            targetX = -1.0
            targetY = -1.0
          }
        }
        val length = math.sqrt(dx * dx + dy * dy)
        if (length > 0.0) {
          val baseSpeed = 2.6 + math.min(2.0, eggsCollected * 0.35)
          val dashBoost = if (dashFrames > 0) 2.4 else 1.0
          playerX += (dx / length) * baseSpeed * dashBoost
          playerY += (dy / length) * baseSpeed * dashBoost
        }
        playerX = math.max(35.0, math.min(canvas.getWidth - 35.0, playerX))
        playerY = math.max(65.0, math.min(canvas.getHeight - 55.0, playerY))
        if (dashFrames > 0) dashFrames -= 1
        if (shieldFrames > 0) shieldFrames -= 1
        if (energy < 100) energy = math.min(100, energy + 1)

        var k = 0
        while (k < wisps.length) {
          val w = wisps(k)
          if (w.frozenFrames > 0) {
            w.frozenFrames -= 1
          } else {
            val vx = playerX - w.x
            val vy = playerY - w.y
            val d = math.sqrt(vx * vx + vy * vy)
            if (d > 1.0) {
              w.x += (vx / d) * (0.75 + realm * 0.08)
              w.y += (vy / d) * (0.75 + realm * 0.08)
            }
            if (d < 30.0) {
              if (shieldFrames <= 0) playerHealth -= 1
              w.x = 850.0 - random.nextInt(100)
              w.y = 90.0 + random.nextInt(math.max(100, canvas.getHeight - 150))
            }
          }
          k += 1
        }
        if (playerHealth <= 0) {
          playerHealth = 65
          playerX = 75.0
          playerY = canvas.getHeight - 100.0
          coins = math.max(0, coins - 10)
          message = "The wisps sent you back to the sanctuary. Regroup and try again."
        }
        if (realm == 3 && localRunes >= 3 && bossHealth <= 0) {
          won = true
          message = "THE ANCIENT DRAGON HAS AWAKENED. YOU RESTORED THE DOMINION!"
        }
        updateHud()
        canvas.repaint()
      }
    }

    def interact(): Unit = {
      if (paused || won || gameOver) return
      var found = false
      var i = 0
      while (i < runes.length && !found) {
        val r = runes(i)
        if (!r.collected && distance(playerX, playerY, r.x, r.y) < 68.0) {
          r.collected = true
          localRunes += 1
          totalRunes += 1
          coins += 25
          energy = math.min(100, energy + 12)
          message = "Ancient rune collected! +25 coins."
          found = true
        }
        i += 1
      }
      if (!found) {
        var j = 0
        while (j < eggs.length && !found) {
          val egg = eggs(j)
          if (!egg.collected && distance(playerX, playerY, egg.x, egg.y) < 72.0) {
            egg.collected = true
            eggsCollected += 1
            coins += 35
            message = "You found a Dragon Egg! +35 coins."
            if (eggsCollected >= 2 && !companionAwake) {
              companionAwake = true
              message = "Your Dragon Companion has awakened and will follow you!"
            }
            found = true
          }
          j += 1
        }
      }
      if (!found && distance(playerX, playerY, canvas.getWidth - 85.0, canvas.getHeight / 2.0) < 90.0) {
        if (localRunes >= 3) {
          if (realm < 3) {
            realm += 1
            loadRealm()
            message = "New realm unlocked: " + realmName(realm)
          } else {
            message = "The Guardian awaits. Use your Ember or Frost powers near it!"
          }
        } else {
          message = "The realm gate needs 3 Ancient Runes. Find the remaining runes."
        }
        found = true
      }
      if (!found && realm == 3 && localRunes >= 3 && distance(playerX, playerY, canvas.getWidth - 180.0, canvas.getHeight / 2.0) < 240.0) {
        message = "Use EMBER PULSE or FROST WAVE to break the Guardian's shields."
      }
      updateHud()
      canvas.repaint()
    }

    def usePower(power: Int): Unit = {
      if (paused || won || gameOver) return
      if (energy < 22) {
        message = "Not enough energy. Collect runes or wait for energy to recharge."
      } else {
        energy -= 22
        if (realm == 3 && localRunes >= 3 && distance(playerX, playerY, canvas.getWidth - 180.0, canvas.getHeight / 2.0) < 260.0) {
          bossHealth -= 1
          if (bossHealth < 0) bossHealth = 0
          if (power == 0) message = "EMBER PULSE hits the Ancient Guardian!"
          else message = "FROST WAVE weakens the Ancient Guardian!"
          if (bossHealth == 0) {
            won = true
            message = "VICTORY! THE ANCIENT DRAGON DOMINION IS RESTORED!"
          }
        } else {
          var nearest: ShadowWisp = null
          var nearestDistance = 99999.0
          var i = 0
          while (i < wisps.length) {
            val d = distance(playerX, playerY, wisps(i).x, wisps(i).y)
            if (d < nearestDistance) {
              nearestDistance = d
              nearest = wisps(i)
            }
            i += 1
          }
          if (nearest != null && nearestDistance < 230.0) {
            nearest.frozenFrames = if (power == 0) 110 else 170
            message = if (power == 0) "EMBER PULSE scatters a Shadow Wisp!" else "FROST WAVE freezes a Shadow Wisp!"
          } else {
            message = if (power == 0) "Ember Pulse released. Find a nearby wisp or the final guardian." else "Frost Wave released. Find a nearby wisp or the final guardian."
          }
        }
      }
      updateHud()
      canvas.repaint()
    }

    def doDash(): Unit = {
      if (!paused && !won && !gameOver && energy >= 10) {
        energy -= 10
        dashFrames = 16
        message = "DRAGON DASH! Move quickly through the realm."
        updateHud()
      }
    }

    def useShield(): Unit = {
      if (!paused && !won && !gameOver && energy >= 18) {
        energy -= 18
        shieldFrames = 150
        message = "Ancient Aura Shield activated."
        updateHud()
      }
    }

    def togglePause(): Unit = {
      if (!won && !gameOver) {
        paused = !paused
        message = if (paused) "Game paused. Press P or PAUSE to continue." else "The adventure continues!"
        updateHud()
        canvas.repaint()
      }
    }

    def restartGame(): Unit = {
      realm = 0
      playerHealth = 100
      energy = 100
      coins = 0
      totalRunes = 0
      eggsCollected = 0
      companionAwake = false
      bossHealth = 4
      paused = false
      won = false
      gameOver = false
      loadRealm()
      requestGameFocus()
    }

    class WorldCanvas extends JPanel {
      setBackground(new Color(13, 27, 29))
      setPreferredSize(new Dimension(1000, 555))

      addKeyListener(new KeyAdapter {
        override def keyPressed(e: KeyEvent): Unit = {
          pressedKeys += e.getKeyCode
          e.getKeyCode match {
            case KeyEvent.VK_E => interact()
            case KeyEvent.VK_SPACE => doDash()
            case KeyEvent.VK_1 => usePower(0)
            case KeyEvent.VK_2 => usePower(1)
            case KeyEvent.VK_Q => useShield()
            case KeyEvent.VK_P => togglePause()
            case KeyEvent.VK_B => onBack()
            case KeyEvent.VK_R => restartGame()
            case _ =>
          }
        }
        override def keyReleased(e: KeyEvent): Unit = {
          pressedKeys -= e.getKeyCode
        }
      })

      addMouseListener(new MouseAdapter {
        override def mousePressed(e: MouseEvent): Unit = {
          targetX = e.getX.toDouble
          targetY = e.getY.toDouble
          requestFocusInWindow()
        }
      })

      override def paintComponent(graphics: Graphics): Unit = {
        super.paintComponent(graphics)
        val g = graphics.asInstanceOf[Graphics2D]
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
        val w = getWidth
        val h = getHeight
        val skyTop = realm match {
          case 0 => new Color(29, 42, 43)
          case 1 => new Color(27, 42, 66)
          case 2 => new Color(29, 49, 58)
          case _ => new Color(44, 29, 53)
        }
        val skyBottom = realm match {
          case 0 => new Color(73, 91, 54)
          case 1 => new Color(67, 77, 110)
          case 2 => new Color(58, 89, 99)
          case _ => new Color(94, 56, 64)
        }
        g.setPaint(new GradientPaint(0, 0, skyTop, 0, h, skyBottom))
        g.fillRect(0, 0, w, h)

        var star = 0
        while (star < 52) {
          val sx = (star * 173 + 37) % math.max(1, w)
          val sy = (star * 83 + 19) % math.max(1, h / 2)
          g.setColor(new Color(255, 244, 198, 150))
          g.fillOval(sx, sy, 2 + (star % 3), 2 + (star % 3))
          star += 1
        }

        g.setColor(new Color(15, 28, 25, 130))
        val mountain1 = new Polygon(Array(0, w / 5, w / 3, w / 2, w * 2 / 3, w, w), Array(h * 2 / 3, h / 3, h * 3 / 5, h / 4, h * 3 / 5, h / 3, h), 7)
        g.fillPolygon(mountain1)
        g.setColor(new Color(19, 39, 30))
        g.fillRect(0, h - 65, w, 65)
        g.setColor(new Color(110, 150, 91))
        g.fillRect(0, h - 67, w, 5)

        var tree = 0
        while (tree < 8) {
          val tx = tree * (w / 7) + 20
          val ty = h - 70
          g.setColor(new Color(67, 45, 31))
          g.fillRect(tx + 12, ty - 75, 13, 75)
          g.setColor(new Color(37 + realm * 4, 91 + (tree % 3) * 8, 54 + realm * 3))
          g.fillOval(tx - 12, ty - 110, 58, 65)
          tree += 1
        }

        g.setColor(new Color(238, 206, 123, 180))
        g.setFont(new Font("SansSerif", Font.BOLD, 18))
        g.drawString(realmName(realm), 24, 32)
        g.setColor(new Color(239, 235, 214))
        g.setFont(new Font("SansSerif", Font.PLAIN, 12))
        g.drawString("Collect 3 runes, find the Dragon Egg, then approach the realm gate.", 24, 52)

        val portalX = w - 83
        val portalY = h / 2
        g.setColor(new Color(255, 208, 116, 65))
        g.fillOval(portalX - 36, portalY - 62, 72, 124)
        g.setColor(new Color(255, 218, 135))
        g.drawOval(portalX - 29, portalY - 55, 58, 110)
        g.setColor(new Color(117, 202, 172, 125))
        g.fillOval(portalX - 19, portalY - 44, 38, 88)
        g.setColor(Color.WHITE)
        g.drawString("GATE", portalX - 18, portalY + 78)

        var i = 0
        while (i < runes.length) {
          val r = runes(i)
          if (!r.collected) {
            g.setColor(new Color(255, 222, 129, 75))
            g.fillOval(r.x - 19, r.y - 19, 38, 38)
            g.setColor(new Color(255, 224, 125))
            val p = new Polygon(Array(r.x, r.x + 12, r.x, r.x - 12), Array(r.y - 16, r.y, r.y + 16, r.y), 4)
            g.fillPolygon(p)
          }
          i += 1
        }

        var eggIndex = 0
        while (eggIndex < eggs.length) {
          val egg = eggs(eggIndex)
          if (!egg.collected) {
            g.setColor(new Color(255, 187, 87, 75))
            g.fillOval(egg.x - 23, egg.y - 23, 46, 46)
            g.setColor(egg.color)
            g.fillOval(egg.x - 13, egg.y - 18, 26, 36)
            g.setColor(new Color(255, 246, 217))
            g.drawOval(egg.x - 13, egg.y - 18, 26, 36)
          }
          eggIndex += 1
        }

        var wi = 0
        while (wi < wisps.length) {
          val wis = wisps(wi)
          val alpha = if (wis.frozenFrames > 0) 210 else 175
          val wispColor = if (wis.frozenFrames > 0) new Color(132, 220, 255, alpha) else new Color(186, 135, 235, alpha)
          g.setColor(wispColor)
          g.fillOval(wis.x.toInt - 15, wis.y.toInt - 15, 30, 30)
          g.setColor(new Color(255, 255, 255, 220))
          g.fillOval(wis.x.toInt - 6, wis.y.toInt - 5, 5, 5)
          g.fillOval(wis.x.toInt + 3, wis.y.toInt - 5, 5, 5)
          wi += 1
        }

        if (realm == 3 && localRunes >= 3 && !won) {
          val bx = w - 180
          val by = h / 2
          g.setColor(new Color(113, 57, 90, 100))
          g.fillOval(bx - 47, by - 58, 94, 116)
          g.setColor(new Color(204, 139, 93))
          g.fillOval(bx - 28, by - 39, 56, 70)
          g.setColor(new Color(255, 236, 185))
          g.fillOval(bx - 17, by - 22, 8, 8)
          g.fillOval(bx + 9, by - 22, 8, 8)
          g.setColor(Color.WHITE)
          g.drawString("ANCIENT GUARDIAN: " + bossHealth, bx - 66, by + 78)
        }

        if (companionAwake) {
          val cx = playerX.toInt - 30
          val cy = playerY.toInt - 34
          g.setColor(new Color(255, 177, 84))
          g.fillOval(cx - 13, cy - 10, 26, 20)
          g.setColor(new Color(255, 215, 135))
          g.fillOval(cx - 22, cy - 22, 18, 13)
          g.fillOval(cx + 5, cy - 22, 18, 13)
          g.setColor(new Color(255, 248, 209))
          g.fillOval(cx - 5, cy - 4, 4, 4)
        }

        if (shieldFrames > 0) {
          g.setColor(new Color(113, 220, 255, 90))
          g.fillOval(playerX.toInt - 26, playerY.toInt - 28, 52, 56)
          g.setColor(new Color(191, 239, 255))
          g.drawOval(playerX.toInt - 26, playerY.toInt - 28, 52, 56)
        }
        g.setColor(new Color(52, 39, 35))
        g.fillRoundRect(playerX.toInt - 11, playerY.toInt - 5, 22, 29, 8, 8)
        g.setColor(new Color(242, 197, 139))
        g.fillOval(playerX.toInt - 10, playerY.toInt - 23, 20, 20)
        g.setColor(new Color(92, 139, 100))
        g.fillRoundRect(playerX.toInt - 15, playerY.toInt - 5, 30, 30, 10, 10)
        g.setColor(new Color(255, 237, 194))
        g.fillOval(playerX.toInt - 5, playerY.toInt - 17, 4, 4)
        g.fillOval(playerX.toInt + 3, playerY.toInt - 17, 4, 4)
        g.setColor(Color.WHITE)
        g.setFont(new Font("SansSerif", Font.BOLD, 11))
        g.drawString(playerName, playerX.toInt - 24, playerY.toInt + 43)

        if (paused) {
          g.setColor(new Color(0, 0, 0, 165))
          g.fillRect(0, 0, w, h)
          g.setColor(new Color(255, 226, 157))
          g.setFont(new Font("SansSerif", Font.BOLD, 38))
          g.drawString("PAUSED", w / 2 - 80, h / 2)
        }
        if (won) {
          g.setColor(new Color(0, 0, 0, 175))
          g.fillRect(0, 0, w, h)
          g.setColor(new Color(255, 224, 144))
          g.setFont(new Font("SansSerif", Font.BOLD, 34))
          g.drawString("DRAGON DOMINION RESTORED!", w / 2 - 270, h / 2 - 12)
          g.setFont(new Font("SansSerif", Font.PLAIN, 18))
          g.drawString("The Ancient Dragon has awakened. Press R to play again.", w / 2 - 245, h / 2 + 28)
        }
      }
    }
  }
}
MythicDragonsRiseOfAncientsEvent05.main(Array[String]())