Compare commits
No commits in common. "c934914ac561e409c1cf1e95260d271fc3d29493" and "358a07dc43fe2edf8b4ce325e5187248184eb737" have entirely different histories.
c934914ac5
...
358a07dc43
7 changed files with 72 additions and 442 deletions
Binary file not shown.
BIN
game/bot.png
BIN
game/bot.png
Binary file not shown.
|
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 708 B |
41
game/main.ts
41
game/main.ts
|
|
@ -1,8 +1,6 @@
|
||||||
import { cls, print, spr, use_texture } from "./graphics";
|
import { cls, print, spr, use_texture } from "./graphics";
|
||||||
import { load_texture } from "./assets";
|
import { load_texture } from "./assets";
|
||||||
import { since_start } from "./time";
|
import { since_start, since_last_frame } from "./time";
|
||||||
import { btn, Button } from "./input";
|
|
||||||
import { new_v2, vadd, vmul, vnorm } from "./vector";
|
|
||||||
|
|
||||||
let bot_sprite: number | undefined = undefined;
|
let bot_sprite: number | undefined = undefined;
|
||||||
|
|
||||||
|
|
@ -16,39 +14,7 @@ export function init() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const friction = 0.6;
|
export function update() {}
|
||||||
let robo_vel = new_v2(0);
|
|
||||||
let robo_pos = new_v2(10);
|
|
||||||
|
|
||||||
export function update() {
|
|
||||||
// Acceleration from input
|
|
||||||
let a = new_v2(0);
|
|
||||||
if (btn(Button.Up)) {
|
|
||||||
a.y -= 1;
|
|
||||||
}
|
|
||||||
if (btn(Button.Down)) {
|
|
||||||
a.y += 1;
|
|
||||||
}
|
|
||||||
if (btn(Button.Left)) {
|
|
||||||
a.x -= 1;
|
|
||||||
}
|
|
||||||
if (btn(Button.Right)) {
|
|
||||||
a.x += 1;
|
|
||||||
}
|
|
||||||
vnorm(a);
|
|
||||||
|
|
||||||
// Friction
|
|
||||||
let v = vmul(robo_vel, friction);
|
|
||||||
v = vadd(v, a);
|
|
||||||
|
|
||||||
// Motion
|
|
||||||
let np = vadd(robo_pos, v);
|
|
||||||
|
|
||||||
// TODO: Collide.
|
|
||||||
|
|
||||||
robo_pos = np;
|
|
||||||
robo_vel = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function draw() {
|
export function draw() {
|
||||||
cls(0.1, 0.2, 0.3);
|
cls(0.1, 0.2, 0.3);
|
||||||
|
|
@ -56,7 +22,8 @@ export function draw() {
|
||||||
// ...it gets resolved here?
|
// ...it gets resolved here?
|
||||||
use_texture(bot_sprite);
|
use_texture(bot_sprite);
|
||||||
|
|
||||||
spr(robo_pos.x, robo_pos.y, 32, 32, 0, 0);
|
let y = (since_start() * 10) % 240;
|
||||||
|
spr(10, y, 32, 32, 0, 0);
|
||||||
}
|
}
|
||||||
// print("FRAME TIME:", since_last_frame());
|
// print("FRAME TIME:", since_last_frame());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,49 +0,0 @@
|
||||||
export interface Vec2 {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function new_v2(x: number, y: number | undefined = undefined): Vec2 {
|
|
||||||
y = y || x;
|
|
||||||
return { x, y };
|
|
||||||
}
|
|
||||||
|
|
||||||
function vecargs(v: Vec2 | number): Vec2 {
|
|
||||||
if (typeof v == "number") {
|
|
||||||
return new_v2(v, v);
|
|
||||||
} else {
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vadd(a: Vec2, b: Vec2 | number): Vec2 {
|
|
||||||
b = vecargs(b);
|
|
||||||
return { x: a.x + b.x, y: a.y + b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vsub(a: Vec2, b: Vec2 | number): Vec2 {
|
|
||||||
b = vecargs(b);
|
|
||||||
return { x: a.x - b.x, y: a.y - b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vmul(a: Vec2, b: Vec2 | number): Vec2 {
|
|
||||||
b = vecargs(b);
|
|
||||||
return { x: a.x * b.x, y: a.y * b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vdiv(a: Vec2, b: Vec2 | number): Vec2 {
|
|
||||||
b = vecargs(b);
|
|
||||||
return { x: a.x / b.x, y: a.y / b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vlen(a: Vec2): number {
|
|
||||||
return Math.sqrt(a.x * a.x + a.y * a.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function vnorm(a: Vec2) {
|
|
||||||
const length = vlen(a);
|
|
||||||
if (length > 0) {
|
|
||||||
a.x /= length;
|
|
||||||
a.y /= length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
11
src/input.ts
11
src/input.ts
|
|
@ -1,11 +0,0 @@
|
||||||
export const Button = {
|
|
||||||
Up: 0,
|
|
||||||
Down: 1,
|
|
||||||
Left: 2,
|
|
||||||
Right: 3,
|
|
||||||
} as const;
|
|
||||||
type Button = (typeof Button)[keyof typeof Button];
|
|
||||||
|
|
||||||
export function btn(_which: Button): boolean {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue