Code Sketch
Bixuu02
Category: Programming
// ============================================================================
// THE AMIGOS MUSEUM
// RAIGAD HERITAGE RESCUE MISSION
// FULL SCALA / KOJO CANVASDRAW GAME
// ============================================================================
cleari()
originBottomLeft()
// ============================================================================
// GAME STATE
// ============================================================================
var screen = 0
// 0 = Mission Letter
// 1 = Accept / Decline
// 2 = Home + Messenger
// 3 = Museum Briefing
// 4 = Car Ready
// 5 = Road Map
// 6 = Raigad Arrival
// 7 = Climbing
// 8 = Raigad Room Entrance
// 9 = Heritage Room
// 10 = Authorized Secret Passage
// 11 = Artifact Collection
// 12 = Return Car
// 13 = Return Road
// 14 = Museum Return
// 15 = Prize / World Record
// 16 = Thank You
var missionAccepted = false
var messengerArrived = false
var letterRead = false
var roadTime = 0
var roadFinished = false
var returning = false
var climbLevel = 0
var maxClimb = 7
var backpackPlaced = false
var backpackOpen = false
var artifact1 = false
var artifact2 = false
var artifact3 = false
var artifact4 = false
var artifact5 = false
var collectedCount = 0
var worldRecord = false
var selectedMessage = 0
// Car
var carX = 80.0
var carY = 80.0
var carSpeed = 2.0
var fastMode = false
// Player
var playerX = 160.0
var playerY = 180.0
// Stars
class Star(val x: Double, val y: Double, val size: Double) {
var phase = randomDouble(6.28)
def step() {
phase += 0.04
}
def view(canvas: CanvasDraw) {
val brightness = 150 + (math.sin(phase) * 80).toInt
canvas.noStroke()
canvas.fill(brightness, brightness, 255, 200)
canvas.ellipse(x, y, size, size)
}
}
val stars = ArrayBuffer.empty[Star]
for (i <- 0 until 70) {
stars.append(
new Star(
randomDouble(cwidth),
randomDouble(cheight),
1.0 + randomDouble(3.0)
)
)
}
// ============================================================================
// HELPER FUNCTIONS
// ============================================================================
def button(
canvas: CanvasDraw,
x: Double,
y: Double,
w: Double,
h: Double,
r: Int,
g: Int,
b: Int,
label: String
) {
canvas.noStroke()
canvas.fill(r, g, b)
canvas.rect(x, y, w, h)
canvas.fill(255, 255, 255)
canvas.text(label, x + 12, y + h / 2)
}
def title(
canvas: CanvasDraw,
textValue: String,
y: Double
) {
canvas.fill(255, 215, 0)
canvas.text(textValue, cwidth / 2 - 210, y)
}
def drawStars(canvas: CanvasDraw) {
repeatFor(stars) { s =>
s.view(canvas)
}
}
// ============================================================================
// PLAYER CHARACTER
// ============================================================================
def drawExplorer(
canvas: CanvasDraw,
x: Double,
y: Double,
scale: Double
) {
canvas.noStroke()
// Backpack
canvas.fill(100, 60, 30)
canvas.rect(
x - 35 * scale,
y + 5 * scale,
25 * scale,
55 * scale
)
// Body
canvas.fill(40, 90, 180)
canvas.rect(
x - 25 * scale,
y,
50 * scale,
60 * scale
)
// Head
canvas.fill(255, 210, 170)
canvas.ellipse(
x,
y + 80 * scale,
45 * scale,
45 * scale
)
// Hat
canvas.fill(110, 70, 25)
canvas.rect(
x - 28 * scale,
y + 99 * scale,
56 * scale,
10 * scale
)
// Legs
canvas.fill(40, 40, 40)
canvas.rect(
x - 20 * scale,
y - 35 * scale,
14 * scale,
35 * scale
)
canvas.rect(
x + 6 * scale,
y - 35 * scale,
14 * scale,
35 * scale
)
// Face
canvas.fill(0, 0, 0)
canvas.ellipse(
x - 9 * scale,
y + 82 * scale,
5 * scale,
6 * scale
)
canvas.ellipse(
x + 9 * scale,
y + 82 * scale,
5 * scale,
6 * scale
)
}
// ============================================================================
// MESSENGER
// ============================================================================
def drawMessenger(
canvas: CanvasDraw,
x: Double,
y: Double
) {
canvas.noStroke()
// Body
canvas.fill(30, 100, 170)
canvas.rect(x - 25, y, 50, 70)
// Head
canvas.fill(255, 210, 170)
canvas.ellipse(x, y + 100, 50, 50)
// Hair
canvas.fill(30, 25, 20)
canvas.ellipse(x, y + 120, 52, 30)
// Eyes
canvas.fill(0, 0, 0)
canvas.ellipse(x - 10, y + 103, 5, 6)
canvas.ellipse(x + 10, y + 103, 5, 6)
// Letter
canvas.fill(255, 248, 220)
canvas.rect(x + 35, y + 25, 45, 35)
canvas.fill(150, 0, 0)
canvas.text("!", x + 53, y + 42)
}
// ============================================================================
// MUSEUM GUIDE
// ============================================================================
def drawMuseumGuide(
canvas: CanvasDraw,
x: Double,
y: Double
) {
canvas.noStroke()
canvas.fill(20, 70, 130)
canvas.rect(x - 25, y, 50, 75)
canvas.fill(255, 215, 180)
canvas.ellipse(x, y + 105, 52, 52)
canvas.fill(40, 25, 15)
canvas.ellipse(x, y + 125, 55, 30)
canvas.fill(0, 0, 0)
canvas.ellipse(x - 10, y + 107, 5, 6)
canvas.ellipse(x + 10, y + 107, 5, 6)
}
// ============================================================================
// CAR
// ============================================================================
def drawAdventureCar(
canvas: CanvasDraw,
x: Double,
y: Double
) {
canvas.noStroke()
// Shadow
canvas.fill(30, 30, 30, 100)
canvas.ellipse(x + 85, y - 5, 180, 20)
// Main body
canvas.fill(210, 40, 40)
canvas.rect(x, y + 15, 170, 50)
// Roof
canvas.fill(170, 30, 30)
canvas.rect(x + 35, y + 55, 100, 35)
// Windows
canvas.fill(150, 220, 245)
canvas.rect(x + 45, y + 60, 35, 25)
canvas.rect(x + 90, y + 60, 35, 25)
// Wheels
canvas.fill(20, 20, 20)
canvas.ellipse(x + 35, y + 10, 40, 40)
canvas.ellipse(x + 135, y + 10, 40, 40)
canvas.fill(180, 180, 180)
canvas.ellipse(x + 35, y + 10, 20, 20)
canvas.ellipse(x + 135, y + 10, 20, 20)
// Headlights
canvas.fill(255, 255, 150)
canvas.ellipse(x + 165, y + 35, 10, 10)
// Museum logo
canvas.fill(255, 215, 0)
canvas.text("AMIGOS", x + 60, y + 35)
}
// ============================================================================
// BACKPACK
// ============================================================================
def drawBackpack(
canvas: CanvasDraw,
x: Double,
y: Double
) {
canvas.noStroke()
canvas.fill(90, 55, 25)
canvas.rect(x - 35, y, 70, 80)
canvas.fill(120, 75, 35)
canvas.rect(x - 28, y + 60, 56, 25)
canvas.fill(255, 215, 0)
canvas.rect(x - 12, y + 38, 24, 8)
canvas.fill(40, 30, 20)
canvas.rect(x - 40, y + 20, 8, 45)
canvas.rect(x + 32, y + 20, 8, 45)
canvas.fill(255, 255, 255)
if (backpackOpen) {
canvas.text("BACKPACK OPEN", x - 50, y - 20)
} else {
canvas.text("BACKPACK", x - 35, y - 20)
}
}
// ============================================================================
// ARTIFACT ICON
// ============================================================================
def drawArtifact(
canvas: CanvasDraw,
x: Double,
y: Double,
kind: Int,
collected: Boolean
) {
if (collected) {
canvas.fill(70, 70, 70)
} else {
canvas.fill(255, 215, 0)
}
canvas.noStroke()
if (kind == 1) {
// Historic photo frame
canvas.rect(x - 45, y - 30, 90, 60)
canvas.fill(70, 40, 20)
canvas.rect(x - 30, y - 20, 60, 40)
canvas.fill(255, 220, 180)
canvas.ellipse(x, y, 20, 20)
}
if (kind == 2) {
// Footprint symbol
canvas.ellipse(x, y, 25, 45)
canvas.ellipse(x + 22, y + 20, 10, 15)
canvas.ellipse(x - 18, y + 22, 10, 15)
}
if (kind == 3) {
// Scroll
canvas.fill(230, 200, 130)
canvas.rect(x - 45, y - 25, 90, 50)
canvas.fill(100, 50, 20)
canvas.ellipse(x - 45, y, 15, 50)
canvas.ellipse(x + 45, y, 15, 50)
}
if (kind == 4) {
// Shield
canvas.fill(120, 120, 130)
canvas.ellipse(x, y, 65, 65)
canvas.fill(255, 215, 0)
canvas.ellipse(x, y, 25, 25)
}
if (kind == 5) {
// Historic sword display symbol
canvas.stroke(220, 220, 220)
canvas.strokeWeight(7)
canvas.line(x - 45, y - 35, x + 45, y + 35)
canvas.strokeWeight(4)
canvas.line(x - 25, y + 30, x + 5, y)
}
}
// ============================================================================
// SCREEN 0
// MISSION LETTER
// ============================================================================
def drawMissionLetter(canvas: CanvasDraw) {
canvas.background(15, 25, 45)
drawStars(canvas)
canvas.fill(255, 248, 220)
canvas.stroke(212, 175, 55)
canvas.strokeWeight(5)
canvas.rect(
cwidth / 2 - 280,
cheight / 2 - 210,
560,
420
)
canvas.noStroke()
canvas.fill(120, 20, 20)
canvas.text(
"THE AMIGOS MUSEUM",
cwidth / 2 - 120,
cheight / 2 + 175
)
canvas.fill(170, 0, 0)
canvas.text(
"SECRET HERITAGE MISSION",
cwidth / 2 - 135,
cheight / 2 + 145
)
canvas.fill(40, 40, 40)
canvas.text(
"Dear Heritage Explorer,",
cwidth / 2 - 245,
cheight / 2 + 105
)
canvas.text(
"You have been selected for a special mission",
cwidth / 2 - 245,
cheight / 2 + 75
)
canvas.text(
"from The Amigos Museum.",
cwidth / 2 - 245,
cheight / 2 + 50
)
canvas.text(
"Your mission is to travel to Raigad Fort and",
cwidth / 2 - 245,
cheight / 2 + 20
)
canvas.text(
"recover historically important Maratha-era",
cwidth / 2 - 245,
cheight / 2 - 5
)
canvas.text(
"heritage items that are being preserved for",
cwidth / 2 - 245,
cheight / 2 - 30
)
canvas.text(
"The Amigos Museum.",
cwidth / 2 - 245,
cheight / 2 - 55
)
canvas.fill(120, 20, 20)
canvas.text(
"The mission includes a historic photo frame,",
cwidth / 2 - 245,
cheight / 2 - 90
)
canvas.text(
"documents, symbols and other protected exhibits.",
cwidth / 2 - 245,
cheight / 2 - 115
)
canvas.fill(0, 100, 50)
canvas.text(
"Complete the mission and earn a special prize!",
cwidth / 2 - 230,
cheight / 2 - 155
)
button(
canvas,
cwidth / 2 - 130,
25,
260,
45,
20,
130,
70,
"READ & CONTINUE"
)
}
// ============================================================================
// SCREEN 1
// ACCEPT / DECLINE
// ============================================================================
def drawAcceptScreen(canvas: CanvasDraw) {
canvas.background(25, 35, 60)
drawStars(canvas)
title(
canvas,
"DO YOU ACCEPT THE MISSION?",
cheight - 70
)
canvas.fill(255, 255, 255)
canvas.text(
"Mission: Raigad Heritage Rescue",
cwidth / 2 - 145,
cheight - 120
)
canvas.text(
"Museum: The Amigos Museum",
cwidth / 2 - 135,
cheight - 150
)
canvas.text(
"Your objective is to preserve and safely return",
cwidth / 2 - 180,
cheight - 190
)
canvas.text(
"the authorized heritage exhibits to the museum.",
cwidth / 2 - 180,
cheight - 215
)
button(
canvas,
cwidth / 2 - 180,
100,
150,
55,
0,
160,
80,
"ACCEPT"
)
button(
canvas,
cwidth / 2 + 30,
100,
150,
55,
190,
50,
50,
"DECLINE"
)
}
// ============================================================================
// SCREEN 2
// HOME + KNOCK KNOCK MESSENGER
// ============================================================================
def drawHomeScreen(canvas: CanvasDraw) {
canvas.background(135, 206, 235)
// Ground
canvas.fill(70, 160, 70)
canvas.rect(0, 0, cwidth, 150)
// House
canvas.fill(235, 190, 140)
canvas.rect(cwidth / 2 - 190, 150, 380, 220)
// Roof
canvas.fill(130, 40, 30)
canvas.rect(cwidth / 2 - 220, 350, 440, 45)
// Door
canvas.fill(110, 60, 25)
canvas.rect(cwidth / 2 - 45, 150, 90, 150)
canvas.fill(255, 215, 0)
canvas.ellipse(cwidth / 2 + 25, 220, 10, 10)
canvas.fill(255, 255, 255)
if (!messengerArrived) {
canvas.text(
"You are at home...",
cwidth / 2 - 90,
cheight - 55
)
canvas.text(
"KNOCK... KNOCK...",
cwidth / 2 - 85,
cheight - 85
)
button(
canvas,
cwidth / 2 - 110,
30,
220,
50,
0,
120,
200,
"OPEN THE DOOR"
)
} else {
drawMessenger(
canvas,
cwidth / 2 + 100,
145
)
canvas.fill(255, 255, 255)
canvas.text(
"Messenger: A letter for you!",
cwidth / 2 - 140,
cheight - 55
)
button(
canvas,
cwidth / 2 - 120,
30,
240,
50,
0,
150,
80,
"ACCEPT LETTER"
)
}
}
// ============================================================================
// SCREEN 3
// MUSEUM BRIEFING
// ============================================================================
def drawMuseumBriefing(canvas: CanvasDraw) {
canvas.background(35, 25, 20)
// Museum walls
canvas.fill(210, 180, 130)
canvas.rect(40, 90, cwidth - 80, cheight - 160)
// Museum sign
canvas.fill(80, 40, 20)
canvas.rect(cwidth / 2 - 190, cheight - 90, 380, 55)
canvas.fill(255, 215, 0)
canvas.text(
"THE AMIGOS MUSEUM",
cwidth / 2 - 105,
cheight - 55
)
drawMuseumGuide(
canvas,
100,
150
)
canvas.fill(40, 30, 20)
canvas.text(
"MUSEUM GUIDE:",
160,
cheight - 130
)
canvas.text(
"Your mission has been approved.",
160,
cheight - 160
)
canvas.text(
"Follow the map to Raigad Fort.",
160,
cheight - 190
)
canvas.text(
"Preserve every authorized exhibit carefully.",
160,
cheight - 220
)
canvas.text(
"Your backpack will store the mission exhibits.",
160,
cheight - 250
)
canvas.fill(120, 20, 20)
canvas.text(
"IMPORTANT: Never damage the fort or any heritage structure.",
160,
cheight - 290
)
button(
canvas,
cwidth / 2 - 130,
30,
260,
50,
0,
140,
80,
"GO TO THE CAR"
)
}
// ============================================================================
// SCREEN 4
// CAR READY
// ============================================================================
def drawCarReady(canvas: CanvasDraw) {
canvas.background(120, 190, 230)
canvas.fill(60, 150, 60)
canvas.rect(0, 0, cwidth, 150)
canvas.fill(70, 70, 75)
canvas.rect(0, 70, cwidth, 75)
canvas.fill(235, 200, 150)
canvas.rect(70, 145, 210, 130)
canvas.fill(120, 60, 20)
canvas.rect(145, 145, 60, 80)
drawAdventureCar(
canvas,
cwidth / 2 - 90,
110
)
canvas.fill(255, 255, 255)
canvas.text(
"THE ADVENTURE CAR IS READY!",
cwidth / 2 - 125,
cheight - 55
)
canvas.text(
"Your route map will appear inside the car.",
cwidth / 2 - 150,
cheight - 85
)
button(
canvas,
cwidth / 2 - 120,
25,
240,
50,
20,
130,
70,
"ENTER THE CAR"
)
}
// ============================================================================
// ROAD MAP
// ============================================================================
def drawRoadMap(canvas: CanvasDraw) {
canvas.background(55, 120, 70)
// Mountains
canvas.fill(75, 90, 75)
canvas.rect(0, 330, cwidth, 120)
canvas.fill(100, 110, 80)
canvas.rect(40, 370, 170, 100)
canvas.fill(80, 100, 75)
canvas.rect(300, 350, 210, 120)
// Road
canvas.fill(70, 70, 70)
canvas.rect(0, 115, cwidth, 110)
// Road lines
canvas.fill(255, 220, 0)
for (i <- 0 until 8) {
canvas.rect(
i * 90,
165,
50,
8
)
}
// Destination
canvas.fill(120, 40, 30)
canvas.rect(cwidth - 130, 230, 70, 130)
canvas.fill(255, 215, 0)
canvas.rect(cwidth - 160, 360, 130, 35)
canvas.fill(0, 0, 0)
canvas.text(
"RAIGAD FORT",
cwidth - 150,
375
)
// Map panel
canvas.fill(245, 240, 210)
canvas.rect(20, cheight - 150, 300, 105)
canvas.fill(40, 40, 40)
canvas.text(
"ROUTE MAP",
40,
cheight - 65
)
canvas.text(
"START -> RIGHT -> LEFT -> STRAIGHT",
40,
cheight - 90
)
canvas.text(
"FOLLOW THE ROAD TO RAIGAD",
40,
cheight - 115
)
// Car
drawAdventureCar(
canvas,
carX,
carY
)
// Top information
canvas.fill(255, 255, 255)
if (!roadFinished) {
canvas.text(
"TRAVELLING TO RAIGAD FORT",
20,
cheight - 25
)
canvas.text(
"TIME: " + roadTime,
400,
cheight - 25
)
} else {
canvas.fill(0, 120, 60)
canvas.text(
"DESTINATION REACHED!",
20,
cheight - 25
)
}
// Arrow controls
button(
canvas,
360,
35,
65,
45,
30,
110,
210,
"LEFT"
)
button(
canvas,
435,
35,
65,
45,
30,
110,
210,
"UP"
)
button(
canvas,
510,
35,
65,
45,
30,
110,
210,
"RIGHT"
)
button(
canvas,
590,
35,
90,
45,
220,
100,
20,
"FAST"
)
if (roadFinished) {
button(
canvas,
cwidth / 2 - 100,
30,
200,
45,
0,
150,
80,
"STOP & GET OUT"
)
}
}
// ============================================================================
// SCREEN 6
// ARRIVAL AT RAIGAD
// ============================================================================
def drawArrival(canvas: CanvasDraw) {
canvas.background(120, 185, 225)
// Fort
canvas.fill(90, 85, 80)
canvas.rect(100, 190, 440, 170)
// Fort towers
canvas.rect(80, 250, 60, 150)
canvas.rect(500, 250, 60, 150)
// Fort top
canvas.fill(70, 65, 60)
canvas.rect(60, 360, 520, 35)
// Gate
canvas.fill(55, 40, 30)
canvas.rect(cwidth / 2 - 55, 190, 110, 130)
canvas.fill(255, 215, 0)
canvas.text(
"YOU HAVE ARRIVED AT YOUR DESTINATION!",
cwidth / 2 - 190,
cheight - 55
)
canvas.fill(255, 255, 255)
canvas.text(
"Raigad Fort",
cwidth / 2 - 55,
cheight - 90
)
button(
canvas,
cwidth / 2 - 110,
25,
220,
50,
0,
130,
80,
"GET OUT OF THE CAR"
)
}
// ============================================================================
// SCREEN 7
// CLIMBING
// ============================================================================
def drawClimbing(canvas: CanvasDraw) {
canvas.background(120, 185, 225)
// Mountain
canvas.fill(90, 100, 80)
canvas.rect(0, 0, cwidth, 130)
canvas.fill(105, 110, 90)
canvas.rect(70, 120, 450, 300)
// Stair/Path
canvas.fill(125, 105, 80)
canvas.rect(110, 120, 330, 35)
canvas.rect(150, 155, 260, 35)
canvas.rect(190, 190, 190, 35)
canvas.rect(230, 225, 120, 35)
canvas.rect(260, 260, 70, 35)
// Fort top
canvas.fill(80, 70, 60)
canvas.rect(250, 295, 80, 100)
// Player
drawExplorer(
canvas,
160 + climbLevel * 45,
135 + climbLevel * 35,
0.7
)
canvas.fill(255, 255, 255)
canvas.text(
"RAIGAD CLIMBING PATH",
30,
cheight - 35
)
canvas.text(
"STEP " + climbLevel + " / " + maxClimb,
30,
cheight - 65
)
canvas.fill(255, 235, 150)
canvas.text(
"HERITAGE RULES:",
30,
cheight - 105
)
canvas.fill(255, 255, 255)
canvas.text(
"Do not damage walls, stones or protected structures.",
30,
cheight - 130
)
canvas.text(
"Stay on the marked visitor path.",
30,
cheight - 155
)
if (climbLevel < maxClimb) {
button(
canvas,
cwidth / 2 - 110,
30,
220,
50,
40,
130,
70,
"CLIMB UP"
)
} else {
button(
canvas,
cwidth / 2 - 130,
30,
260,
50,
40,
130,
70,
"ENTER THE RAIGAD ROOM"
)
}
}
// ============================================================================
// SCREEN 8
// RAIGAD ROOM ENTRANCE
// ============================================================================
def drawRaigadRoomEntrance(canvas: CanvasDraw) {
canvas.background(80, 65, 50)
// Large room
canvas.fill(190, 165, 125)
canvas.rect(45, 70, cwidth - 90, cheight - 120)
// Door
canvas.fill(70, 40, 25)
canvas.rect(cwidth / 2 - 90, 100, 180, 230)
canvas.fill(255, 215, 0)
canvas.text(
"RAIGAD HERITAGE ROOM",
cwidth / 2 - 130,
cheight - 60
)
canvas.fill(255, 255, 255)
canvas.text(
"Authorized preservation area",
cwidth / 2 - 105,
cheight - 95
)
button(
canvas,
cwidth / 2 - 120,
25,
240,
50,
120,
70,
25,
"ENTER ROOM"
)
}
// ============================================================================
// SCREEN 9
// HERITAGE ROOM
// ============================================================================
def drawHeritageRoom(canvas: CanvasDraw) {
canvas.background(65, 50, 40)
// Wall
canvas.fill(190, 160, 115)
canvas.rect(30, 60, cwidth - 60, cheight - 100)
// Frames
canvas.fill(80, 45, 20)
canvas.rect(80, 250, 120, 90)
canvas.rect(240, 270, 120, 90)
canvas.rect(400, 250, 120, 90)
canvas.fill(255, 225, 180)
canvas.ellipse(140, 295, 45, 45)
canvas.ellipse(300, 315, 45, 45)
canvas.ellipse(460, 295, 45, 45)
// Footprint display
canvas.fill(90, 70, 50)
canvas.rect(150, 110, 260, 70)
canvas.fill(255, 215, 0)
canvas.text(
"HERITAGE DISPLAY",
205,
145
)
// Explorer
drawExplorer(
canvas,
70,
100,
0.55
)
canvas.fill(255, 255, 255)
canvas.text(
"Explore the room carefully.",
60,
cheight - 45
)
canvas.text(
"A protected authorized passage is located behind the display.",
60,
cheight - 75
)
button(
canvas,
cwidth / 2 - 120,
25,
240,
45,
90,
70,
30,
"OPEN PASSAGE"
)
}
// ============================================================================
// SCREEN 10
// AUTHORIZED SECRET PASSAGE
// ============================================================================
def drawSecretPassage(canvas: CanvasDraw) {
canvas.background(25, 25, 35)
// Stone tunnel
canvas.fill(80, 80, 85)
canvas.rect(80, 70, cwidth - 160, cheight - 120)
// Tunnel blocks
canvas.stroke(50, 50, 55)
canvas.strokeWeight(3)
for (i <- 0 until 7) {
canvas.line(
100 + i * 70,
80,
100 + i * 70,
cheight - 70
)
}
canvas.noStroke()
canvas.fill(255, 215, 0)
canvas.text(
"AUTHORIZED PRESERVATION PASSAGE",
cwidth / 2 - 175,
cheight - 55
)
canvas.fill(255, 255, 255)
canvas.text(
"The museum team has authorized this passage.",
cwidth / 2 - 170,
cheight - 90
)
drawBackpack(
canvas,
cwidth / 2,
180
)
canvas.fill(255, 255, 255)
canvas.text(
"BACKPACK READY",
cwidth / 2 - 65,
150
)
button(
canvas,
cwidth / 2 - 130,
25,
260,
50,
0,
140,
80,
"PUT ON BACKPACK"
)
}
// ============================================================================
// SCREEN 11
// ARTIFACT COLLECTION
// ============================================================================
def drawCollectionRoom(canvas: CanvasDraw) {
canvas.background(50, 40, 35)
canvas.fill(200, 175, 125)
canvas.rect(30, 60, cwidth - 60, cheight - 110)
canvas.fill(60, 40, 25)
canvas.rect(45, cheight - 100, cwidth - 90, 45)
canvas.fill(255, 215, 0)
canvas.text(
"AUTHORIZED HERITAGE COLLECTION",
cwidth / 2 - 175,
cheight - 70
)
canvas.fill(255, 255, 255)
canvas.text(
"Move near an exhibit and press B to place it in the backpack.",
55,
cheight - 115
)
// Artifact 1
drawArtifact(
canvas,
120,
270,
1,
artifact1
)
// Artifact 2
drawArtifact(
canvas,
250,
270,
2,
artifact2
)
// Artifact 3
drawArtifact(
canvas,
380,
270,
3,
artifact3
)
// Artifact 4
drawArtifact(
canvas,
180,
150,
4,
artifact4
)
// Artifact 5
drawArtifact(
canvas,
420,
150,
5,
artifact5
)
// Backpack
drawBackpack(
canvas,
cwidth - 80,
90
)
canvas.fill(255, 255, 255)
canvas.text(
"ITEMS: " + collectedCount + " / 5",
cwidth - 135,
60
)
// Player
drawExplorer(
canvas,
playerX,
playerY,
0.55
)
canvas.fill(255, 255, 255)
if (collectedCount < 5) {
canvas.text(
"Explore the exhibits.",
55,
30
)
} else {
canvas.fill(0, 150, 70)
canvas.text(
"ALL AUTHORIZED EXHIBITS COLLECTED!",
55,
30
)
button(
canvas,
cwidth / 2 - 120,
30,
240,
45,
0,
140,
80,
"RETURN OUTSIDE"
)
}
}
// ============================================================================
// SCREEN 12
// RETURN TO CAR
// ============================================================================
def drawReturnCar(canvas: CanvasDraw) {
canvas.background(120, 185, 225)
canvas.fill(80, 150, 70)
canvas.rect(0, 0, cwidth, 150)
drawAdventureCar(
canvas,
cwidth / 2 - 85,
110
)
drawBackpack(
canvas,
cwidth / 2,
210
)
canvas.fill(255, 255, 255)
canvas.text(
"The protected exhibits are safely packed.",
cwidth / 2 - 160,
cheight - 55
)
button(
canvas,
cwidth / 2 - 120,
25,
240,
50,
0,
130,
80,
"ENTER THE CAR"
)
}
// ============================================================================
// SCREEN 13
// RETURN ROAD
// ============================================================================
def drawReturnRoad(canvas: CanvasDraw) {
canvas.background(55, 120, 70)
canvas.fill(70, 70, 70)
canvas.rect(0, 100, cwidth, 120)
canvas.fill(255, 220, 0)
for (i <- 0 until 8) {
canvas.rect(
i * 90,
155,
50,
8
)
}
// Museum destination
canvas.fill(210, 180, 130)
canvas.rect(cwidth - 140, 230, 100, 150)
canvas.fill(80, 40, 20)
canvas.rect(cwidth - 115, 230, 50, 80)
canvas.fill(255, 215, 0)
canvas.text(
"MUSEUM",
cwidth - 125,
355
)
drawAdventureCar(
canvas,
carX,
105
)
canvas.fill(255, 255, 255)
canvas.text(
"RETURNING TO THE AMIGOS MUSEUM",
20,
cheight - 30
)
canvas.text(
"Follow the road back to the museum.",
20,
cheight - 60
)
if (roadFinished) {
button(
canvas,
cwidth / 2 - 110,
30,
220,
45,
0,
150,
80,
"ENTER MUSEUM"
)
}
}
// ============================================================================
// SCREEN 14
// MUSEUM RETURN
// ============================================================================
def drawMuseumReturn(canvas: CanvasDraw) {
canvas.background(40, 30, 20)
canvas.fill(210, 180, 130)
canvas.rect(40, 70, cwidth - 80, cheight - 120)
canvas.fill(80, 40, 20)
canvas.rect(cwidth / 2 - 200, cheight - 90, 400, 55)
canvas.fill(255, 215, 0)
canvas.text(
"THE AMIGOS MUSEUM",
cwidth / 2 - 105,
cheight - 55
)
drawMuseumGuide(
canvas,
120,
150
)
drawBackpack(
canvas,
cwidth - 120,
145
)
canvas.fill(40, 30, 20)
canvas.text(
"MUSEUM GUIDE:",
180,
cheight - 130
)
canvas.text(
"Excellent work! The heritage exhibits",
180,
cheight - 160
)
canvas.text(
"have been safely returned for preservation.",
180,
cheight - 190
)
canvas.fill(0, 120, 60)
canvas.text(
"MISSION SUCCESS!",
180,
cheight - 230
)
button(
canvas,
cwidth / 2 - 130,
25,
260,
50,
220,
160,
0,
"SUBMIT EXHIBITS"
)
}
// ============================================================================
// SCREEN 15
// PRIZE + WORLD RECORD
// ============================================================================
def drawWorldRecord(canvas: CanvasDraw) {
canvas.background(15, 25, 50)
drawStars(canvas)
canvas.fill(255, 215, 0)
canvas.text(
"MISSION COMPLETED!",
cwidth / 2 - 125,
cheight - 60
)
canvas.fill(255, 255, 255)
canvas.text(
"THE AMIGOS MUSEUM",
cwidth / 2 - 105,
cheight - 100
)
canvas.fill(255, 215, 0)
canvas.text(
"WORLD RECORD",
cwidth / 2 - 100,
cheight - 145
)
canvas.fill(255, 255, 255)
canvas.text(
"You completed the Raigad Heritage Rescue Mission.",
cwidth / 2 - 190,
cheight - 190
)
canvas.text(
"All 5 authorized exhibits were returned safely.",
cwidth / 2 - 175,
cheight - 220
)
canvas.fill(255, 215, 0)
canvas.text(
"SPECIAL PRIZE UNLOCKED!",
cwidth / 2 - 140,
cheight - 270
)
// Trophy
canvas.fill(255, 215, 0)
canvas.rect(cwidth / 2 - 25, 120, 50, 75)
canvas.ellipse(cwidth / 2, 200, 80, 35)
canvas.fill(255, 255, 255)
canvas.text(
"HERITAGE HERO",
cwidth / 2 - 70,
90
)
button(
canvas,
cwidth / 2 - 120,
25,
240,
45,
0,
150,
80,
"FINISH MISSION"
)
}
// ============================================================================
// SCREEN 16
// THANK YOU
// ============================================================================
def drawThankYou(canvas: CanvasDraw) {
canvas.background(20, 60, 35)
drawStars(canvas)
canvas.fill(255, 215, 0)
canvas.text(
"THANK YOU!",
cwidth / 2 - 70,
cheight - 75
)
canvas.fill(255, 255, 255)
canvas.text(
"You successfully completed",
cwidth / 2 - 115,
cheight - 125
)
canvas.text(
"The Amigos Museum Raigad Heritage Mission.",
cwidth / 2 - 170,
cheight - 155
)
canvas.fill(255, 215, 0)
canvas.text(
"PRESERVE HISTORY ? RESPECT HERITAGE ? LEARN",
cwidth / 2 - 205,
cheight - 210
)
canvas.fill(255, 255, 255)
canvas.text(
"MISSION COMPLETE",
cwidth / 2 - 100,
100
)
canvas.text(
"Congratulations, Heritage Explorer!",
cwidth / 2 - 140,
70
)
}
// ============================================================================
// ROAD ANIMATION
// ============================================================================
def updateRoadAnimation() {
if (screen == 5 && !roadFinished) {
var speedNow = 2.0
if (fastMode) {
speedNow = 4.0
}
carX += speedNow
roadTime += 1
if (carX > cwidth - 190) {
carX = cwidth - 190
roadFinished = true
}
}
if (screen == 13 && !roadFinished) {
var returnSpeed = 2.0
if (fastMode) {
returnSpeed = 4.0
}
carX += returnSpeed
roadTime += 1
if (carX > cwidth - 190) {
carX = cwidth - 190
roadFinished = true
}
}
}
// ============================================================================
// ARTIFACT COLLECTION
// ============================================================================
def collectArtifact(kind: Int) {
if (kind == 1 && !artifact1) {
artifact1 = true
collectedCount += 1
}
if (kind == 2 && !artifact2) {
artifact2 = true
collectedCount += 1
}
if (kind == 3 && !artifact3) {
artifact3 = true
collectedCount += 1
}
if (kind == 4 && !artifact4) {
artifact4 = true
collectedCount += 1
}
if (kind == 5 && !artifact5) {
artifact5 = true
collectedCount += 1
}
}
// ============================================================================
// MAIN CLICK HANDLER
// ============================================================================
def handleClick(x: Double, y: Double) {
// --------------------------------------------------------
// SCREEN 0
// --------------------------------------------------------
if (screen == 0) {
if (
x >= cwidth / 2 - 130 &&
x <= cwidth / 2 + 130 &&
y >= 25 &&
y <= 70
) {
screen = 1
}
}
// --------------------------------------------------------
// SCREEN 1
// --------------------------------------------------------
else if (screen == 1) {
// ACCEPT
if (
x >= cwidth / 2 - 180 &&
x <= cwidth / 2 - 30 &&
y >= 100 &&
y <= 155
) {
missionAccepted = true
screen = 2
}
// DECLINE
else if (
x >= cwidth / 2 + 30 &&
x <= cwidth / 2 + 180 &&
y >= 100 &&
y <= 155
) {
screen = 0
}
}
// --------------------------------------------------------
// SCREEN 2
// --------------------------------------------------------
else if (screen == 2) {
if (
x >= cwidth / 2 - 110 &&
x <= cwidth / 2 + 110 &&
y >= 30 &&
y <= 80
) {
messengerArrived = true
}
if (
messengerArrived &&
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 30 &&
y <= 80
) {
letterRead = true
screen = 3
}
}
// --------------------------------------------------------
// SCREEN 3
// --------------------------------------------------------
else if (screen == 3) {
if (
x >= cwidth / 2 - 130 &&
x <= cwidth / 2 + 130 &&
y >= 30 &&
y <= 80
) {
screen = 4
}
}
// --------------------------------------------------------
// SCREEN 4
// --------------------------------------------------------
else if (screen == 4) {
if (
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 25 &&
y <= 75
) {
carX = 50
carY = 95
roadTime = 0
roadFinished = false
fastMode = false
screen = 5
}
}
// --------------------------------------------------------
// SCREEN 5
// --------------------------------------------------------
else if (screen == 5) {
// LEFT
if (
x >= 360 &&
x <= 425 &&
y >= 35 &&
y <= 80
) {
carX -= 25
if (carX < 0) {
carX = 0
}
}
// UP
else if (
x >= 435 &&
x <= 500 &&
y >= 35 &&
y <= 80
) {
carX += 20
}
// RIGHT
else if (
x >= 510 &&
x <= 575 &&
y >= 35 &&
y <= 80
) {
carX += 35
}
// FAST
else if (
x >= 590 &&
x <= 680 &&
y >= 35 &&
y <= 80
) {
fastMode = !fastMode
}
// STOP
else if (
roadFinished &&
x >= cwidth / 2 - 100 &&
x <= cwidth / 2 + 100 &&
y >= 30 &&
y <= 75
) {
screen = 6
}
}
// --------------------------------------------------------
// SCREEN 6
// --------------------------------------------------------
else if (screen == 6) {
if (
x >= cwidth / 2 - 110 &&
x <= cwidth / 2 + 110 &&
y >= 25 &&
y <= 75
) {
screen = 7
climbLevel = 0
}
}
// --------------------------------------------------------
// SCREEN 7
// --------------------------------------------------------
else if (screen == 7) {
if (climbLevel < maxClimb) {
if (
x >= cwidth / 2 - 110 &&
x <= cwidth / 2 + 110 &&
y >= 30 &&
y <= 80
) {
climbLevel += 1
}
} else {
if (
x >= cwidth / 2 - 130 &&
x <= cwidth / 2 + 130 &&
y >= 30 &&
y <= 80
) {
screen = 8
}
}
}
// --------------------------------------------------------
// SCREEN 8
// --------------------------------------------------------
else if (screen == 8) {
if (
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 25 &&
y <= 75
) {
screen = 9
}
}
// --------------------------------------------------------
// SCREEN 9
// --------------------------------------------------------
else if (screen == 9) {
if (
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 25 &&
y <= 70
) {
screen = 10
}
}
// --------------------------------------------------------
// SCREEN 10
// --------------------------------------------------------
else if (screen == 10) {
if (
x >= cwidth / 2 - 130 &&
x <= cwidth / 2 + 130 &&
y >= 25 &&
y <= 75
) {
backpackPlaced = true
backpackOpen = true
screen = 11
}
}
// --------------------------------------------------------
// SCREEN 11
// ARTIFACT COLLECTION
// --------------------------------------------------------
else if (screen == 11) {
// B-style collection zones using click
// Artifact 1
if (
x >= 75 &&
x <= 165 &&
y >= 240 &&
y <= 320
) {
collectArtifact(1)
}
// Artifact 2
else if (
x >= 205 &&
x <= 295 &&
y >= 240 &&
y <= 320
) {
collectArtifact(2)
}
// Artifact 3
else if (
x >= 335 &&
x <= 425 &&
y >= 240 &&
y <= 320
) {
collectArtifact(3)
}
// Artifact 4
else if (
x >= 140 &&
x <= 220 &&
y >= 115 &&
y <= 185
) {
collectArtifact(4)
}
// Artifact 5
else if (
x >= 380 &&
x <= 465 &&
y >= 115 &&
y <= 185
) {
collectArtifact(5)
}
// Return
else if (
collectedCount == 5 &&
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 30 &&
y <= 75
) {
screen = 12
}
}
// --------------------------------------------------------
// SCREEN 12
// --------------------------------------------------------
else if (screen == 12) {
if (
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 25 &&
y <= 75
) {
carX = 50
roadFinished = false
roadTime = 0
fastMode = false
screen = 13
}
}
// --------------------------------------------------------
// SCREEN 13
// --------------------------------------------------------
else if (screen == 13) {
if (
roadFinished &&
x >= cwidth / 2 - 110 &&
x <= cwidth / 2 + 110 &&
y >= 30 &&
y <= 75
) {
screen = 14
}
}
// --------------------------------------------------------
// SCREEN 14
// --------------------------------------------------------
else if (screen == 14) {
if (
x >= cwidth / 2 - 130 &&
x <= cwidth / 2 + 130 &&
y >= 25 &&
y <= 80
) {
worldRecord = true
screen = 15
}
}
// --------------------------------------------------------
// SCREEN 15
// --------------------------------------------------------
else if (screen == 15) {
if (
x >= cwidth / 2 - 120 &&
x <= cwidth / 2 + 120 &&
y >= 25 &&
y <= 70
) {
screen = 16
}
}
}
// ============================================================================
// MOUSE
// ============================================================================
onMouseClick {
(x, y) =>
handleClick(x, y)
}
// ============================================================================
// KEYBOARD
// ============================================================================
// B = collect nearby authorized exhibit
// F = fast car
// Arrow-like keys can also move the car in the road scene.
onKeyPress {
key =>
if (screen == 11 && key == 'b') {
if (playerX < 180 && playerY > 220) {
collectArtifact(1)
}
else if (playerX >= 180 && playerX < 330 && playerY > 220) {
collectArtifact(2)
}
else if (playerX >= 330 && playerY > 220) {
collectArtifact(3)
}
else if (playerX < 300 && playerY <= 220) {
collectArtifact(4)
}
else if (playerX >= 300 && playerY <= 220) {
collectArtifact(5)
}
}
else if (screen == 5 && key == 'f') {
fastMode = !fastMode
}
else if (screen == 13 && key == 'f') {
fastMode = !fastMode
}
else if (screen == 11 && key == 'a') {
playerX -= 15
}
else if (screen == 11 && key == 'd') {
playerX += 15
}
else if (screen == 11 && key == 'w') {
playerY += 15
}
else if (screen == 11 && key == 's') {
playerY -= 15
}
}
// ============================================================================
// MAIN ANIMATION LOOP
// ============================================================================
animateWithCanvasDraw { canvas =>
repeatFor(stars) { s =>
s.step()
}
updateRoadAnimation()
if (screen == 0) {
drawMissionLetter(canvas)
}
else if (screen == 1) {
drawAcceptScreen(canvas)
}
else if (screen == 2) {
drawHomeScreen(canvas)
}
else if (screen == 3) {
drawMuseumBriefing(canvas)
}
else if (screen == 4) {
drawCarReady(canvas)
}
else if (screen == 5) {
drawRoadMap(canvas)
}
else if (screen == 6) {
drawArrival(canvas)
}
else if (screen == 7) {
drawClimbing(canvas)
}
else if (screen == 8) {
drawRaigadRoomEntrance(canvas)
}
else if (screen == 9) {
drawHeritageRoom(canvas)
}
else if (screen == 10) {
drawSecretPassage(canvas)
}
else if (screen == 11) {
drawCollectionRoom(canvas)
}
else if (screen == 12) {
drawReturnCar(canvas)
}
else if (screen == 13) {
drawReturnRoad(canvas)
}
else if (screen == 14) {
drawMuseumReturn(canvas)
}
else if (screen == 15) {
drawWorldRecord(canvas)
}
else if (screen == 16) {
drawThankYou(canvas)
}
}