Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
71e7e067f2 |
1 changed files with 81 additions and 22 deletions
79
src/main.ts
79
src/main.ts
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env -S deno run -A
|
#!/usr/bin/env -S deno run -A
|
||||||
|
|
||||||
import { writeAll } from "https://deno.land/std@0.224.0/io/mod.ts"
|
import { writeAll } from "https://deno.land/std@0.224.0/io/mod.ts"
|
||||||
|
|
||||||
|
import { Crayon, crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts"
|
||||||
import { mkSimplexNoise, SimplexNoise } from "npm:@spissvinkel/simplex-noise@1.0.1"
|
import { mkSimplexNoise, SimplexNoise } from "npm:@spissvinkel/simplex-noise@1.0.1"
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -8,7 +10,7 @@ async function main() {
|
||||||
const fishes = await Fishes.load("./assets/fishes")
|
const fishes = await Fishes.load("./assets/fishes")
|
||||||
for await (const moved of fishes.movements()) {
|
for await (const moved of fishes.movements()) {
|
||||||
console.log(moved.name, "at", moved.position)
|
console.log(moved.name, "at", moved.position)
|
||||||
const displayed = esc_clear() + fishes.fishes.map(display).join("") + "\n"
|
const displayed = esc_clear() + fishes.fishes.map((f) => f.display()).join("") + "\n"
|
||||||
connections.send(displayed)
|
connections.send(displayed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,9 +93,8 @@ class Fish {
|
||||||
if (this.position[0] > bounds[1][0]) this.position[0] = bounds[1][0]
|
if (this.position[0] > bounds[1][0]) this.position[0] = bounds[1][0]
|
||||||
if (this.position[1] > bounds[1][1]) this.position[1] = bounds[1][1]
|
if (this.position[1] > bounds[1][1]) this.position[1] = bounds[1][1]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ```
|
* ```
|
||||||
* _ <name>
|
* _ <name>
|
||||||
* /
|
* /
|
||||||
|
@ -101,19 +102,77 @@ class Fish {
|
||||||
* #####
|
* #####
|
||||||
* #####
|
* #####
|
||||||
* ```
|
* ```
|
||||||
*
|
|
||||||
* @param fish Fish to display.
|
|
||||||
*/
|
*/
|
||||||
function display(fish: Fish) {
|
public display() {
|
||||||
const tick_pad = " ".repeat(fish.size[0])
|
const tick_pad = " ".repeat(this.size[0])
|
||||||
// TODO : add position and color
|
// TODO : add position and color
|
||||||
return [
|
return [
|
||||||
tick_pad + " _ " + fish.name,
|
tick_pad + " _ " + this.name,
|
||||||
tick_pad + "/",
|
tick_pad + "/",
|
||||||
...fish.shape,
|
...this.shape,
|
||||||
]
|
]
|
||||||
.map((l, i) => esc_goto([fish.position[0], fish.position[1] + i]) + l)
|
.map((l, i) => esc_goto([this.position[0], this.position[1] + i]) + l)
|
||||||
.join("") + "\n"
|
.join("") + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Vec2 {
|
||||||
|
public constructor(
|
||||||
|
public x: number,
|
||||||
|
public y: number,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
static of(ord: number) {
|
||||||
|
return new Vec2(ord, ord)
|
||||||
|
}
|
||||||
|
|
||||||
|
add(rhs: Vec2) {
|
||||||
|
return new Vec2(
|
||||||
|
this.x + rhs.x,
|
||||||
|
this.y + rhs.y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sub(rhs: Vec2) {
|
||||||
|
return new Vec2(
|
||||||
|
this.x - rhs.x,
|
||||||
|
this.y - rhs.y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
mul(rhs: Vec2) {
|
||||||
|
return new Vec2(
|
||||||
|
this.x * rhs.x,
|
||||||
|
this.y * rhs.y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
div(rhs: Vec2) {
|
||||||
|
return new Vec2(
|
||||||
|
this.x / rhs.x,
|
||||||
|
this.y / rhs.y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fac(rhs: number) {
|
||||||
|
return new Vec2(
|
||||||
|
this.x * rhs,
|
||||||
|
this.y * rhs,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sprite {
|
||||||
|
public constructor(
|
||||||
|
public size: Vec2,
|
||||||
|
public parts: [Vec2, Crayon, string][],
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public static from(lines: string[]) {
|
||||||
|
const size = new Vec2(lines.map((l) => l.length).reduce((a, b) => Math.max(a, b)), lines.length)
|
||||||
|
const result = new Sprite(size, [])
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pick<T>(arr: T[], random = Math.random) {
|
function pick<T>(arr: T[], random = Math.random) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue