This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
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
3 changed files
with
136 additions
and
113 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,31 @@ | ||
--- | ||
title: Kaboom v3000.2 | ||
author: tga | ||
date: 12/31/2023 | ||
description: Record mode, pretty texts, new events and more in this new version! | ||
image: 2000.1.png | ||
--- | ||
|
||
# Kaboom v3000.2 | ||
|
||
> tga, 12/31/2023 | ||
## Stream Audio | ||
|
||
Audio files are often the biggest file you load in Kaboom if you have long background music. Previously you can only use `loadSound()` which would loads the entire file before the game starts and blocks the loading screen. | ||
|
||
The new `loadMusic()` will load an audio file without blocking loading | ||
|
||
```js | ||
loadMusic("background", "/assets/music/background.mp3") | ||
// note that browser requires user input before audio can be played! | ||
play("background") | ||
``` | ||
|
||
## Canvas | ||
|
||
Kaboom adds the ability to use offscreen canvas! | ||
|
||
```js | ||
const canvas = canvas() | ||
``` |
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,143 +1,143 @@ | ||
kaboom() | ||
|
||
add([ | ||
pos(80, 80), | ||
circle(40), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Circle(this.pos, this.radius) | ||
} | ||
} | ||
pos(80, 80), | ||
circle(40), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Circle(this.pos, this.radius) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(180, 210), | ||
circle(20), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Circle(this.pos, this.radius) | ||
} | ||
} | ||
pos(180, 210), | ||
circle(20), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Circle(this.pos, this.radius) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(40, 180), | ||
rect(20, 40), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Rect(this.pos, this.width, this.height) | ||
} | ||
} | ||
pos(40, 180), | ||
rect(20, 40), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Rect(this.pos, this.width, this.height) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(140, 130), | ||
rect(60, 50), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Rect(this.pos, this.width, this.height) | ||
} | ||
} | ||
pos(140, 130), | ||
rect(60, 50), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Rect(this.pos, this.width, this.height) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(180, 40), | ||
polygon([vec2(-60, 60), vec2(0, 0), vec2(60, 60)]), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Polygon(this.pts.map((pt) => pt.add(this.pos))) | ||
} | ||
} | ||
pos(180, 40), | ||
polygon([vec2(-60, 60), vec2(0, 0), vec2(60, 60)]), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Polygon(this.pts.map((pt) => pt.add(this.pos))) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(280, 130), | ||
polygon([vec2(-20, 20), vec2(0, 0), vec2(20, 20)]), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Polygon(this.pts.map((pt) => pt.add(this.pos))) | ||
} | ||
} | ||
pos(280, 130), | ||
polygon([vec2(-20, 20), vec2(0, 0), vec2(20, 20)]), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
getShape() { | ||
return new Polygon(this.pts.map((pt) => pt.add(this.pos))) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(280, 80), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
draw() { | ||
drawLine({ | ||
p1: vec2(30, 0), | ||
p2: vec2(0, 30), | ||
width: 4, | ||
color: this.color, | ||
}) | ||
}, | ||
getShape() { | ||
return new Line(vec2(30, 0).add(this.pos), vec2(0, 30).add(this.pos)) | ||
} | ||
} | ||
pos(280, 80), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
draw() { | ||
drawLine({ | ||
p1: vec2(30, 0), | ||
p2: vec2(0, 30), | ||
width: 4, | ||
color: this.color, | ||
}) | ||
}, | ||
getShape() { | ||
return new Line(vec2(30, 0).add(this.pos), vec2(0, 30).add(this.pos)) | ||
}, | ||
}, | ||
]) | ||
|
||
add([ | ||
pos(260, 80), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
draw() { | ||
drawRect({ | ||
pos: vec2(-1, -1), | ||
width: 3, | ||
height: 3, | ||
color: this.color | ||
}) | ||
}, | ||
getShape() { | ||
pos(260, 80), | ||
color(BLUE), | ||
"shape", | ||
{ | ||
draw() { | ||
drawRect({ | ||
pos: vec2(-1, -1), | ||
width: 3, | ||
height: 3, | ||
color: this.color, | ||
}) | ||
}, | ||
getShape() { | ||
// This would be point if we had a real class for it | ||
return new Rect(vec2(-1, -1).add(this.pos), 3, 3) | ||
} | ||
} | ||
return new Rect(vec2(-1, -1).add(this.pos), 3, 3) | ||
}, | ||
}, | ||
]) | ||
|
||
onUpdate(() => { | ||
const shapes = get("shape") | ||
shapes.forEach(s1 => { | ||
if (shapes.some(s2 => s1 !== s2 && s1.getShape().collides(s2.getShape()))) { | ||
s1.color = RED | ||
} | ||
else { | ||
s1.color = BLUE | ||
} | ||
}) | ||
const shapes = get("shape") | ||
shapes.forEach(s1 => { | ||
if (shapes.some(s2 => s1 !== s2 && s1.getShape().collides(s2.getShape()))) { | ||
s1.color = RED | ||
} | ||
else { | ||
s1.color = BLUE | ||
} | ||
}) | ||
}) | ||
|
||
let selection | ||
|
||
onMousePress(() => { | ||
const shapes = get("shape") | ||
const pos = mousePos() | ||
const pickList = shapes.filter((shape) => shape.getShape().contains(pos)) | ||
selection = pickList[pickList.length - 1] | ||
const shapes = get("shape") | ||
const pos = mousePos() | ||
const pickList = shapes.filter((shape) => shape.getShape().contains(pos)) | ||
selection = pickList[pickList.length - 1] | ||
}) | ||
|
||
onMouseMove((pos, delta) => { | ||
if (selection) { | ||
selection.moveBy(delta) | ||
} | ||
if (selection) { | ||
selection.moveBy(delta) | ||
} | ||
}) | ||
|
||
onMouseRelease(() => { | ||
selection = null | ||
}) | ||
selection = null | ||
}) |
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