Code Sketch
sniper_0718
Category: Art
cleari()
// --- Game Dimensions ---
val canvasWidth = 800 //> val canvasWidth: Int = 800
val canvasHeight = 600 //> val canvasHeight: Int = 600
val roadWidth = 340 //> val roadWidth: Int = 340
// --- Realistic Terrain Background ---
val bg = Picture.rectangle(canvasWidth, canvasHeight) //> val bg: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1098902562
bg.setFillColor(Color(10, 25, 10, 255))
bg.setPenColor(noColor)
bg.setPosition(-canvasWidth / 2, -canvasHeight / 2)
bg.draw()
val road = Picture.rectangle(roadWidth, canvasHeight) //> val road: net.kogics.kojo.picture.RectanglePic = Picture with Id: 614399511
road.setFillColor(Color(35, 35, 38, 255))
road.setPenColor(noColor)
road.setPosition(-roadWidth / 2, -canvasHeight / 2)
road.draw()
// --- Road Boundary Marking Lines ---
val lineLeft = Picture.rectangle(6, canvasHeight) //> val lineLeft: net.kogics.kojo.picture.RectanglePic = Picture with Id: 205500657
lineLeft.setFillColor(white)
lineLeft.setPenColor(noColor)
lineLeft.setPosition(-roadWidth / 2 + 5, -canvasHeight / 2)
lineLeft.draw()
val lineRight = Picture.rectangle(6, canvasHeight) //> val lineRight: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1909943087
lineRight.setFillColor(white)
lineRight.setPenColor(noColor)
lineRight.setPosition(roadWidth / 2 - 11, -canvasHeight / 2)
lineRight.draw()
// --- Smooth Animated Lane Markers ---
val dashCount = 8 //> val dashCount: Int = 8
val dashHeight = 40 //> val dashHeight: Int = 40
val dashGap = 50 //> val dashGap: Int = 50
var dashOffset = 0.0 //> var dashOffset: Double = 0.0
val yellowDashesL = Array.fill(dashCount) {
val d = Picture.rectangle(4, dashHeight)
d.setFillColor(Color(255, 204, 0, 255))
d.setPenColor(noColor)
d.draw()
d
} //> val yellowDashesL: Array[net.kogics.kojo.picture.RectanglePic] = Array(Picture with Id: 333304301, Picture with Id: 601514731, Picture with Id: 1534870047, Picture with Id: 1043060184, Picture with Id: 1124346185, Picture with Id: 859424504, Picture with Id: 174855738, Picture with Id: 1779009466)
val yellowDashesR = Array.fill(dashCount) {
val d = Picture.rectangle(4, dashHeight)
d.setFillColor(Color(255, 204, 0, 255))
d.setPenColor(noColor)
d.draw()
d
} //> val yellowDashesR: Array[net.kogics.kojo.picture.RectanglePic] = Array(Picture with Id: 1117808745, Picture with Id: 1555110778, Picture with Id: 227280802, Picture with Id: 2032929241, Picture with Id: 940496309, Picture with Id: 1815114501, Picture with Id: 32299062, Picture with Id: 404192019)
def updateDashes(): Unit = {
dashOffset = (dashOffset - 12) % (dashHeight + dashGap)
for (i <- 0 until dashCount) {
val yPos = (canvasHeight / 2) - (i * (dashHeight + dashGap)) + dashOffset
yellowDashesL(i).setPosition(-5, yPos)
yellowDashesR(i).setPosition(1, yPos)
}
} //> def updateDashes(): Unit
// --- Night Overlay ---
val nightOverlay = Picture.rectangle(canvasWidth, canvasHeight) //> val nightOverlay: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1890064355
nightOverlay.setFillColor(Color(0, 0, 0, 160))
nightOverlay.setPenColor(noColor)
nightOverlay.setPosition(-canvasWidth / 2, -canvasHeight / 2)
nightOverlay.draw()
// --- Mini Map on Top-Right Corner ---
val mapBg = Picture.rectangle(160, 110) //> val mapBg: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1678930744
mapBg.setFillColor(Color(20, 20, 30, 230))
mapBg.setPenColor(white)
mapBg.setPosition(canvasWidth / 2 - 180, canvasHeight / 2 - 150)
mapBg.draw()
val mapTitle = Picture.text("GPS MAP", 12) //> val mapTitle: net.kogics.kojo.picture.TextPic = TextPic (Id: 924511582)
mapTitle.setFillColor(Color(0, 230, 255, 255))
mapTitle.setPosition(canvasWidth / 2 - 165, canvasHeight / 2 - 50)
mapTitle.draw()
val mapNode1 = Picture.circle(6) //> val mapNode1: net.kogics.kojo.picture.CirclePic = Picture with Id: 1531840256
mapNode1.setFillColor(Color(0, 255, 100, 255))
mapNode1.setPenColor(noColor)
mapNode1.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
mapNode1.draw()
val mapNode2 = Picture.circle(6) //> val mapNode2: net.kogics.kojo.picture.CirclePic = Picture with Id: 685881973
mapNode2.setFillColor(Color(255, 50, 50, 255))
mapNode2.setPenColor(noColor)
mapNode2.setPosition(canvasWidth / 2 - 90, canvasHeight / 2 - 90)
mapNode2.draw()
val mapNode3 = Picture.circle(6) //> val mapNode3: net.kogics.kojo.picture.CirclePic = Picture with Id: 1275085734
mapNode3.setFillColor(gray)
mapNode3.setPenColor(noColor)
mapNode3.setPosition(canvasWidth / 2 - 115, canvasHeight / 2 - 120)
mapNode3.draw()
val mapPlayerPin = Picture.circle(4) //> val mapPlayerPin: net.kogics.kojo.picture.CirclePic = Picture with Id: 859989177
mapPlayerPin.setFillColor(yellow)
mapPlayerPin.setPenColor(noColor)
mapPlayerPin.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
mapPlayerPin.draw()
// --- Square Menu Button on Right Corner (Above Map) ---
val menuButtonBg = Picture.rectangle(35, 35) //> val menuButtonBg: net.kogics.kojo.picture.RectanglePic = Picture with Id: 419550765
menuButtonBg.setFillColor(Color(50, 50, 70, 255))
menuButtonBg.setPenColor(cyan)
menuButtonBg.setPosition(canvasWidth / 2 - 55, canvasHeight / 2 - 45)
menuButtonBg.draw()
val menuButtonIcon = Picture.text("?", 18) //> val menuButtonIcon: net.kogics.kojo.picture.TextPic = TextPic (Id: 1398854372)
menuButtonIcon.setFillColor(white)
menuButtonIcon.setPosition(canvasWidth / 2 - 47, canvasHeight / 2 - 25)
menuButtonIcon.draw()
// --- Destination List Modal Panel ---
val listPanelBg = Picture.rectangle(320, 180) //> val listPanelBg: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1798355227
listPanelBg.setFillColor(Color(15, 15, 25, 245))
listPanelBg.setPenColor(cyan)
listPanelBg.setPosition(-160, -90)
val listHeader = Picture.text("--- DESTINATION LIST ---", 14) //> val listHeader: net.kogics.kojo.picture.TextPic = TextPic (Id: 1957177526)
listHeader.setFillColor(Color(255, 200, 0, 255))
listHeader.setPosition(-140, 60)
val routeItem1 = Picture.text("1. Suryamukhi Mandir ? Mumbai", 13) //> val routeItem1: net.kogics.kojo.picture.TextPic = TextPic (Id: 281555004)
routeItem1.setFillColor(white)
routeItem1.setPosition(-150, 30)
val routeItem2 = Picture.text("2. Bhimratna Niwas ? Dagdusheth", 13) //> val routeItem2: net.kogics.kojo.picture.TextPic = TextPic (Id: 1149527929)
routeItem2.setFillColor(white)
routeItem2.setPosition(-150, 0)
val routeItem3 = Picture.text("3. Aurangabad ? Nepal", 13) //> val routeItem3: net.kogics.kojo.picture.TextPic = TextPic (Id: 1758965289)
routeItem3.setFillColor(white)
routeItem3.setPosition(-150, -30)
val listCloseHint = Picture.text("Click anywhere outside or 'M' to Close", 11) //> val listCloseHint: net.kogics.kojo.picture.TextPic = TextPic (Id: 560026796)
listCloseHint.setFillColor(gray)
listCloseHint.setPosition(-140, -65)
// --- Player Truck (White Heavy Cargo Truck) ---
val playerCab = Picture.rectangle(52, 40) //> val playerCab: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1724793835
playerCab.setFillColor(Color(245, 245, 250, 255))
playerCab.setPenColor(black)
val playerGlass = Picture.rectangle(44, 16) //> val playerGlass: net.kogics.kojo.picture.RectanglePic = Picture with Id: 826488226
playerGlass.setFillColor(Color(20, 40, 60, 255))
playerGlass.setPenColor(noColor)
val playerBed = Picture.rectangle(50, 65) //> val playerBed: net.kogics.kojo.picture.RectanglePic = Picture with Id: 591562970
playerBed.setFillColor(Color(180, 40, 40, 255))
playerBed.setPenColor(black)
val playerTailL = Picture.rectangle(8, 6) //> val playerTailL: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1508504634
playerTailL.setFillColor(Color(220, 20, 20, 255))
playerTailL.setPenColor(noColor)
val playerTailR = Picture.rectangle(8, 6) //> val playerTailR: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1225530949
playerTailR.setFillColor(Color(220, 20, 20, 255))
playerTailR.setPenColor(noColor)
val playerHeadL = Picture.rectangle(9, 6) //> val playerHeadL: net.kogics.kojo.picture.RectanglePic = Picture with Id: 700228318
playerHeadL.setFillColor(gray)
playerHeadL.setPenColor(noColor)
val playerHeadR = Picture.rectangle(9, 6) //> val playerHeadR: net.kogics.kojo.picture.RectanglePic = Picture with Id: 287470073
playerHeadR.setFillColor(gray)
playerHeadR.setPenColor(noColor)
// High-Intensity Upper Dipper Light Beams (Bright White)
val beamL = Picture.fromPath { p =>
p.moveTo(0, 0)
p.lineTo(-50, 200)
p.lineTo(25, 200)
p.lineTo(9, 0)
} //> val beamL: net.kogics.kojo.picture.PathPic = Picture with Id: 1865104762
beamL.setFillColor(Color(255, 255, 255, 200))
beamL.setPenColor(noColor)
val beamR = Picture.fromPath { p =>
p.moveTo(0, 0)
p.lineTo(-25, 200)
p.lineTo(50, 200)
p.lineTo(9, 0)
} //> val beamR: net.kogics.kojo.picture.PathPic = Picture with Id: 284476866
beamR.setFillColor(Color(255, 255, 255, 200))
beamR.setPenColor(noColor)
playerBed.draw()
playerCab.draw()
playerGlass.draw()
playerTailL.draw()
playerTailR.draw()
playerHeadL.draw()
playerHeadR.draw()
// --- Traffic Vehicles: Car, Truck, Bus ---
val trafficCarBody = Picture.rectangle(50, 90) //> val trafficCarBody: net.kogics.kojo.picture.RectanglePic = Picture with Id: 2044712654
trafficCarBody.setFillColor(Color(30, 100, 200, 255))
trafficCarBody.setPenColor(gray)
val trafficCarRoof = Picture.rectangle(42, 32) //> val trafficCarRoof: net.kogics.kojo.picture.RectanglePic = Picture with Id: 755026947
trafficCarRoof.setFillColor(Color(40, 120, 220, 255))
trafficCarRoof.setPenColor(noColor)
trafficCarBody.draw()
trafficCarRoof.draw()
val trafficTruckBed = Picture.rectangle(48, 70) //> val trafficTruckBed: net.kogics.kojo.picture.RectanglePic = Picture with Id: 620339127
trafficTruckBed.setFillColor(Color(80, 80, 80, 255))
trafficTruckBed.setPenColor(black)
val trafficTruckCab = Picture.rectangle(50, 38) //> val trafficTruckCab: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1173633986
trafficTruckCab.setFillColor(Color(200, 150, 0, 255))
trafficTruckCab.setPenColor(black)
trafficTruckBed.draw()
trafficTruckCab.draw()
val trafficBusBody = Picture.rectangle(52, 130) //> val trafficBusBody: net.kogics.kojo.picture.RectanglePic = Picture with Id: 71552676
trafficBusBody.setFillColor(Color(200, 40, 40, 255))
trafficBusBody.setPenColor(black)
val trafficBusRoof = Picture.rectangle(44, 110) //> val trafficBusRoof: net.kogics.kojo.picture.RectanglePic = Picture with Id: 1954401691
trafficBusRoof.setFillColor(Color(220, 60, 60, 255))
trafficBusRoof.setPenColor(noColor)
trafficBusBody.draw()
trafficBusRoof.draw()
// --- Roadside Destination / Parking Bay Graphics ---
val parkingBay = Picture.rectangle(70, 140) //> val parkingBay: net.kogics.kojo.picture.RectanglePic = Picture with Id: 2061013946
parkingBay.setFillColor(Color(50, 120, 50, 255))
parkingBay.setPenColor(white)
parkingBay.setPosition(roadWidth / 2 + 10, 50)
val parkingText = Picture.text("PARKING", 14) //> val parkingText: net.kogics.kojo.picture.TextPic = TextPic (Id: 203654680)
parkingText.setFillColor(white)
parkingText.setPosition(roadWidth / 2 + 15, 110)
// --- Movement Variables ---
var carX = -26.0 //> var carX: Double = -26.0
var carY = -220.0 //> var carY: Double = -220.0
val carSteerSpeed = 6.0 //> val carSteerSpeed: Double = 6.0
var leftLaneType = 0 //> var leftLaneType: Int = 0
var leftEnemyX = -roadWidth / 2.0 + 25.0 //> var leftEnemyX: Double = -145.0
var leftEnemyY = -canvasHeight / 2.0 - 150.0 //> var leftEnemyY: Double = -450.0
var leftEnemySpeed = 2.0 //> var leftEnemySpeed: Double = 2.0
var rightLaneType = 0 //> var rightLaneType: Int = 0
var rightEnemyX = roadWidth / 2.0 - 75.0 //> var rightEnemyX: Double = 95.0
var rightEnemyY = canvasHeight / 2.0 + 150.0 //> var rightEnemyY: Double = 450.0
var rightEnemySpeed = 4.5 //> var rightEnemySpeed: Double = 4.5
var isLightActive = false //> var isLightActive: Boolean = false
var aKeyWasPressed = false //> var aKeyWasPressed: Boolean = false
var mKeyWasPressed = false //> var mKeyWasPressed: Boolean = false
var showDestinationList = false //> var showDestinationList: Boolean = false
var lastMouseState = false //> var lastMouseState: Boolean = false
def updatePlayerPos(): Unit = {
playerBed.setPosition(carX + 1, carY)
playerCab.setPosition(carX + 1, carY + 63)
playerGlass.setPosition(carX + 5, carY + 80)
playerTailL.setPosition(carX + 3, carY + 2)
playerTailR.setPosition(carX + 39, carY + 2)
playerHeadL.setPosition(carX + 3, carY + 101)
playerHeadR.setPosition(carX + 39, carY + 101)
if (isLightActive) {
beamL.setPosition(carX + 3, carY + 107)
beamR.setPosition(carX + 39, carY + 107)
}
} //> def updatePlayerPos(): Unit
def hideAllTraffic(): Unit = {
trafficCarBody.setPosition(-1000, -1000)
trafficCarRoof.setPosition(-1000, -1000)
trafficTruckBed.setPosition(-1000, -1000)
trafficTruckCab.setPosition(-1000, -1000)
trafficBusBody.setPosition(-1000, -1000)
trafficBusRoof.setPosition(-1000, -1000)
} //> def hideAllTraffic(): Unit
def updateLeftEnemyPos(): Unit = {
if (leftLaneType == 0) {
trafficCarBody.setPosition(leftEnemyX, leftEnemyY)
trafficCarRoof.setPosition(leftEnemyX + 4, leftEnemyY + 29)
} else {
trafficTruckBed.setPosition(leftEnemyX + 1, leftEnemyY)
trafficTruckCab.setPosition(leftEnemyX + 1, leftEnemyY + 68)
}
} //> def updateLeftEnemyPos(): Unit
def updateRightEnemyPos(): Unit = {
if (rightLaneType == 0) {
trafficCarBody.setPosition(rightEnemyX, rightEnemyY)
trafficCarRoof.setPosition(rightEnemyX + 4, rightEnemyY + 29)
} else if (rightLaneType == 1) {
trafficTruckBed.setPosition(rightEnemyX + 1, rightEnemyY)
trafficTruckCab.setPosition(rightEnemyX + 1, rightEnemyY + 68)
} else {
trafficBusBody.setPosition(rightEnemyX, rightEnemyY)
trafficBusRoof.setPosition(rightEnemyX + 4, rightEnemyY + 10)
}
} //> def updateRightEnemyPos(): Unit
def resetLeftEnemy(): Unit = {
leftLaneType = random(0, 2)
leftEnemyX = -roadWidth / 2.0 + 25.0
leftEnemyY = -canvasHeight / 2.0 - 150.0
leftEnemySpeed = 2.0
hideAllTraffic()
updateLeftEnemyPos()
updateRightEnemyPos()
} //> def resetLeftEnemy(): Unit
def resetRightEnemy(): Unit = {
rightLaneType = random(0, 3)
rightEnemyX = roadWidth / 2.0 - 75.0
rightEnemyY = canvasHeight / 2.0 + 150.0
rightEnemySpeed = random(35, 55) / 10.0
hideAllTraffic()
updateLeftEnemyPos()
updateRightEnemyPos()
} //> def resetRightEnemy(): Unit
resetLeftEnemy()
resetRightEnemy()
updatePlayerPos()
// --- Routes and Destinations System ---
val routes = Array(
("Suryamukhi Mandir", "Mumbai"),
("Bhimratna Niwas", "Dagdusheth"),
("Aurangabad", "Nepal")
) //> val routes: Array[(String, String)] = Array((Suryamukhi Mandir,Mumbai), (Bhimratna Niwas,Dagdusheth), (Aurangabad,Nepal))
var currentRouteIndex = 0 //> var currentRouteIndex: Int = 0
var isParkingMode = false //> var isParkingMode: Boolean = false
var noticeDrawn = false //> var noticeDrawn: Boolean = false
// --- HUD / Score Board ---
var score = 0 //> var score: Int = 0
var gameOver = false //> var gameOver: Boolean = false
val scoreText = Picture.text(s"SPEED: 0 KM/H | SCORE: $score", 18) //> val scoreText: net.kogics.kojo.picture.TextPic = TextPic (Id: 215769679)
scoreText.setFillColor(white)
scoreText.setPosition(-canvasWidth / 2 + 20, canvasHeight / 2 - 40)
scoreText.draw()
val routeText = Picture.text(s"ROUTE: ${routes(currentRouteIndex)._1} ? ${routes(currentRouteIndex)._2}", 16) //> val routeText: net.kogics.kojo.picture.TextPic = TextPic (Id: 136522671)
routeText.setFillColor(Color(255, 200, 0, 255))
routeText.setPosition(-canvasWidth / 2 + 20, canvasHeight / 2 - 70)
routeText.draw()
val helpText = Picture.text("Steer: Left/Right | Drive: Hold SPACE | Dipper: 'A' | Park: 'P'", 15) //> val helpText: net.kogics.kojo.picture.TextPic = TextPic (Id: 353968726)
helpText.setFillColor(Color(0, 230, 255, 255))
helpText.setPosition(-canvasWidth / 2 + 20, -canvasHeight / 2 + 20)
helpText.draw()
val destinationNotice = Picture.text("DESTINATION REACHED! Park on roadside & Press 'P'", 20) //> val destinationNotice: net.kogics.kojo.picture.TextPic = TextPic (Id: 1412731547)
destinationNotice.setFillColor(Color(0, 255, 100, 255))
destinationNotice.setPosition(-230, 100)
val gameOverText = Picture.text("CRASHED! Press 'R' to Restart", 26) //> val gameOverText: net.kogics.kojo.picture.TextPic = TextPic (Id: 1957445803)
gameOverText.setFillColor(Color(255, 50, 50, 255))
gameOverText.setPosition(-180, 0)
// --- Game Loop ---
animate {
if (!gameOver) {
if (isKeyPressed(Kc.VK_LEFT)) {
carX -= carSteerSpeed
}
if (isKeyPressed(Kc.VK_RIGHT)) {
carX += carSteerSpeed
}
val minX = -roadWidth / 2 + 12
val maxX = roadWidth / 2 - 64
if (carX < minX) carX = minX
if (carX > maxX) carX = maxX
// Upper Dipper High-Beam Light Control via 'A' Key
val aPressedNow = isKeyPressed(Kc.VK_A)
if (aPressedNow && !aKeyWasPressed) {
isLightActive = !isLightActive
if (isLightActive) {
playerHeadL.setFillColor(Color(255, 255, 255, 255))
playerHeadR.setFillColor(Color(255, 255, 255, 255))
beamL.draw()
beamR.draw()
} else {
playerHeadL.setFillColor(gray)
playerHeadR.setFillColor(gray)
beamL.erase()
beamR.erase()
}
}
aKeyWasPressed = aPressedNow
// Toggle Destination List via 'M' Key
val mPressedNow = isKeyPressed(Kc.VK_M)
if (mPressedNow && !mKeyWasPressed) {
showDestinationList = !showDestinationList
if (showDestinationList) {
listPanelBg.draw()
listHeader.draw()
routeItem1.draw()
routeItem2.draw()
routeItem3.draw()
listCloseHint.draw()
} else {
listPanelBg.erase()
listHeader.erase()
routeItem1.erase()
routeItem2.erase()
routeItem3.erase()
listCloseHint.erase()
}
}
mKeyWasPressed = mPressedNow
// Mouse click handling for menu button and outside/side clicks to close
val mouseNow = isMousePressed
if (mouseNow && !lastMouseState) {
val clickedMenuButton = mouseX >= 320 && mouseX <= 400 && mouseY >= 220 && mouseY <= 280
if (clickedMenuButton) {
showDestinationList = !showDestinationList
if (showDestinationList) {
listPanelBg.draw()
listHeader.draw()
routeItem1.draw()
routeItem2.draw()
routeItem3.draw()
listCloseHint.draw()
} else {
listPanelBg.erase()
listHeader.erase()
routeItem1.erase()
routeItem2.erase()
routeItem3.erase()
listCloseHint.erase()
}
} else if (showDestinationList) {
// Clicking on the side / outside closes the destination list
showDestinationList = false
listPanelBg.erase()
listHeader.erase()
routeItem1.erase()
routeItem2.erase()
routeItem3.erase()
listCloseHint.erase()
}
}
lastMouseState = mouseNow
if (isParkingMode) {
scoreText.update(s"SPEED: 0 KM/H | SCORE: $score")
parkingBay.draw()
parkingText.draw()
if (carY >= 0 && !noticeDrawn) {
destinationNotice.draw()
noticeDrawn = true
}
mapPlayerPin.setPosition(canvasWidth / 2 - 90, canvasHeight / 2 - 90)
val inParkingZone = carX > roadWidth / 2 - 80 && carY >= 0 && carY <= 120
if (inParkingZone && isKeyPressed(Kc.VK_P)) {
isParkingMode = false
noticeDrawn = false
parkingBay.erase()
parkingText.erase()
destinationNotice.erase()
currentRouteIndex = (currentRouteIndex + 1) % routes.length
routeText.update(s"ROUTE: ${routes(currentRouteIndex)._1} ? ${routes(currentRouteIndex)._2}")
mapPlayerPin.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
resetLeftEnemy()
resetRightEnemy()
}
} else {
if (isKeyPressed(Kc.VK_SPACE)) {
scoreText.update(s"SPEED: 60 KM/H | SCORE: $score")
updateDashes()
val pinX = (canvasWidth / 2 - 140) + ((score.toDouble / 50.0) * 50.0) min (canvasWidth / 2 - 90)
mapPlayerPin.setPosition(pinX, canvasHeight / 2 - 90)
leftEnemyY += leftEnemySpeed
if (leftEnemyY > canvasHeight / 2 + 150) {
score += 10
if (score >= 50 && currentRouteIndex == 0) {
isParkingMode = true
} else if (score % 50 == 0) {
currentRouteIndex = (currentRouteIndex + 1) % routes.length
routeText.update(s"ROUTE: ${routes(currentRouteIndex)._1} ? ${routes(currentRouteIndex)._2}")
mapPlayerPin.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
}
scoreText.update(s"SPEED: 60 KM/H | SCORE: $score")
resetLeftEnemy()
}
updateLeftEnemyPos()
rightEnemyY -= rightEnemySpeed
if (rightEnemyY < -canvasHeight / 2 - 150) {
score += 10
if (score >= 50 && currentRouteIndex == 0) {
isParkingMode = true
} else if (score % 50 == 0) {
currentRouteIndex = (currentRouteIndex + 1) % routes.length
routeText.update(s"ROUTE: ${routes(currentRouteIndex)._1} ? ${routes(currentRouteIndex)._2}")
mapPlayerPin.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
}
scoreText.update(s"SPEED: 60 KM/H | SCORE: $score")
resetRightEnemy()
}
updateRightEnemyPos()
val leftHeight = if (leftLaneType == 0) 90 else 108
val rightHeight = if (rightLaneType == 0) 90 else if (rightLaneType == 1) 108 else 130
val collisionLeft = Math.abs((carX + 26) - (leftEnemyX + 26)) < 44 && Math.abs((carY + 55) - (leftEnemyY + leftHeight / 2.0)) < (90 + leftHeight) / 2.0
val collisionRight = Math.abs((carX + 26) - (rightEnemyX + 26)) < 44 && Math.abs((carY + 55) - (rightEnemyY + rightHeight / 2.0)) < (90 + rightHeight) / 2.0
if (collisionLeft || collisionRight) {
gameOver = true
gameOverText.draw()
}
} else {
scoreText.update(s"SPEED: 0 KM/H | SCORE: $score")
}
}
updatePlayerPos()
} else {
if (isKeyPressed(Kc.VK_R)) {
gameOver = false
score = 0
currentRouteIndex = 0
isParkingMode = false
noticeDrawn = false
showDestinationList = false
listPanelBg.erase()
listHeader.erase()
routeItem1.erase()
routeItem2.erase()
routeItem3.erase()
listCloseHint.erase()
parkingBay.erase()
parkingText.erase()
destinationNotice.erase()
mapPlayerPin.setPosition(canvasWidth / 2 - 140, canvasHeight / 2 - 90)
scoreText.update(s"SPEED: 0 KM/H | SCORE: $score")
routeText.update(s"ROUTE: ${routes(currentRouteIndex)._1} ? ${routes(currentRouteIndex)._2}")
gameOverText.erase()
carX = -26.0
resetLeftEnemy()
resetRightEnemy()
updatePlayerPos()
}
}
} //> val res366: java.util.concurrent.Future[edu.umd.cs.piccolo.activities.PActivity] = net.kogics.kojo.util.FutureResult@37dc7210