generated from remarkablegames/kaplay-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be25094
commit 8cafea1
Showing
5 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './tags' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum Tag { | ||
'player' = 'player', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import { Tag } from '../constants' | ||
import { ghosty } from '../sprites' | ||
|
||
const ENEMY_SPEED = 200 | ||
|
||
export function addEnemy(x: number, y: number) { | ||
return add([ghosty, pos(x, y), anchor('center')]) | ||
const enemy = add([ghosty, pos(x, y), anchor('center')]) | ||
|
||
enemy.onUpdate(() => { | ||
const player = get(Tag.player)[0] | ||
|
||
if (!player) { | ||
return | ||
} | ||
|
||
const dir = player.pos.sub(enemy.pos).unit() | ||
enemy.move(dir.scale(ENEMY_SPEED)) | ||
}) | ||
|
||
return enemy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { Tag } from '../constants' | ||
import { addCursorKeys } from '../events' | ||
import { bean } from '../sprites' | ||
|
||
export function addPlayer(x = center().x, y = center().y) { | ||
return add([bean, pos(x, y), rotate(0), anchor('center')]) | ||
const player = add([bean, pos(x, y), rotate(0), anchor('center'), Tag.player]) | ||
|
||
player.onUpdate(() => { | ||
player.angle += 120 * dt() | ||
}) | ||
|
||
addCursorKeys(player) | ||
|
||
return player | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters