Skip to content

Commit

Permalink
Now the car move forward and reverse in acceleration speed but no bou…
Browse files Browse the repository at this point in the history
…ndry for the edges
  • Loading branch information
THEKINGSTAR committed Dec 8, 2023
1 parent 342835e commit d3a5c9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions main_project/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ class Car{
this.width=width;
this.height=height;

this.speed=0;
this.acceleration=0.2;

this.controls=new Controls();
}

update(){
if(this.controls.forward){
this.y-=2;
this.speed+=this.acceleration;
}
if(this.controls.reverse){
this.y+=2;
this.speed-=this.acceleration;
}
this.y-=this.speed;
}

draw(ctx){
Expand Down
3 changes: 2 additions & 1 deletion main_project/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const canvas=document.getElementById("myCanvas");
canvas.height=window.innerHeight;

canvas.width=200;


Expand All @@ -11,6 +11,7 @@ animate();

function animate(){
car.update();
canvas.height=window.innerHeight;
car.draw(ctx);
requestAnimationFrame(animate);
}

0 comments on commit d3a5c9c

Please sign in to comment.