xxxxxxxxxx
125
//var Actor Movmt
let xActor = 225;
let yActor = 0;
let hit = false;
let gameScore = 3;
function showActor(){
image(imageActor, xActor, yActor, 35, 35);
}
function moveActor(){
if (keyIsDown(DOWN_ARROW)){
yActor += 3;
}
if (keyIsDown(UP_ARROW)){
if (checkBorderUp()){
yActor -= 3;
}
}
if (keyIsDown(LEFT_ARROW)){
if (checkBorderLeft()){
xActor -= 6;
}
}
if (keyIsDown(RIGHT_ARROW)){
if (checkBorderRight()){
xActor += 6;
}
}
}
function checkTouchActor(){
for (let i = 0; i < imageCars.length; i++){
hit = collideRectCircle(xCars[i], yCars[i], widthCars, heightCars, xActor, yActor, 15)
if (hit){
accidentFX.play();
backtoStartPosition();
//if (scoreGreaterThanZero()){
gameScore -= 1;
//}
}
}
for (let i = 0; i < imageCars2.length; i++){
hit = collideRectCircle(xCars2[i], yCars2[i], widthCars, heightCars, xActor, yActor, 15)
if (hit){
accidentFX.play();
backtoStartPosition();
//if (scoreGreaterThanZero()){
gameScore -= 1;
//}
}
}
}
function backtoStartPosition(){
xActor = 225;
yActor = 0;
}
//function scoreGreaterThanZero(){
// return gameScore > 0
//}
function addScoreboard(){
stroke(50);
textAlign(CENTER);
textSize(25);
fill(color(0,0,128));
text(gameScore, width / 5, 27);
}
function scoreCount(){
if (yActor > height - 30){
scoreFX.play();
gameScore += 1
backtoStartPosition();
}
}
//Actor Mvmt Limits
function checkBorderUp(){
return yActor > 0;
}
function checkBorderLeft(){
return xActor > 0;
}
function checkBorderRight(){
return xActor < 470;
}
function youWin(){
if (gameScore > 9){
congratsYouWin();
speedCars = 0;
yActor = 370;
}
}
function congratsYouWin(){
stroke(0);
textAlign(CENTER);
textStyle(BOLD);
textSize(65);
fill(color(0,255,100));
text('YOU WIN!', width / 2, height / 2 + 20);
}
function endGame(){
if (gameScore < 0){
gameOver();
speedCars = 0;
xActor = 225;
yActor = 200;
}
}
function gameOver(){
stroke(0);
textAlign(CENTER);
textSize(70);
fill(color(175,0,0));
text('GAME OVER', width / 2, height / 2 + 20);
}