Code Sketch
Bixuu02
Category: Programming
// ============================================================
// TEACHER'S DAY ANIMATED MISSION GAME - TEACHER IN CAR
// ============================================================
cleari()
originBottomLeft()
// ============================================================
// GAME STATES & ANIMATION VARIABLES
// ============================================================
var screen = 0
var selectedClass = ""
var selectedStudent = ""
// Delivery Animation State Variables
var carX = -120.0
var carY = 100.0
var isCarAtHouse = false
var showStudentWithTeacher = false
var isCarGoingFinalHome = false
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 60) {
stars.append(new Star(randomDouble(cwidth), randomDouble(cheight), 1.0 + randomDouble(3.0)))
}
// ============================================================
// DRAW DETAILED AVATARS (TEACHER & STUDENT)
// ============================================================
def drawDetailedAvatar(canvas: CanvasDraw, x: Double, y: Double, gender: String, scale: Double) {
canvas.noStroke()
if (gender == "WOMAN") {
canvas.fill(30, 20, 15)
canvas.ellipse(x, y + 20 * scale, 75 * scale, 85 * scale)
canvas.fill(255, 220, 180)
canvas.ellipse(x, y + 25 * scale, 55 * scale, 60 * scale)
canvas.fill(100, 30, 180)
canvas.rect(x - 30 * scale, y - 60 * scale, 60 * scale, 70 * scale)
canvas.fill(255, 215, 0)
canvas.line(x - 30 * scale, y - 60 * scale, x + 20 * scale, y + 5 * scale)
canvas.fill(220, 0, 0)
canvas.ellipse(x, y + 33 * scale, 8 * scale, 8 * scale)
} else {
canvas.fill(30, 30, 30)
canvas.ellipse(x, y + 40 * scale, 60 * scale, 30 * scale)
canvas.fill(255, 220, 180)
canvas.ellipse(x, y + 20 * scale, 55 * scale, 55 * scale)
canvas.fill(240, 240, 240)
canvas.rect(x - 30 * scale, y - 60 * scale, 60 * scale, 70 * scale)
canvas.fill(30, 50, 100)
canvas.rect(x - 25 * scale, y - 60 * scale, 50 * scale, 60 * scale)
}
canvas.fill(0, 0, 0)
canvas.ellipse(x - 12 * scale, y + 22 * scale, 6 * scale, 8 * scale)
canvas.ellipse(x + 12 * scale, y + 22 * scale, 6 * scale, 8 * scale)
canvas.stroke(180, 50, 50)
canvas.strokeWeight(2 * scale)
canvas.line(x - 10 * scale, y + 8 * scale, x + 10 * scale, y + 8 * scale)
}
// ============================================================
// DETAILED CAR DRAWING WITH TEACHER INSIDE
// ============================================================
def drawDetailedCarWithTeacher(canvas: CanvasDraw, x: Double, y: Double) {
canvas.noStroke()
canvas.fill(50, 50, 50, 100)
canvas.ellipse(x + 75, y - 5, 160, 20)
// Main Body
canvas.fill(30, 144, 255)
canvas.rect(x, y + 10, 150, 45)
canvas.rect(x + 30, y + 55, 85, 35)
// Windows (Glass Details)
canvas.fill(180, 220, 255)
canvas.rect(x + 35, y + 58, 35, 28)
canvas.rect(x + 75, y + 58, 35, 28)
// TEACHER SITTING INSIDE THE CAR
drawDetailedAvatar(canvas, x + 92, y + 68, "WOMAN", 0.35)
canvas.noStroke()
val wheelPositions = Array(x + 35, x + 115)
for (wx <- wheelPositions) {
canvas.fill(20, 20, 20)
canvas.ellipse(wx, y + 8, 36, 36)
canvas.fill(200, 200, 200)
canvas.ellipse(wx, y + 8, 20, 20)
}
}
// ============================================================
// SCREEN 0: LETTER SCREEN
// ============================================================
def drawLetterScreen(canvas: CanvasDraw) {
canvas.background(20, 30, 50)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 248, 220)
canvas.stroke(212, 175, 55)
canvas.strokeWeight(4)
canvas.rect(cwidth/2 - 220, cheight/2 - 180, 440, 360)
canvas.fill(180, 0, 0)
canvas.text("HAPPY TEACHER'S DAY!", cwidth/2 - 140, cheight/2 + 130)
canvas.fill(50, 50, 50)
canvas.text("Dear Teacher,", cwidth/2 - 190, cheight/2 + 90)
canvas.text("Thank you for choosing to become a teacher", cwidth/2 - 190, cheight/2 + 60)
canvas.text("and guiding us to crack NEET and JEE exams!", cwidth/2 - 190, cheight/2 + 35)
canvas.fill(0, 100, 0)
canvas.text("You always make learning so fun with games.", cwidth/2 - 190, cheight/2 - 5)
canvas.fill(220, 50, 50)
canvas.noStroke()
canvas.rect(cwidth/2 - 100, cheight/2 - 110, 200, 45)
canvas.fill(255, 255, 255)
canvas.text("Select Class & Students", cwidth/2 - 90, cheight/2 - 85)
}
// ============================================================
// SCREEN 1: CLASS SELECTION
// ============================================================
def drawClassSelection(canvas: CanvasDraw) {
canvas.background(30, 30, 60)
canvas.fill(255, 255, 255)
canvas.text("SELECT YOUR CLASS BATCH", cwidth/2 - 130, cheight - 80)
canvas.fill(0, 150, 136)
canvas.rect(cwidth/2 - 180, cheight/2 - 40, 150, 80)
canvas.fill(255, 255, 255)
canvas.text("NEET BATCH", cwidth/2 - 150, cheight/2 - 5)
canvas.fill(230, 81, 0)
canvas.rect(cwidth/2 + 30, cheight/2 - 40, 150, 80)
canvas.fill(255, 255, 255)
canvas.text("JEE BATCH", cwidth/2 + 60, cheight/2 - 5)
}
// ============================================================
// SCREEN 2: STUDENT SELECTION
// ============================================================
def drawStudentSelection(canvas: CanvasDraw) {
canvas.background(40, 40, 70)
canvas.fill(255, 255, 255)
canvas.text(s"STUDENTS LIST ($selectedClass)", cwidth/2 - 110, cheight - 80)
val students = if (selectedClass == "NEET") Array("Rahul", "Ananya", "Amit") else Array("Pranav", "Sneha", "Aditya")
for (i <- 0 until 3) {
val bx = cwidth/2 - 100
val by = cheight/2 + 60 - (i * 70)
canvas.fill(0, 120, 200)
canvas.rect(bx, by, 200, 50)
canvas.fill(255, 255, 255)
canvas.text(students(i), bx + 65, by + 20)
}
}
// ============================================================
// SCREEN 3: ANIMATION SCENE (TEACHER IN CAR DRIVING TO HOUSE)
// ============================================================
def drawDeliveryAnimationScene(canvas: CanvasDraw) {
canvas.background(135, 206, 235)
canvas.noStroke()
canvas.fill(40, 160, 60)
canvas.rect(0, 0, cwidth, 160)
canvas.fill(70, 70, 75)
canvas.rect(0, 80, cwidth, 70)
val houseX = cwidth - 190.0
val houseY = 140.0
canvas.fill(255, 230, 180)
canvas.rect(houseX, houseY, 160, 130)
canvas.fill(180, 50, 40)
canvas.rect(houseX - 10, houseY + 130, 180, 45)
canvas.fill(80, 40, 20)
canvas.rect(houseX + 60, houseY, 50, 80)
// Draw Car with Teacher sitting inside
drawDetailedCarWithTeacher(canvas, carX, carY)
// Show student greeting teacher after clicking "See Home"
if (showStudentWithTeacher) {
drawDetailedAvatar(canvas, houseX + 45, houseY + 20, "MAN", 0.45)
}
// 1. Show "SEE HOME" button when car reaches house
if (isCarAtHouse && !showStudentWithTeacher && !isCarGoingFinalHome) {
canvas.fill(0, 180, 80)
canvas.noStroke()
canvas.rect(cwidth / 2 - 90, 20, 180, 45)
canvas.fill(255, 255, 255)
canvas.text("SEE HOME", cwidth / 2 - 45, 38)
}
// 2. Show dialogue & "GO TO HOME" button after clicking "See Home"
if (showStudentWithTeacher && !isCarGoingFinalHome) {
canvas.fill(255, 255, 255)
canvas.stroke(0, 0, 0)
canvas.strokeWeight(2)
canvas.rect(houseX - 220, houseY + 60, 240, 75)
canvas.fill(0, 0, 0)
canvas.text(s"Student: $selectedStudent", houseX - 210, houseY + 115)
canvas.text("Thank you for playing games with us!", houseX - 210, houseY + 95)
canvas.fill(180, 0, 60)
canvas.text("Happy Teacher's Day!", houseX - 210, houseY + 75)
// GO TO HOME BUTTON
canvas.fill(220, 50, 50)
canvas.noStroke()
canvas.rect(cwidth / 2 - 90, 20, 180, 45)
canvas.fill(255, 255, 255)
canvas.text("GO TO HOME", cwidth / 2 - 50, 38)
}
}
// ============================================================
// SCREEN 4: FINAL COMPLETION SCREEN
// ============================================================
def drawCompletionScreen(canvas: CanvasDraw) {
canvas.background(20, 60, 30)
repeatFor(stars) { s => s.view(canvas) }
canvas.fill(255, 215, 0)
canvas.text("HAPPY TEACHER'S DAY!", cwidth/2 - 110, cheight/2 + 60)
canvas.fill(255, 255, 255)
canvas.text("Thank you for being an amazing teacher,", cwidth/2 - 140, cheight/2 + 15)
canvas.text("guiding our NEET/JEE path, and playing fun games!", cwidth/2 - 175, cheight/2 - 15)
}
// ============================================================
// ANIMATION UPDATER
// ============================================================
def updateDeliveryAnimation() {
if (screen == 3) {
if (!isCarGoingFinalHome) {
if (!isCarAtHouse) {
carX += 3.5
if (carX >= cwidth - 360) {
isCarAtHouse = true
}
}
} else {
// Car driving further to final home / finish screen
carX += 4.0
if (carX > cwidth + 100) {
screen = 4
}
}
}
}
// ============================================================
// CLICK HANDLER
// ============================================================
def handleClick(x: Double, y: Double) {
if (screen == 0) {
if (x >= cwidth/2 - 100 && x <= cwidth/2 + 100 && y >= cheight/2 - 110 && y <= cheight/2 - 65) {
screen = 1
}
} else if (screen == 1) {
if (y >= cheight/2 - 40 && y <= cheight/2 + 40) {
if (x >= cwidth/2 - 180 && x <= cwidth/2 - 30) {
selectedClass = "NEET"
screen = 2
} else if (x >= cwidth/2 + 30 && x <= cwidth/2 + 180) {
selectedClass = "JEE"
screen = 2
}
}
} else if (screen == 2) {
val students = if (selectedClass == "NEET") Array("Rahul", "Ananya", "Amit") else Array("Pranav", "Sneha", "Aditya")
for (i <- 0 until 3) {
val bx = cwidth/2 - 100
val by = cheight/2 + 60 - (i * 70)
if (x >= bx && x <= bx + 200 && y >= by && y <= by + 50) {
selectedStudent = students(i)
screen = 3
}
}
} else if (screen == 3) {
// Click "SEE HOME" button
if (isCarAtHouse && !showStudentWithTeacher) {
if (x >= cwidth / 2 - 90 && x <= cwidth / 2 + 90 && y >= 20 && y <= 65) {
showStudentWithTeacher = true
}
}
// Click "GO TO HOME" button
else if (showStudentWithTeacher && !isCarGoingFinalHome) {
if (x >= cwidth / 2 - 90 && x <= cwidth / 2 + 90 && y >= 20 && y <= 65) {
isCarGoingFinalHome = true
}
}
}
}
onMouseClick { (x, y) => handleClick(x, y) }
// ============================================================
// MAIN LOOP
// ============================================================
animateWithCanvasDraw { canvas =>
repeatFor(stars) { s => s.step() }
updateDeliveryAnimation()
if (screen == 0) drawLetterScreen(canvas)
else if (screen == 1) drawClassSelection(canvas)
else if (screen == 2) drawStudentSelection(canvas)
else if (screen == 3) drawDeliveryAnimationScene(canvas)
else if (screen == 4) drawCompletionScreen(canvas)
}