Game refinement project 2 - Car Ride
This activity has the following desired goals:
- Learning to understand a given game and refine it using images and sounds (M, T).
- Practice with exporting a game as a web-app (M, T).
Steps to be followed:
- Understand the game below.
- Refine the game-play (make the other cars obstruct myCar more, allow game to continue after a collision with reduced energy, etc).
- Add background and character images to the game to make it more attractive.
- Add sounds to the game to make it more attractive.
- Load all assets from the web.
- Test the game in iKojo.
- Export the game as a web-app.
- Test on PC and mobile.
Game starter code
The code for the game is shown below. Study it to fully understand how the game works.
cleari()
originBottomLeft()
drawStage(black)
def rectanglePic(w: Int, h: Int) = Picture {
repeat(2) {
forward(h)
right()
forward(w)
right()
}
}
val myCar = rectanglePic(40, 80)
myCar.setPenColor(cm.darkGray)
myCar.setFillColor(cm.lightBlue)
myCar.setPosition(cwidth / 2, cheight / 2)
draw(myCar)
def otherCarMaker(x: Double) = {
val car = rectanglePic(40, 80)
car.setPenColor(cm.darkGray)
car.setFillColor(cm.lightCoral)
car.setPosition(x, cheight)
car
}
val cars = HashSet.empty[Picture]
val otherSpeed = 8
val mySpeed = 6
timer(700) {
val otherCar = otherCarMaker(randomDouble(0, cwidth - 40))
draw(otherCar)
cars.add(otherCar)
}
animate {
repeatFor(cars) { car =>
car.translate(0, -otherSpeed)
if (car.collidesWith(myCar)) {
stopAnimation()
drawCenteredMessage("You Lose", red, 30)
}
}
if (isKeyPressed(Kc.VK_UP)) {
myCar.translate(0, mySpeed)
}
if (isKeyPressed(Kc.VK_DOWN)) {
myCar.translate(0, -mySpeed)
}
if (isKeyPressed(Kc.VK_RIGHT)) {
myCar.translate(mySpeed, 0)
}
if (isKeyPressed(Kc.VK_LEFT)) {
myCar.translate(-mySpeed, 0)
}
}
showGameTime(60, "You Win", green, 15)
activateCanvas()
Copyright © 2010–2024 Kogics Foundation. Licensed as per Terms of Use.