STORY LOOP FURRY PORN GAMES C SERVICES [?] [R] RND POPULAR | Archived flashes: 229593 |
/disc/ · /res/ — /show/ · /fap/ · /gg/ · /swf/ | P0001 · P2595 · P5190 |
This is the info page for Flash #41739 |
this site will (soon) contain demos, articles, resources, and source code. my interests are in realtime physics (and game-dev in general), but i might also throw in some music or whatever.. who knows. mare and i are working on a series of tutorials explaining stuff like collision detection and rigid body simulation, as well as a bit of character-animation stuff we've been fooling with. in the meantime, i'll be putting up various demos and other bits to perhaps pique your curiosity... |
left/right/down arrows: flex edges spacebar: grab/throw with mouse (click in the box to set focus) |
ActionScript [AS1/AS2]
Frame 1function Particle(px, py) { this.px = px; this.py = py; this.ox = px; this.oy = py; } function Stick(a, b, minlen, maxlen) { this.a = a; this.b = b; this.minl = minlen; this.maxl = maxlen; this.curl = maxlen; } function Integrate() { var g = GRAV; var d = DRAG; var p; var d1; var d2; var px; var py; for (var i in pList) { p = pList[i]; d2 = d; d1 = d + 1; px = p.px; py = p.py; p.px = (d1 * px) - (d2 * p.ox); p.py = ((d1 * py) - (d2 * p.oy)) + g; p.ox = px; p.oy = py; } } function Constrain() { var p = pList; var s; var a; var b; var dx; var dy; var dL; var d; var l; for (var i in sList) { s = sList[i]; a = p[s.a]; b = p[s.b]; dx = b.px - a.px; dy = b.py - a.py; dL = Math.sqrt((dx * dx) + (dy * dy)); l = s.curl; d = (dL - l) / dL; dx = dx * d; dy = dy * d; a.px = a.px + (0.5 * dx); a.py = a.py + (0.5 * dy); b.px = b.px - (0.5 * dx); b.py = b.py - (0.5 * dy); } } function Collide() { var p; var x; var y; for (var i in pList) { p = pList[i]; x = p.px; y = p.py; if (XMAX < x) { p.px = XMAX; } else if (x < XMIN) { p.px = XMIN; } if (YMAX < y) { var vy = (p.py - p.oy); p.py = YMAX; var vx = (p.px - p.ox); vx = vx * FRICTION; p.ox = p.px - vx; vy = vy * BOUNCE; p.oy = YMAX + vy; } else if (y < YMIN) { p.py = YMIN; } } } function Input() { if (Key.isDown(32)) { pList[0].px = _xmouse; pList[0].py = _ymouse; } var s; for (var i in sList) { s = sList[i]; if (Key.isDown(keys[i])) { s.curl = s.curl * SHORTENSPEED; if (s.curlen < s.minl) { s.curl = s.minl; } } else { s.curl = s.maxl; } } } keys = new Array(); keys[0] = 37; keys[1] = 40; keys[2] = 39; function Renderer() { this.mc = _root.createEmptyMovieClip("renderoutputMC", 100); } Renderer.prototype.Draw = function () { var p0 = pList[0]; var p1 = pList[1]; var p2 = pList[2]; this.mc.clear(); this.mc.lineStyle(0, 0, 100); this.mc.moveTo(p0.px, p0.py); this.mc.lineTo(p1.px, p1.py); this.mc.lineTo(p2.px, p2.py); this.mc.lineTo(p0.px, p0.py); }; XMIN = 50; XMAX = 650; YMIN = 150; YMAX = 550; FRICTION = 0.8; DRAG = 0.99; GRAV = 0.2; BOUNCE = 0.6; MAXLEN = 85; MINLEN = 50; SHORTENSPEED = 0.9; pList = new Array(); pList.push(new Particle(XMIN, YMIN)); pList.push(new Particle(XMIN, YMIN + MAXLEN)); pList.push(new Particle(XMIN + MAXLEN, YMIN)); sList = new Array(); sList.push(new Stick(0, 1, MINLEN, MAXLEN)); sList.push(new Stick(1, 2, MINLEN, MAXLEN)); sList.push(new Stick(2, 0, MINLEN, MAXLEN)); gfx = new Renderer(); function Tick() { Integrate(); Input(); Constrain(); Collide(); gfx.Draw(); } _root.onEnterFrame = Tick;
Library Items
Symbol 1 Graphic | Used by:Timeline | ||
Symbol 2 Font | Used by:3 4 | ||
Symbol 3 Text | Uses:2 | Used by:Timeline | |
Symbol 4 Text | Uses:2 | Used by:Timeline |
|