-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Showing
6 changed files
with
136 additions
and
54 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,41 @@ | ||
// @ts-check | ||
|
||
|
||
kaplay(); | ||
|
||
const sprites = [ | ||
"apple", | ||
"heart", | ||
"coin", | ||
"meat", | ||
"lightening", | ||
]; | ||
|
||
sprites.forEach((spr) => { | ||
loadSprite(spr, `/sprites/${spr}.png`); | ||
}); | ||
|
||
setGravity(800); | ||
|
||
// Spawn one object every 0.1 second | ||
loop(0.1, () => { | ||
// Compose object properties with components | ||
const item = add([ | ||
pos(center()), | ||
sprite(choose(sprites)), | ||
anchor("center"), | ||
scale(rand(0.5, 1)), | ||
area({ collisionIgnore: ["fruit"] }), | ||
body(), | ||
// lifespan() comp destroys the object after desired seconds | ||
lifespan(1, { | ||
// it will fade after 0.5 seconds | ||
fade: 0.5 | ||
}), | ||
opacity(1), | ||
move(choose([LEFT, RIGHT]), rand(60, 240)), | ||
"fruit", | ||
]); | ||
|
||
item.jump(rand(320, 640)); | ||
}); |
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,43 +1,49 @@ | ||
// @ts-check | ||
|
||
// Particle spawning | ||
// Creating particles using Particle Component | ||
|
||
kaplay(); | ||
|
||
const sprites = [ | ||
"apple", | ||
"heart", | ||
"coin", | ||
"meat", | ||
"lightening", | ||
]; | ||
loadSprite("star", "./examples/sprites/particle_star_filled.png"); | ||
|
||
sprites.forEach((spr) => { | ||
loadSprite(spr, `/sprites/${spr}.png`); | ||
onLoad(() => { | ||
go("game") | ||
}); | ||
|
||
setGravity(800); | ||
|
||
// Spawn one particle every 0.1 second | ||
loop(0.1, () => { | ||
// TODO: they are resolving collision with each other for some reason | ||
// Compose particle properties with components | ||
const item = add([ | ||
pos(mousePos()), | ||
sprite(choose(sprites)), | ||
anchor("center"), | ||
scale(rand(0.5, 1)), | ||
area({ collisionIgnore: ["particle"] }), | ||
body(), | ||
lifespan(1, { fade: 0.5 }), | ||
opacity(1), | ||
move(choose([LEFT, RIGHT]), rand(60, 240)), | ||
"particle", | ||
function woah() { | ||
const parts = add([ | ||
pos(center()), | ||
particles({ | ||
max: 20, | ||
speed: [50, 100], | ||
angle: [0, 360], | ||
angularVelocity: [45, 90], | ||
lifeTime: [1.0, 1.5], | ||
colors: [rgb(128, 128, 255), WHITE], | ||
opacities: [0.1, 1.0, 0.0], | ||
scales: [1, 2, 1], | ||
texture: getSprite("star").data.tex, | ||
quads: [getSprite("star").data.frames[0]], | ||
}, { | ||
lifetime: 1.5, | ||
rate: 0, | ||
direction: -90, | ||
spread: 40, | ||
}), | ||
]); | ||
|
||
item.onCollide("particle", (p) => { | ||
console.log("dea"); | ||
parts.emit(20); | ||
} | ||
|
||
scene("game", () => { | ||
onKeyPress("space", () => { | ||
woah(); | ||
}); | ||
|
||
onMousePress(() => { | ||
woah(); | ||
}); | ||
|
||
item.jump(rand(320, 640)); | ||
add([ | ||
text("press space for particles"), | ||
]); | ||
}); | ||
|
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