Skip to content

Commit

Permalink
chore(gameobjects): increase bullet size and decrease rate of fire
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 22, 2025
1 parent 6db9124 commit 0878b8f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/gameobjects/bullet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Tag } from '../constants'
import type { Enemy, Player } from '../types'

const BULLET_SPEED = 600
const BULLET_SPEED = 200
const BULLET_DAMAGE = 20

export function addBullet(player: Player) {
const bullet = add([
pos(player.pos),
move(getBulletDir(player), BULLET_SPEED),
circle(6),
circle(30),
area(),
offscreen({ destroy: true }),
anchor('center'),
Expand Down
28 changes: 27 additions & 1 deletion src/gameobjects/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Sprite, Tag } from '../constants'
import { addCursorKeys } from '../events'
import type { Player } from '../types'
import { addBullet } from './bullet'

export function addPlayer(x = center().x, y = center().y) {
Expand All @@ -18,9 +19,34 @@ export function addPlayer(x = center().x, y = center().y) {

addCursorKeys(player)

const attack = new Attack(player)

onClick(() => {
addBullet(player)
if (attack.canAttack()) {
attack.update()
addBullet(player)
}
})

return player
}

class Attack {
private attackDelay = 1
private lastAttacked = 0
private player

constructor(player: Player) {
this.player = player
}

update() {
this.lastAttacked = time()
}

canAttack() {
return !this.lastAttacked
? true
: this.lastAttacked + this.attackDelay < time()
}
}

0 comments on commit 0878b8f

Please sign in to comment.