Ulexes [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=42956 Making a pendulum with an increasing swing <h2>The Question</h2> <p>Hello everyone,</p> <p>I am ludicrously close to finishing the engine for my game, but some physics equations have me stuck. Here is what I'm trying to achieve:</p> <ul> <li>The players are effectively nodes that can switch between being pendulum bobs and fulcrums. One can be anchored to serve as a fulcrum while the other swings. If both are anchored, neither moves. If both try to un-anchor themselves, they fall.</li> <li>In order to let the players navigate the playfield, I want the swing of a pendulum bob to increase bit by bit. (This will let players climb the playfield by swinging upward instead of just descending.)</li> <li>Once a bob makes a full loop around the fulcrum, I want it to continue in a circle at a more-or-less consistent speed.</li> </ul> <p>With the help of <a href="https://math.libretexts.org/Bookshelves/Scientific_Computing_Simulations_and_Modeling/Scientific_Computing_(Chasnov)/II%3A_Dynamical_Systems_and_Chaos/10%3A_The_Simple_Pendulum">this math writeup</a>, I managed to assemble a simplified set of physics variables and equations that do an okay job of simulating momentum and creating a non-degrading swing (i.e., the swing distance never shrinks due to friction). But I haven't figured out how to make the desired <em>increase</em> in swing distance happen. I'm sure it's a single value or sign that I haven't identified.</p> <p>I suspect I need to do something to increment the value of <code>p.a</code> in the function <code>move_player(p)</code>, but I am not sure how to approach it -- adding a value, multiplying by a value, etc.</p> <p>Could someone better at physics/math please offer suggestions?</p> <p>Thank you for any and all pointers!</p> <p>The annotated code is below. It's 200 lines in total, but the relevant parts are the first ~90.</p> <p> <table><tr><td> <a href="/bbs/?pid=149913#p"> <img src="/bbs/thumbs/pico8_zafebaraza-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=149913#p"> zafebaraza</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=149913#p"> [Click to Play]</a> </td></tr></table> </p> <h2>The Code</h2> <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 class=scrollable_with_touch style="width:100%; 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 _init() screen_center=63 player_size=5 tether_length=25 g=20 --gravity/momentum. more=stronger pull. negative values flip the swing's arc. k=-(g/tether_length) default_v=0 --negative=swing left, positive=swing right default_dt=0.01 --period/speed of swing (screwy if &gt;=1) dt_cap=0.1 dt_boost=dt_cap/(g*10) red={ controller=0, button=5, control_mode=&quot;toggle&quot;, --&quot;hold&quot; or &quot;toggle&quot; x=screen_center-tether_length/2, y=screen_center, colors={2,8,2}, r=player_size, a=0, v=default_v, dt=default_dt, glyph=nil, anchor=nil } blue={ controller=0, button=4, control_mode=&quot;toggle&quot;, x=screen_center+tether_length/2, y=screen_center, colors={1,12,1}, r=player_size, a=0, v=default_v, dt=default_dt, glyph=nil, anchor=nil } red.partner=blue blue.partner=red players={red,blue} for p in all(players) do set_glyph(p) end end --&gt;8 --updates function _update() for p in all(players) do control_player(p) check_angle(p) move_player(p) end end function move_player(p) if p.anchor==false and p.partner.anchor==true then p.v+=k*cos(p.a)*p.dt --to do: steadily increase swing length --to do: circular movement at consistent speed after looping --what i really want to do is boost dt and angle at the end of each swing p.a+=p.v*p.dt --dt should start small, increase, and cap around 0.1 p.dt+=dt_boost if p.dt&gt;dt_cap then p.dt=dt_cap end p.x=p.partner.x+tether_length*cos(p.a) p.y=p.partner.y+tether_length*sin(p.a) end if p.anchor==false and p.partner.anchor==false then --to-do: let swinging players finish their swing p.y+=g/5 end end --everything below this line works, and is included in case anyone wants to paste the full code into a cart function control_player(p) if p.control_mode==&quot;toggle&quot; then if p.anchor==nil then p.anchor=true end if btnp(p.button,p.controller) then if not out_of_bounds(p) then p.anchor=not p.anchor p.dt=default_dt p.v=default_v end end if p.anchor==true then p.colors[3]=7 else p.colors[3]=p.colors[1] end elseif p.control_mode==&quot;hold&quot; then if p.anchor==nil then p.anchor=false end if btn(p.button,p.controller) then if not out_of_bounds(p) then p.anchor=true end else p.anchor=false end if p.anchor==true then p.dt=default_dt p.v=default_v p.colors[3]=7 elseif p.anchor==false then p.colors[3]=p.colors[1] end end end function check_angle(p) local angle=atan2(p.x-p.partner.x,p.y-p.partner.y) p.a=angle end function out_of_bounds(p) if p.x&gt;128 or p.x&lt;0 or p.y&gt;128 or p.y&lt;0 then return true end end function set_glyph(p) local glyphs={&quot;⬅️&quot;,&quot;➡️&quot;,&quot;⬆️&quot;,&quot;⬇️&quot;,&quot;🅾️&quot;,&quot;❎&quot;} p.glyph=glyphs[p.button+1] end --&gt;8 --draws function _draw() cls() draw_debug(red,1) draw_debug(blue,85) draw_tether(red,blue) for p in all(players) do draw_player(p) end end function draw_player(p) circfill(p.x,p.y,p.r,p.colors[1]) circfill(p.x,p.y,p.r-1,p.colors[2]) circfill(p.x,p.y,p.r-3,p.colors[3]) print(p.glyph,p.x-3,p.y-2,p.colors[2]) for i=1,2 do pset(p.x+1+i,p.y-5+i,7) end end function draw_tether(p1,p2) line(p1.x,p1.y,p2.x,p2.y,10) end function draw_debug(p,spot) local bottom=123 local col=p.colors[2] if p.anchor==true then print(&quot;anchored&quot;,spot,bottom-21,col) else print(&quot;unanchored&quot;,spot,bottom-21,col) end print(&quot;v: &quot;..p.v,spot,bottom-14,col) print(&quot;a: &quot;..p.a,spot,bottom-7,col) print(&quot;dt: &quot;..p.dt,spot,bottom,col) 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=142704 https://www.lexaloffle.com/bbs/?tid=142704 Fri, 14 Jun 2024 03:05:17 UTC Help: Circle math for angled projectiles <p>I am working on a little shooter where players can move up and down a fixed track, and can aim a cannon to shoot a projectile at an angle. Ideally, this angle can run parallel to the track, but shouldn't intersect it.</p> <p>I thought I had the math down, but I am running into an issue where the players' projectiles are able to intersect the track. It appears that, even though I constrain the angles that player cannons can point and fire, players seem to be able to extend and shoot a <em>tiny</em> bit beyond it. Strangely, a simple debug test that prints the angles indicates that they <em>should</em> be parallel to the track in these situations.</p> <img style="margin-bottom:16px" border=0 src="/media/42956/bat_ui_test_0.gif" alt="" /> <p>Angle constraint formulas:</p> <div> <div class=scrollable_with_touch style="width:100%; 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>--player 1 is on the left side, and aims right if p1.a&lt;270 and p1.a&gt;100 then p1.a=270 end if p1.a&gt;90 and p1.a&lt;270 then p1.a=90 end --player 2 is on the right side, and aims left if p2.a&lt;90 then p2.a=90 end if p2.a&gt;270 then p2.a=270 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>Cannon aiming formulas:</p> <div> <div class=scrollable_with_touch style="width:100%; 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> if btn(⬅️, p.c) then p.a+=target_speed p.tx=p.x+radius*cos(p.a/360) p.ty=p.y+radius*sin(p.a/360) if p.a&gt;360 then p.a=0 end end if btn(➡️, p.c) then p.a-=target_speed p.tx=p.x+radius*cos(p.a/360) p.ty=p.y+radius*sin(p.a/360) if p.a&lt;0 then p.a=360 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>Have I found a bug with how PICO-8 does its circle math? Or have I erred somewhere? (It's probably the latter, but I can't see what I'm doing wrong.)</p> <p> <table><tr><td> <a href="/bbs/?pid=116799#p"> <img src="/bbs/thumbs/pico8_ponezabaka-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=116799#p"> ponezabaka</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=116799#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=49157 https://www.lexaloffle.com/bbs/?tid=49157 Fri, 02 Sep 2022 22:31:59 UTC Snail Maker <p> <table><tr><td> <a href="/bbs/?pid=115020#p"> <img src="/bbs/thumbs/pico8_snailmaker-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=115020#p"> snailmaker</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=115020#p"> [Click to Play]</a> </td></tr></table> </p> <p>A silly little toy I threw together. Click your mouse to generate a bunch of randomly-colored snails that flee at varying speeds to the left and right of the screen.</p> https://www.lexaloffle.com/bbs/?tid=48711 https://www.lexaloffle.com/bbs/?tid=48711 Sat, 30 Jul 2022 18:44:23 UTC Robosumo! <p> <table><tr><td> <a href="/bbs/?pid=87609#p"> <img src="/bbs/thumbs/pico8_robosumo_1-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=87609#p"> robosumo_1</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=87609#p"> [Click to Play]</a> </td></tr></table> </p> <p>I'm pleased to unveil my finished weekend project: <strong>Robosumo</strong>! Inspired by <a href="https://www.youtube.com/watch?v=QCqxOzKNFks&amp;amp;amp%3Bt=0s">this entertaining video</a> a friend showed me this week. </p> <p>Special thanks to:</p> <p>freds72, for helping me in the forums.<br /> huulong, for an invaluable <a href="https://github.com/hsandt/pico-boots/blob/master/src/engine/render/sprite.lua">sprite rotation function</a>.<br /> NuSan, for a number of useful physics functions in <a href="https://www.lexaloffle.com/bbs/?tid=3467">Combo Pool</a>.<br /> Daisyfield's archive of <a href="http://daisyfield.com/music/htm/-genres/japan.htm">public domain Japanese music</a>.</p> <h1>Introduction</h1> <p>It's sumo, but with robots! Ram your opponent and send them flying from the dohyō. Speed and finesse are your only weapons &ndash; but take care they're not turned against you.</p> <h1>Features</h1> <ul> <li><strong>Old-school competitive play</strong>: Local multiplayer for up to four players.</li> <li><strong>Configurable game length</strong>: Play one round, or one-hundred!</li> <li><strong>Single-player practice mode</strong>: Hone your skills in a stress-free sandbox.</li> </ul> <h1>Scoring</h1> <ul> <li><strong>1-Player​</strong>: Score is not kept in 1-Player mode.</li> <li><strong>2-Player​</strong>: Gain a point whenever the other player falls out of the ring.</li> <li><strong>3- or 4-Player​</strong>: Gain a point if you landed the last hit on the player who fell out of the ring. (It is possible for a round to conclude with no points scored.)</li> </ul> <h1>Controls</h1> <h2>Main Menu</h2> <ul> <li><strong>UP</strong>/<strong>DOWN</strong>: Move cursor</li> <li><strong>LEFT</strong>/<strong>RIGHT</strong>: Toggle selected option</li> <li><strong>Z</strong>/<strong>X</strong>: Begin game</li> </ul> <h2>Game Screen</h2> <h3>Player 1</h3> <ul> <li><strong>UP</strong>: Move robot forward</li> <li><strong>DOWN</strong>: Move robot backward</li> <li><strong>LEFT</strong>/<strong>RIGHT</strong>: Rotate robot</li> <li><strong>Z</strong>/<strong>X</strong>: Restart game (practice mode only)</li> </ul> <h3>Player 2</h3> <ul> <li><strong>E</strong>: Move robot forward</li> <li><strong>D</strong>: Move robot backward</li> <li><strong>S</strong>/<strong>F</strong>: Rotate robot</li> </ul> <h3>Players 3 and 4</h3> <p><strong>Note</strong>: Joysticks or gamepads are required for 3- or 4-player games, as Pico-8 does not have native keyboard mappings for third- and fourth-player controllers.</p> <ul> <li><strong>UP</strong>: Move robot forward</li> <li><strong>DOWN</strong>: Move robot backward</li> <li><strong>LEFT</strong>/<strong>RIGHT</strong>: Rotate robot</li> </ul> <h1>Other Notes</h1> <p>Downloadable binaries for offline play are available for free on <a href="https://aeneas-nin.itch.io/robosumo">Robosumo's itch page</a>.</p> <p>EDITS: Removed list formatting from &quot;Special Thanks&quot; section, because it prevented the hyperlinks from displaying. Added a &quot;Scoring&quot; section.</p> https://www.lexaloffle.com/bbs/?tid=41552 https://www.lexaloffle.com/bbs/?tid=41552 Sun, 14 Feb 2021 01:37:38 UTC Syntax help: Comparing a table to itself <p>Hi everyone,</p> <p>I'm working on a little robotic sumo game for a friend after seeing an <a href="https://www.youtube.com/watch?v=QCqxOzKNFks&amp;amp;t=0s">IRL video</a> about it. I decided to include a 4-player mode, because I like multiplayer games.</p> <img style="margin-bottom:16px" border=0 src="/media/42956/robosumo_0.gif" alt="" /> <p>I want players to score only if they're the ones who knocked the player out of the arena when play is halted (basically like in Super Smash Bros), but I'm having trouble recording that information.</p> <p>Here's the relevant code:</p> <div> <div class=scrollable_with_touch style="width:100%; 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>--main game loop for p in all(players) do check_hit(p) --other stuff end function check_hit(p) for o in all(players) do if circlehit(p,o) and --Basic collision function. p.col~=o.col then --This line is meant to keep players from hitting themselves. p.lasthit=o.col --Here, &quot;col&quot; is the player's color, and &quot;lasthit&quot; is who last hit them. end --In another function, I award points to the player whose color end --matches the &quot;lasthit&quot; value of the ko'd player. 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>I need to prevent players from &quot;hitting&quot; themselves, because otherwise <em>they</em> would score when they're knocked from the ring. (If I remove the &quot;p.col~=o.col&quot; line, that's exactly what happens.)</p> <p>But right now, scores don't register properly because of a bug with check_hit(p). My testing tells me there's something wrong with this function alone -- it's not recording a &quot;lasthit&quot; value as currently written. I'm not sure whether the problem is the &quot;p.col~=o.col&quot; comparison, or running a for loop within a for loop, or what.</p> <p>Does anyone have a sense of what I've done wrong, or suggestions for doing this more efficiently? Thank you in advance for any and all advice.</p> https://www.lexaloffle.com/bbs/?tid=41527 https://www.lexaloffle.com/bbs/?tid=41527 Fri, 12 Feb 2021 20:43:02 UTC Syntax help: Accessing a table within a table <p>Hi everyone!</p> <p>I am making a little game where you scare off crows to protect your vegetable garden:</p> <img style="margin-bottom:16px" border=0 src="/media/42956/scrowverwatch_0.gif" alt="" /> <p>I am trying to make the crows pick a vegetable to target when they spawn. I have a function that will make them chase down a point by entering its X and Y value. My problem is that I don't know how to extract the vegetables' X and Y values because of how I've set things up.</p> <p>Every vegetable is decided at random at the game's outset, and stored inside another table, like so:</p> <div> <div class=scrollable_with_touch style="width:100%; 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>[note: dif is an integer, adding more vegetables at higher difficulties] function setup() for i=1,dif do add(vegetables, { x=originx+(rnd(40)+10)*cos(rnd(360)/360), y=originy+(rnd(40)+10)*sin(rnd(360)/360), w=6, h=6, [more variables and stuff you don't need to care about...] }) 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>My question is, how would I go about accessing the X and Y values for these? I have been trying something like this...</p> <div> <div class=scrollable_with_touch style="width:100%; 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>vegselect=flr(rnd(dif))+1 vegx=vegetables[vegselect][1] vegy=vegetables[vegselect][2]</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>...but it has failed as a nil value every time.</p> <p>Any advice is appreciated. Thanks for considering my problem!</p> <p>EDIT: I classified the post incorrectly. Apologies!</p> https://www.lexaloffle.com/bbs/?tid=40747 https://www.lexaloffle.com/bbs/?tid=40747 Thu, 10 Dec 2020 22:59:48 UTC Star Shield (Demo) <p>It's a long way from finished, but I now have something approximating a playable demo of a 1- to 4-player cart I've been working on. </p> <img style="margin-bottom:16px" border=0 src="/media/42956/starshield_lines_0.gif" alt="" /> <p>Here is <em>Star Shield</em> for your... Uh... Enjoyment? Or whatever you want to do with it.</p> <h1>Premise</h1> <p>Defend your base against the stars' relentless assault by activating your left or right shield at the correct moment. Rack up a high score in single player, or be the last base standing in multiplayer!</p> <p>Stars speed up after several deflections, and new stars appear at high point thresholds. Extra lives are awarded to particularly beleaguered players.</p> <h1>Controls</h1> <ul> <li>LEFT or (o): Activate left shield.</li> <li>RIGHT or (x): Activate right shield.</li> </ul> <p>For proper orientation, imagine yourself seated behind your station, looking into the circle.</p> <ul> <li>Player 1: Red (South)</li> <li>Player 2: Blue (North)</li> <li>Player 3: Yellow (West)</li> <li>Player 4: Green (East)</li> </ul> <p> <table><tr><td> <a href="/bbs/?pid=74322#p"> <img src="/bbs/thumbs/pico8_starshield_demo_v05-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=74322#p"> starshield_demo_v05</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=74322#p"> [Click to Play]</a> </td></tr></table> </p> <h1>To-Do List</h1> <p>There is a <strong>lot</strong> that I'm still working on. Namely:</p> <ul> <li>Moving stars along lines at intersections, rather than teleporting. <ul> <li>In an ideal world, the stars randomly decide whether to hop on a line when they pass them, and then randomly decide to travel counter/clockwise at the end of the line. I'm really struggling to come up with ways to go from circular movement to linear movement and back... The stars always fly off into space, never to be seen again!</li> <li>The travel to the center circle is necessary for 3- and 4-player games, so that stars aren't trapped between two players.</li> </ul></li> <li>Better shield activation windows. <ul> <li>BTNP allows an indefinite shield (defeating the point of the game), but BTN keeps it up way too briefly.</li> </ul></li> <li>Displaying &quot;empty&quot; life markers when lives are lost.</li> <li>Nicer title and menu screen.</li> <li>Music and sounds.</li> <li>Optimized maps and starting positions for 3-player games.</li> <li>Much cleaner code!</li> </ul> <p>I will update this thread as I progress.</p> <p>Thanks for reading/playing!</p> https://www.lexaloffle.com/bbs/?tid=37211 https://www.lexaloffle.com/bbs/?tid=37211 Mon, 30 Mar 2020 04:23:43 UTC Seeking table arrangement suggestions <p>Hi everybody!</p> <p>So, for a <a href="https://itch.io/jam/mini-jam-50-islands">jam</a> I'm far too unskilled to have considered, I'm putting together a little game where up to four players can pilot tiny ships and defend a fort. The ships can move about, and (eventually) shoot in the direction of a target that can be rotated around the ship by holding a button. It looks like this in practice:</p> <img style="margin-bottom:16px" border=0 src="/media/42956/fort midwater_1.gif" alt="" /> <p>(Enemies and animations forthcoming.)</p> <p>Right now, I am attempting to optimize the code, because the player inputs eat a LOT of tokens in their current form. I currently have four different sets of inputs, one for each player, and each also moves a target that is specified as its own object (target1 with .x and .y, target2 with .x and .y, etc.). This is obviously no good, given the immense redundancies.</p> <p>I think one could probably code a generic input function by making each target a property of its ship, using something like this:</p> <div> <div class=scrollable_with_touch style="width:100%; 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 input(p) if btn(0,p.c) then p.x=p.x-1 p.targetx=p.targetx-1 --repositions player and target if p.x&lt;0 then p.x=0 end --prevents leaving the screen if p.targetx&lt;0 then p.targetx=p.x+radius*cos(p.a/360) end end if btn(1,p.c) then p.x=p.x+1 p.targetx=p.targetx+1 --repositions player and target if p.x&gt;120 then p.x=120 end --prevents leaving the screen if p.targetx&gt;120 then p.targetx=p.x+radius*cos(p.a/360) end end if btn(2,p.c) then p.y=p.y-1 p.targety=p.targety-1 --repositions player and target if p.y&lt;16 then p.y=16 end --prevents moving into sandbar at top of screen end if btn(3,p.c) then p.y=p.y+1 p.targety=p.targety+1 --repositions player and target if p.y&gt;120 then p.y=120 end --prevents leaving the screen if p.targety&gt;120+radius then p.targety=p.y+radius*sin(p.a/360) end end if btn(4,p.c) then end --fires bullet (to be implemented) if btn(5,p.c) then p.a+=target_speed --rotates target p.targetx=p.x+radius*cos(p.a/360) p.targety=p.y+radius*sin(p.a/360) if p.a&gt;360 then p.a=0 --resets target angle if needed elseif p.a&lt;0 then p.a=360 end 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>Basically, as long as we specify the controller (c) associated with each player (p), we can use one function to dictate all player inputs. So, for each player, we have to put together a simple table of attributes.</p> <p>And here is where my problem occurs: <strong>those stupid little targets</strong>.</p> <p>Here's what I have tried to use for the first player's attribute table:</p> <div> <div class=scrollable_with_touch style="width:100%; 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> p1={ exist=false, dead=false, idle=true, x=50, y=50, a=180, idlesprite=3, movesprite=7, w=8, h=8, score=0, lives=3, c=0, targetx=p1.x+radius*cos(p1.a/360), --PICO-8 doesn't like this line. targety=p1.y+radius*sin(p1.a/360), --Or this one. targetsprite=16 }</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>It seems PICO-8 doesn't accept putting p1.x, p1.y, and p1.a in those trig functions for p1.targetx and p1.targety. It raises an error, saying that they indicate an attempt to index a nil value. I guess I could just throw in a raw number for them? But I kind of need those variables, I think, since the location of the player's target must depend on the location of the player's ship.</p> <p><strong>TL;DR</strong>: A table isn't working like my noob brain would expect, and I have three questions:</p> <ul> <li>Why are p1.x, p1.y, and p1.a nil values, if I already provide values for them in the table?</li> <li>How else might I define targetx and targety, such that they remain properties of p1?</li> <li>If the method I've proposed is stupid, what might you suggest as a workaround?</li> </ul> https://www.lexaloffle.com/bbs/?tid=37020 https://www.lexaloffle.com/bbs/?tid=37020 Sat, 21 Mar 2020 18:53:06 UTC Arguments won't pass? <p>I'm having an issue where it seems like I absolutely cannot pass an argument to a function, no matter what I do.</p> <p>For starters, I am using doc_robs' <a href="https://www.youtube.com/watch?v=LwMNPEG4OPo">famous hitbox function</a>:</p> <div> <div class=scrollable_with_touch style="width:100%; 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 player_hit(x1,y1,w1,h1, x2,y2,w2,h2) local hit=false local xs=w1/2+w2/2 local ys=h1/2+h2/2 local xd=abs((x1+(w1/2))-(x2+(w2/2))) local yd=abs((y1+(h1/2))-(y2+(h2/2))) if xd&lt;xs and yd&lt;ys then hit=true end return hit 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>So far, so good, right? Then I pass the following arguments along to it from another function:</p> <div> <div class=scrollable_with_touch style="width:100%; 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> if player_hit(p1.x,p1.y,pw,ph,star1.x,star1.y,sw,sh) then --stuff happens in here 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>All of the values in the preceding if statement are defined at _init(). The values pw, ph, sw, and sh are all 2, defined as global variables. The p1 and star1 values come from tables.</p> <p>But every time I run my program, this error occurs:</p> <div> <div class=scrollable_with_touch style="width:100%; 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>RUNTIME ERROR local xs=w1/2+w2/2 Attempt to perform arithmetic on local 'w1' (a nil value)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Now, I can't find the reason why w1 registers as nil. The value pw (2) should be subbed in for it, since it's being provided in the function call.</p> <p>Strangely, the same error occurs even if I manually type &quot;2&quot; in place of pw in the player_hit() call.</p> https://www.lexaloffle.com/bbs/?tid=37104 https://www.lexaloffle.com/bbs/?tid=37104 Thu, 19 Mar 2020 23:20:47 UTC Best way to mimic NES bass? <p>If you grew up with the NES, you remember that their basslines had a certain &quot;snappiness&quot; to them (for lack of a better word). Here are two of my favorite examples:</p> <p><object width="640" height="400"><param name="movie" value="https://www.youtube.com/v/WmD_gH-m6jk&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/WmD_gH-m6jk&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="400"></embed></object></p> <p><object width="640" height="400"><param name="movie" value="https://www.youtube.com/v/-xAOecKb1eA&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/-xAOecKb1eA&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="400"></embed></object></p> <p>DAT BASS!</p> <p>Anyway, I've been trying to mimic that type of bass as closely as I can in my PICO-8 carts, but I haven't quite hit the mark yet.</p> <p>Does anyone have instrument/effect suggestions for achieving this kind of sound?</p> https://www.lexaloffle.com/bbs/?tid=37059 https://www.lexaloffle.com/bbs/?tid=37059 Thu, 19 Mar 2020 18:22:40 UTC Can we compare coordinate values? (Syntax error help) <p>This is probably a ludicrously simple thing that I never learned, so please forgive me in advance.</p> <p>I'm trying to write a function that checks whether a thing (star1) moving in a circle intersects with any of four lines (four_p_lineX) that connect to the circle. The best way I can think to do this is to make the function check whether the X and Y coordinates of star1 match the X and Y coordinates of any of the line endpoints.</p> <p>The thing is, PICO-8 doesn't like what I've written:</p> <div> <div class=scrollable_with_touch style="width:100%; 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 check_direction() local s1switch=flr(rnd(1)) --You wonderful forum people can ignore this part. if (star1.x,star1.y)==(four_p_line1.x1,four_p_line1.y1) or (four_p_line1.x2,four_p_line1.y2) or (four_p_line2.x1,four_p_line2.y1) or (four_p_line2.x2,four_p_line2.y2) or (four_p_line3.x1,four_p_line3.y1) or (four_p_line3.x2,four_p_line3.y2) or (four_p_line4.x1,four_p_line4.y1) or (four_p_line4.x2,four_p_line4.y2) then if s1switch==1 then --Ignore this, too. star1.line=not(star1.line) end 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>The above code produces the following syntax error:</p> <div> <div class=scrollable_with_touch style="width:100%; 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>SYNTAX ERROR LINE 187 (TAB 2) if (star1.x,star1.y)==(four_p_line1.x1,four_p_line1.y1) or ')' expected near ','</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I can't really figure out what the error is telling me. Is it as simple as me forgetting some punctuation, or can I not make the comparison I'm trying to make?</p> https://www.lexaloffle.com/bbs/?tid=37095 https://www.lexaloffle.com/bbs/?tid=37095 Wed, 18 Mar 2020 01:11:33 UTC Compensating for sprite corners in movement <p>Hi everyone!</p> <p>I'm hard at work on a 1-4 player cart, but I've run into a snag when it comes to moving a sprite around in a circle.</p> <p>I more or less have the movement down (thanks to <a href="https://www.lexaloffle.com/bbs/?tid=29094">tonechild</a>), but it looks like the <em>wrong part</em> of the sprite is tracing the circle I want:</p> <img style="margin-bottom:16px" border=0 src="/media/42956/starshield_0.gif" alt="" /> <p>(Please excuse the incomplete graphics and such.)</p> <p>It appears that the upper-left corner of the sprite is tracing the circle here, when I'd really prefer something closer to the center of the sprite. Is there a way to make this happen? Or, if not, is there a workaround any of you might recommend?</p> <p>Here are the relevant points of my (messy) code. You'll notice the star is able to &quot;trace&quot; the track because it uses the same variables I used to draw the circle.</p> <div> <div class=scrollable_with_touch style="width:100%; 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> --variables scene=&quot;logo&quot; last=time() game_over=false --determines that a solo player has lost player_win=false --determines that a player won in multiplayer radius1=55 --determines outer circle size radius2=25 --determines inner circle size originx=63 --center of screen/track originy=63 --center of screen/track flashcol=11 --star 1 data star1={} star1.exist=false star1.angle=13 star1.x=originx+radius1*cos(star1.angle/360) star1.y=originy+radius1*sin(star1.angle/360) star1.speed=3 star1.sprite=56</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <div> <div class=scrollable_with_touch style="width:100%; 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>--moves stars along track function move_stars() --moves star 1 star1.angle+=star1.speed star1.x=originx+radius1*cos(star1.angle/360) star1.y=originy+radius1*sin(star1.angle/360) if star1.angle&gt;360 then star1.angle=0 elseif star1.angle&lt;0 then star1.angle=360 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> <div> <div class=scrollable_with_touch style="width:100%; 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> --draws track that stars follow function draw_track() circ(originx,originy,radius1,2) circ(originx,originy,radius2,2) 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>Thank you for reading, and for considering the problem! I promise I'll be a better forum participant in the near future, when I know a bit more about this whole Lua thing.</p> https://www.lexaloffle.com/bbs/?tid=37082 https://www.lexaloffle.com/bbs/?tid=37082 Mon, 16 Mar 2020 01:54:40 UTC Bastard Squash <p>With many thanks to <a href="https://www.lexaloffle.com/bbs/?uid=40166">packbat</a> for helping me in the forum, I can finally say my first real cart is complete!</p> <p>I give you: <strong>BASTARD SQUASH</strong>.</p> <p> <table><tr><td> <a href="/bbs/?pid=73884#p"> <img src="/bbs/thumbs/pico8_bastard_squash_v1-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=73884#p"> bastard_squash_v1</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=73884#p"> [Click to Play]</a> </td></tr></table> </p> <p>I don't have any training in programming or math, so this isn't as impressive as most debut carts. Still, we all have to start somewhere! I hope you find something to enjoy in it. Also, don't mind the unused sound samples, and general code inelegance...</p> <h2>Description</h2> <p>Have you ever thought your game of squash needed to hate you a little more? Then do I have a cart for you!</p> <p>Your paddle shrinks with each successive hit. Past certain point thresholds, it also begins to creep toward the ceiling. Extra lives are granted every 300 points, because I love you, even if my game doesn't.</p> <h2>Controls</h2> <ul> <li>LEFT/RIGHT: Move the paddle</li> <li>X (x): Hold to increase paddle speed</li> <li>Z (o): Hold to decrease paddle speed</li> </ul> <p>(EDIT: Added link to packbat's user profile for better crediting.)</p> https://www.lexaloffle.com/bbs/?tid=37061 https://www.lexaloffle.com/bbs/?tid=37061 Fri, 13 Mar 2020 15:33:52 UTC Granting extra lives <p>I'm looking for some advice on how to grant the player extra lives after the score crosses a certain point interval.</p> <p>I've checked a few carts that do this, but I'm not able to make sense of the functions they use, and I was wondering whether anybody had a simple method handy.</p> <p>At the moment, I only have a brute-force method. My cart uses two straightforward variables: &quot;lives&quot; counts the player's lives, and &quot;score&quot; counts the score. Let's say I want to give the player an extra life for every 300 points they score. Right now, I only have this:</p> <div> <div class=scrollable_with_touch style="width:100%; 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 gainlife() if score=300 then lives+=1 elseif score=600 then lives+=1 elseif score=900 then lives+=1 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>It kinda works (assuming the player loses interest in the game after around 1,000 points). But I figure there HAS to be a way to capture the interval in a neater function. Unfortunately, my stupid brain can't figure it out!</p> <p>Thank you for whatever wisdom you have to share.</p> https://www.lexaloffle.com/bbs/?tid=37058 https://www.lexaloffle.com/bbs/?tid=37058 Fri, 13 Mar 2020 04:00:37 UTC New Learning Project: Red Planet Mission <p>Once again using Dylan Bennett's <em>Game Development with PICO-8</em> as the backbone, I've rolled out a new project based on his &quot;Lander&quot; recipe. Presenting <em>Red Planet Mission</em>:</p> <p> <table><tr><td> <a href="/bbs/?pid=73836#p"> <img src="/bbs/thumbs/pico8_yasodahiba-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=73836#p"> yasodahiba</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=73836#p"> [Click to Play]</a> </td></tr></table> </p> <p>I've tweaked the sprites, added a start screen (with art!), and managed to put together menu and gameplay themes.</p> <p>I couldn't figure out how to randomize the star background each time you start up the game, but I'll keep trying.</p> <p>It's quite exciting to have put all the features of PICO-8 to use in a cart! The next step is to do something using my own code next time.</p> https://www.lexaloffle.com/bbs/?tid=37048 https://www.lexaloffle.com/bbs/?tid=37048 Wed, 11 Mar 2020 22:03:08 UTC Unused measures in SFX/music entries <p>Hi everybody,</p> <p>I'm having some difficulty figuring out how to solve a problem with how PICO-8 handles music, and I was wondering whether any of you out there could help me.</p> <p>Let's say I have a few SFX files that I intend to collate into a music composition for my game, like in the following image:</p> <img style="margin-bottom:16px" border=0 src="/media/42956/Music Question.png" alt="" /> <p>Notice that there are a few unused measures for this clip. Let's assume that I have several other clips that are similarly structured.</p> <p>When I try to string these together in the music editor, the system plays all those empty measures like they are rests. But what I would really like to happen is for the music to &quot;jump&quot; directly from the end of the clip to the beginning of the next one.</p> <p>Is there a way to make this happen?</p> <p>Thank you for any and all input!</p> https://www.lexaloffle.com/bbs/?tid=37041 https://www.lexaloffle.com/bbs/?tid=37041 Wed, 11 Mar 2020 04:19:50 UTC First Game Attempt: Bat Cave <p>I sampled PICO-8 for the first time this weekend. Being a rank novice at programming, I have little idea of what I'm doing. Luckily, given the abundance of PICO-8 resources here and elsewhere, I'm learning quickly!</p> <p>Here is my first attempt at a game: a barely modified version of <em>Cave Diver</em> from Dylan Bennett's <em>Game Development with PICO-8</em>. I give you: <em>Bat Cave</em>!</p> <p> <table><tr><td> <a href="/bbs/?pid=73779#p"> <img src="/bbs/thumbs/pico8_dasanidez-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=73779#p"> Bat Cave</a><br><br> by <a href="/bbs/?uid=42956"> Ulexes</a> <br><br><br> <a href="/bbs/?pid=73779#p"> [Click to Play]</a> </td></tr></table> </p> <p>It leaves a bit to be desired as a &quot;game,&quot; but in terms of newbie accomplishments, I'm pretty proud of figuring out how to insert a title screen. That will certainly come in handy later.</p> <p>Here's to producing better games in the future!</p> https://www.lexaloffle.com/bbs/?tid=37029 https://www.lexaloffle.com/bbs/?tid=37029 Mon, 09 Mar 2020 03:57:04 UTC