xxxxxxxxxx
62
let xCow = 50;
let yCow = 370;
let colision = false;
let points = 0;
function ShowActor()
{
image(cowImage,xCow,yCow, 30, 30);
}
function CowMove(){
if(keyIsDown(UP_ARROW)){yCow-=2;}
if(keyIsDown(DOWN_ARROW)){if(CanMove())
yCow+=2;}
if(keyIsDown(LEFT_ARROW)){xCow-=2;}
if(keyIsDown(RIGHT_ARROW)){xCow+=2;}
}
function IsThereColision()
{
for (let i = 0; i<carImages.length; i++)
{
colision = collideRectCircle(xCars[i],yCars[i],carWidth,carLength,xCow, yCow, 15)
if(colision){Dead(); if (PointsNotZero()){points -=1;}
colisionSound.play();
}
}
}
function Dead()
{
yCow = 365;
xCow = 50;
}
function ShowPoints()
{
textAlign(CENTER);
textSize(25);
fill(color(255,0,200));
text(points, width/5, 25);
}
function ScorePoints()
{
if (yCow<15){
points+=1; Dead();
pointSound.play();
}
}
function PointsNotZero (){
return points>0;
}
function CanMove(){
return yCow<365;
}
//collideRectCircle(x1, y1, width1, height1, cx, cy, diameter)