-
Notifications
You must be signed in to change notification settings - Fork 1
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
ae82044
commit 9be18ac
Showing
3 changed files
with
85 additions
and
11 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
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,64 @@ | ||
import { k } from '../kaboom'; | ||
import { Comp, Vec2 } from 'kaboom'; | ||
|
||
const { | ||
add, | ||
anchor, | ||
area, | ||
pos, | ||
sprite, | ||
vec2, | ||
wait, | ||
} = k; | ||
|
||
export interface SaltComp extends Comp { | ||
saltDelay: number; | ||
saltDir: Vec2; | ||
saltQty: number; | ||
throwSalt: ()=>void; | ||
} | ||
|
||
export function canSalt(): SaltComp { | ||
return { | ||
id: "can-salt", | ||
require: ["peter", "can-walk"], | ||
saltDelay: 0.6, | ||
saltDir: vec2(1, 0), | ||
saltQty: 5, | ||
add() { | ||
this.onDirChange(newdir=>{ | ||
// Set last MOVING direction, never the idle state. | ||
if (!newdir.isZero()) this.saltDir = newdir; | ||
}); | ||
}, | ||
throwSalt() { | ||
if (!this.saltQty) { | ||
// TODO: Play empty salt sound | ||
return; | ||
} | ||
this.saltQty-=1; | ||
const saltPos = this.pos.sub(0, this.height/4).add(this.saltDir.x*this.width*0.75, this.saltDir.y*this.height), | ||
saltTop = add([ | ||
sprite('salt', { frame: 1, flipX: this.saltDir.x>0 }), | ||
anchor('center'), | ||
pos(saltPos), | ||
area({collisionIgnore: ['player']}), | ||
]), | ||
saltBottom = add([ | ||
sprite('salt', { frame: 2, flipX: this.saltDir.x>0 }), | ||
anchor('center'), | ||
pos(saltPos.add(0, saltTop.height)), | ||
area({collisionIgnore: ['player']}), | ||
]); | ||
// TODO: Play salt sound | ||
const anim = this.saltDir.x ? 'throw' : this.saltDir.y<0 ? 'throw-up' : 'throw-down'; | ||
this.flipX = this.saltDir.x>0; | ||
this.play(anim); | ||
wait(this.saltDelay, ()=>{ | ||
this.setAnim(this.dir); | ||
saltTop.destroy(); | ||
saltBottom.destroy(); | ||
}); | ||
}, | ||
}; | ||
}; |
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