Lolik

not404

nothing
x
bilibili
github
telegram
steam
follow

canvas shooting game

vue, ts, object-oriented, canvas2d
demo: https://2412322029.github.io/mctato/

The idea started in January. At first, I wrote 7 or 8 JS files in order into the script tags of the HTML, which was really tiring.
Later, I used Vite and TypeScript to refactor and import them mutually, and finally packaged it.

Main Idea

Player, Zombie class, Special Effects class, Projectile class, all inherit from the Rectangle class.
The Rectangle class has methods for drawing, moving, etc.

  • Listen for key presses to move
  • Collision detection uses broad phase detection, first checking one dimension to filter some cases
  • Monster pathfinding is based on waypoints
    • Monsters and players each find the visible (no walls blocking the line) shortest waypoint, connect the nearest waypoints, and then solve the shortest path problem of a weighted undirected graph (considering the distance from both starting ends and adding it to the short path calculation)
    • The shortest path problem of a weighted undirected graph uses Dijkstra's algorithm (can cache some calculation results, but did not do so, which has little impact)

Wrote for a long time, but the final effect is not very good.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.