Skip to content

Commit

Permalink
Added shooting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfyxon committed Dec 18, 2023
1 parent 6b2dd64 commit 2c242ef
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/jetfighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ window.addEventListener("load",function(){
plrJet.restrictMovement = true;
const speed = 5;

const projectiles = [];

setInterval(function(){
if(isBtnPressed("A")){
const proj = Sprite(
imgProjectile,
plrJet.getX()+plrJet.area.getWidth()/2-2,
plrJet.getY()
);
projectiles.push(proj);
}
},100)

setInterval(function(){
clearCanvas(canvas);

Expand All @@ -18,6 +31,11 @@ window.addEventListener("load",function(){
if(isBtnPressed("Left")) plrJet.moveXY(-speed,0);
if(isBtnPressed("Right")) plrJet.moveXY(speed,0);

for(var i=0;i<projectiles.length;i++){
const proj = projectiles[i];
proj.moveXY(0,-speed*2);
proj.render(canvas);
}

plrJet.render(canvas);
},optiItv());
Expand Down

0 comments on commit 2c242ef

Please sign in to comment.