Skip to content

Commit

Permalink
refactor(gameobjects): use getDirection helper in bullet
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 24, 2025
1 parent 245f403 commit 80a06d7
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/gameobjects/bullet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Sound, Tag } from '../constants'
import { getDirection } from '../helpers'
import type { Enemy, Player } from '../types'

const BULLET_SPEED = 200
Expand All @@ -7,7 +8,7 @@ const BULLET_DAMAGE = 20
export function addBullet(player: Player) {
const bullet = add([
pos(player.pos),
move(getBulletDir(player), BULLET_SPEED),
move(getDirection(player.screenPos()!, mousePos()), BULLET_SPEED),
circle(30),
area(),
offscreen({ destroy: true }),
Expand All @@ -25,14 +26,3 @@ export function addBullet(player: Player) {

return bullet
}

function getBulletDir(player: Player) {
const mousePosition = mousePos()
const playerPosition = player.screenPos()
const angle = Math.atan2(
mousePosition.y - playerPosition!.y,
mousePosition.x - playerPosition!.x,
)
const degrees = (angle * 180) / Math.PI
return degrees
}

0 comments on commit 80a06d7

Please sign in to comment.