ReeceGames [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=32539 2d vector math <h1>Vector math for PICO-8!</h1> <p>Have you ever been looking at your code and been like:<br /> &quot;Hmm, i sure do add two numbers to another set of two numbers a lot,&quot; then do i have the solution for you!<br /> At the low low price of like 400 tokens, PICO-8 vector math can be yours!<br /> I originally made this to streamline a platformer I may or may not ever finish, but I realized that other people might want this, flagrant waste of tokens or not.</p> <h3>Features!</h3> <p><div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"><br /> -Constructor function: vec2(x,y) will make a vector, vec2(x) copies x twice<br /> -The four basic functions, plus exponetation<br /> -The concentation operator (..) does dot products<br /> -A normalize function<br /> </div></div></div></p> <h3>The code</h3> <p>There are two versions of the whole program. One handles errors more gracefully, while the other has a smaller token footprint</p> <h2>Required functions:</h2> <p>The metatable depends heavily on these two functions</p> <p><div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"></p> <ul> <li>Constructor</li> </ul> <p>This function creates and gives the right metatable to the given two numbers, saving a few tokens every time you or the metatable itself wants to make a new metatable</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function vec2(x,y) if (not y) y=x return setmetatable({x=x,y=y},vec2mt) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <ul> <li>Argument preperation</li> </ul> <p>This function returns a list of two vectors, either the two vectors passed, or a vector and then a doubles number. <strong>This function means you cannot divide a number by a vector, or subtract a vector from a number.</strong></p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function vecargs(a,b) if(type(a)==&quot;number&quot;)a,b=b,a if type(b)==&quot;number&quot; then return {a,vec2(b)} elseif getmetatable(b)==vec2mt then return {a,b} end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p></div></div></div></p> <h3>Fault tolerant metatable</h3> <p><div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"></p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>vec2mt={ __index={x=0,y=0}, __newindex=function (tble, k, v) if k=='x' or k=='y' then rawset(tble,k,v) else printh(&quot;bad key&quot;) end end, __unm = function(tble) return vec2(-tble.x,-tble.y) end, __add = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x+b.x,a.y+b.y) end, __mul = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x*b.x,a.y*b.y) end, __div = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x/b.x,a.y/b.y) end, __sub = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return a+(-b) end, __pow = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x^b.x,a.y^b.y) end, __concat = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return a.x*b.x+a.y*b.y --15 end, } </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p></div></div></div></p> <h3>Fault intolerant metatable</h3> <p><div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"></p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>vec2mt={ __unm = function(tble) return vec2(-tble.x,-tble.y) end, __add = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x+b.x,a.y+b.y) end, __mul = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x*b.x,a.y*b.y) end, __div = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x/b.x,a.y/b.y) end, __sub = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return a+(-b) end, __pow = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return vec2(a.x^b.x,a.y^b.y) end, __concat = function(a,b) local c=vecargs(a,b) a,b=c[1],c[2] return a.x*b.x+a.y*b.y --15 end, }</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p></div></div></div></p> <h3>Normalize function</h3> <p><div><div><input type="button" value=" Show " onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerText = ''; this.value = ' Hide '; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = ' Show '; }"></div><div><div style="display: none;"></p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function norm(vec) local power=vec^2 return vec/sqrt(power.x+power.y) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p></div></div></div></p> https://www.lexaloffle.com/bbs/?tid=37015 https://www.lexaloffle.com/bbs/?tid=37015 Sun, 08 Mar 2020 17:37:04 UTC rg_tweettweet2 <p> <table><tr><td> <a href="/bbs/?pid=64606#p"> <img src="/bbs/thumbs/pico8_rg_tweettweet2-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=64606#p"> rg_tweettweet2</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=64606#p"> [Click to Play]</a> </td></tr></table> <br /> My entry for the second tweettweetjam<br /> Play the game <a href="https://ian-destroyer.itch.io/tweettweetjam2-jumper">here.</a></p> https://www.lexaloffle.com/bbs/?tid=34279 https://www.lexaloffle.com/bbs/?tid=34279 Mon, 20 May 2019 03:36:47 UTC karel_the_robot <h1>look its karel the robot</h1> <p> <table><tr><td> <a href="/bbs/?pid=64137#p"> <img src="/bbs/thumbs/pico8_karel_the_robot-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=64137#p"> karel_the_robot</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=64137#p"> [Click to Play]</a> </td></tr></table> </p> <p>wow karel is an intro-duction to programming that ueses phive whole instructions.<br /> karel can move(), which makes it go forewarde<br /> karel can turnleft() whchic should be obvious<br /> karel may dropchip() thath puts a chip on the ground?<br /> karel can takechip() and that picks up any chips that are on the same tile as it<br /> karel is capable of checkchip() whitch returns the chipcode of the chip its on</p> <p>okay if you want human redable instruction go to <a href="https://github.com/Ian-destroyer/pico-karel/tree/master">this</a> link</p> https://www.lexaloffle.com/bbs/?tid=34119 https://www.lexaloffle.com/bbs/?tid=34119 Thu, 02 May 2019 03:55:14 UTC Christmas Tweetcart! <p> <table><tr><td> <a href="/bbs/?pid=60279#p"> <img src="/bbs/thumbs/pico8_rg_snowytweet-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=60279#p"> rg_snowytweet</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=60279#p"> [Click to Play]</a> </td></tr></table> <br /> I was getting a little bored of my main project, so i took a detour and made a tweetcart!<br /> All it has are 2 little houses on a snowy hill, but it looks pretty nice in my opinion.</p> https://www.lexaloffle.com/bbs/?tid=32682 https://www.lexaloffle.com/bbs/?tid=32682 Sun, 23 Dec 2018 02:37:57 UTC Phagocytosis 1.0 <h1>Release!</h1> <p> <table><tr><td> <a href="/bbs/?pid=58902#p"> <img src="/bbs/thumbs/pico8_phagocytosis_reecegames-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=58902#p"> Phagocytosis 1.0</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=58902#p"> [Click to Play]</a> </td></tr></table> <br /> It's done! I might still add on to it, but it's a finished game now!</p> <h2>How to play</h2> <p>This is you:<br /> <table><tr><td width=64> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_0.png" width=64 height=64> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_0"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_0.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_0"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [16x16]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_0" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> Move with the directions, and start digesting with [O]<br /> Moving and digesting take up energy, and if you run out of energy, you take <em>massive</em> damage to the health meter</p> <h1>Enemies</h1> <p><strong>Viruses</strong><br /> <table><tr><td width=32> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_1.png" width=32 height=32> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_1"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_1.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_1"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [8x8]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_1" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> These simply drift across the screen, and deal damage if they go off of it.<br /> Touch them while digesting to defeat them</p> <p><strong>Green Bacteria</strong><br /> <table><tr><td width=32> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_2.png" width=32 height=32> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_2"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_2.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_2"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [8x8]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_2" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> These spawn where you see this symbol:<br /> <table><tr><td width=64> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_3.png" width=64 height=64> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_3"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_3.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_3"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [16x16]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_3" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> They slowly drift away from you.</p> <p><strong>Yellow Bacteria</strong><br /> <table><tr><td width=32> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_4.png" width=32 height=32> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_4"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_4.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_4"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [8x8]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_4" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> They have a short healthbar that you have to deplete, but are otherwise just like viruses.</p> <p><strong>Allergens</strong><br /> <table><tr><td width=32> <img src="https://www.lexaloffle.com/bbs/gfxc/32539_5.png" width=32 height=32> </td> <td valign=bottom> <a style="cursor:pointer;font-size:8pt" onclick=' var el = document.getElementById("gfxcode_32539_5"); if (el.style.display == "none") el.style.display = ""; else el.style.display = "none"; microAjax("https://www.lexaloffle.com/bbs/gfxc/32539_5.txt", function (retdata){ var el = document.getElementById("gfxcode_32539_5"); el.innerHTML = retdata; el.focus(); el.select(); } ); '> [8x8]</a> </td></tr> <tr><td colspan=2> <textarea rows=3 class=lexinput id="gfxcode_32539_5" style="width:640px;background-color:#fed;display:none;overflow:hidden; font-size:6pt;"></textarea> </td> </tr> </table> <br /> Drift across the screen and hurt you if you try to digest them</p> <h1>Powerups</h1> <p><strong>Multiplier</strong><br /> Multiplies your score by 10</p> <p><strong>Red and white pill</strong> (antibiotic)<br /> Prevents both kinds of bacteria from spawning</p> <p><strong>Yellow bottle</strong> (allergy pen)<br /> Allergens will not hurt you</p> <p><strong>Beige thing</strong> (platelet)<br /> Halves spawn rate of all enemies</p> <p><strong>Green arrows</strong> (abstract green arrows)<br /> Makes you accelerate faster</p> <h2>Beta 2</h2> <p> <table><tr><td> <a href="/bbs/?pid=58902#p"> <img src="/bbs/thumbs/pico59291.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=58902#p"> Phagocytosis beta 2</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=58902#p"> [Click to Play]</a> </td></tr></table> <br /> --Changes<br /> -Title Screen!<br /> -Better Music<br /> -Difficulty Curve<br /> -New enemy<br /> -Bacteria<br /> -Can run away from you</p> <h2>Beta 1</h2> <p> <table><tr><td> <a href="/bbs/?pid=58902#p"> <img src="/bbs/thumbs/pico58901.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=58902#p"> Phagocytosis beta 1</a><br><br> by <a href="/bbs/?uid=32539"> ReeceGames</a> <br><br><br> <a href="/bbs/?pid=58902#p"> [Click to Play]</a> </td></tr></table> <br /> This is my first playable game, very simple right now.<br /> <strong>Gameplay</strong><br /> Move with the arrows. Viruses spawn on occasion, if they reach the other side of the screen, the human you're in takes damage. Use (O) to enter phagocytosis. If you touch a virus in phagocytosis mode, you will kill it.<br /> But be careful! Both moving and phagocytosis deplete energy. If you run out of energy, the human rapidly loses health. If the human runs out of health, you lose! Eat food to gain back energy.</p> https://www.lexaloffle.com/bbs/?tid=32210 https://www.lexaloffle.com/bbs/?tid=32210 Fri, 09 Nov 2018 17:22:48 UTC