1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import * as player from '/static/games/rms/player.js';
import * as gates from '/static/games/rms/gates.js';
import * as constants from '/static/games/rms/constants.js';
export function straight_bullet_act(straight_bullet) {
const x = straight_bullet.x;
const d_x = straight_bullet.d_x;
straight_bullet.x += d_x;
const y = straight_bullet.y;
const d_y = straight_bullet.d_y;
straight_bullet.y += d_y;
}
export function straight_bullet_delete(straight_bullet) {
straight_bullet.x = -1000; // LMAO
}
export class PBullet {
constructor(x, d_x, y, d_y) {
this.x = x;
this.y = y;
this.d_x = d_x;
this.d_y = d_y;
}
damage() {
return 0.01
}
radius() {
return 10;
}
center() {
return [16, 22];
}
}
export class State {
constructor() {
this.player = new player.Player();
this.enemies = [new gates.Gates()];
this.bullets = [];
this.count = 0;
this.player_bullets = [];
}
}
function dist(x1, y1, x2, y2) {
const xdist = x1 - x2;
const ydist = y1 - y2;
return Math.sqrt(xdist * xdist + ydist * ydist);
}
export function overlaps(self, other) {
const sx = self.x;
const ox = other.x;
const sy = self.y;
const oy = other.y;
const threshold = self.radius() + other.radius();
if (Math.abs(sx - ox) >= threshold || Math.abs(sy - oy) >= threshold) {
return false;
}
const d = dist(sx, sy, ox, oy);
return d < threshold;
}
export function outside(positioned) {
const x = positioned.x;
const y = positioned.y;
return x < -100
|| x > constants.x_dim + 100
|| y < -100
|| y > constants.y_dim + 100;
}
export function draw(positioned, ctx, bitmap) {
const [cx, cy] = positioned.center();
const x0 = Math.round(positioned.x) - cx;
const y0 = Math.round(positioned.y) - cy;
ctx.drawImage(bitmap, x0, y0);
}
|