STORY   LOOP   FURRY   PORN   GAMES
• C •   SERVICES [?] [R] RND   POPULAR
Archived flashes:
229652
/disc/ · /res/     /show/ · /fap/ · /gg/ · /swf/P0001 · P2596 · P5191

<div style="position:absolute;top:-99px;left:-99px;"><img src="http://swfchan.com:57475/45063198?noj=FRM45063198-30DC" width="1" height="1"></div>

tutB_demo04.swf

This is the info page for
Flash #41740

(Click the ID number above for more basic data on this flash file.)


Text
p0

[arrow keys]: thrust
[spacebar] + [drag mouse]: shove object
[click + hold] + [drag mouse]: raycast

change obj shape

ActionScript [AS1/AS2]

Frame 1
function Vector2(x, y) { this.x = x; this.y = y; } Vector2.prototype.ToString = function () { return(((("(" + this.x) + ",") + this.y) + ")"); }; Vector2.prototype.clone = function () { var v = new Vector2(this.x, this.y); return(v); }; Vector2.prototype.plus = function (v2) { var v = new Vector2(this.x + v2.x, this.y + v2.y); return(v); }; Vector2.prototype.minus = function (v2) { var v = new Vector2(this.x - v2.x, this.y - v2.y); return(v); }; Vector2.prototype.normR = function () { var v = new Vector2(this.y * -1, this.x); return(v); }; Vector2.prototype.dir = function () { var v = this.clone(); v.normalize(); return(v); }; Vector2.prototype.proj = function (v2) { var den = v2.dot(v2); if (den == 0) { var v = this.clone(); } else { var v = v2.clone(); v.mult(this.dot(v2) / den); } return(v); }; Vector2.prototype.projLen = function (v2) { var den = v2.dot(v2); if (den == 0) { return(0); } return(Math.abs(this.dot(v2) / den)); }; Vector2.prototype.dot = function (v2) { return((this.x * v2.x) + (this.y * v2.y)); }; Vector2.prototype.cross = function (v2) { return((this.x * v2.y) - (this.y * v2.x)); }; Vector2.prototype.len = function () { return(Math.sqrt((this.x * this.x) + (this.y * this.y))); }; Vector2.prototype.copy = function (v2) { this.x = v2.x; this.y = v2.y; }; Vector2.prototype.mult = function (s) { this.x = this.x * s; this.y = this.y * s; }; Vector2.prototype.normalize = function () { var L = this.len(); if (L != 0) { this.x = this.x / L; this.y = this.y / L; } }; Vector2.prototype.pluseq = function (v2) { this.x = this.x + v2.x; this.y = this.y + v2.y; }; Vector2.prototype.minuseq = function (v2) { this.x = this.x - v2.x; this.y = this.y - v2.y; }; function InputManager() { this.vrend = new VectorRenderer(); this.mPos = new Vector2(this.vrend.buffer._xmouse, this.vrend.buffer._ymouse); this.mOldpos = new Vector2(this.vrend.buffer._xmouse, this.vrend.buffer._ymouse); this.mDelta = new Vector2(0, 0); this.mDownPos = new Vector2(0, 0); this.mUpPos = new Vector2(0, 0); this.onMouseDown = this.CaptureMouseDown; this.onMouseUp = this.CaptureMouseUp; Mouse.addListener(this); this.mState = false; this.mOldState = false; this.mPressed = false; this.mReleased = false; this.kCode = new Array(); this.kState = new Array(); this.kOldState = new Array(); this.tKey = new Array(); this.tState = new Array(); } InputManager.prototype.RegisterKey = function (knum) { var n = this.kCode.length; this.kCode.push(knum); this.kState[n] = false; this.kOldState[n] = false; return(n); }; InputManager.prototype.RegisterToggle = function (knum) { var n = this.tKey.length; this.tKey.push(this.RegisterKey(knum)); this.tState[n] = false; return(n); }; InputManager.prototype.Update = function () { this.mOldpos.x = this.mPos.x; this.mOldpos.y = this.mPos.y; this.mPos.x = this.vrend.buffer._xmouse; this.mPos.y = this.vrend.buffer._ymouse; this.mDelta.x = this.mPos.x - this.mOldpos.x; this.mDelta.y = this.mPos.y - this.mOldpos.y; if (this.mState && (!this.mOldState)) { this.mPressed = true; this.mOldState = true; this.mDownPos.x = this.mPos.x; this.mDownPos.y = this.mPos.y; } else { this.mPressed = false; } if ((!this.mState) && (this.mOldState)) { this.mReleased = true; this.mOldState = false; this.mUpPos.x = this.mPos.x; this.mUpPos.y = this.mPos.y; } else { this.mReleased = false; } if (this.mState) { this.mUpPos.x = this.mPos.x; this.mUpPos.y = this.mPos.y; } var i = 0; while (i < this.kCode.length) { this.kOldState[i] = Key.isDown(this.kCode[i]); i++; } var temp = this.kOldState; this.kOldState = this.kState; this.kState = temp; var i = 0; while (i < this.tKey.length) { if (this.Pressed(this.tKey[i])) { this.tState[i] = !this.tState[i]; } i++; } }; InputManager.prototype.CaptureMouseDown = function () { this.mOldState = false; this.mState = true; }; InputManager.prototype.CaptureMouseUp = function () { this.mOldState = true; this.mState = false; }; InputManager.prototype.getMousePos = function () { return(this.mPos.clone()); }; InputManager.prototype.getMouseDelta = function () { return(this.mDelta.clone()); }; InputManager.prototype.getMouseDragDelta = function () { return(this.mUpPos.minus(this.mDownPos)); }; InputManager.prototype.getMouseDownPos = function () { return(this.mDownPos.clone()); }; InputManager.prototype.getMouseUpPos = function () { return(this.mUpPos.clone()); }; InputManager.prototype.MousePressed = function () { return(this.mPressed); }; InputManager.prototype.MouseReleased = function () { return(this.mReleased); }; InputManager.prototype.MouseDown = function () { return(this.mState); }; InputManager.prototype.Down = function (knum) { return(this.kState[knum]); }; InputManager.prototype.Pressed = function (knum) { return(this.kState[knum] && (!this.kOldState[knum])); }; InputManager.prototype.Released = function (knum) { return((!this.kState[knum]) && (this.kOldState[knum])); }; InputManager.prototype.Toggled = function (tnum) { return(this.tState[tnum]); }; function VectorRenderer() { this.buffer = gfx.CreateEmptySprite(); this.buffer._x = 0; this.buffer._y = 0; this.thickness = 0; this.rgb = 0; this.alpha = 100; } VectorRenderer.prototype.Clear = function () { this.buffer.clear(); this.buffer.lineStyle(this.thickness, this.rgb, this.alpha); }; VectorRenderer.prototype.SetStyle = function (thick, rgb, alpha) { this.buffer.lineStyle(thick, rgb, alpha); }; VectorRenderer.prototype.StartFill = function (x, y, rgb, alpha) { this.buffer.moveTo(x, y); this.buffer.beginFill(rgb, alpha); }; VectorRenderer.prototype.StopFill = function () { this.buffer.endFill(); }; VectorRenderer.prototype.DrawLine = function (va, vb) { this.buffer.moveTo(va.x, va.y); this.buffer.lineTo(vb.x, vb.y); }; VectorRenderer.prototype.DrawLine_S = function (x0, y0, x1, y1) { this.buffer.moveTo(x0, y0); this.buffer.lineTo(x1, y1); }; VectorRenderer.prototype.DrawLinestrip = function (vList) { this.buffer.moveTo(vList[0].x, vList[0].y); var i = 0; while (i < vList.length) { this.buffer.lineTo(vList[i].x, vList[i].y); i++; } }; VectorRenderer.prototype.DrawTri = function (va, vb, vc) { this.buffer.moveTo(va.x, va.y); this.buffer.lineTo(vb.x, vb.y); this.buffer.lineTo(vc.x, vc.y); this.buffer.lineTo(va.x, va.y); }; VectorRenderer.prototype.DrawTri_S = function (vax, vay, vbx, vby, vcx, vcy) { this.buffer.moveTo(vax, vay); this.buffer.lineTo(vbx, vby); this.buffer.lineTo(vcx, vcy); this.buffer.lineTo(vax, vay); }; VectorRenderer.prototype.DrawQuad = function (a, b, c, d) { this.buffer.moveTo(a.x, a.y); this.buffer.lineTo(b.x, b.y); this.buffer.lineTo(c.x, c.y); this.buffer.lineTo(d.x, d.y); this.buffer.lineTo(a.x, a.y); }; VectorRenderer.prototype.DrawQuad_S = function (ax, ay, bx, by, cx, cy, dx, dy) { this.buffer.moveTo(ax, ay); this.buffer.lineTo(bx, by); this.buffer.lineTo(cx, cy); this.buffer.lineTo(dx, dy); this.buffer.lineTo(ax, ay); }; VectorRenderer.prototype.DrawPlus = function (v) { this.buffer.moveTo(v.x - 1, v.y); this.buffer.lineTo(v.x + 1, v.y); this.buffer.moveTo(v.x, v.y - 1); this.buffer.lineTo(v.x, v.y + 1); }; VectorRenderer.prototype.DrawPlus_S = function (vx, vy) { this.buffer.moveTo(vx - 1, vy); this.buffer.lineTo(vx + 1, vy); this.buffer.moveTo(vx, vy - 1); this.buffer.lineTo(vx, vy + 1); }; VectorRenderer.prototype.DrawPlusR = function (v, r) { this.buffer.moveTo(v.x - r, v.y); this.buffer.lineTo(v.x + r, v.y); this.buffer.moveTo(v.x, v.y - r); this.buffer.lineTo(v.x, v.y + r); }; VectorRenderer.prototype.DrawCross = function (v) { this.buffer.moveTo(v.x - 1, v.y - 1); this.buffer.lineTo(v.x + 1, v.y + 1); this.buffer.moveTo(v.x + 1, v.y - 1); this.buffer.lineTo(v.x - 1, v.y + 1); }; VectorRenderer.prototype.DrawCross_S = function (vx, vy) { this.buffer.moveTo(vx - 1, vy - 1); this.buffer.lineTo(vx + 1, vy + 1); this.buffer.moveTo(vx + 1, vy - 1); this.buffer.lineTo(vx - 1, vy + 1); }; VectorRenderer.prototype.DrawCrossR = function (v, r) { this.buffer.moveTo(v.x - r, v.y - r); this.buffer.lineTo(v.x + r, v.y + r); this.buffer.moveTo(v.x + r, v.y - r); this.buffer.lineTo(v.x - r, v.y + r); }; VectorRenderer.prototype.DrawCircle = function (v, r) { var x = v.x; var y = v.y; this.buffer.moveTo(x + r, y); this.buffer.curveTo(r + x, (0.4142 * r) + y, (0.7071 * r) + x, (0.7071 * r) + y); this.buffer.curveTo((0.4142 * r) + x, r + y, x, r + y); this.buffer.curveTo((-0.4142 * r) + x, r + y, (-0.7071 * r) + x, (0.7071 * r) + y); this.buffer.curveTo((-r) + x, (0.4142 * r) + y, (-r) + x, y); this.buffer.curveTo((-r) + x, (-0.4142 * r) + y, (-0.7071 * r) + x, (-0.7071 * r) + y); this.buffer.curveTo((-0.4142 * r) + x, (-r) + y, x, (-r) + y); this.buffer.curveTo((0.4142 * r) + x, (-r) + y, (0.7071 * r) + x, (-0.7071 * r) + y); this.buffer.curveTo(r + x, (-0.4142 * r) + y, r + x, y); }; VectorRenderer.prototype.DrawCircle_S = function (x, y, r) { this.buffer.moveTo(x + r, y); this.buffer.curveTo(r + x, (0.4142 * r) + y, (0.7071 * r) + x, (0.7071 * r) + y); this.buffer.curveTo((0.4142 * r) + x, r + y, x, r + y); this.buffer.curveTo((-0.4142 * r) + x, r + y, (-0.7071 * r) + x, (0.7071 * r) + y); this.buffer.curveTo((-r) + x, (0.4142 * r) + y, (-r) + x, y); this.buffer.curveTo((-r) + x, (-0.4142 * r) + y, (-0.7071 * r) + x, (-0.7071 * r) + y); this.buffer.curveTo((-0.4142 * r) + x, (-r) + y, x, (-r) + y); this.buffer.curveTo((0.4142 * r) + x, (-r) + y, (0.7071 * r) + x, (-0.7071 * r) + y); this.buffer.curveTo(r + x, (-0.4142 * r) + y, r + x, y); }; VectorRenderer.prototype.DrawArc = function (p0, p1, c) { this.buffer.moveTo(p0.x, p0.y); this.buffer.curveTo(c.x, c.y, p1.x, p1.y); }; VectorRenderer.prototype.DrawArc_S = function (x0, y0, x1, y1, xc, yc) { this.buffer.moveTo(x0, y0); this.buffer.curveTo(xc, yc, x1, y1); }; VectorRenderer.prototype.DrawAABB = function (p, xw, yw) { var v0 = new Vector2(p.x + xw, p.y + yw); var v1 = new Vector2(p.x - xw, p.y + yw); var v2 = new Vector2(p.x - xw, p.y - yw); var v3 = new Vector2(p.x + xw, p.y - yw); this.DrawQuad(v0, v1, v2, v3); }; VectorRenderer.prototype.DrawAABB_S = function (minx, maxx, miny, maxy) { var v0 = new Vector2(maxx, maxy); var v1 = new Vector2(minx, maxy); var v2 = new Vector2(minx, miny); var v3 = new Vector2(maxx, miny); this.DrawQuad(v0, v1, v2, v3); }; VectorRenderer.prototype.DrawConcaveCCWArc_S = function (cx, cy, px, py) { var p0x = px; var p0y = py; var vx = (p0x - cx); var vy = (p0y - cy); var r = Math.sqrt((vx * vx) + (vy * vy)); var nx = vy; var ny = (-vx); var p1x = ((p0x + nx) - cx); var p1y = ((p0y + ny) - cy); var len = Math.sqrt((p1x * p1x) + (p1y * p1y)); p1x = p1x / len; p1y = p1y / len; p1x = p1x * r; p1y = p1y * r; p1x = p1x + cx; p1y = p1y + cy; var c0x = (((p0x + p1x) * 0.5) - cx); var c0y = (((p0y + p1y) * 0.5) - cy); var clen = Math.sqrt((c0x * c0x) + (c0y * c0y)); var dlen = (r - clen); c0x = c0x / clen; c0y = c0y / clen; c0x = c0x * (r + dlen); c0y = c0y * (r + dlen); c0x = c0x + cx; c0y = c0y + cy; this.buffer.moveTo(p0x, p0y); this.buffer.curveTo(c0x, c0y, p1x, p1y); var p0x = p1x; var p0y = p1y; var vx = (p0x - cx); var vy = (p0y - cy); var r = Math.sqrt((vx * vx) + (vy * vy)); var nx = vy; var ny = (-vx); var p1x = ((p0x + nx) - cx); var p1y = ((p0y + ny) - cy); var len = Math.sqrt((p1x * p1x) + (p1y * p1y)); p1x = p1x / len; p1y = p1y / len; p1x = p1x * r; p1y = p1y * r; p1x = p1x + cx; p1y = p1y + cy; var c0x = (((p0x + p1x) * 0.5) - cx); var c0y = (((p0y + p1y) * 0.5) - cy); var clen = Math.sqrt((c0x * c0x) + (c0y * c0y)); var dlen = (r - clen); c0x = c0x / clen; c0y = c0y / clen; c0x = c0x * (r + dlen); c0y = c0y * (r + dlen); c0x = c0x + cx; c0y = c0y + cy; this.buffer.curveTo(c0x, c0y, p1x, p1y); }; function Point(x, y, title, col, isDraggable, dragFunc, xmin, ymin, xmax, ymax) { this.pos = new Vector2(x, y); this.title = title; this.mc = CreateMC("pointMC", "point_" + title); this.mc.title = this.mc.attachMovie("titleMC", "title_" + title, 1); this.mc.title.txt = this.title; this.mc.title._x = 4; this.mc.title._y = 1; var temp = new Color(this.mc.gfx); temp.setRGB(col); this.mc._x = x; this.mc._y = y; if (isDraggable) { this.mc.hitArea = this.mc.gfx; this.mc.onPress = function () { this.startDrag(false, xmin, ymin, xmax, ymax); this.onEnterFrame = dragFunc; }; this.mc.onMouseUp = function () { this.stopDrag(); this.onEnterFrame(); this.onEnterFrame = null; }; } } function NinjaGraphicsSystem() { this.rootbuffer = _root.createEmptyMovieClip("rootbuffer", 1000); this.front_depth = 1000; this.back_depth = 1000; this.stepsize = 100; } NinjaGraphicsSystem.prototype.CreateSprite = function (linkage) { var dep = this.GetNextDepth_Front(); var mc = this.rootbuffer.attachMovie(linkage, linkage + dep, dep); return(mc); }; NinjaGraphicsSystem.prototype.CreateEmptySprite = function () { var dep = this.GetNextDepth_Front(); var mc = this.rootbuffer.createEmptyMovieClip("emptyMC" + dep, dep); return(mc); }; NinjaGraphicsSystem.prototype.DestroyMC = function (mc) { mc.swapDepths(1048000); mc.removeMovieClip(); }; NinjaGraphicsSystem.prototype.GetNextDepth_Front = function () { this.front_depth = this.front_depth + this.stepsize; return(this.front_depth); }; NinjaGraphicsSystem.prototype.GetNextDepth_Back = function () { this.back_depth = this.back_depth - this.stepsize; return(this.back_depth); }; function CreateMC(linkName, instanceName) { var depth = gfx.GetNextDepth_Front(); if (linkName == "EMPTY_MC") { return(_root.createEmptyMovieClip(instanceName, depth)); } if (linkName == "TEXT_MC") { return(_root.createTextField(instanceName, depth, 0, 0, 100, 100)); } return(_root.attachMovie(linkName, instanceName + depth, depth)); } DestroyMC = function (mc) { mc.swapDepths(1048000); mc.removeMovieClip(); }; function TileMap(rows, cols, xw, yw) { this.xw = xw; this.yw = yw; this.tw = 2 * this.xw; this.th = 2 * this.yw; this.rows = rows; this.cols = cols; this.fullrows = this.rows + 2; this.fullcols = this.cols + 2; this.minX = this.tw; this.minY = this.th; this.maxX = this.tw + (rows * this.tw); this.maxY = this.th + (cols * this.th); this.grid = new Object(); this.BUILD_STEPS_REMAINING = 9; this.rend = new VectorRenderer(); this.rend.Clear(); } TileMap.prototype.Building = function () { var x = this.xw; var y = this.yw; var fullrows = this.fullrows; var fullcols = this.fullcols; var rows = this.rows; var cols = this.cols; if (this.BUILD_STEPS_REMAINING == 9) { var i = 0; while (i < fullrows) { this.grid[i] = new Object(); var j = 0; while (j < fullcols) { this.grid[i][j] = new TileMapCell(i, j, x, y, this.xw, this.yw); y = y + this.th; j++; } x = x + this.tw; y = this.yw; i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 8) { var i = 0; while (i < (fullrows - 1)) { var j = 0; while (j < fullcols) { this.grid[i][j].LinkR(this.grid[i + 1][j]); j++; } i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 7) { var i = 1; while (i < fullrows) { var j = 0; while (j < fullcols) { this.grid[i][j].LinkL(this.grid[i - 1][j]); j++; } i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 6) { var i = 0; while (i < fullrows) { var j = 0; while (j < (fullcols - 1)) { this.grid[i][j].LinkD(this.grid[i][j + 1]); j++; } i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 5) { var i = 0; while (i < fullrows) { var j = 1; while (j < fullcols) { this.grid[i][j].LinkU(this.grid[i][j - 1]); j++; } i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 4) { var i = 0; while (i < fullrows) { this.grid[i][0].SetState(TID_FULL); i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 3) { var i = 0; while (i < fullrows) { this.grid[i][fullcols - 1].SetState(TID_FULL); i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 2) { var i = 0; while (i < fullcols) { this.grid[0][i].SetState(TID_FULL); i++; } this.BUILD_STEPS_REMAINING--; return(true); } if (this.BUILD_STEPS_REMAINING == 1) { var i = 0; while (i < fullcols) { this.grid[fullrows - 1][i].SetState(TID_FULL); i++; } this.BUILD_STEPS_REMAINING--; return(true); } return(false); }; TileMap.prototype.ClearGrid = function () { var temp; for (var i in this.grid) { temp = this.grid[i]; for (var j in temp) { temp[j].next = null; temp[j].prev = null; } } }; TileMap.prototype.GetTile_S = function (x, y) { return(this.grid[Math.floor(x / this.tw)][Math.floor(y / this.th)]); }; TileMap.prototype.GetTile_V = function (p) { return(this.grid[Math.floor(p.x / this.tw)][Math.floor(p.y / this.th)]); }; TileMap.prototype.GetTile_I = function (i, j) { return(this.grid[i][j]); }; TileMap.prototype.GetIndex_S = function (v, x, y) { v.x = Math.floor(x / this.tw); v.y = Math.floor(y / this.th); }; TileMap.prototype.GetIndex_V = function (v, p) { v.x = Math.floor(p.x / this.tw); v.y = Math.floor(p.y / this.th); }; function TileMapCell(i, j, x, y, xw, yw) { this.ID = TID_EMPTY; this.CTYPE = CTYPE_EMPTY; this.i = i; this.j = j; this.nU = null; this.nD = null; this.nL = null; this.nR = null; this.eU = EID_OFF; this.eD = EID_OFF; this.eL = EID_OFF; this.eR = EID_OFF; this.gx = 0; this.gy = GRAV; this.d = DRAG; this.next = null; this.prev = null; this.objcounter = 0; this.pos = new Vector2(x, y); this.xw = xw; this.yw = yw; this.minx = this.pos.x - this.xw; this.maxx = this.pos.x + this.xw; this.miny = this.pos.y - this.yw; this.maxy = this.pos.y + this.yw; this.signx = 0; this.signy = 0; this.sx = 0; this.sy = 0; var outlined = false; if (!outlined) { this.mc = gfx.CreateSprite("tileMC", LAYER_TILES); this.mc.gotoAndStop(1); this.mc._xscale = this.xw * 2; this.mc._yscale = this.yw * 2; this.mc._x = this.pos.x; this.mc._y = this.pos.y; var col = new Color(this.mc); col.setRGB(7960968); } else { this.mc = gfx.CreateSprite("tileMC2", LAYER_TILES2); this.mc.gotoAndStop(1); this.mc._xscale = this.xw * 2; this.mc._yscale = this.yw * 2; this.mc._x = this.pos.x; this.mc._y = this.pos.y; } } TID_EMPTY = 0; TID_FULL = 1; TID_45DEGpn = 2; TID_45DEGnn = 3; TID_45DEGnp = 4; TID_45DEGpp = 5; TID_CONCAVEpn = 6; TID_CONCAVEnn = 7; TID_CONCAVEnp = 8; TID_CONCAVEpp = 9; TID_CONVEXpn = 10; TID_CONVEXnn = 11; TID_CONVEXnp = 12; TID_CONVEXpp = 13; TID_22DEGpnS = 14; TID_22DEGnnS = 15; TID_22DEGnpS = 16; TID_22DEGppS = 17; TID_22DEGpnB = 18; TID_22DEGnnB = 19; TID_22DEGnpB = 20; TID_22DEGppB = 21; TID_67DEGpnS = 22; TID_67DEGnnS = 23; TID_67DEGnpS = 24; TID_67DEGppS = 25; TID_67DEGpnB = 26; TID_67DEGnnB = 27; TID_67DEGnpB = 28; TID_67DEGppB = 29; TID_HALFd = 30; TID_HALFr = 31; TID_HALFu = 32; TID_HALFl = 33; CTYPE_EMPTY = 0; CTYPE_FULL = 1; CTYPE_45DEG = 2; CTYPE_CONCAVE = 6; CTYPE_CONVEX = 10; CTYPE_22DEGs = 14; CTYPE_22DEGb = 18; CTYPE_67DEGs = 22; CTYPE_67DEGb = 26; CTYPE_HALF = 30; EID_OFF = 0; EID_INTERESTING = 1; EID_SOLID = 2; TileMapCell.prototype.LinkU = function (t) { this.nU = t; }; TileMapCell.prototype.LinkD = function (t) { this.nD = t; }; TileMapCell.prototype.LinkL = function (t) { this.nL = t; }; TileMapCell.prototype.LinkR = function (t) { this.nR = t; }; TileMapCell.prototype.ToString = function () { var str = (((("(" + this.i) + ",") + this.j) + ")"); return(str); }; TileMapCell.prototype.Draw = function () { this.mc.gotoAndStop(this.ID + 1); }; TileMapCell.prototype.SetState = function (ID) { if (ID == TID_EMPTY) { this.Clear(); } else { this.ID = ID; this.UpdateType(); this.UpdateEdges(); this.UpdateNeighbors(); } }; TileMapCell.prototype.Clear = function () { this.ID = TID_EMPTY; this.UpdateType(); this.UpdateEdges(); this.UpdateNeighbors(); this.Draw(); }; TileMapCell.prototype.UpdateNeighbors = function () { if (this.nU != null) { this.nU.UpdateEdges(); } if (this.nD != null) { this.nD.UpdateEdges(); } if (this.nL != null) { this.nL.UpdateEdges(); } if (this.nR != null) { this.nR.UpdateEdges(); } }; TileMapCell.prototype.UpdateType = function () { if (0 < this.ID) { if (this.ID < CTYPE_45DEG) { this.CTYPE = CTYPE_FULL; this.signx = 0; this.signy = 0; this.sx = 0; this.sy = 0; } else if (this.ID < CTYPE_CONCAVE) { this.CTYPE = CTYPE_45DEG; if (this.ID == TID_45DEGpn) { this.signx = 1; this.signy = -1; this.sx = this.signx / Math.SQRT2; this.sy = this.signy / Math.SQRT2; } else if (this.ID == TID_45DEGnn) { this.signx = -1; this.signy = -1; this.sx = this.signx / Math.SQRT2; this.sy = this.signy / Math.SQRT2; } else if (this.ID == TID_45DEGnp) { this.signx = -1; this.signy = 1; this.sx = this.signx / Math.SQRT2; this.sy = this.signy / Math.SQRT2; } else if (this.ID == TID_45DEGpp) { this.signx = 1; this.signy = 1; this.sx = this.signx / Math.SQRT2; this.sy = this.signy / Math.SQRT2; } else { return(false); } } else if (this.ID < CTYPE_CONVEX) { this.CTYPE = CTYPE_CONCAVE; if (this.ID == TID_CONCAVEpn) { this.signx = 1; this.signy = -1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONCAVEnn) { this.signx = -1; this.signy = -1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONCAVEnp) { this.signx = -1; this.signy = 1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONCAVEpp) { this.signx = 1; this.signy = 1; this.sx = 0; this.sy = 0; } else { return(false); } } else if (this.ID < CTYPE_22DEGs) { this.CTYPE = CTYPE_CONVEX; if (this.ID == TID_CONVEXpn) { this.signx = 1; this.signy = -1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONVEXnn) { this.signx = -1; this.signy = -1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONVEXnp) { this.signx = -1; this.signy = 1; this.sx = 0; this.sy = 0; } else if (this.ID == TID_CONVEXpp) { this.signx = 1; this.signy = 1; this.sx = 0; this.sy = 0; } else { return(false); } } else if (this.ID < CTYPE_22DEGb) { this.CTYPE = CTYPE_22DEGs; if (this.ID == TID_22DEGpnS) { this.signx = 1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGnnS) { this.signx = -1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGnpS) { this.signx = -1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGppS) { this.signx = 1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else { return(false); } } else if (this.ID < CTYPE_67DEGs) { this.CTYPE = CTYPE_22DEGb; if (this.ID == TID_22DEGpnB) { this.signx = 1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGnnB) { this.signx = -1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGnpB) { this.signx = -1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else if (this.ID == TID_22DEGppB) { this.signx = 1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 1) / slen; this.sy = (this.signy * 2) / slen; } else { return(false); } } else if (this.ID < CTYPE_67DEGb) { this.CTYPE = CTYPE_67DEGs; if (this.ID == TID_67DEGpnS) { this.signx = 1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGnnS) { this.signx = -1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGnpS) { this.signx = -1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGppS) { this.signx = 1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else { return(false); } } else if (this.ID < CTYPE_HALF) { this.CTYPE = CTYPE_67DEGb; if (this.ID == TID_67DEGpnB) { this.signx = 1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGnnB) { this.signx = -1; this.signy = -1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGnpB) { this.signx = -1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else if (this.ID == TID_67DEGppB) { this.signx = 1; this.signy = 1; var slen = 2.23606797749979; this.sx = (this.signx * 2) / slen; this.sy = (this.signy * 1) / slen; } else { return(false); } } else { this.CTYPE = CTYPE_HALF; if (this.ID == TID_HALFd) { this.signx = 0; this.signy = -1; this.sx = this.signx; this.sy = this.signy; } else if (this.ID == TID_HALFu) { this.signx = 0; this.signy = 1; this.sx = this.signx; this.sy = this.signy; } else if (this.ID == TID_HALFl) { this.signx = 1; this.signy = 0; this.sx = this.signx; this.sy = this.signy; } else if (this.ID == TID_HALFr) { this.signx = -1; this.signy = 0; this.sx = this.signx; this.sy = this.signy; } else { return(false); } } } else { this.CTYPE = CTYPE_EMPTY; this.signx = 0; this.signy = 0; this.sx = 0; this.sy = 0; } }; TileMapCell.prototype.UpdateEdges = function () { var n = this.nU; if (this.ID == TID_EMPTY) { if (n.ID == TID_EMPTY) { this.eU = EID_OFF; } else if (n.ID == TID_FULL) { this.eU = EID_SOLID; } else if ((((n.signy * -1) <= 0) || (n.ID == TID_67DEGpnS)) || (n.ID == TID_67DEGnnS)) { this.eU = EID_INTERESTING; } else { this.eU = EID_SOLID; } } else if (this.ID == TID_FULL) { if (n.ID == TID_FULL) { this.eU = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eU = EID_OFF; } else if ((((n.signy * -1) <= 0) || (n.ID == TID_67DEGpnS)) || (n.ID == TID_67DEGnnS)) { this.eU = EID_INTERESTING; } else { this.eU = EID_OFF; } } else if (0 <= (this.signy * -1)) { if (n.ID == TID_EMPTY) { this.eU = EID_OFF; } else if (n.ID == TID_FULL) { this.eU = EID_SOLID; } else if ((((n.signy * -1) <= 0) || (n.ID == TID_67DEGpnS)) || (n.ID == TID_67DEGnnS)) { this.eU = EID_INTERESTING; } else { this.eU = EID_SOLID; } } else if ((this.ID == TID_67DEGppS) || (this.ID == TID_67DEGnpS)) { if (n.ID == TID_EMPTY) { this.eU = EID_OFF; } else if (n.ID == TID_FULL) { this.eU = EID_SOLID; } else if ((((n.signy * -1) <= 0) || (n.ID == TID_67DEGpnS)) || (n.ID == TID_67DEGnnS)) { this.eU = EID_INTERESTING; } else if ((0 < (n.signy * -1)) || (n.ID == TID_FULL)) { this.eU = EID_SOLID; } else { this.eU = EID_OFF; } } else if (n.ID == TID_FULL) { this.eU = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eU = EID_OFF; } else if ((((n.signy * -1) <= 0) || (n.ID == TID_67DEGpnS)) || (n.ID == TID_67DEGnnS)) { this.eU = EID_INTERESTING; } else { this.eU = EID_OFF; } var n = this.nD; if (this.ID == TID_EMPTY) { if (n.ID == TID_EMPTY) { this.eD = EID_OFF; } else if (n.ID == TID_FULL) { this.eD = EID_SOLID; } else if ((((n.signy * 1) <= 0) || (n.ID == TID_67DEGppS)) || (n.ID == TID_67DEGnpS)) { this.eD = EID_INTERESTING; } else { this.eD = EID_SOLID; } } else if (this.ID == TID_FULL) { if (n.ID == TID_FULL) { this.eD = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eD = EID_OFF; } else if ((((n.signy * 1) <= 0) || (n.ID == TID_67DEGppS)) || (n.ID == TID_67DEGnpS)) { this.eD = EID_INTERESTING; } else { this.eD = EID_OFF; } } else if (0 <= (this.signy * 1)) { if (n.ID == TID_EMPTY) { this.eD = EID_OFF; } else if (n.ID == TID_FULL) { this.eD = EID_SOLID; } else if ((((n.signy * 1) <= 0) || (n.ID == TID_67DEGppS)) || (n.ID == TID_67DEGnpS)) { this.eD = EID_INTERESTING; } else { this.eD = EID_SOLID; } } else if ((this.ID == TID_67DEGpnS) || (this.ID == TID_67DEGnnS)) { if (n.ID == TID_EMPTY) { this.eD = EID_OFF; } else if (n.ID == TID_FULL) { this.eD = EID_SOLID; } else if ((((n.signy * 1) <= 0) || (n.ID == TID_67DEGppS)) || (n.ID == TID_67DEGnpS)) { this.eD = EID_INTERESTING; } else if ((0 < (n.signy * 1)) || (n.ID == TID_FULL)) { this.eD = EID_SOLID; } else { this.eD = EID_OFF; } } else if (n.ID == TID_FULL) { this.eD = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eD = EID_OFF; } else if ((((n.signy * 1) <= 0) || (n.ID == TID_67DEGppS)) || (n.ID == TID_67DEGnpS)) { this.eD = EID_INTERESTING; } else { this.eD = EID_OFF; } var n = this.nR; if (this.ID == TID_EMPTY) { if (n.ID == TID_EMPTY) { this.eR = EID_OFF; } else if (n.ID == TID_FULL) { this.eR = EID_SOLID; } else if ((((n.signx * 1) <= 0) || (n.ID == TID_22DEGpnS)) || (n.ID == TID_22DEGppS)) { this.eR = EID_INTERESTING; } else { this.eR = EID_SOLID; } } else if (this.ID == TID_FULL) { if (n.ID == TID_FULL) { this.eR = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eR = EID_OFF; } else if ((((n.signx * 1) <= 0) || (n.ID == TID_22DEGpnS)) || (n.ID == TID_22DEGppS)) { this.eR = EID_INTERESTING; } else { this.eR = EID_OFF; } } else if (0 <= (this.signx * 1)) { if (n.ID == TID_EMPTY) { this.eR = EID_OFF; } else if (n.ID == TID_FULL) { this.eR = EID_SOLID; } else if ((((n.signx * 1) <= 0) || (n.ID == TID_22DEGpnS)) || (n.ID == TID_22DEGppS)) { this.eR = EID_INTERESTING; } else { this.eR = EID_SOLID; } } else if ((this.ID == TID_22DEGnnS) || (this.ID == TID_22DEGnpS)) { if (n.ID == TID_EMPTY) { this.eR = EID_OFF; } else if (n.ID == TID_FULL) { this.eR = EID_SOLID; } else if ((((n.signx * 1) <= 0) || (n.ID == TID_22DEGpnS)) || (n.ID == TID_22DEGppS)) { this.eR = EID_INTERESTING; } else if ((n.ID == TID_FULL) || (0 < (n.signx * 1))) { this.eR = EID_SOLID; } else { this.eR = EID_OFF; } } else if (n.ID == TID_FULL) { this.eR = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eR = EID_OFF; } else if ((((n.signx * 1) <= 0) || (n.ID == TID_22DEGpnS)) || (n.ID == TID_22DEGppS)) { this.eR = EID_INTERESTING; } else { this.eR = EID_OFF; } var n = this.nL; if (this.ID == TID_EMPTY) { if (n.ID == TID_EMPTY) { this.eL = EID_OFF; } else if (n.ID == TID_FULL) { this.eL = EID_SOLID; } else if ((((n.signx * -1) <= 0) || (n.ID == TID_22DEGnnS)) || (n.ID == TID_22DEGnpS)) { this.eL = EID_INTERESTING; } else { this.eL = EID_SOLID; } } else if (this.ID == TID_FULL) { if (n.ID == TID_FULL) { this.eL = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eL = EID_OFF; } else if ((((n.signx * -1) <= 0) || (n.ID == TID_22DEGnnS)) || (n.ID == TID_22DEGnpS)) { this.eL = EID_INTERESTING; } else { this.eL = EID_OFF; } } else if (0 <= (this.signx * -1)) { if (n.ID == TID_EMPTY) { this.eL = EID_OFF; } else if (n.ID == TID_FULL) { this.eL = EID_SOLID; } else if ((((n.signx * -1) <= 0) || (n.ID == TID_22DEGnnS)) || (n.ID == TID_22DEGnpS)) { this.eL = EID_INTERESTING; } else { this.eL = EID_SOLID; } } else if ((this.ID == TID_22DEGpnS) || (this.ID == TID_22DEGppS)) { if (n.ID == TID_EMPTY) { this.eL = EID_OFF; } else if (n.ID == TID_FULL) { this.eL = EID_SOLID; } else if ((((n.signx * -1) <= 0) || (n.ID == TID_22DEGnnS)) || (n.ID == TID_22DEGnpS)) { this.eL = EID_INTERESTING; } else if ((0 < (n.signx * -1)) || (n.ID == TID_FULL)) { this.eL = EID_SOLID; } else { this.eL = EID_OFF; } } else if (n.ID == TID_FULL) { this.eL = EID_OFF; } else if (n.ID == TID_EMPTY) { this.eL = EID_OFF; } else if ((((n.signx * -1) <= 0) || (n.ID == TID_22DEGnnS)) || (n.ID == TID_22DEGnpS)) { this.eL = EID_INTERESTING; } else { this.eL = EID_OFF; } this.Draw(); }; TileMapCell.prototype.InsertObj = function (obj) { obj.next = this.next; obj.prev = this; this.prev = null; if (this.next != null) { this.next.prev = obj; } this.next = obj; this.objcounter++; }; TileMapCell.prototype.RemoveObj = function (obj) { obj.prev.next = obj.next; if (obj.next != null) { obj.next.prev = obj.prev; } obj.next = null; obj.prev = null; this.objcounter--; }; CHAR_PAD = 48; TileMap.prototype.GetTileStates = function () { var n = this.rows; var m = this.cols; var grid = this.grid; var output = ""; var col; var i = 0; while (i < n) { col = grid[i + 1]; var j = 0; while (j < m) { output = output + String.fromCharCode(col[j + 1].ID + CHAR_PAD); j++; } i++; } return(output); }; TileMap.prototype.SetTileState = function (i, j, char) { this.grid[i + 1][j + 1].SetState(char - CHAR_PAD); }; TileMap.prototype.SetTileStates = function (instr) { var n = this.rows; var m = this.cols; var grid = this.grid; var charList = new Array(); var col; var i = 0; while (i < n) { charList[i] = new Array(); var j = 0; while (j < m) { var char = instr.charCodeAt(cnum); charList[i][j] = char; cnum++; j++; } i++; } var col; var i = 0; while (i < n) { col = grid[i + 1]; var j = 0; while (j < m) { col[j + 1].SetState(charList[i][j] - CHAR_PAD); j++; } i++; } }; COL_NONE = 0; COL_AXIS = 1; COL_OTHER = 2; function CollideAABBvsTileMap() { var pos = this.pos; var c = tiles.GetTile_V(pos); this.cell = c; var tx = c.pos.x; var ty = c.pos.y; var txw = c.xw; var tyw = c.yw; var dx = (pos.x - tx); var dy = (pos.y - ty); if (0 < c.ID) { var px = ((txw + this.xw) - Math.abs(dx)); var py = ((tyw + this.yw) - Math.abs(dy)); if (px < py) { if (dx < 0) { px = px * -1; py = 0; } else { py = 0; } } else if (dy < 0) { px = 0; py = py * -1; } else { px = 0; } ResolveBoxTile(px, py, this, c); } var crossV = false; var hitV = false; var dy = (pos.y - ty); var py = ((Math.abs(dy) + this.yw) - tyw); if (0 < py) { crossV = true; var eV; var nV; var pV; var signY; if (dy < 0) { eV = c.eU; nV = c.nU; pV = py; signY = 1; } else { eV = c.eD; nV = c.nD; pV = -py; signY = -1; } if (0 < eV) { if (eV == EID_SOLID) { hitV = COL_AXIS; this.ReportCollisionVsWorld(0, pV, 0, signY, nV); } else { hitV = ResolveBoxTile(0, pV, this, nV); } } } var crossH = false; var hitH = false; var dx = (pos.x - tx); var px = ((Math.abs(dx) + this.xw) - txw); if (0 < px) { crossH = true; var eH; var nH; var pH; var signX; if (dx < 0) { eH = c.eL; nH = c.nL; pH = px; signX = 1; } else { eH = c.eR; nH = c.nR; pH = -px; signX = -1; } if (0 < eH) { if (eH == EID_SOLID) { hitH = COL_AXIS; this.ReportCollisionVsWorld(pH, 0, signX, 0, nH); } else { hitH = ResolveBoxTile(pH, 0, this, nH); } } } if (((crossH && (hitH != COL_AXIS)) && (crossV)) && (hitV != COL_AXIS)) { var dx = (pos.x - tx); var dy = (pos.y - ty); var px = ((Math.abs(dx) + this.xw) - txw); var py = ((Math.abs(dy) + this.yw) - tyw); var rx = 0; var ry = 0; var hit = false; var eH; var eV; var dTile; if ((dx < 0) && (dy < 0)) { eH = c.nU.eL; eV = c.nL.eU; dTile = c.nU.nL; } else if ((dx < 0) && (0 < dy)) { eH = c.nD.eL; eV = c.nL.eD; dTile = c.nD.nL; } else if ((0 < dx) && (0 < dy)) { eH = c.nD.eR; eV = c.nR.eD; dTile = c.nD.nR; } else if ((0 < dx) && (dy < 0)) { eH = c.nU.eR; eV = c.nR.eU; dTile = c.nU.nR; } var nx; var ny; if (px < py) { ry = (ny = 0); if (dx < 0) { rx = px; nx = 1; } else { rx = -px; nx = -1; } } else { rx = (nx = 0); if (dy < 0) { ry = py; ny = 1; } else { ry = -py; ny = -1; } } if (0 < eH) { if (0 < eV) { if (eH == EID_SOLID) { if (eV == EID_SOLID) { this.ReportCollisionVsWorld(rx, ry, nx, ny, dTile); } else { var temp = ResolveBoxTile(rx, ry, this, dTile); if (temp == COL_NONE) { this.ReportCollisionVsWorld(pH, 0, signX, 0, dTile); } } } else if (eV == EID_SOLID) { var temp = ResolveBoxTile(rx, ry, this, dTile); if (temp == COL_NONE) { this.ReportCollisionVsWorld(0, pV, 0, signY, dTile); } } else { ResolveBoxTile(rx, ry, this, dTile); } } else if (eH == EID_SOLID) { this.ReportCollisionVsWorld(pH, 0, signX, 0, dTile); } else { ResolveBoxTile(rx, ry, this, dTile); } } else if (0 < eV) { if (eV == EID_SOLID) { this.ReportCollisionVsWorld(0, pV, 0, signY, dTile); } else { ResolveBoxTile(rx, ry, this, dTile); } } } } function ProjAABB_Full(x, y, obj, t) { var l = Math.sqrt((x * x) + (y * y)); obj.ReportCollisionVsWorld(x, y, x / l, y / l, t); return(COL_AXIS); } function ProjAABB_Half(x, y, obj, t) { var sx = t.signx; var sy = t.signy; var ox = ((obj.pos.x - (sx * obj.xw)) - t.pos.x); var oy = ((obj.pos.y - (sy * obj.yw)) - t.pos.y); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.signx, t.signy, t); return(COL_OTHER); } return(COL_NONE); } function ProjAABB_Concave(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var ox = ((t.pos.x + (signx * t.xw)) - (obj.pos.x - (signx * obj.xw))); var oy = ((t.pos.y + (signy * t.yw)) - (obj.pos.y - (signy * obj.yw))); var twid = (t.xw * 2); var rad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (len - rad); if (0 < pen) { var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < pen) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } return(COL_NONE); } function ProjAABB_Convex(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var ox = ((obj.pos.x - (signx * obj.xw)) - (t.pos.x - (signx * t.xw))); var oy = ((obj.pos.y - (signy * obj.yw)) - (t.pos.y - (signy * t.yw))); var len = Math.sqrt((ox * ox) + (oy * oy)); var twid = (t.xw * 2); var rad = Math.sqrt((twid * twid) + 0); var pen = (rad - len); if (((signx * ox) < 0) || ((signy * oy) < 0)) { var lenP = Math.sqrt((x * x) + (y * y)); obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } return(COL_NONE); } function ProjAABB_45Deg(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var ox = ((obj.pos.x - (signx * obj.xw)) - t.pos.x); var oy = ((obj.pos.y - (signy * obj.yw)) - t.pos.y); var sx = t.sx; var sy = t.sy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy); return(COL_OTHER); } return(COL_NONE); } function ProjAABB_22DegS(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var py = (obj.pos.y - (signy * obj.yw)); var penY = (t.pos.y - py); if (0 < (penY * signy)) { var ox = ((obj.pos.x - (signx * obj.xw)) - (t.pos.x + (signx * t.xw))); var oy = ((obj.pos.y - (signy * obj.yw)) - (t.pos.y - (signy * t.yw))); var sx = t.sx; var sy = t.sy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); var aY = Math.abs(penY); if (lenP < lenN) { if (aY < lenP) { obj.ReportCollisionVsWorld(0, penY, 0, penY / aY, t); return(COL_OTHER); } obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } if (aY < lenN) { obj.ReportCollisionVsWorld(0, penY, 0, penY / aY, t); return(COL_OTHER); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjAABB_22DegB(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var ox = ((obj.pos.x - (signx * obj.xw)) - (t.pos.x - (signx * t.xw))); var oy = ((obj.pos.y - (signy * obj.yw)) - (t.pos.y + (signy * t.yw))); var sx = t.sx; var sy = t.sy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } return(COL_NONE); } function ProjAABB_67DegS(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var px = (obj.pos.x - (signx * obj.xw)); var penX = (t.pos.x - px); if (0 < (penX * signx)) { var ox = ((obj.pos.x - (signx * obj.xw)) - (t.pos.x - (signx * t.xw))); var oy = ((obj.pos.y - (signy * obj.yw)) - (t.pos.y + (signy * t.yw))); var sx = t.sx; var sy = t.sy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); var aX = Math.abs(penX); if (lenP < lenN) { if (aX < lenP) { obj.ReportCollisionVsWorld(penX, 0, penX / aX, 0, t); return(COL_OTHER); } obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } if (aX < lenN) { obj.ReportCollisionVsWorld(penX, 0, penX / aX, 0, t); return(COL_OTHER); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjAABB_67DegB(x, y, obj, t) { var signx = t.signx; var signy = t.signy; var ox = ((obj.pos.x - (signx * obj.xw)) - (t.pos.x + (signx * t.xw))); var oy = ((obj.pos.y - (signy * obj.yw)) - (t.pos.y - (signy * t.yw))); var sx = t.sx; var sy = t.sy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } return(COL_NONE); } function ResolveBoxTile(x, y, box, t) { if (0 < t.ID) { return(Proj_AABBTile[t.CTYPE](x, y, box, t)); } return(false); } Proj_AABBTile = new Object(); Proj_AABBTile[CTYPE_FULL] = ProjAABB_Full; Proj_AABBTile[CTYPE_45DEG] = ProjAABB_45Deg; Proj_AABBTile[CTYPE_CONCAVE] = ProjAABB_Concave; Proj_AABBTile[CTYPE_CONVEX] = ProjAABB_Convex; Proj_AABBTile[CTYPE_22DEGs] = ProjAABB_22DegS; Proj_AABBTile[CTYPE_22DEGb] = ProjAABB_22DegB; Proj_AABBTile[CTYPE_67DEGs] = ProjAABB_67DegS; Proj_AABBTile[CTYPE_67DEGb] = ProjAABB_67DegB; Proj_AABBTile[CTYPE_HALF] = ProjAABB_Half; function CollideCirclevsTileMap() { var pos = this.pos; var rad = this.r; var c = tiles.GetTile_V(pos); var tx = c.pos.x; var ty = c.pos.y; var txw = c.xw; var tyw = c.yw; var dx = (pos.x - tx); var dy = (pos.y - ty); if (0 < c.ID) { var px = ((txw + rad) - Math.abs(dx)); var py = ((tyw + rad) - Math.abs(dy)); ResolveCircleTile(px, py, 0, 0, this, c); } var crossV = false; var hitV = false; var dy = (pos.y - ty); var py = ((Math.abs(dy) + rad) - tyw); if (0 < py) { crossV = true; var eV; var nV; var oV; if (dy < 0) { eV = c.eU; nV = c.nU; oV = 1; } else { eV = c.eD; nV = c.nD; oV = -1; } if (0 < eV) { if (eV == EID_SOLID) { hitV = COL_AXIS; this.ReportCollisionVsWorld(0, py * oV, 0, oV, nV); } else { hitV = ResolveCircleTile(0, py, 0, oV, this, nV); } } } var crossH = false; var hitH = false; var dx = (pos.x - tx); var px = ((Math.abs(dx) + rad) - txw); if (0 < px) { crossH = true; var eH; var nH; var oH; if (dx < 0) { eH = c.eL; nH = c.nL; oH = 1; } else { eH = c.eR; nH = c.nR; oH = -1; } if (0 < eH) { if (eH == EID_SOLID) { hitH = COL_AXIS; this.ReportCollisionVsWorld(px * oH, 0, oH, 0, nH); } else { hitH = ResolveCircleTile(px, 0, oH, 0, this, nH); } } } if (((crossH && (hitH != COL_AXIS)) && (crossV)) && (hitV != COL_AXIS)) { var dTile; var hit = false; if ((dx < 0) && (dy < 0)) { eH = c.nU.eL; eV = c.nL.eU; dTile = c.nU.nL; } else if ((dx < 0) && (0 < dy)) { eH = c.nD.eL; eV = c.nL.eD; dTile = c.nD.nL; } else if ((0 < dx) && (0 < dy)) { eH = c.nD.eR; eV = c.nR.eD; dTile = c.nD.nR; } else if ((0 < dx) && (dy < 0)) { eH = c.nU.eR; eV = c.nR.eU; dTile = c.nU.nR; } if (0 < (eH + eV)) { if ((eH == EID_SOLID) || (eV == EID_SOLID)) { var vx = (dTile.pos.x + (oH * dTile.xw)); var vy = (dTile.pos.y + (oV * dTile.yw)); var dx = (this.pos.x - vx); var dy = (this.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (this.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } this.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, dTile); } } else { dx = pos.x - dTile.pos.x; dy = pos.y - dTile.pos.y; px = (Math.abs(dx) + rad) - dTile.xw; py = (Math.abs(dy) + rad) - dTile.yw; ResolveCircleTile(px, py, oH, oV, this, dTile); } } } } function ProjCircle_Full(x, y, oH, oV, obj, t) { if (oH == 0) { if (oV == 0) { if (x < y) { var dx = (obj.pos.x - t.pos.x); if (dx < 0) { obj.ReportCollisionVsWorld(-x, 0, -1, 0, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(x, 0, 1, 0, t); return(COL_AXIS); } var dy = (obj.pos.y - t.pos.y); if (dy < 0) { obj.ReportCollisionVsWorld(0, -y, 0, -1, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(0, y, 0, 1, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } if (oV == 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } return(COL_NONE); } function ProjCircle_Half(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; var celldp = ((oH * signx) + (oV * signy)); if (0 < celldp) { return(COL_NONE); } if (oH == 0) { if (oV == 0) { var r = obj.r; var ox = ((obj.pos.x - (signx * r)) - t.pos.x); var oy = ((obj.pos.y - (signy * r)) - t.pos.y); var sx = signx; var sy = signy; var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); var lenP = Math.sqrt((x * x) + (y * y)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.signx, t.signy); return(COL_OTHER); } } else if (celldp == 0) { var r = obj.r; var dx = (obj.pos.x - t.pos.x); if ((dx * signx) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var dy = (obj.pos.y - (t.pos.y + (oV * t.yw))); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = signx / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } else { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } } else { if (oV == 0) { if (celldp == 0) { var r = obj.r; var dy = (obj.pos.y - t.pos.y); if ((dy * signy) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var dx = (obj.pos.x - (t.pos.x + (oH * t.xw))); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = signx / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } // unexpected jump } obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_45Deg(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (oH == 0) { if (oV == 0) { var sx = t.sx; var sy = t.sy; var ox = ((obj.pos.x - (sx * obj.r)) - t.pos.x); var oy = ((obj.pos.y - (sy * obj.r)) - t.pos.y); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } var lenN = Math.sqrt((sx * sx) + (sy * sy)); if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } else { if ((signy * oV) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var sx = t.sx; var sy = t.sy; var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y + (oV * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (0 < ((perp * signx) * signy)) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t); return(COL_OTHER); } } } } else if (oV == 0) { if ((signx * oH) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var sx = t.sx; var sy = t.sy; var ox = (obj.pos.x - (t.pos.x + (oH * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (((perp * signx) * signy) < 0) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t); return(COL_OTHER); } } } else { if (0 < ((signx * oH) + (signy * oV))) { return(COL_NONE); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_Concave(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (oH == 0) { if (oV == 0) { var ox = ((t.pos.x + (signx * t.xw)) - obj.pos.x); var oy = ((t.pos.y + (signy * t.yw)) - obj.pos.y); var twid = (t.xw * 2); var trad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = ((len + obj.r) - trad); if (0 < pen) { if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < pen) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } return(COL_NONE); } if ((signy * oV) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var vx = (t.pos.x - (signx * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = 0; dy = oV; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } else if (oV == 0) { if ((signx * oH) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y - (signy * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH; dy = 0; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } else { if (0 < ((signx * oH) + (signy * oV))) { return(COL_NONE); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_Convex(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (oH == 0) { if (oV == 0) { var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var twid = (t.xw * 2); var trad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = ((trad + obj.r) - len); if (0 < pen) { if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < pen) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { if ((signy * oV) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var twid = (t.xw * 2); var trad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = ((trad + obj.r) - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } } else if (oV == 0) { if ((signx * oH) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var twid = (t.xw * 2); var trad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = ((trad + obj.r) - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else if (0 < ((signx * oH) + (signy * oV))) { var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var twid = (t.xw * 2); var trad = Math.sqrt((twid * twid) + 0); var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = ((trad + obj.r) - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_22DegS(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (0 < (signy * oV)) { return(COL_NONE); } if (oH == 0) { if (oV == 0) { var sx = t.sx; var sy = t.sy; var r = obj.r; var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - t.pos.y); var perp = ((ox * (-sy)) + (oy * sx)); if (0 < ((perp * signx) * signy)) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { ox = ox - (r * sx); oy = oy - (r * sy); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } // unexpected jump } obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } if (oV == 0) { if ((signx * oH) < 0) { var vx = (t.pos.x - (signx * t.xw)); var vy = t.pos.y; var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); if ((dy * signy) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } else { var sx = t.sx; var sy = t.sy; var ox = (obj.pos.x - (t.pos.x + (oH * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (((perp * signx) * signy) < 0) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t); return(COL_OTHER); } } } } else { var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_22DegB(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (oH == 0) { if (oV == 0) { var sx = t.sx; var sy = t.sy; var r = obj.r; var ox = ((obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw))); var oy = ((obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw))); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } else { if ((signy * oV) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var sx = t.sx; var sy = t.sy; var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y + (signy * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (0 < ((perp * signx) * signy)) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t); return(COL_OTHER); } } } } else if (oV == 0) { if ((signx * oH) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var ox = (obj.pos.x - (t.pos.x + (signx * t.xw))); var oy = (obj.pos.y - t.pos.y); if ((oy * signy) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var sx = t.sx; var sy = t.sy; var perp = ((ox * (-sy)) + (oy * sx)); if (((perp * signx) * signy) < 0) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t); return(COL_OTHER); } } } else { if (0 < ((signx * oH) + (signy * oV))) { var slen = 2.23606797749979; var sx = ((signx * 1) / slen); var sy = ((signy * 2) / slen); var r = obj.r; var ox = ((obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw))); var oy = ((obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw))); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { obj.ReportCollisionVsWorld((-sx) * dp, (-sy) * dp, t.sx, t.sy, t); return(COL_OTHER); } return(COL_NONE); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_67DegS(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (0 < (signx * oH)) { return(COL_NONE); } if (oH == 0) { if (oV == 0) { var sx = t.sx; var sy = t.sy; var r = obj.r; var ox = (obj.pos.x - t.pos.x); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (((perp * signx) * signy) < 0) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { ox = ox - (r * sx); oy = oy - (r * sy); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } } else if ((signy * oV) < 0) { var vx = t.pos.x; var vy = (t.pos.y - (signy * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); if ((dx * signx) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } else { var sx = t.sx; var sy = t.sy; var ox = (obj.pos.x - (t.pos.x - (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y + (oV * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (0 < ((perp * signx) * signy)) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t); return(COL_OTHER); } } } } else { if (oV == 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ProjCircle_67DegB(x, y, oH, oV, obj, t) { var signx = t.signx; var signy = t.signy; if (oH == 0) { if (oV == 0) { var sx = t.sx; var sy = t.sy; var r = obj.r; var ox = ((obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw))); var oy = ((obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw))); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { sx = sx * (-dp); sy = sy * (-dp); var lenN = Math.sqrt((sx * sx) + (sy * sy)); if (x < y) { lenP = x; y = 0; if ((obj.pos.x - t.pos.x) < 0) { x = x * -1; } } else { lenP = y; x = 0; if ((obj.pos.y - t.pos.y) < 0) { y = y * -1; } } if (lenP < lenN) { obj.ReportCollisionVsWorld(x, y, x / lenP, y / lenP, t); return(COL_AXIS); } obj.ReportCollisionVsWorld(sx, sy, t.sx, t.sy, t); return(COL_OTHER); } } else { if ((signy * oV) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var ox = (obj.pos.x - t.pos.x); var oy = (obj.pos.y - (t.pos.y + (signy * t.yw))); if ((ox * signx) < 0) { obj.ReportCollisionVsWorld(0, y * oV, 0, oV, t); return(COL_AXIS); } var sx = t.sx; var sy = t.sy; var perp = ((ox * (-sy)) + (oy * sx)); if (0 < ((perp * signx) * signy)) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t); return(COL_OTHER); } } } } else if (oV == 0) { if ((signx * oH) < 0) { obj.ReportCollisionVsWorld(x * oH, 0, oH, 0, t); return(COL_AXIS); } var slen = 2.23606797749979; var sx = ((signx * 2) / slen); var sy = ((signy * 1) / slen); var ox = (obj.pos.x - (t.pos.x + (signx * t.xw))); var oy = (obj.pos.y - (t.pos.y - (signy * t.yw))); var perp = ((ox * (-sy)) + (oy * sx)); if (((perp * signx) * signy) < 0) { var len = Math.sqrt((ox * ox) + (oy * oy)); var pen = (obj.r - len); if (0 < pen) { ox = ox / len; oy = oy / len; obj.ReportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t); return(COL_OTHER); } } else { var dp = ((ox * sx) + (oy * sy)); var pen = (obj.r - Math.abs(dp)); if (0 < pen) { obj.ReportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t); return(COL_OTHER); } } } else { if (0 < ((signx * oH) + (signy * oV))) { var sx = t.sx; var sy = t.sy; var r = obj.r; var ox = ((obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw))); var oy = ((obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw))); var dp = ((ox * sx) + (oy * sy)); if (dp < 0) { obj.ReportCollisionVsWorld((-sx) * dp, (-sy) * dp, t.sx, t.sy, t); return(COL_OTHER); } return(COL_NONE); } var vx = (t.pos.x + (oH * t.xw)); var vy = (t.pos.y + (oV * t.yw)); var dx = (obj.pos.x - vx); var dy = (obj.pos.y - vy); var len = Math.sqrt((dx * dx) + (dy * dy)); var pen = (obj.r - len); if (0 < pen) { if (len == 0) { dx = oH / Math.SQRT2; dy = oV / Math.SQRT2; } else { dx = dx / len; dy = dy / len; } obj.ReportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t); return(COL_OTHER); } } return(COL_NONE); } function ResolveCircleTile(x, y, oH, oV, obj, t) { if (0 < t.ID) { return(Proj_CircleTile[t.CTYPE](x, y, oH, oV, obj, t)); } return(false); } Proj_CircleTile = new Object(); Proj_CircleTile[CTYPE_FULL] = ProjCircle_Full; Proj_CircleTile[CTYPE_45DEG] = ProjCircle_45Deg; Proj_CircleTile[CTYPE_CONCAVE] = ProjCircle_Concave; Proj_CircleTile[CTYPE_CONVEX] = ProjCircle_Convex; Proj_CircleTile[CTYPE_22DEGs] = ProjCircle_22DegS; Proj_CircleTile[CTYPE_22DEGb] = ProjCircle_22DegB; Proj_CircleTile[CTYPE_67DEGs] = ProjCircle_67DegS; Proj_CircleTile[CTYPE_67DEGb] = ProjCircle_67DegB; Proj_CircleTile[CTYPE_HALF] = ProjCircle_Half; function QueryRayObj(out, p0, p1, obj) { var c = tiles.GetTile_V(p0); var i0 = c.i; var j0 = c.j; var dx = (p1.x - p0.x); var dy = (p1.y - p0.y); var len = Math.sqrt((dx * dx) + (dy * dy)); if (len != 0) { dx = dx / len; dy = dy / len; } else { return(false); } var X = i0; var Y = j0; if (dx < 0) { var stepX = -1; var tMaxX = (((c.pos.x - c.xw) - p0.x) / dx); var tDeltaX = ((2 * c.xw) / (-dx)); } else if (0 < dx) { var stepX = 1; var tMaxX = (((c.pos.x + c.xw) - p0.x) / dx); var tDeltaX = ((2 * c.xw) / dx); } else { var stepX = 0; var tMaxX = 100000000; var tDeltaX = 0; } if (dy < 0) { var stepY = -1; var tMaxY = (((c.pos.y - c.yw) - p0.y) / dy); var tDeltaY = ((2 * c.yw) / (-dy)); } else if (0 < dy) { var stepY = 1; var tMaxY = (((c.pos.y + c.yw) - p0.y) / dy); var tDeltaY = ((2 * c.yw) / dy); } else { var stepY = 0; var tMaxY = 100000000; var tDeltaY = 0; } var px = p0.x; var py = p0.y; if (TestRayTile(out, px, py, dx, dy, c)) { var tx = out.x; var ty = out.y; if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { var dpO = (((p0.x - out.x) * dx) + ((p0.y - out.y) * dy)); var dpT = (((p0.x - tx) * dx) + ((p0.y - ty) * dy)); if (dpO < dpT) { out.x = tx; out.y = ty; return(false); } return(true); } out.x = tx; out.y = ty; return(false); } var e; var n; while (c != null) { if (tMaxX < tMaxY) { if (stepX < 0) { e = c.eL; n = c.nL; } else { e = c.eR; n = c.nR; } if (0 < e) { px = p0.x + (tMaxX * dx); py = p0.y + (tMaxX * dy); if (e == EID_SOLID) { var tx = px; var ty = py; if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { var dpO = (((p0.x - out.x) * dx) + ((p0.y - out.y) * dy)); var dpT = (((p0.x - tx) * dx) + ((p0.y - ty) * dy)); if (dpO < dpT) { out.x = tx; out.y = ty; return(false); } return(true); } out.x = tx; out.y = ty; return(false); } if (TestRayTile(out, px, py, dx, dy, n)) { var tx = out.x; var ty = out.y; if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { var dpO = (((p0.x - out.x) * dx) + ((p0.y - out.y) * dy)); var dpT = (((p0.x - tx) * dx) + ((p0.y - ty) * dy)); if (dpO < dpT) { out.x = tx; out.y = ty; return(false); } return(true); } out.x = tx; out.y = ty; return(false); } } tMaxX = tMaxX + tDeltaX; X = X + stepX; } else { if (stepY < 0) { e = c.eU; n = c.nU; } else { e = c.eD; n = c.nD; } if (0 < e) { px = p0.x + (tMaxY * dx); py = p0.y + (tMaxY * dy); if (e == EID_SOLID) { var tx = px; var ty = py; if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { var dpO = (((p0.x - out.x) * dx) + ((p0.y - out.y) * dy)); var dpT = (((p0.x - tx) * dx) + ((p0.y - ty) * dy)); if (dpO < dpT) { out.x = tx; out.y = ty; return(false); } return(true); } out.x = tx; out.y = ty; return(false); } if (TestRayTile(out, px, py, dx, dy, n)) { var tx = out.x; var ty = out.y; if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { var dpO = (((p0.x - out.x) * dx) + ((p0.y - out.y) * dy)); var dpT = (((p0.x - tx) * dx) + ((p0.y - ty) * dy)); if (dpO < dpT) { out.x = tx; out.y = ty; return(false); } return(true); } out.x = tx; out.y = ty; return(false); } } tMaxY = tMaxY + tDeltaY; Y = Y + stepY; } c = n; } if (TestRayObj(out, p0.x, p0.y, dx, dy, obj)) { return(true); } return(false); } function CollideRayvsTiles(out, p0, p1) { var c = tiles.GetTile_V(p0); var i0 = c.i; var j0 = c.j; var dx = (p1.x - p0.x); var dy = (p1.y - p0.y); var len = Math.sqrt((dx * dx) + (dy * dy)); if (len != 0) { dx = dx / len; dy = dy / len; } else { return(false); } var X = i0; var Y = j0; if (dx < 0) { var stepX = -1; var tMaxX = (((c.pos.x - c.xw) - p0.x) / dx); var tDeltaX = ((2 * c.xw) / (-dx)); } else if (0 < dx) { var stepX = 1; var tMaxX = (((c.pos.x + c.xw) - p0.x) / dx); var tDeltaX = ((2 * c.xw) / dx); } else { var stepX = 0; var tMaxX = 100000000; var tDeltaX = 0; } if (dy < 0) { var stepY = -1; var tMaxY = (((c.pos.y - c.yw) - p0.y) / dy); var tDeltaY = ((2 * c.yw) / (-dy)); } else if (0 < dy) { var stepY = 1; var tMaxY = (((c.pos.y + c.yw) - p0.y) / dy); var tDeltaY = ((2 * c.yw) / dy); } else { var stepY = 0; var tMaxY = 100000000; var tDeltaY = 0; } var px = p0.x; var py = p0.y; if (TestRayTile(out, px, py, dx, dy, c)) { return(true); } var e; var n; while (c != null) { if (tMaxX < tMaxY) { if (stepX < 0) { e = c.eL; n = c.nL; } else { e = c.eR; n = c.nR; } if (0 < e) { px = p0.x + (tMaxX * dx); py = p0.y + (tMaxX * dy); if (e == EID_SOLID) { out.x = px; out.y = py; return(true); } if (TestRayTile(out, px, py, dx, dy, n)) { return(true); } } tMaxX = tMaxX + tDeltaX; X = X + stepX; } else { if (stepY < 0) { e = c.eU; n = c.nU; } else { e = c.eD; n = c.nD; } if (0 < e) { px = p0.x + (tMaxY * dx); py = p0.y + (tMaxY * dy); if (e == EID_SOLID) { out.x = px; out.y = py; return(true); } if (TestRayTile(out, px, py, dx, dy, n)) { return(true); } } tMaxY = tMaxY + tDeltaY; Y = Y + stepY; } c = n; } return(false); } function TestRay_Circle(out, px, py, dx, dy, obj) { var abx = (px - obj.pos.x); var aby = (py - obj.pos.y); var a = ((dx * dx) + (dy * dy)); var b = (2 * ((dx * abx) + (dy * aby))); var rad = obj.r; var c = (((abx * abx) + (aby * aby)) - (rad * rad)); var q = ((b * b) - ((4 * a) * c)); if (0 <= q) { var sq = Math.sqrt(q); var d = (1 / (2 * a)); var u0 = (((-b) + sq) * d); var u1 = (((-b) - sq) * d); var u; if (u1 < 0) { if (u0 < 0) { return(false); } u = u0; } else if (u0 < 0) { u = u1; } else if (u1 < u0) { u = u1; } else { u = u0; } out.x = px + (u * dx); out.y = py + (u * dy); return(true); } return(false); } function TestRay_AABB(out, px, py, dx, dy, obj) { var bx = obj.pos.x; var by = obj.pos.y; var xw = obj.xw; var yw = obj.yw; var xval; var yval; if (px < bx) { xval = bx - xw; } else { xval = bx + xw; } if (py < by) { yval = by - yw; } else { yval = by + yw; } var t; var x0; var y0; var x1; var y1; if (dx == 0) { if (dy == 0) { return(false); } x0 = bx - xw; x1 = bx + xw; y0 = (y1 = yval); t = (yval - py) / dy; } else if (dy == 0) { y0 = by - yw; y1 = by + yw; x0 = (x1 = xval); t = (xval - px) / dx; } else { var tX = ((xval - px) / dx); var tY = ((yval - py) / dy); if (tX < tY) { x0 = bx - xw; x1 = bx + xw; y0 = (y1 = yval); t = tY; } else { y0 = by - yw; y1 = by + yw; x0 = (x1 = xval); t = tX; } } if (0 < t) { var qx = (px + (100 * dx)); var qy = (py + (100 * dy)); var areaPQ0 = (((qx - px) * (y0 - py)) - ((x0 - px) * (qy - py))); var areaPQ1 = (((qx - px) * (y1 - py)) - ((x1 - px) * (qy - py))); if ((areaPQ0 * areaPQ1) < 0) { out.x = px + (t * dx); out.y = py + (t * dy); return(true); } return(false); } return(false); } function TestRay_Full(out, px, py, dx, dy, t) { return(false); } function TestRay_45Deg(out, px, py, dx, dy, t) { var sx = t.signx; var sy = t.signy; if (0 <= ((sx * dx) + (sy * dy))) { return(false); } var ux = (sx * t.xw); var uy = ((-sy) * t.yw); var wx = (t.pos.x - px); var wy = (t.pos.y - py); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = t.pos.x + (s * ux); out.y = t.pos.y + (s * uy); return(true); } return(false); } function TestRay_Concave(out, px, py, dx, dy, t) { var sx = t.signx; var sy = t.signy; if (0 <= ((sx * dx) + (sy * dy))) { return(false); } var ux = (sx * t.xw); var uy = ((-sy) * t.yw); var wx = (t.pos.x - px); var wy = (t.pos.y - py); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { var abx = ((-ux) - wx); var aby = (uy - wy); var a = ((dx * dx) + (dy * dy)); var b = (2 * ((dx * abx) + (dy * aby))); var rad = (t.xw * 2); var c = (((abx * abx) + (aby * aby)) - (rad * rad)); var q = ((b * b) - ((4 * a) * c)); if (0 <= q) { var sq = Math.sqrt(q); var d = (1 / (2 * a)); var u0 = (((-b) + sq) * d); var u1 = (((-b) - sq) * d); if (u1 < u0) { out.x = px + (u0 * dx); out.y = py + (u0 * dy); } else { out.x = px + (u1 * dx); out.y = py + (u1 * dy); } return(true); } return(false); } return(false); } function TestRay_Convex(out, px, py, dx, dy, t) { var sx = t.signx; var sy = t.signy; var abx = (px - (t.pos.x - (sx * t.xw))); var aby = (py - (t.pos.y - (sy * t.yw))); var a = ((dx * dx) + (dy * dy)); var b = (2 * ((dx * abx) + (dy * aby))); var rad = (t.xw * 2); var c = (((abx * abx) + (aby * aby)) - (rad * rad)); var q = ((b * b) - ((4 * a) * c)); if (0 <= q) { var sq = Math.sqrt(q); var d = (1 / (2 * a)); var u0 = (((-b) + sq) * d); var u1 = (((-b) - sq) * d); if (u1 < u0) { out.x = px + (u1 * dx); out.y = py + (u1 * dy); } else { out.x = px + (u0 * dx); out.y = py + (u0 * dy); } return(true); } return(false); } function TestRay_Half(out, px, py, dx, dy, t) { var sx = t.signx; var sy = t.signy; var wx = (t.pos.x - px); var wy = (t.pos.y - py); if (0 <= ((wx * sx) + (wy * sy))) { out.x = px; out.y = py; return(true); } if (0 <= ((sx * dx) + (sy * dy))) { return(false); } var ux = (sy * t.xw); var uy = (sx * t.yw); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = t.pos.x + (s * ux); out.y = t.pos.y + (s * uy); return(true); } return(false); } function TestRay_22DegS(out, px, py, dx, dy, t) { var sx = t.sx; var sy = t.sy; var signx = t.signx; var signy = t.signy; var wx = ((t.pos.x - (signx * t.xw)) - px); var wy = (t.pos.y - py); if ((0 <= (wx * signx)) && (0 <= (wy * signy))) { out.x = px; out.y = py; return(true); } if (0 <= ((sx * dx) + (sy * dy))) { return(false); } wx = wx + (signx * t.xw); var vy = ((signy * 0.5) * t.yw); wy = wy - vy; var ux = ((-signy) * t.xw); var uy = ((0.5 * signx) * t.yw); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = t.pos.x + (s * ux); out.y = (t.pos.y - vy) + (s * uy); return(true); } return(false); } function TestRay_22DegB(out, px, py, dx, dy, t) { var sx = t.sx; var sy = t.sy; var signx = t.signx; var signy = t.signy; var wx = (t.pos.x - px); var wy = (t.pos.y - py); if (((wx * signx) <= 0) && (0 <= (wy * signy))) { out.x = px; out.y = py; return(true); } if (0 <= ((sx * dx) + (sy * dy))) { return(false); } var vy = ((signy * 0.5) * t.yw); wy = wy + vy; var ux = ((-signy) * t.xw); var uy = ((0.5 * signx) * t.yw); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = t.pos.x + (s * ux); out.y = (t.pos.y + vy) + (s * uy); return(true); } return(false); } function TestRay_67DegS(out, px, py, dx, dy, t) { var sx = t.sx; var sy = t.sy; var signx = t.signx; var signy = t.signy; var wx = (t.pos.x - px); var wy = ((t.pos.y - (signy * t.yw)) - py); if ((0 <= (wx * signx)) && (0 <= (wy * signy))) { out.x = px; out.y = py; return(true); } if (0 <= ((sx * dx) + (sy * dy))) { return(false); } wy = wy + (signy * t.yw); var vx = ((signx * 0.5) * t.xw); wx = wx - vx; var ux = ((-0.5 * signy) * t.xw); var uy = (signx * t.yw); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = (t.pos.x - vx) + (s * ux); out.y = t.pos.y + (s * uy); return(true); } return(false); } function TestRay_67DegB(out, px, py, dx, dy, t) { var sx = t.sx; var sy = t.sy; var signx = t.signx; var signy = t.signy; var wx = (t.pos.x - px); var wy = (t.pos.y - py); if (((wy * signy) <= 0) && (0 <= (wx * signx))) { out.x = px; out.y = py; return(true); } if (0 <= ((sx * dx) + (sy * dy))) { return(false); } var vx = ((signx * 0.5) * t.xw); wx = wx + vx; var ux = ((-0.5 * signy) * t.xw); var uy = (signx * t.yw); var s = (((dy * wx) - (dx * wy)) / ((dx * uy) - (dy * ux))); if (Math.abs(s) <= 1) { out.x = (t.pos.x + vx) + (s * ux); out.y = t.pos.y + (s * uy); return(true); } return(false); } function TestRayTile(out, px, py, dx, dy, t) { if (0 < t.ID) { return(TestRay_Tile[t.CTYPE](out, px, py, dx, dy, t)); } return(false); } TestRay_Tile = new Object(); TestRay_Tile[CTYPE_FULL] = TestRay_Full; TestRay_Tile[CTYPE_45DEG] = TestRay_45Deg; TestRay_Tile[CTYPE_CONCAVE] = TestRay_Concave; TestRay_Tile[CTYPE_CONVEX] = TestRay_Convex; TestRay_Tile[CTYPE_22DEGs] = TestRay_22DegS; TestRay_Tile[CTYPE_22DEGb] = TestRay_22DegB; TestRay_Tile[CTYPE_67DEGs] = TestRay_67DegS; TestRay_Tile[CTYPE_67DEGb] = TestRay_67DegB; TestRay_Tile[CTYPE_HALF] = TestRay_Half; function TestRayObj(out, px, py, dx, dy, obj) { if (obj.OTYPE == OTYPE_AABB) { return(TestRay_AABB(out, px, py, dx, dy, obj)); } return(TestRay_Circle(out, px, py, dx, dy, obj)); } function ReportCollisionVsWorld(px, py, dx, dy, obj) { var p = this.pos; var o = this.oldpos; var vx = (p.x - o.x); var vy = (p.y - o.y); var dp = ((vx * dx) + (vy * dy)); var nx = (dp * dx); var ny = (dp * dy); var tx = (vx - nx); var ty = (vy - ny); var b; var bx; var by; var f; var fx; var fy; if (dp < 0) { f = FRICTION; fx = tx * f; fy = ty * f; b = 1 + BOUNCE; bx = nx * b; by = ny * b; } else { bx = (by = (fx = (fy = 0))); } p.x = p.x + px; p.y = p.y + py; o.x = o.x + ((px + bx) + fx); o.y = o.y + ((py + by) + fy); } function IntegrateVerlet() { var d = DRAG; var g = GRAV; p = this.pos; o = this.oldpos; ox = o.x; oy = o.y; o.x = (px = p.x); o.y = (py = p.y); p.x = p.x + ((d * px) - (d * ox)); p.y = p.y + (((d * py) - (d * oy)) + g); } function CollideCircleVsWorldBounds() { var p = this.pos; var r = this.r; var dx = (XMIN - (p.x - r)); if (0 < dx) { this.ReportCollisionVsWorld(dx, 0, 1, 0, null); } else { dx = (p.x + r) - XMAX; if (0 < dx) { this.ReportCollisionVsWorld(-dx, 0, -1, 0, null); } } var dy = (YMIN - (p.y - r)); if (0 < dy) { this.ReportCollisionVsWorld(0, dy, 0, 1, null); } else { dy = (p.y + r) - YMAX; if (0 < dy) { this.ReportCollisionVsWorld(0, -dy, 0, -1, null); } } } function CollideAABBVsWorldBounds() { var p = this.pos; var xw = this.xw; var yw = this.yw; var dx = (XMIN - (p.x - xw)); if (0 < dx) { this.ReportCollisionVsWorld(dx, 0, 1, 0, null); } else { dx = (p.x + xw) - XMAX; if (0 < dx) { this.ReportCollisionVsWorld(-dx, 0, -1, 0, null); } } var dy = (YMIN - (p.y - yw)); if (0 < dy) { this.ReportCollisionVsWorld(0, dy, 0, 1, null); } else { dy = (p.y + yw) - YMAX; if (0 < dy) { this.ReportCollisionVsWorld(0, -dy, 0, -1, null); } } } function AABB(pos, xw, yw) { this.OTYPE = OTYPE_AABB; this.pos = pos.clone(); this.oldpos = this.pos.clone(); this.xw = Math.abs(xw); this.yw = Math.abs(yw); } function Circle(pos, r) { this.OTYPE = OTYPE_CIRCLE; this.pos = pos.clone(); this.oldpos = this.pos.clone(); this.r = Math.abs(r); } OTYPE_AABB = 0; OTYPE_CIRCLE = 1; AABB.prototype.Draw = function (rend) { rend.DrawAABB(this.pos, this.xw, this.yw); }; AABB.prototype.Verlet = IntegrateVerlet; AABB.prototype.ReportCollisionVsWorld = ReportCollisionVsWorld; AABB.prototype.CollideVsTileMap = CollideAABBvsTileMap; Circle.prototype.Draw = function (rend) { rend.DrawCircle(this.pos, this.r); }; Circle.prototype.Verlet = IntegrateVerlet; Circle.prototype.ReportCollisionVsWorld = ReportCollisionVsWorld; Circle.prototype.CollideVsTileMap = CollideCirclevsTileMap; function TickInit() { if (!tiles.Building()) { _root.onEnterFrame = TickLoad; loader.Load(MAPSTR); } } function TickLoad() { var i = 18; while (i--) { if (!loader.Loading()) { _root.onEnterFrame = TickDemo; } } } function TickDemo() { input.Update(); debug_rend.Clear(); ray_rend.Clear(); var m = input.getMousePos(); var d = input.getMouseDelta(); if (input.MouseDown() && (m.y < 400)) { if (input.MousePressed()) { RAY_O.x = m.x; RAY_O.y = m.y; } else { var result = new Vector2(0, 0); var dx = (m.x - RAY_O.x); var dy = (m.y - RAY_O.y); var len = Math.sqrt((dx * dx) + (dy * dy)); if (len != 0) { if (QueryRayObj(result, RAY_O, m, demoObj)) { dx = dx / len; dy = dy / len; var rayshove = 1; demoObj.pos.x = demoObj.pos.x + (dx * rayshove); demoObj.pos.y = demoObj.pos.y + (dy * rayshove); } ray_rend.SetStyle(0, 8921736, 100); ray_rend.DrawLine(RAY_O, result); ray_rend.DrawPlus(RAY_O); ray_rend.SetStyle(2, 8921736, 100); ray_rend.DrawCross(result); } } } demoObj.Verlet(); if (Key.isDown(32)) { if (m.y < YMAX) { var dragScale = 0.1; demoObj.pos.x = demoObj.pos.x + (d.x * dragScale); demoObj.pos.y = demoObj.pos.y + (d.y * dragScale); } } else { var fx = 0; var fy = 0; if (Key.isDown(37)) { fx = fx - OBJSPEED; } if (Key.isDown(39)) { fx = fx + OBJSPEED; } if (Key.isDown(38)) { fy = fy - (OBJSPEED + GRAV); } if (Key.isDown(40)) { fy = fy + OBJSPEED; } var p = demoObj.pos; var o = demoObj.oldpos; var vx = (p.x - o.x); var vy = (p.y - o.y); var newx = Math.min(MAXSPEED, Math.max(-MAXSPEED, vx + fx)); var newy = Math.min(MAXSPEED, Math.max(-MAXSPEED, vy + fy)); p.x = o.x + newx; p.y = o.y + newy; } demoObj.CollideVsTileMap(); debug_rend.SetStyle(0, 7960968, 100); debug_rend.buffer.beginFill(13290192, 100); demoObj.Draw(debug_rend); debug_rend.buffer.endFill(); } RAY_O = new Vector2(0, 0); function MapLoader() { this.Init(); } MapLoader.prototype.Init = function () { this.CUR_CHAR = 0; this.NUM_ROWS = tiles.cols; this.NUM_COLS = tiles.rows; this.CUR_COL = 0; this.CUR_ROW = 0; this.mapStr = ""; }; MapLoader.prototype.Load = function (str) { this.Init(); this.mapStr = str; }; MapLoader.prototype.Loading = function () { if (this.NUM_ROWS <= this.CUR_ROW) { this.CUR_COL++; this.CUR_ROW = 0; } if (this.NUM_COLS <= this.CUR_COL) { return(false); } tiles.SetTileState(this.CUR_COL, this.CUR_ROW, this.mapStr.charCodeAt(this.CUR_CHAR)); this.CUR_CHAR++; this.CUR_ROW++; return(true); }; function GDragged() { _root.pointG.pos.x = this._x; _root.pointG.pos.y = this._y; GRefresh(pointG.pos); } function GRefresh(pos) { var temp = ((pos.x - slider_min) / (slider_max - slider_min)); GRAV = temp * MAX_G; } function BDragged() { _root.pointB.pos.x = this._x; _root.pointB.pos.y = this._y; BRefresh(pointB.pos); } function BRefresh(pos) { var temp = ((pos.x - slider_min) / (slider_max - slider_min)); BOUNCE = temp * MAX_B; } function FDragged() { _root.pointF.pos.x = this._x; _root.pointF.pos.y = this._y; FRefresh(pointF.pos); } function FRefresh(pos) { var temp = ((pos.x - slider_min) / (slider_max - slider_min)); temp = temp * temp; temp = temp * temp; temp = temp * temp; FRICTION = temp * MAX_F; } function ToggleObjShape() { var p = demoObj.pos; var o = demoObj.oldpos; if (demoObj.OTYPE == OTYPE_CIRCLE) { demoObj = new AABB(new Vector2(p.x, p.y), OBJRAD * 0.7, OBJRAD); } else { demoObj = new Circle(new Vector2(p.x, p.y), OBJRAD); } demoObj.oldpos.x = o.x; demoObj.oldpos.y = o.y; } gfx = new NinjaGraphicsSystem(); debug_rend = new VectorRenderer(); input = new InputManager(); static_rend = new VectorRenderer(); ray_rend = new VectorRenderer(); GRAV = 0.2; DRAG = 0.999999; BOUNCE = 0.3; FRICTION = 0.05; MIN_F = 0; MAX_F = 1; MIN_B = 0; MAX_B = 0.99; MIN_G = 0; MAX_G = 1; XMIN = 0; XMAX = 400; YMIN = 0; YMAX = 400; TILERAD = 20; OBJRAD = 16; OBJSPEED = 0.2; MAXSPEED = 20; MAPSTR = "A6E00002000?E000000NA0070C0N00;10B0N00:10>0>L0060000F000@0GH0003"; tiles = new TileMap(8, 8, TILERAD, TILERAD); loader = new MapLoader(); demoObj = new Circle(new Vector2(75, 90), OBJRAD); _root.onEnterFrame = TickInit; _root.attachMovie("guiTxt", "guiTxt", 9999); slider_min = 200; slider_max = 350; pointG = new Point((GRAV * 150) + 200, 420, "gravity", 2263074, true, GDragged, slider_min, 420, slider_max, 420); pointB = new Point((BOUNCE * 150) + 200, 440, "bounce", 2237064, true, BDragged, slider_min, 440, slider_max, 440); pointF = new Point(290, 460, "friction", 8921634, true, FDragged, slider_min, 460, slider_max, 460); BRefresh(pointB.pos); GRefresh(pointG.pos); FRefresh(pointF.pos); static_rend.SetStyle(0, 2263074, 100); static_rend.DrawLine_S(slider_min, 420, slider_max, 420); static_rend.SetStyle(0, 2237064, 100); static_rend.DrawLine_S(slider_min, 440, slider_max, 440); static_rend.SetStyle(0, 8921634, 100); static_rend.DrawLine_S(slider_min, 460, slider_max, 460);
Instance of Symbol 42 MovieClip in Frame 1
on (rollOver) { this.gotoAndStop(2); } on (rollOut) { this.gotoAndStop(1); } on (release) { _root.ToggleObjShape(); }
Symbol 42 MovieClip Frame 1
this.stop();
Symbol 42 MovieClip Frame 2
this.stop();

Library Items

Symbol 1 FontUsed by:2 38 43
Symbol 2 EditableTextUses:1Used by:3
Symbol 3 MovieClip [titleMC]Uses:2
Symbol 4 GraphicUsed by:5
Symbol 5 MovieClipUses:4Used by:6
Symbol 6 MovieClip [pointMC]Uses:5
Symbol 7 GraphicUsed by:37
Symbol 8 GraphicUsed by:37
Symbol 9 GraphicUsed by:37
Symbol 10 GraphicUsed by:37
Symbol 11 GraphicUsed by:37
Symbol 12 GraphicUsed by:37
Symbol 13 GraphicUsed by:37
Symbol 14 GraphicUsed by:37
Symbol 15 GraphicUsed by:37
Symbol 16 GraphicUsed by:37
Symbol 17 GraphicUsed by:37
Symbol 18 GraphicUsed by:37
Symbol 19 GraphicUsed by:37
Symbol 20 GraphicUsed by:37
Symbol 21 GraphicUsed by:37
Symbol 22 GraphicUsed by:37
Symbol 23 GraphicUsed by:37
Symbol 24 GraphicUsed by:37
Symbol 25 GraphicUsed by:37
Symbol 26 GraphicUsed by:37
Symbol 27 GraphicUsed by:37
Symbol 28 GraphicUsed by:37
Symbol 29 GraphicUsed by:37
Symbol 30 GraphicUsed by:37
Symbol 31 GraphicUsed by:37
Symbol 32 GraphicUsed by:37
Symbol 33 GraphicUsed by:37
Symbol 34 GraphicUsed by:37
Symbol 35 GraphicUsed by:37
Symbol 36 GraphicUsed by:37
Symbol 37 MovieClip [tileMC]Uses: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
Symbol 38 TextUses:1Used by:39
Symbol 39 MovieClip [guiTxt]Uses:38
Symbol 40 GraphicUsed by:42
Symbol 41 GraphicUsed by:42
Symbol 42 MovieClipUses:40 41Used by:Timeline
Symbol 43 TextUses:1Used by:Timeline

Instance Names

"gfx"Symbol 6 MovieClip [pointMC] Frame 1Symbol 5 MovieClip

Special Tags

ExportAssets (56)Timeline Frame 1Symbol 3 as "titleMC"
ExportAssets (56)Timeline Frame 1Symbol 6 as "pointMC"
ExportAssets (56)Timeline Frame 1Symbol 37 as "tileMC"
ExportAssets (56)Timeline Frame 1Symbol 39 as "guiTxt"

Dynamic Text Variables

txtSymbol 2 EditableText"p0"




http://swfchan.com/9/41740/info.shtml
Created: 10/5 -2019 05:52:22 Last modified: 10/5 -2019 05:52:22 Server time: 30/12 -2024 16:25:11