debug draw fix
This commit is contained in:
parent
9045f435a0
commit
8172620214
|
@ -32,6 +32,7 @@ struct rgba kinematic_color = {255, 194, 64, 255};
|
|||
struct rgba static_color = {73,209,80,255};
|
||||
|
||||
static const unsigned char col_alpha = 40;
|
||||
static const float sensor_seg = 10;
|
||||
|
||||
unsigned int category_masks[32];
|
||||
|
||||
|
@ -338,7 +339,12 @@ void phys2d_dbgdrawbox(struct phys2d_box *box) {
|
|||
for (int i = 0; i < n; i++)
|
||||
points[i] = bodytransformpoint(cpShapeGetBody(box->shape.shape), cpPolyShapeGetVert(box->shape.shape, i));
|
||||
|
||||
draw_poly(points, n, shape_color(box->shape.shape), shape_color(box->shape.shape), 0);
|
||||
struct rgba c = shape_color(box->shape.shape);
|
||||
struct rgba cl = c;
|
||||
cl.a = col_alpha;
|
||||
float seglen = cpShapeGetSensor(box->shape.shape) ? sensor_seg : 0;
|
||||
draw_line(points, n, cl,seglen, 1, 0);
|
||||
draw_poly(points, n, c);
|
||||
}
|
||||
/************** POLYGON ************/
|
||||
|
||||
|
@ -404,7 +410,9 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
|
|||
for (int i = 0; i < n; i++)
|
||||
points[i] = bodytransformpoint(cpShapeGetBody(poly->shape.shape), cpPolyShapeGetVert(poly->shape.shape, i));
|
||||
|
||||
draw_poly(points, n, color, line_color, 0);
|
||||
draw_poly(points, n, color);
|
||||
float seglen = cpShapeGetSensor(poly->shape.shape) ? sensor_seg : 0;
|
||||
draw_line(points, n, line_color, seglen, 1, 0);
|
||||
}
|
||||
}
|
||||
/****************** EDGE 2D**************/
|
||||
|
@ -529,7 +537,7 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge) {
|
|||
drawpoints[i] = bodytransformpoint(cpShapeGetBody(edge->shapes[0]), drawpoints[i]);
|
||||
}
|
||||
|
||||
float seglen = cpShapeGetSensor(edge->shapes[0]) ? 10 : 1;
|
||||
float seglen = cpShapeGetSensor(edge->shapes[0]) ? sensor_seg : 0;
|
||||
struct rgba color = shape_color(edge->shapes[0]);
|
||||
struct rgba line_color = color;
|
||||
color.a = col_alpha;
|
||||
|
|
|
@ -40,6 +40,7 @@ struct line_vert {
|
|||
float dist;
|
||||
struct rgba color;
|
||||
float seg_len;
|
||||
float seg_speed;
|
||||
};
|
||||
static int line_c = 0;
|
||||
static int line_v = 0;
|
||||
|
@ -186,7 +187,8 @@ void debugdraw_init()
|
|||
[0].format = SG_VERTEXFORMAT_FLOAT2, /* pos */
|
||||
[1].format = SG_VERTEXFORMAT_FLOAT, /* dist */
|
||||
[2].format = SG_VERTEXFORMAT_UBYTE4N, /* color */
|
||||
[3].format = SG_VERTEXFORMAT_FLOAT /* seg length */
|
||||
[3].format = SG_VERTEXFORMAT_FLOAT, /* seg length */
|
||||
[4].format = SG_VERTEXFORMAT_FLOAT /* dashed line speed */
|
||||
}
|
||||
},
|
||||
.primitive_type = SG_PRIMITIVETYPE_LINES,
|
||||
|
@ -306,7 +308,7 @@ void debugdraw_init()
|
|||
});
|
||||
}
|
||||
|
||||
void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int closed)
|
||||
void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int closed, float seg_speed)
|
||||
{
|
||||
if (a_n < 2) return;
|
||||
|
||||
|
@ -325,6 +327,7 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
|
|||
v[i].dist = dist;
|
||||
v[i].color = color;
|
||||
v[i].seg_len = seg_len;
|
||||
v[i].seg_speed = seg_speed;
|
||||
dist += cpvdist(points[i], points[i+1]);
|
||||
}
|
||||
|
||||
|
@ -332,6 +335,7 @@ void draw_line(cpVect *a_points, int a_n, struct rgba color, float seg_len, int
|
|||
v[n-1].dist = dist;
|
||||
v[n-1].color = color;
|
||||
v[n-1].seg_len = seg_len;
|
||||
v[n-1].seg_speed = seg_speed;
|
||||
|
||||
int i_c = (n-1)*2;
|
||||
|
||||
|
@ -483,7 +487,7 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
|
|||
|
||||
/* Now drawing the line outlines */
|
||||
if (thickness == 1) {
|
||||
draw_line(points,n,line_color,line_seg, 0);
|
||||
draw_line(points,n,line_color,line_seg, 0, 0);
|
||||
} else {
|
||||
/* Draw inside and outside lines */
|
||||
cpVect in_p[n];
|
||||
|
@ -495,48 +499,43 @@ void draw_edge(cpVect *points, int n, struct rgba color, int thickness, int clos
|
|||
for (int i = 1, v = 0; i < n*2; i+=2,v++)
|
||||
out_p[v] = vertices[i].pos;
|
||||
|
||||
draw_line(in_p,n,line_color,line_seg,1);
|
||||
draw_line(out_p,n,line_color,line_seg,1);
|
||||
draw_line(in_p,n,line_color,line_seg,1,0);
|
||||
draw_line(out_p,n,line_color,line_seg,1,0);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float segsize)
|
||||
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float seg)
|
||||
{
|
||||
struct circle_vertex cv;
|
||||
cv.pos[0] = x;
|
||||
cv.pos[1] = y;
|
||||
cv.radius = radius;
|
||||
cv.color = color;
|
||||
cv.segsize = segsize/radius;
|
||||
cv.segsize = seg/radius;
|
||||
cv.fill = pixels/radius;
|
||||
memcpy(circle_b+circle_count, &cv, sizeof(struct circle_vertex));
|
||||
circle_count++;
|
||||
}
|
||||
|
||||
void draw_rect(int x, int y, int w, int h, struct rgba color)
|
||||
{
|
||||
float hw = w / 2.f;
|
||||
float hh = h / 2.f;
|
||||
|
||||
cpVect verts[4] = {
|
||||
{ .x = x-hw, .y = y-hh },
|
||||
{ .x = x+hw, .y = y-hh },
|
||||
{ .x = x+hw, .y = y+hh },
|
||||
{ .x = x-hw, .y = y+hh }
|
||||
};
|
||||
|
||||
draw_poly(verts, 4, color, color, 0);
|
||||
}
|
||||
|
||||
void draw_box(struct cpVect c, struct cpVect wh, struct rgba color)
|
||||
{
|
||||
draw_rect(c.x, c.y, wh.x, wh.y, color);
|
||||
float hw = wh.x / 2.f;
|
||||
float hh = wh.y / 2.f;
|
||||
|
||||
cpVect verts[4] = {
|
||||
{ .x = c.x-hw, .y = c.y-hh },
|
||||
{ .x = c.x+hw, .y = c.y-hh },
|
||||
{ .x = c.x+hw, .y = c.y+hh },
|
||||
{ .x = c.x-hw, .y = c.y+hh }
|
||||
};
|
||||
|
||||
draw_poly(verts, 4, color);
|
||||
}
|
||||
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct rgba color, int capsize)
|
||||
{
|
||||
cpVect points[2] = {start, end};
|
||||
draw_line(points, 2, color, 0, 0);
|
||||
draw_line(points, 2, color, 0, 0,0);
|
||||
draw_cppoint(end, capsize, color);
|
||||
}
|
||||
|
||||
|
@ -580,10 +579,8 @@ void draw_points(struct cpVect *points, int n, float size, struct rgba color)
|
|||
draw_cppoint(points[i], size, color);
|
||||
}
|
||||
|
||||
void draw_poly(cpVect *points, int n, struct rgba color, struct rgba line_color, float line_seg)
|
||||
void draw_poly(cpVect *points, int n, struct rgba color)
|
||||
{
|
||||
draw_line(points, n, line_color, line_seg, 1);
|
||||
|
||||
/* Find polygon mesh */
|
||||
int tric = n - 2;
|
||||
|
||||
|
|
|
@ -8,16 +8,14 @@ void debugdraw_init();
|
|||
void draw_cppoint(struct cpVect point, float r, struct rgba color);
|
||||
void draw_points(struct cpVect *points, int n, float size, struct rgba color);
|
||||
|
||||
void draw_line(cpVect *points, int n, struct rgba color, float seg_len, int closed);
|
||||
void draw_line(cpVect *points, int n, struct rgba color, float seg_len, int closed, float seg_speed);
|
||||
void draw_arrow(struct cpVect start, struct cpVect end, struct rgba, int capsize);
|
||||
void draw_edge(struct cpVect *points, int n, struct rgba color, int thickness, int closed, int flags, struct rgba line_color, float line_seg);
|
||||
|
||||
/* pixels - how many pixels thick, segsize - dashed line seg len */
|
||||
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float segsize);
|
||||
|
||||
void draw_rect(int x, int y, int w, int h, struct rgba color);
|
||||
void draw_circle(int x, int y, float radius, float pixels, struct rgba color, float seg);
|
||||
void draw_box(struct cpVect c, struct cpVect wh, struct rgba color);
|
||||
void draw_poly(cpVect *points, int n, struct rgba color, struct rgba line_color, float line_seg);
|
||||
void draw_poly(cpVect *points, int n, struct rgba color);
|
||||
|
||||
void draw_grid(int width, int span, struct rgba color);
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
|
||||
log_print(buffer);
|
||||
|
||||
if (priority >= 2)
|
||||
if (category == 1 && priority >= 2)
|
||||
js_stacktrace();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -968,6 +968,29 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
case 102:
|
||||
eye = HMM_AddV3(eye,(HMM_Vec3){0,0,0.01});
|
||||
break;
|
||||
case 103:
|
||||
return num2js(js2go(argv[1])->scale);
|
||||
|
||||
case 104:
|
||||
return bool2js(js2go(argv[1])->flipx);
|
||||
|
||||
case 105:
|
||||
return bool2js(js2go(argv[1])->flipy);
|
||||
|
||||
case 106:
|
||||
js2go(argv[1])->e = js2num(argv[2]);
|
||||
break;
|
||||
|
||||
case 107:
|
||||
return num2js(js2go(argv[1])->e);
|
||||
|
||||
case 108:
|
||||
js2go(argv[1])->f = js2num(argv[2]);
|
||||
break;
|
||||
case 109:
|
||||
return num2js(js2go(argv[1])->f);
|
||||
case 110:
|
||||
return num2js(js2go(argv[1])
|
||||
}
|
||||
|
||||
if (str)
|
||||
|
@ -1355,6 +1378,12 @@ JSValue duk_cmd_circle2d(JSContext *js, JSValueConst this, int argc, JSValueCons
|
|||
case 1:
|
||||
circle->offset = js2vec2(argv[2]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return num2js(circle->radius);
|
||||
|
||||
case 3:
|
||||
return vec2js(circle->offset);
|
||||
}
|
||||
|
||||
phys2d_applycircle(circle);
|
||||
|
|
|
@ -226,17 +226,16 @@ struct sFont *MakeFont(const char *fontfile, int height) {
|
|||
|
||||
static int curchar = 0;
|
||||
|
||||
void draw_char_box(struct Character c, float cursor[2], float scale, float color[3]) {
|
||||
int x, y, w, h;
|
||||
void draw_char_box(struct Character c, cpVect cursor, float scale, struct rgba color)
|
||||
{
|
||||
cpVect wh;
|
||||
|
||||
x = cursor[0];
|
||||
y = cursor[1];
|
||||
w = 8 * scale;
|
||||
h = 14;
|
||||
x += w / 2.f;
|
||||
y += h / 2.f;
|
||||
wh.x = 8 * scale;
|
||||
wh.y = 14;
|
||||
cursor.x += wh.x / 2.f;
|
||||
cursor.y += wh.y / 2.f;
|
||||
|
||||
draw_rect(x, y, w, h, color);
|
||||
draw_box(cursor, wh, color);
|
||||
}
|
||||
|
||||
void text_flush() {
|
||||
|
|
|
@ -26,25 +26,15 @@ var component = {
|
|||
|
||||
var sprite = clone(component, {
|
||||
name: "sprite",
|
||||
_path: "",
|
||||
get path() { return this._path; },
|
||||
set path(x) { this._path = x; this.load_img(x); },
|
||||
_pos: [0, 0],
|
||||
get layer() {
|
||||
if (!this.gameobject)
|
||||
return 0;
|
||||
else
|
||||
return this.gameobject.draw_layer;
|
||||
},
|
||||
path: "",
|
||||
layer: 0,
|
||||
pos: [0,0],
|
||||
enabled: true,
|
||||
get visible() { return this.enabled; },
|
||||
set visible(x) { this.enabled = x; },
|
||||
angle: 0,
|
||||
rect: {s0:0, s1: 1, t0: 0, t1: 1},
|
||||
|
||||
get pos() { return this._pos; },
|
||||
set pos(x) {
|
||||
this._pos = x;
|
||||
this.sync();
|
||||
},
|
||||
|
||||
input_kp9_pressed() { this.pos = [0,0]; },
|
||||
input_kp8_pressed() { this.pos = [-0.5,0]; },
|
||||
input_kp7_pressed() { this.pos = [-1,0]; },
|
||||
input_kp6_pressed() { this.pos = [0,-0.5]; },
|
||||
input_kp5_pressed() { this.pos = [-0.5,-0.5]; },
|
||||
|
@ -65,57 +55,30 @@ var sprite = clone(component, {
|
|||
return cwh2bb(realpos, dim);
|
||||
},
|
||||
|
||||
set asset(x) {
|
||||
if (!x) return;
|
||||
if (!x.endsWith(".png")) {
|
||||
Log.error("Can't set texture to a non image.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.path = x;
|
||||
Log.info("path is now " + x);
|
||||
this.sync();
|
||||
},
|
||||
|
||||
_enabled: true,
|
||||
set enabled(x) { this._enabled = x; cmd(20, this.id, x); },
|
||||
get enabled() { return this._enabled; return cmd(21, this.id); },
|
||||
get visible() { return this.enabled; },
|
||||
set visible(x) { this.enabled = x; },
|
||||
|
||||
_angle: 0,
|
||||
get angle() { return this._angle; },
|
||||
set angle(x) {
|
||||
this._angle = x;
|
||||
sync();
|
||||
},
|
||||
|
||||
make(go) {
|
||||
var sprite = clone(this);
|
||||
Object.defineProperty(sprite, 'id', {value:make_sprite(go,this.path,this.pos)});
|
||||
sprite.sync();
|
||||
var old = this;
|
||||
var sprite = clone(this, {
|
||||
get enabled() { return cmd(21,this.id); },
|
||||
set enabled(x) { cmd(20,this.id,x); },
|
||||
set color(x) { cmd(96,this.id,x); },
|
||||
set pos(x) { cmd(37,this.id,x); },
|
||||
set layer(x) { cmd(60, this.id, x); },
|
||||
get layer() { return this.gameobject.draw_layer; },
|
||||
set path(x) { cmd(12,this.id,x,this.rect); },
|
||||
|
||||
kill() { cmd(9,this.id); },
|
||||
});
|
||||
|
||||
var id = make_sprite(go,old.path,old.pos);
|
||||
|
||||
Object.defineProperty(sprite, 'id', {value:id});
|
||||
|
||||
Object.assign(sprite, this);
|
||||
|
||||
return sprite;
|
||||
},
|
||||
|
||||
rect: {s0:0, s1: 1, t0: 0, t1: 1},
|
||||
|
||||
sync() {
|
||||
if (!this.hasOwn('id')) return;
|
||||
cmd(60, this.id, this.layer);
|
||||
cmd(37, this.id, this.pos);
|
||||
},
|
||||
|
||||
set color(x) {
|
||||
cmd(96, this.id, x);
|
||||
},
|
||||
|
||||
load_img(img) {
|
||||
cmd(12, this.id, img, this.rect);
|
||||
},
|
||||
|
||||
kill() {
|
||||
cmd(9, this.id);
|
||||
},
|
||||
});
|
||||
|
||||
/* Container to play sprites and anim2ds */
|
||||
|
@ -217,14 +180,7 @@ var char2d = clone(sprite, {
|
|||
/* For all colliders, "shape" is a pointer to a phys2d_shape, "id" is a pointer to the shape data */
|
||||
var collider2d = clone(component, {
|
||||
name: "collider 2d",
|
||||
|
||||
_sensor: false,
|
||||
set sensor(x) {
|
||||
this._sensor = x;
|
||||
if (this.shape)
|
||||
cmd(18, this.shape, x);
|
||||
},
|
||||
get sensor() { return this._sensor; },
|
||||
sensor: false,
|
||||
|
||||
input_s_pressed() {
|
||||
if (!Keys.alt()) return;
|
||||
|
@ -238,25 +194,28 @@ var collider2d = clone(component, {
|
|||
this.enabled = !this.enabled;
|
||||
},
|
||||
|
||||
coll_sync() {
|
||||
cmd(18, this.shape, this.sensor);
|
||||
},
|
||||
|
||||
_enabled: true,
|
||||
set enabled(x) {this._enabled = x; if (this.id) cmd(22, this.id, x); },
|
||||
enabled: true,
|
||||
get enabled() { return this._enabled; },
|
||||
kill() {}, /* No killing is necessary - it is done through the gameobject's kill */
|
||||
|
||||
register_hit(fn, obj) {
|
||||
register_collide(1, fn, obj, this.gameobject.body, this.shape);
|
||||
},
|
||||
|
||||
make_fns: {
|
||||
set sensor(x) { cmd(18,this.shape,x); },
|
||||
set enabled(x) { cmd(22,this.id,x); }
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
||||
var polygon2d = clone(collider2d, {
|
||||
name: "polygon 2d",
|
||||
points: [],
|
||||
help: "Ctrl-click Add a point\nShift-click Remove a point",
|
||||
mirrorx: false,
|
||||
mirrory: false,
|
||||
|
||||
clone(spec) {
|
||||
var obj = Object.create(this);
|
||||
obj.points = this.points.copy();
|
||||
|
@ -266,6 +225,7 @@ var polygon2d = clone(collider2d, {
|
|||
|
||||
make(go) {
|
||||
var poly = Object.create(this);
|
||||
complete_assign(poly, this.make_fns);
|
||||
Object.assign(poly, make_poly2d(go, this.points));
|
||||
Object.defineProperty(poly, 'id', {enumerable:false});
|
||||
Object.defineProperty(poly, 'shape', {enumerable:false});
|
||||
|
@ -280,6 +240,8 @@ var polygon2d = clone(collider2d, {
|
|||
return points2bb(scaledpoints);
|
||||
},
|
||||
|
||||
help: "Ctrl-click Add a point\nShift-click Remove a point",
|
||||
|
||||
input_f10_pressed() {
|
||||
this.points = sortpointsccw(this.points);
|
||||
},
|
||||
|
@ -353,9 +315,6 @@ var polygon2d = clone(collider2d, {
|
|||
return cmd(80, this.shape);
|
||||
},
|
||||
|
||||
mirrorx: false,
|
||||
mirrory: false,
|
||||
|
||||
input_m_pressed() {
|
||||
if (Keys.ctrl())
|
||||
this.mirrory = !this.mirrory;
|
||||
|
@ -485,15 +444,24 @@ var bucket = clone(collider2d, {
|
|||
|
||||
samples: 10,
|
||||
points:[],
|
||||
thickness:0, /* Number of pixels out the edge is */
|
||||
|
||||
make(go) {
|
||||
var edge = Object.create(this);
|
||||
Object.assign(edge, make_edge2d(go, this.points, this.thickness));
|
||||
Object.defineProperty(edge, 'id', {enumerable:false});
|
||||
Object.defineProperty(edge, 'shape', {enumerable:false});
|
||||
complete_assign(edge, {
|
||||
set thickness(x) {
|
||||
cmd_edge2d(1,this.id,x);
|
||||
}
|
||||
});
|
||||
edge.defn('points', []);
|
||||
// Object.defineProperty(edge, 'points', {enumerable:false});
|
||||
|
||||
edge.sync();
|
||||
|
||||
var synctriggers = ['samples', 'thickness'];
|
||||
|
||||
return edge;
|
||||
},
|
||||
|
||||
|
@ -519,12 +487,6 @@ var bucket = clone(collider2d, {
|
|||
this.sync();
|
||||
},
|
||||
|
||||
_thickness:0, /* Number of pixels out the edge is */
|
||||
get thickness() { return this._thickness; },
|
||||
set thickness(x) {
|
||||
this._thickness = Math.max(x, 0);
|
||||
cmd_edge2d(1, this.id, this._thickness);
|
||||
},
|
||||
|
||||
input_v_pressrep() {
|
||||
if (!Keys.alt()) return;
|
||||
|
@ -638,14 +600,8 @@ var bucket = clone(collider2d, {
|
|||
|
||||
var circle2d = clone(collider2d, {
|
||||
name: "circle 2d",
|
||||
get radius() {
|
||||
return this.rradius;
|
||||
},
|
||||
rradius: 10,
|
||||
set radius(x) {
|
||||
this.rradius = x;
|
||||
cmd_circle2d(0, this.id, this.rradius);
|
||||
},
|
||||
radius: 10,
|
||||
offset: [0,0],
|
||||
|
||||
get boundingbox() {
|
||||
if (!this.gameobject) return null;
|
||||
|
@ -656,11 +612,7 @@ var circle2d = clone(collider2d, {
|
|||
get scale() { return this.radius; },
|
||||
set scale(x) { this.radius = x; },
|
||||
|
||||
ofset: [0,0],
|
||||
get offset() { return this.ofset; },
|
||||
set offset(x) { this.ofset = x; cmd_circle2d(1, this.id, this.ofset); },
|
||||
|
||||
get pos() { return this.ofset; },
|
||||
get pos() { return this.offset; },
|
||||
set pos(x) { this.offset = x; },
|
||||
|
||||
make(go) {
|
||||
|
@ -669,6 +621,18 @@ var circle2d = clone(collider2d, {
|
|||
Object.assign(circle, circ);
|
||||
Object.defineProperty(circle, 'id', {enumerable:false});
|
||||
Object.defineProperty(circle, 'shape', {enumerable:false});
|
||||
|
||||
complete_assign(circle, {
|
||||
set radius(x) { cmd_circle2d(0,this.id,x); },
|
||||
get radius() { return cmd_circle2d(3,this.id); },
|
||||
|
||||
set offset(x) { cmd_circle2d(1,this.id,this.offset); },
|
||||
get offset() { return cmd_circle2d(4,this.id); },
|
||||
|
||||
});
|
||||
|
||||
complete_assign(circle, this.make_fns);
|
||||
|
||||
return circle;
|
||||
},
|
||||
|
||||
|
@ -678,12 +642,6 @@ var circle2d = clone(collider2d, {
|
|||
this.radius = Nuke.pprop("Radius", this.radius);
|
||||
this.offset = Nuke.pprop("offset", this.offset);
|
||||
},
|
||||
|
||||
sync() {
|
||||
cmd_circle2d(0, this.id, this.rradius);
|
||||
cmd_circle2d(-1, this.id);
|
||||
this.coll_sync();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -1311,9 +1311,7 @@ var gameobject = {
|
|||
}
|
||||
},
|
||||
|
||||
_mass: 1,
|
||||
set mass(x) { this._mass = Math.max(0,x); },
|
||||
get mass() { return this._mass; },
|
||||
mass: 1,
|
||||
bodytype: {
|
||||
dynamic: 0,
|
||||
kinematic: 1,
|
||||
|
@ -1331,19 +1329,11 @@ var gameobject = {
|
|||
this.phys = Nuke.radio("kinematic", this.phys, 1);
|
||||
this.phys = Nuke.radio("static", this.phys, 2);
|
||||
},
|
||||
_friction: 0,
|
||||
set friction(x) { this._friction = Math.max(0,x); },
|
||||
get friction() { return this._friction; },
|
||||
_elasticity: 0,
|
||||
set elasticity(x) { this._elasticity = Math.max(0, x); },
|
||||
get elasticity() { return this._elasticity; },
|
||||
friction: 0,
|
||||
elasticity: 0,
|
||||
flipx: false,
|
||||
flipy: false,
|
||||
|
||||
_flipx: false,
|
||||
_flipy: false,
|
||||
get flipx() { return this._flipx; },
|
||||
set flipx(x) { this._flipx = x; if (this.alive) cmd(55, this.body, x); this.sync(); },
|
||||
get flipy() { return this._flipy; },
|
||||
set flipy(x) { this._flipy = x; if (this.alive) cmd(56, this.body, x); this.sync(); },
|
||||
|
||||
body: -1,
|
||||
controlled: false,
|
||||
|
@ -1379,14 +1369,7 @@ var gameobject = {
|
|||
|
||||
varname: "",
|
||||
|
||||
_pos: [0,0],
|
||||
set pos(x) { this._pos = x; set_body(2, this.body, x); this.sync(); },
|
||||
get pos() {
|
||||
if (this.body !== -1)
|
||||
return q_body(1, this.body);
|
||||
else
|
||||
return this._pos;
|
||||
},
|
||||
pos: [0,0],
|
||||
|
||||
set relpos(x) {
|
||||
if (!this.level) {
|
||||
|
@ -1404,14 +1387,7 @@ var gameobject = {
|
|||
return Vector.rotate(offset, -Math.deg2rad(this.level.angle));
|
||||
},
|
||||
|
||||
_angle: 0,
|
||||
set angle(x) { this._angle = x; set_body(0, this.body, Math.deg2rad(x)); this.sync(); },
|
||||
get angle() {
|
||||
if (this.body !== -1)
|
||||
return Math.rad2deg(q_body(2, this.body)) % 360;
|
||||
else
|
||||
return this._angle;
|
||||
},
|
||||
angle: 0,
|
||||
|
||||
get relangle() {
|
||||
if (!this.level) return this.angle;
|
||||
|
@ -1447,9 +1423,6 @@ var gameobject = {
|
|||
set_body(1, this.body, this.phys);
|
||||
cmd(75,this.body,this.layer);
|
||||
cmd(54, this.body);
|
||||
if (this.components)
|
||||
for (var key in this.components)
|
||||
this.components[key].sync();
|
||||
},
|
||||
|
||||
syncall() {
|
||||
|
@ -1532,8 +1505,6 @@ var gameobject = {
|
|||
prop_obj() {
|
||||
var obj = JSON.parse(JSON.stringify(this));
|
||||
delete obj.name;
|
||||
delete obj._pos;
|
||||
delete obj._angle;
|
||||
delete obj.from;
|
||||
return obj;
|
||||
},
|
||||
|
@ -1598,6 +1569,30 @@ var gameobject = {
|
|||
obj.sync();
|
||||
obj.defn('components', {});
|
||||
|
||||
complete_assign(obj, {
|
||||
set scale(x) { cmd(36, this.body, x); },
|
||||
get scale() { return cmd(103, this.body); },
|
||||
get flipx() { return cmd(104,this.body); },
|
||||
set flipx(x) { cmd(55, this.body, x); },
|
||||
get flipy() { return cmd(105,this.body); },
|
||||
set flipy(x) { cmd(56, this.body, x); },
|
||||
|
||||
get angle() { return Math.rad2deg(q_body(2,this.body))%360; },
|
||||
set angle(x) { set_body(0,this.body, Math.deg2rad(x)); },
|
||||
|
||||
set pos(x) { set_body(2,this.body,x); },
|
||||
get pos() { return q_body(1,this.body); },
|
||||
|
||||
get elasticity() { return cmd(107,this.body); },
|
||||
set elasticity(x) { cmd(106,this.body,x); },
|
||||
|
||||
get friction() { return cmd(109,this.body); },
|
||||
set friction(x) { cmd(108,this.body,x); },
|
||||
|
||||
set mass(x) { set_body(7,this.body,x); },
|
||||
get mass() { return cmd(
|
||||
});
|
||||
|
||||
for (var prop in obj) {
|
||||
if (typeof obj[prop] === 'object' && 'make' in obj[prop]) {
|
||||
if (prop === 'flipper') return;
|
||||
|
@ -1648,7 +1643,7 @@ var gameobject = {
|
|||
}
|
||||
|
||||
|
||||
var locks = ['draw_layer', 'friction','elasticity', 'visible', 'body', 'flipx', 'flipy', 'controlled', 'selectable', 'save', 'velocity', 'angularvelocity', 'alive', 'boundingbox', 'name', 'scale', 'angle', 'properties', 'moi', 'relpos', 'relangle', 'up', 'down', 'right', 'left', 'bodytype', 'gizmo', 'pos'];
|
||||
var locks = ['visible', 'body', 'controlled', 'selectable', 'save', 'velocity', 'angularvelocity', 'alive', 'boundingbox', 'name', 'scale', 'angle', 'properties', 'moi', 'relpos', 'relangle', 'up', 'down', 'right', 'left', 'bodytype', 'gizmo', 'pos'];
|
||||
locks.forEach(function(x) {
|
||||
Object.defineProperty(gameobject, x, {enumerable:false});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ out vec4 color;
|
|||
|
||||
in float dist;
|
||||
in vec4 fcolor;
|
||||
in float seg_speed;
|
||||
|
||||
in float seg_len;
|
||||
float pat = 0.5;
|
||||
|
@ -16,7 +17,7 @@ void main()
|
|||
color = fcolor;
|
||||
if (seg_len == 0) return;
|
||||
|
||||
if (mod(dist+time*seg_len,seg_len)/seg_len < 0.5)
|
||||
if (mod(dist+(time*seg_speed)*seg_len,seg_len)/seg_len < 0.5)
|
||||
discard;
|
||||
/*
|
||||
int d = int(dist);
|
||||
|
|
|
@ -3,10 +3,12 @@ layout (location = 0) in vec2 apos;
|
|||
layout (location = 1) in float adist;
|
||||
layout (location = 2) in vec4 acolor;
|
||||
layout (location = 3) in float aseglen;
|
||||
layout (location = 4) in float asegspeed;
|
||||
|
||||
out float dist;
|
||||
out vec4 fcolor;
|
||||
out float seg_len;
|
||||
out float seg_speed;
|
||||
|
||||
uniform mat4 proj;
|
||||
|
||||
|
@ -16,4 +18,5 @@ void main()
|
|||
fcolor = acolor;
|
||||
dist = adist;
|
||||
seg_len = aseglen;
|
||||
seg_speed = asegspeed;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue