Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Feb 1, 2024
1 parent 3826cfd commit 396fb79
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 113 deletions.
31 changes: 31 additions & 0 deletions blog/3000.2.md
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()
```
208 changes: 104 additions & 104 deletions examples/overlap.js
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
})
10 changes: 1 addition & 9 deletions src/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,15 +753,7 @@ export function testLineLine(l1: Line, l2: Line): Vec2 | null {
}

export function testRectLine(r: Rect, l: Line): boolean {
/*if (testRectPoint(r, l.p1) || testRectPoint(r, l.p2)) {
return true
}
const pts = r.points()
return !!testLineLine(l, new Line(pts[0], pts[1]))
|| !!testLineLine(l, new Line(pts[1], pts[2]))
|| !!testLineLine(l, new Line(pts[2], pts[3]))
|| !!testLineLine(l, new Line(pts[3], pts[0]))*/
let dir = l.p2.sub(l.p1)
const dir = l.p2.sub(l.p1)
let tmin = Number.NEGATIVE_INFINITY, tmax = Number.POSITIVE_INFINITY

if (dir.x != 0.0) {
Expand Down

0 comments on commit 396fb79

Please sign in to comment.