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
f874cd8
commit 261db76
Showing
13 changed files
with
178 additions
and
45 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { Sound } from '../constants' | ||
import { addBubble, game } from '../gameobjects' | ||
import { Time } from '../helpers' | ||
import type { Player } from '../types' | ||
|
||
export function addAttack(player: Player) { | ||
const time = new Time() | ||
|
||
onClick(() => { | ||
if (game.paused || !time.passedDelay()) { | ||
return | ||
if (canAttack(player)) { | ||
player.attack.lastFired = time() | ||
addBubble(player) | ||
play(Sound.Hit, { detune: rand(-100, 100) }) | ||
} | ||
|
||
play(Sound.Hit, { detune: rand(-100, 100) }) | ||
addBubble(player) | ||
time.setUpdatedAt() | ||
}) | ||
} | ||
|
||
function canAttack(player: Player) { | ||
return ( | ||
!game.paused && time() - player.attack.lastFired - player.attack.delay > 0 | ||
) | ||
} |
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
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,5 @@ | ||
export let game = add([timer()]) | ||
export let game = add([timer(), { reward: false }]) | ||
|
||
export function addGame() { | ||
game = add([timer()]) | ||
game = add([timer(), { reward: false }]) | ||
} |
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
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,12 +1,18 @@ | ||
export function addModal({ hidden = false }) { | ||
interface Options { | ||
hidden?: boolean | ||
} | ||
|
||
export function addModal(options?: Options) { | ||
const modal = add([ | ||
rect(width(), height()), | ||
color(0, 0, 0), | ||
opacity(0.5), | ||
fixed(), | ||
]) | ||
|
||
modal.hidden = hidden | ||
if (typeof options?.hidden === 'boolean') { | ||
modal.hidden = options.hidden | ||
} | ||
|
||
return modal | ||
} |
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
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
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,109 @@ | ||
import { addButton, addModal, addText, game, getPlayer } from '.' | ||
|
||
const rewards = [ | ||
{ | ||
text: 'Heal 20% HP', | ||
action() { | ||
const player = getPlayer()! | ||
player.heal(player.maxHP()! * 0.2) | ||
}, | ||
}, | ||
|
||
{ | ||
text: 'Max HP +10%', | ||
action() { | ||
const player = getPlayer()! | ||
const maxHP = player.maxHP()! | ||
const hpIncrease = maxHP * 0.1 | ||
player.setMaxHP(maxHP + hpIncrease) | ||
player.heal(hpIncrease) | ||
}, | ||
}, | ||
|
||
{ | ||
text: 'Player Speed +10%', | ||
action() { | ||
const player = getPlayer()! | ||
player.speed *= 1.1 | ||
}, | ||
}, | ||
|
||
{ | ||
text: 'Fire Rate +10%', | ||
action() { | ||
const player = getPlayer()! | ||
player.attack.delay *= 0.9 | ||
}, | ||
}, | ||
|
||
{ | ||
text: 'Bubble Damage +10%', | ||
action() { | ||
const player = getPlayer()! | ||
player.attack.bubbleDamage *= 1.1 | ||
}, | ||
}, | ||
|
||
{ | ||
text: 'Bubble Speed +10%', | ||
action() { | ||
const player = getPlayer()! | ||
player.attack.bubbleSpeed *= 1.1 | ||
}, | ||
}, | ||
] | ||
|
||
export function addReward() { | ||
game.reward = true | ||
game.paused = true | ||
|
||
const modal = addModal() | ||
const container = modal.add([pos(center())]) | ||
|
||
addText({ | ||
width: 550, | ||
height: 80, | ||
x: 0, | ||
y: -120, | ||
text: 'Choose a reward', | ||
fontSize: 48, | ||
parent: container, | ||
}) | ||
|
||
getRewards().forEach((reward, index) => { | ||
addButton({ | ||
width: reward.text.length * 25, | ||
height: 80, | ||
radius: 8, | ||
x: 0, | ||
y: index * 100, | ||
text: reward.text, | ||
onClick() { | ||
reward.action() | ||
modal.destroy() | ||
game.reward = false | ||
game.paused = false | ||
}, | ||
parent: container, | ||
}) | ||
}) | ||
|
||
tween( | ||
container.pos, | ||
center(), | ||
1, | ||
(position) => (container.pos = position), | ||
easings.easeOutElastic, | ||
) | ||
} | ||
|
||
function getRewards(total = 2) { | ||
const result = [] | ||
const copy = rewards.slice() | ||
|
||
for (let i = 0; i < total; i++) { | ||
result.push(copy.splice(randi(copy.length), 1)[0]) | ||
} | ||
|
||
return result | ||
} |
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
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
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
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
This file was deleted.
Oops, something went wrong.