Skip to content

hamzaSorani83/canvas-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

canvas-game

(canvas && js && gsap)

to create canvas:

  • canvas = document.querySelector('canvas');
  • c = canvas.getContext('2d');

to draw circle:

  • c.beginPath();
  • c.arc(x, y, radius, 0, Math.PI * 2, false);
  • c.fillStyle = color;
  • c.fill();

we have : player && projectiles && enemies

to get angle between enemy and player:

we are using velocity to change enemy position

  • velocity = { x: Math.cos(angle), y: Math.sin(angle) }
  • enemy.x += enemy.velocity.x
  • enemy.y += enemy.velocity.y

to get distance between enemy and player:

to get distance between enemy and projectile:

  • dist = Math.hypot(projectile.x - enemy.x, projectile.y - enemy.y)
  • if(dist - enemy.radius - projectile.radius <= 0) then removeProjectile && removeEnemy
    • but if(enemy.radius > 18) then gsap.to(enemy, { radius: enemy.radius - 10 });
    • else removeEnemy
  • we are using particles to convert enemy to 5 particles

to get random color:

  • color = hsl(${Math.random() * 360}, 50%, 50%)

About

html5 canvas css js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published