Code Sketch
Bixuu CyberNovaFutureRevolutionEvent02
Category: Programming
import java.awt.{BasicStroke, BorderLayout, Color, Dimension, Font, GradientPaint, Graphics, Graphics2D, Polygon, RenderingHints}
import java.awt.event.{ActionEvent, ActionListener, MouseAdapter, MouseEvent, WindowAdapter, WindowEvent}
import java.awt.geom.{Ellipse2D, RoundRectangle2D}
import javax.swing.{AbstractAction, BorderFactory, JButton, JFrame, JLabel, JPanel, JTextField, JComponent, KeyStroke, SwingConstants, SwingUtilities, Timer, WindowConstants}
import scala.collection.mutable.ArrayBuffer
object CyberNovaFutureRevolutionEvent02 {
val dark = new Color(7, 12, 31)
val panelDark = new Color(13, 24, 49)
val cyan = new Color(64, 235, 255)
val magenta = new Color(255, 75, 190)
val violet = new Color(143, 111, 255)
val mint = new Color(116, 255, 196)
val white = new Color(237, 246, 255)
val gold = new Color(255, 210, 105)
var mainFrame: JFrame = null
var activeGame: CyberNovaGamePanel = null
def makeButton(caption: String): JButton = {
val button = new JButton(caption)
button.setFont(new Font("SansSerif", Font.BOLD, 13))
button.setForeground(white)
button.setBackground(new Color(22, 48, 78))
button.setFocusPainted(false)
button.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(69, 213, 243), 1),
BorderFactory.createEmptyBorder(9, 14, 9, 14)
))
button.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR))
button
}
def makeLabel(text: String, size: Int, color: Color): JLabel = {
val label = new JLabel(text, SwingConstants.CENTER)
label.setFont(new Font("SansSerif", Font.BOLD, size))
label.setForeground(color)
label
}
def main(args: Array[String]): Unit = {
SwingUtilities.invokeLater(new Runnable {
def run(): Unit = {
if (mainFrame == null || !mainFrame.isDisplayable) {
mainFrame = new JFrame("TITANVERSE: AGE OF LEGENDS | CYBERNOVA")
mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
mainFrame.setSize(1080, 760)
mainFrame.setMinimumSize(new Dimension(900, 660))
mainFrame.setLocationRelativeTo(null)
mainFrame.addWindowListener(new WindowAdapter {
override def windowClosing(e: WindowEvent): Unit = {
if (activeGame != null) activeGame.stopGame()
}
})
showLogin()
mainFrame.setVisible(true)
} else {
mainFrame.toFront()
}
}
})
}
def showLogin(): Unit = {
if (mainFrame == null) return
if (activeGame != null) {
activeGame.stopGame()
activeGame = null
}
val root = new JPanel(new BorderLayout(12, 12))
root.setBackground(dark)
root.setBorder(BorderFactory.createEmptyBorder(22, 30, 22, 30))
val heading = makeLabel("TITANVERSE: AGE OF LEGENDS", 28, cyan)
val subtitle = makeLabel("EVENT 02 | CYBERNOVA: FUTURE REVOLUTION", 19, magenta)
val header = new JPanel(new BorderLayout(4, 5))
header.setOpaque(false)
header.add(heading, BorderLayout.NORTH)
header.add(subtitle, BorderLayout.SOUTH)
val artwork = new CyberNovaIntroPanel()
artwork.setPreferredSize(new Dimension(900, 470))
val bottom = new JPanel()
bottom.setOpaque(false)
val prompt = makeLabel("ENTER YOUR EXPLORER NAME", 13, white)
val nameField = new JTextField(17)
nameField.setFont(new Font("SansSerif", Font.BOLD, 17))
nameField.setForeground(new Color(17, 30, 48))
nameField.setPreferredSize(new Dimension(220, 38))
val startButton = makeButton("ENTER NEON CITY")
bottom.add(prompt)
bottom.add(nameField)
bottom.add(startButton)
startButton.addActionListener(new ActionListener {
def actionPerformed(e: ActionEvent): Unit = {
val raw = nameField.getText.trim
val player = if (raw.length == 0) "Nova Explorer" else raw.take(18)
showGame(player)
}
})
nameField.addActionListener(new ActionListener {
def actionPerformed(e: ActionEvent): Unit = startButton.doClick()
})
root.add(header, BorderLayout.NORTH)
root.add(artwork, BorderLayout.CENTER)
root.add(bottom, BorderLayout.SOUTH)
mainFrame.setContentPane(root)
mainFrame.revalidate()
mainFrame.repaint()
}
def showGame(playerName: String): Unit = {
if (mainFrame == null) return
if (activeGame != null) activeGame.stopGame()
val root = new JPanel(new BorderLayout(8, 8))
root.setBackground(dark)
root.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10))
val top = new JPanel(new BorderLayout(8, 4))
top.setBackground(panelDark)
top.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(57, 151, 205)),
BorderFactory.createEmptyBorder(7, 12, 7, 12)
))
val playerLabel = makeLabel("EXPLORER " + playerName, 13, cyan)
playerLabel.setHorizontalAlignment(SwingConstants.LEFT)
val statsLabel = makeLabel("DISTRICT 1 | CORES 0/4 | CITIZENS 0/1 | CREDITS 0 | ENERGY 100", 13, white)
top.add(playerLabel, BorderLayout.WEST)
top.add(statsLabel, BorderLayout.CENTER)
activeGame = new CyberNovaGamePanel(playerName, new Runnable {
def run(): Unit = {
if (activeGame != null) statsLabel.setText(activeGame.statusText())
}
}, new Runnable {
def run(): Unit = showLogin()
})
val controls = new JPanel()
controls.setBackground(new Color(8, 17, 37))
val dashButton = makeButton("HOVER DASH [SPACE]")
val pulseButton = makeButton("PULSE TAG [F]")
val interactButton = makeButton("INTERACT [E]")
val pauseButton = makeButton("PAUSE [P]")
val backButton = makeButton("BACK TO LOGIN [B]")
controls.add(dashButton)
controls.add(pulseButton)
controls.add(interactButton)
controls.add(pauseButton)
controls.add(backButton)
dashButton.addActionListener(new ActionListener { def actionPerformed(e: ActionEvent): Unit = if (activeGame != null) activeGame.dash() })
pulseButton.addActionListener(new ActionListener { def actionPerformed(e: ActionEvent): Unit = if (activeGame != null) activeGame.usePulse() })
interactButton.addActionListener(new ActionListener { def actionPerformed(e: ActionEvent): Unit = if (activeGame != null) activeGame.interact() })
pauseButton.addActionListener(new ActionListener { def actionPerformed(e: ActionEvent): Unit = if (activeGame != null) activeGame.togglePause() })
backButton.addActionListener(new ActionListener { def actionPerformed(e: ActionEvent): Unit = showLogin() })
root.add(top, BorderLayout.NORTH)
root.add(activeGame, BorderLayout.CENTER)
root.add(controls, BorderLayout.SOUTH)
mainFrame.setContentPane(root)
mainFrame.revalidate()
mainFrame.repaint()
activeGame.requestFocusInWindow()
}
class CyberNovaIntroPanel extends JPanel {
setOpaque(true)
setBackground(dark)
override def paintComponent(graphics: Graphics): Unit = {
super.paintComponent(graphics)
val g = graphics.create().asInstanceOf[Graphics2D]
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
val w = getWidth
val h = getHeight
g.setPaint(new GradientPaint(0, 0, new Color(18, 26, 71), 0, h, new Color(5, 10, 26)))
g.fillRect(0, 0, w, h)
var i = 0
while (i < 90) {
val x = (i * 97 + 31) % math.max(1, w)
val y = (i * 53 + 17) % math.max(1, h)
g.setColor(new Color(120, 220, 255, 90 + (i % 5) * 25))
g.fillOval(x, y, 2 + (i % 3), 2 + (i % 3))
i += 1
}
val horizon = h - 95
g.setColor(new Color(15, 30, 66))
g.fillRect(0, horizon, w, h - horizon)
i = 0
while (i < 15) {
val bw = 34 + (i * 13 % 38)
val bh = 75 + (i * 47 % 180)
val x = i * (w / 14) - 10
g.setColor(new Color(16, 34, 69))
g.fillRoundRect(x, horizon - bh, bw, bh, 5, 5)
g.setColor(if (i % 2 == 0) cyan else magenta)
g.setStroke(new BasicStroke(2f))
g.drawLine(x + 6, horizon - bh + 18, x + bw - 6, horizon - bh + 18)
var wy = horizon - bh + 32
while (wy < horizon - 12) {
g.setColor(new Color(88, 210, 255, 150))
g.fillRect(x + 7, wy, 5, 8)
g.setColor(new Color(255, 80, 195, 145))
g.fillRect(x + 18, wy, 5, 8)
wy += 22
}
i += 1
}
val cx = w / 2
val cy = h / 2 - 10
g.setColor(new Color(64, 235, 255, 35))
g.fillOval(cx - 145, cy - 145, 290, 290)
g.setStroke(new BasicStroke(5f))
g.setColor(cyan)
g.drawOval(cx - 108, cy - 108, 216, 216)
g.setStroke(new BasicStroke(2f))
g.setColor(magenta)
g.drawOval(cx - 82, cy - 82, 164, 164)
g.setFont(new Font("SansSerif", Font.BOLD, 30))
g.setColor(white)
val title = "CYBERNOVA"
val fm = g.getFontMetrics
g.drawString(title, cx - fm.stringWidth(title) / 2, cy + 10)
g.setFont(new Font("SansSerif", Font.BOLD, 15))
g.setColor(cyan)
val tag = "FUTURE REVOLUTION"
g.drawString(tag, cx - g.getFontMetrics.stringWidth(tag) / 2, cy + 39)
g.setFont(new Font("SansSerif", Font.PLAIN, 13))
g.setColor(new Color(220, 235, 255))
val line = "Restore the city. Rescue its people. Reboot the future."
g.drawString(line, cx - g.getFontMetrics.stringWidth(line) / 2, h - 28)
g.dispose()
}
}
class CyberNovaGamePanel(val playerName: String, val statusChanged: Runnable, val backAction: Runnable) extends JPanel {
val worldWidth = 960.0
val worldHeight = 540.0
var playerX = 85.0
var playerY = 270.0
var facingX = 1.0
var facingY = 0.0
var credits = 0
var energy = 100
var health = 100
var district = 0
var coresCollected = 0
var citizensRescued = 0
var paused = false
var won = false
var gameOver = false
var message = "Collect energy cores and help the city citizens."
var messageTicks = 220
var pulseCooldown = 0
var dashCooldown = 0
var pulseTicks = 0
var slowTicks = 0
var tickCount = 0
var bossHitsLeft = 3
var upHeld = false
var downHeld = false
var leftHeld = false
var rightHeld = false
var mouseTargetX = -1.0
var mouseTargetY = -1.0
val random = new scala.util.Random(21L)
case class Core(var x: Double, var y: Double, var collected: Boolean, val kind: Int)
case class Citizen(var x: Double, var y: Double, var rescued: Boolean)
case class Drone(var x: Double, var y: Double, var stunned: Int, val phase: Double, val boss: Boolean)
val cores = ArrayBuffer[Core]()
val citizens = ArrayBuffer[Citizen]()
val drones = ArrayBuffer[Drone]()
val districtNames = Array("Neon Downtown", "Skybridge Sector", "Hologram Gardens", "Quantum Reactor")
val districtMissions = Array(
"Restore street power and guide a stranded citizen to safety.",
"Cross the skybridges and stabilize the floating energy relays.",
"Reboot the hologram gardens and rescue the garden keeper.",
"Protect the Quantum Core and complete the final city reboot."
)
val requiredCores = Array(4, 4, 5, 6)
val requiredCitizens = Array(1, 1, 1, 2)
setOpaque(true)
setBackground(dark)
setPreferredSize(new Dimension(960, 540))
setFocusable(true)
setDoubleBuffered(true)
def clamp(value: Double, low: Double, high: Double): Double = math.max(low, math.min(high, value))
def distance(ax: Double, ay: Double, bx: Double, by: Double): Double = math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by))
def say(text: String): Unit = { message = text; messageTicks = 180; statusChanged.run() }
def resetDistrict(index: Int): Unit = {
district = index
playerX = 82.0
playerY = 270.0
coresCollected = 0
citizensRescued = 0
cores.clear()
citizens.clear()
drones.clear()
val spots = Array((170.0, 125.0), (290.0, 390.0), (445.0, 150.0), (580.0, 365.0), (735.0, 135.0), (775.0, 390.0))
var i = 0
val count = requiredCores(district)
while (i < count) {
val p = spots((i + district) % spots.length)
cores += Core(p._1, p._2, false, i % 3)
i += 1
}
citizens += Citizen(360.0 + district * 35.0, 260.0, false)
if (district == 3) citizens += Citizen(660.0, 200.0, false)
drones += Drone(420.0, 105.0, 0, 0.4, false)
drones += Drone(650.0, 420.0, 0, 1.6, false)
if (district == 3) drones += Drone(760.0, 270.0, 0, 2.4, true)
message = "DISTRICT " + (district + 1) + " | " + districtNames(district) + " | " + districtMissions(district)
messageTicks = 260
statusChanged.run()
repaint()
}
def statusText(): String = {
"DISTRICT " + (district + 1) + "/4 | CORES " + coresCollected + "/" + requiredCores(district) +
" | CITIZENS " + citizensRescued + "/" + requiredCitizens(district) +
" | CREDITS " + credits + " | ENERGY " + energy + " | HEALTH " + health
}
def startGameTimer(): Unit = gameTimer.start()
def stopGame(): Unit = gameTimer.stop()
def addKey(key: String, name: String, action: => Unit): Unit = {
val input = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
val actions = getActionMap
input.put(KeyStroke.getKeyStroke(key), name)
actions.put(name, new AbstractAction {
def actionPerformed(e: ActionEvent): Unit = action
})
}
def installKeys(): Unit = {
addKey("pressed W", "upOn", { upHeld = true })
addKey("released W", "upOff", { upHeld = false })
addKey("pressed S", "downOn", { downHeld = true })
addKey("released S", "downOff", { downHeld = false })
addKey("pressed A", "leftOn", { leftHeld = true })
addKey("released A", "leftOff", { leftHeld = false })
addKey("pressed D", "rightOn", { rightHeld = true })
addKey("released D", "rightOff", { rightHeld = false })
addKey("pressed UP", "upArrowOn", { upHeld = true })
addKey("released UP", "upArrowOff", { upHeld = false })
addKey("pressed DOWN", "downArrowOn", { downHeld = true })
addKey("released DOWN", "downArrowOff", { downHeld = false })
addKey("pressed LEFT", "leftArrowOn", { leftHeld = true })
addKey("released LEFT", "leftArrowOff", { leftHeld = false })
addKey("pressed RIGHT", "rightArrowOn", { rightHeld = true })
addKey("released RIGHT", "rightArrowOff", { rightHeld = false })
addKey("pressed SPACE", "dash", { dash() })
addKey("pressed F", "pulse", { usePulse() })
addKey("pressed E", "interact", { interact() })
addKey("pressed P", "pause", { togglePause() })
addKey("pressed B", "back", { stopGame(); backAction.run() })
}
def dash(): Unit = {
if (!paused && !won && !gameOver && dashCooldown <= 0) {
val boost = 78.0
playerX = clamp(playerX + facingX * boost, 28.0, worldWidth - 28.0)
playerY = clamp(playerY + facingY * boost, 55.0, worldHeight - 55.0)
dashCooldown = 85
slowTicks = math.max(0, slowTicks - 20)
say("HOVER DASH! Neon trail activated.")
repaint()
}
}
def usePulse(): Unit = {
if (!paused && !won && !gameOver && pulseCooldown <= 0) {
pulseCooldown = 75
pulseTicks = 24
var chosen: Drone = null
var best = 175.0
for (d <- drones) {
val dist = distance(playerX, playerY, d.x, d.y)
if (dist < best && d.stunned <= 0) { best = dist; chosen = d }
}
if (chosen != null) {
if (chosen.boss) {
bossHitsLeft -= 1
chosen.stunned = 100
if (bossHitsLeft <= 0) {
drones -= chosen
credits += 120
say("QUANTUM GUARDIAN TAGGED! The reactor is stable.")
} else {
say("BOSS PULSE " + (4 - bossHitsLeft) + "/3! Keep your distance and pulse again.")
}
} else {
chosen.stunned = 115
credits += 8
say("ROGUE DRONE TAGGED! +8 CREDITS")
}
} else {
say("PULSE WAVE RELEASED. Move closer to tag a drone.")
}
energy = math.max(0, energy - 5)
statusChanged.run()
repaint()
}
}
def interact(): Unit = {
if (paused || won || gameOver) return
var found: Citizen = null
var best = 48.0
for (c <- citizens) {
if (!c.rescued) {
val d = distance(playerX, playerY, c.x, c.y)
if (d < best) { best = d; found = c }
}
}
if (found != null) {
found.rescued = true
citizensRescued += 1
credits += 35
say("CITIZEN RESCUED! +35 CREDITS")
} else if (distance(playerX, playerY, worldWidth - 72.0, 270.0) < 70.0) {
val coresReady = coresCollected >= requiredCores(district)
val peopleReady = citizensRescued >= requiredCitizens(district)
val bossReady = district != 3 || drones.forall(d => !d.boss)
if (coresReady && peopleReady && bossReady) {
if (district < 3) {
resetDistrict(district + 1)
say("DISTRICT STABILIZED! Welcome to " + districtNames(district) + ".")
} else {
won = true
say("CYBERNOVA RESTORED! YOU REBOOTED THE FUTURE.")
}
} else {
say("GATE LOCKED: collect all cores, rescue citizens and tag the Quantum Guardian.")
}
} else {
say("Move close to a citizen to rescue them, or approach the glowing gate.")
}
statusChanged.run()
repaint()
}
def togglePause(): Unit = {
if (won || gameOver) return
paused = !paused
say(if (paused) "GAME PAUSED" else "WELCOME BACK, EXPLORER!")
repaint()
}
def restartDistrict(): Unit = {
health = 100
energy = 100
resetDistrict(district)
gameOver = false
won = false
say("DISTRICT RESTARTED. Good luck!")
}
def updateGame(): Unit = {
if (paused || won || gameOver) return
tickCount += 1
if (pulseCooldown > 0) pulseCooldown -= 1
if (dashCooldown > 0) dashCooldown -= 1
if (pulseTicks > 0) pulseTicks -= 1
if (slowTicks > 0) slowTicks -= 1
if (messageTicks > 0) messageTicks -= 1
var dx = 0.0
var dy = 0.0
if (upHeld) dy -= 1.0
if (downHeld) dy += 1.0
if (leftHeld) dx -= 1.0
if (rightHeld) dx += 1.0
if (mouseTargetX >= 0.0) {
val md = distance(playerX, playerY, mouseTargetX, mouseTargetY)
if (md < 7.0) mouseTargetX = -1.0
else {
dx = (mouseTargetX - playerX) / md
dy = (mouseTargetY - playerY) / md
}
}
val len = math.sqrt(dx * dx + dy * dy)
if (len > 0.0) {
dx /= len
dy /= len
facingX = dx
facingY = dy
val speed = (3.25 + math.min(credits.toDouble / 220.0, 1.5)) * (if (slowTicks > 0) 0.58 else 1.0)
playerX = clamp(playerX + dx * speed, 26.0, worldWidth - 26.0)
playerY = clamp(playerY + dy * speed, 55.0, worldHeight - 55.0)
}
for (core <- cores if !core.collected) {
if (distance(playerX, playerY, core.x, core.y) < 27.0) {
core.collected = true
coresCollected += 1
credits += 15
energy = math.min(100, energy + 8)
say("ENERGY CORE COLLECTED! +15 CREDITS")
}
}
for (drone <- drones) {
if (drone.stunned > 0) drone.stunned -= 1
else {
val dist = distance(playerX, playerY, drone.x, drone.y)
if (dist < 265.0 && dist > 1.0) {
val chaseSpeed = if (drone.boss) 1.0 else 0.72
drone.x += ((playerX - drone.x) / dist) * chaseSpeed
drone.y += ((playerY - drone.y) / dist) * chaseSpeed
} else {
drone.x += math.sin((tickCount + drone.phase * 100.0) * 0.025) * 0.55
drone.y += math.cos((tickCount + drone.phase * 100.0) * 0.021) * 0.45
}
if (dist < 27.0 && tickCount % 22 == 0) {
health = math.max(0, health - 7)
slowTicks = 90
say("DRONE GLITCH! Use PULSE TAG to disable nearby drones.")
if (health <= 0) {
gameOver = true
say("ENERGY DEPLETED. Press R to restart this district.")
}
}
}
}
if (tickCount % 5 == 0) statusChanged.run()
repaint()
}
val gameTimer = new Timer(32, new ActionListener {
def actionPerformed(e: ActionEvent): Unit = updateGame()
})
installKeys()
resetDistrict(0)
gameTimer.start()
addMouseListener(new MouseAdapter {
override def mousePressed(e: MouseEvent): Unit = {
if (!paused && !won && !gameOver) {
val sx = worldWidth / math.max(1.0, getWidth.toDouble)
val sy = worldHeight / math.max(1.0, getHeight.toDouble)
mouseTargetX = e.getX.toDouble * sx
mouseTargetY = e.getY.toDouble * sy
}
}
})
override def paintComponent(graphics: Graphics): Unit = {
super.paintComponent(graphics)
val g = graphics.create().asInstanceOf[Graphics2D]
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
g.scale(getWidth.toDouble / worldWidth, getHeight.toDouble / worldHeight)
drawWorld(g)
g.dispose()
}
def drawWorld(g: Graphics2D): Unit = {
val w = worldWidth.toInt
val h = worldHeight.toInt
val palettes = Array(
(new Color(8, 18, 48), new Color(7, 48, 70), cyan),
(new Color(23, 13, 54), new Color(35, 29, 90), magenta),
(new Color(7, 37, 42), new Color(10, 70, 75), mint),
(new Color(36, 13, 50), new Color(16, 35, 79), gold)
)
val p = palettes(district)
g.setPaint(new GradientPaint(0, 0, p._1, 0, h, p._2))
g.fillRect(0, 0, w, h)
var i = 0
while (i < 75) {
val sx = (i * 131 + 37) % w
val sy = (i * 67 + 19) % h
g.setColor(new Color(170, 230, 255, 90 + (i % 4) * 30))
g.fillOval(sx, sy, 2 + (i % 2), 2 + (i % 2))
i += 1
}
g.setColor(new Color(9, 18, 40, 150))
g.fillRect(0, 415, w, 125)
g.setStroke(new BasicStroke(1.0f))
i = 0
while (i < 18) {
val x = i * 58
g.setColor(new Color(67, 165, 211, 55))
g.drawLine(x, 415, x - 70, h)
g.drawLine(x, 415, x + 70, h)
i += 1
}
i = 0
while (i < 9) {
val x = i * 125 - 25
val bh = 95 + (i * 43 % 175)
g.setColor(new Color(8, 22, 51))
g.fillRoundRect(x, 410 - bh, 82, bh, 8, 8)
g.setColor(new Color(p._3.getRed, p._3.getGreen, p._3.getBlue, 105))
g.setStroke(new BasicStroke(2.0f))
g.drawRoundRect(x, 410 - bh, 82, bh, 8, 8)
var wy = 410 - bh + 18
while (wy < 397) {
g.setColor(new Color(p._3.getRed, p._3.getGreen, p._3.getBlue, 115))
g.fillRect(x + 13, wy, 7, 11)
g.fillRect(x + 31, wy, 7, 11)
g.setColor(new Color(255, 70, 194, 95))
g.fillRect(x + 50, wy, 7, 11)
wy += 25
}
i += 1
}
g.setColor(new Color(17, 35, 63, 215))
g.fillRoundRect(18, 16, 390, 72, 16, 16)
g.setColor(new Color(p._3.getRed, p._3.getGreen, p._3.getBlue, 170))
g.drawRoundRect(18, 16, 390, 72, 16, 16)
g.setFont(new Font("SansSerif", Font.BOLD, 15))
g.setColor(white)
g.drawString(districtNames(district).toUpperCase, 34, 43)
g.setFont(new Font("SansSerif", Font.PLAIN, 11))
g.setColor(p._3)
g.drawString("MISSION: " + districtMissions(district), 34, 65)
drawGate(g, 875, 270)
for (core <- cores if !core.collected) drawCore(g, core)
for (citizen <- citizens if !citizen.rescued) drawCitizen(g, citizen)
for (drone <- drones) drawDrone(g, drone)
drawPlayer(g)
drawBottomMessage(g)
if (paused) drawOverlay(g, "PAUSED", "Press P to resume")
if (gameOver) drawOverlay(g, "ENERGY DEPLETED", "Press R to restart this district")
if (won) drawOverlay(g, "CYBERNOVA RESTORED!", "The future is bright. You are the City Guardian!")
}
def drawCore(g: Graphics2D, core: Core): Unit = {
val colors = Array(cyan, magenta, mint)
val c = colors(core.kind)
val x = core.x.toInt
val y = core.y.toInt
g.setColor(new Color(c.getRed, c.getGreen, c.getBlue, 45))
g.fillOval(x - 21, y - 21, 42, 42)
val xs = Array(x, x + 12, x + 8, x, x - 8, x - 12)
val ys = Array(y - 17, y - 3, y + 12, y + 18, y + 12, y - 3)
g.setColor(c)
g.fillPolygon(xs, ys, 6)
g.setColor(white)
g.drawLine(x, y - 11, x, y + 10)
}
def drawCitizen(g: Graphics2D, c: Citizen): Unit = {
val x = c.x.toInt
val y = c.y.toInt
g.setColor(new Color(255, 219, 135, 50))
g.fillOval(x - 20, y - 27, 40, 50)
g.setColor(new Color(255, 220, 155))
g.fillOval(x - 8, y - 22, 16, 16)
g.setColor(new Color(245, 174, 90))
g.fillRoundRect(x - 11, y - 5, 22, 27, 8, 8)
g.setColor(white)
g.drawString("HELP", x - 15, y - 31)
}
def drawDrone(g: Graphics2D, d: Drone): Unit = {
val x = d.x.toInt
val y = d.y.toInt
val c = if (d.boss) magenta else new Color(255, 105, 132)
if (d.stunned > 0) {
g.setColor(new Color(120, 245, 255, 70))
g.fillOval(x - 28, y - 28, 56, 56)
}
g.setColor(new Color(c.getRed, c.getGreen, c.getBlue, 65))
g.fillOval(x - (if (d.boss) 35 else 24), y - (if (d.boss) 35 else 24), if (d.boss) 70 else 48, if (d.boss) 70 else 48)
val size = if (d.boss) 20 else 14
val xs = Array(x, x + size, x + size + 5, x, x - size - 5, x - size)
val ys = Array(y - size - 5, y - 5, y + size, y + size + 5, y + size, y - 5)
g.setColor(if (d.stunned > 0) cyan else c)
g.fillPolygon(xs, ys, 6)
g.setColor(white)
g.fillOval(x - 3, y - 3, 6, 6)
if (d.boss) {
g.setFont(new Font("SansSerif", Font.BOLD, 11))
g.setColor(white)
g.drawString("QUANTUM GUARDIAN " + bossHitsLeft + " TAGS", x - 68, y - 32)
}
}
def drawPlayer(g: Graphics2D): Unit = {
val x = playerX.toInt
val y = playerY.toInt
g.setColor(new Color(45, 230, 255, 55))
g.fillOval(x - 25, y - 25, 50, 50)
g.setColor(cyan)
g.setStroke(new BasicStroke(3.0f))
g.drawOval(x - 14, y - 14, 28, 28)
g.setColor(white)
g.fillOval(x - 7, y - 17, 14, 14)
g.setColor(new Color(40, 120, 205))
g.fillRoundRect(x - 10, y - 3, 20, 22, 7, 7)
g.setColor(magenta)
g.fillRoundRect(x - 17, y + 17, 34, 6, 4, 4)
g.setColor(white)
g.drawLine(x, y, x + (facingX * 19).toInt, y + (facingY * 19).toInt)
if (pulseTicks > 0) {
g.setColor(new Color(64, 235, 255, 115))
g.setStroke(new BasicStroke(3.0f))
val radius = (24 - pulseTicks) * 7
g.drawOval(x - radius, y - radius, radius * 2, radius * 2)
}
}
def drawGate(g: Graphics2D, x: Int, y: Int): Unit = {
val ready = coresCollected >= requiredCores(district) && citizensRescued >= requiredCitizens(district) && (district != 3 || drones.forall(d => !d.boss))
val c = if (ready) mint else violet
g.setColor(new Color(c.getRed, c.getGreen, c.getBlue, 45))
g.fillOval(x - 42, y - 55, 84, 110)
g.setStroke(new BasicStroke(6.0f))
g.setColor(c)
g.drawOval(x - 27, y - 45, 54, 90)
g.setStroke(new BasicStroke(2.0f))
g.setColor(white)
g.drawOval(x - 17, y - 34, 34, 68)
g.setFont(new Font("SansSerif", Font.BOLD, 10))
g.drawString(if (ready) "OPEN GATE" else "LOCKED", x - 29, y + 66)
}
def drawBottomMessage(g: Graphics2D): Unit = {
g.setColor(new Color(5, 11, 29, 220))
g.fillRoundRect(18, 466, 924, 57, 13, 13)
g.setColor(new Color(62, 180, 220, 125))
g.drawRoundRect(18, 466, 924, 57, 13, 13)
g.setFont(new Font("SansSerif", Font.BOLD, 13))
g.setColor(if (messageTicks > 0) gold else white)
g.drawString(message, 34, 490)
g.setFont(new Font("SansSerif", Font.PLAIN, 11))
g.setColor(cyan)
g.drawString("WASD MOVE | SPACE DASH | F PULSE TAG | E INTERACT | P PAUSE | B BACK", 34, 510)
}
def drawOverlay(g: Graphics2D, title: String, subtitle: String): Unit = {
g.setColor(new Color(3, 7, 20, 205))
g.fillRoundRect(190, 165, 580, 190, 22, 22)
g.setStroke(new BasicStroke(3.0f))
g.setColor(cyan)
g.drawRoundRect(190, 165, 580, 190, 22, 22)
g.setFont(new Font("SansSerif", Font.BOLD, 28))
g.setColor(white)
g.drawString(title, 250, 245)
g.setFont(new Font("SansSerif", Font.PLAIN, 15))
g.setColor(mint)
g.drawString(subtitle, 250, 282)
}
}
}
CyberNovaFutureRevolutionEvent02.main(Array[String]())