grobstein [Lexaloffle Blog Feed] Sprite rotation demo <p> <table><tr><td> <a href="/bbs/?pid=12064#p"> <img src="/bbs/thumbs/pico12063.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=12064#p"> Sprite rotation demo</a><br><br> by <a href="/bbs/?uid=10274"> grobstein</a> <br><br><br> <a href="/bbs/?pid=12064#p"> [Click to Play]</a> </td></tr></table> </p> <p>I got to wondering whether you could rotate a sprite in PICO-8. Of course this facility is not provided, but it should be achievable, I thought. </p> <p>How this works: 3 rotating objects. Arrows move the green cursor among them, and Z or X to toggle each object on or off. </p> <p>The rotations are slightly ugly, but I think accurate. Smoothing could probably make them look better, but maybe not at reasonable cost. I don't know! Rotating the large sprite is CPU-intensive (<em>and</em> ugly!). I think for small objects this could be used in a game. </p> <p>Issues: </p> <ul> <li>Sprites are rotated about their top left corner. I think this is needed to guarantee that atan2 is one-to-one. But it would be better to rotate around an arbitrary center! </li> <li>I forgot what the other issues are. </li> </ul> Thu, 30 Jul 2015 19:30:49 UTC Orbital mechanics demo <p> <table><tr><td> <a href="/bbs/?pid=12038#p"> <img src="/bbs/thumbs/pico12102.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=12038#p"> Orbital mechanics demo 0.15</a><br><br> by <a href="/bbs/?uid=10274"> grobstein</a> <br><br><br> <a href="/bbs/?pid=12038#p"> [Click to Play]</a> </td></tr></table> </p> <p>ADDED (7/31): Fixed some missing interactions; elastic collisions apply to the ship; re-did overlay; you can switch views; gravity calc is dropped at high distances.</p> <p>Press 'Z' to switch views among ship and planetoids. Current view is displayed in overlay. </p> <p>ADDED (7/31): Only detect collisions for nearby objects (fixes integer overflow issue).<br /> ADDED (7/31): Elastic collisions (for planetoids), sound and music.</p> <p>I've implemented perfectly elastic collisions between the planetoids. (I haven't done collisions for the ship, yet, partly because it's easier to detect collisions for circles.) </p> <p>When two planetoids collide, a crashing sound plays and the planets exchange some energy and momentum (<a href="">details</a>). I'm pretty sure the math is accurate -- at least, the collisions look reasonably accurate. As with gravity, however, the math involved can involve large numbers and integer overflow could be a problem -- I don't know whether it actually does cause issues in the conditions I've built. (EDIT: I think it does. In particular, collision detection uses distance. But, because of integer overflow and sqrt, distances over ~181 roll back to 0. So very distant objects constantly collide with each other and go crazy. This makes the system less stable than it should be. A solution would be to only check collisions for nearby objects, using some cheap and safe heuristic (e.g. Manhattan distance).)</p> <p>One thing that the new logic makes obvious is that the initial conditions are not dynamically stable. The first collision will happen after just a couple orbits, and then a lot more collisions will happen. If you let it run for a while, the planets will line up and do a huge croquet shot, sending at least one of them off into infinity. </p> <p>I'm starting to think there might be a workable game in the neighborhood of <em>space billiards</em>.</p> <p>Sound: just fiddled with the sfx toy to get something noisy.<br /> Music: naive implementation of Bach, Prelude No. 1 from the <em>Well-Tempered Clavier</em>. </p> <p>To do: </p> <ul> <li>Collision detection and physics model for the ship. </li> <li>Start thinking about what space billiards would be like. </li> <li>Can the sound be made into an interesting function of the collision, e.g. scaled somehow to the energy of the bodies? </li> </ul> <p>UPDATED (7/30): Added third body (plus ship), de-uglified map. Sim should now start in a kinda-stable three-body configuration.</p> <p>This is an extremely sketchy little orbital mechanics demo. It mostly happened because I was trying to learn about the camera! Now it is a pretty barebones 3.5-body simulator. </p> <p>Arrow keys give thrust in direction of arrow. You are limited to 50 delta v units (approximately 1px / frame^2 total I think). </p> <p>Thrust is meant to be used sparingly or you will fly off into boring space. </p> Thu, 30 Jul 2015 10:55:47 UTC