Peej [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=56501 Whats wrong with my sky? <p>Hello all.<br /> I'm probably missing something really important but I'm trying to put a gradient sky on my game.<br /> I spotted some code I thought would do the trick in another thread.</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>poke(0x5f5f,0x3c) -- 0x3c is the colour of the blue sky to be replaced. pal({[0]=0x82,0x82,0x84,0x84,4,4,0x89,0x89,0x8e,0x8e,0x8f,0x8f,15,15,0x87,0x87},2) memset(0x5f70,0xaa,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's supposed to do a sunset gradient-styled sky, but I only get this:</p> <img style="margin-bottom:16px" border=0 src="/media/56501/GameGrab.png" alt="" /> <p>Editing the colours in the table result in the same!</p> <p>Ideally, I'd like it different shades of blue as in the other example, but I'll cross that bridge later.</p> <p>Can someone please help out with what I'm doing wrong?</p> <p>Thanks in advance</p> https://www.lexaloffle.com/bbs/?tid=53845 https://www.lexaloffle.com/bbs/?tid=53845 Tue, 22 Aug 2023 20:47:55 UTC Leading 0s <p>Hello all...<br /> I've been looking up how to have leading 0s on my score displayed on screen.<br /> Some of the explanations I've seen look very complicated.</p> <p>How difficult is it to have, say 00050 rather than just 50 displayed as the player score.</p> <p>Thanks</p> <p>Peej</p> https://www.lexaloffle.com/bbs/?tid=45389 https://www.lexaloffle.com/bbs/?tid=45389 Wed, 17 Nov 2021 22:35:09 UTC Embarrassing. Circle fill code question <p>Hello again.<br /> Following on from the other topic where I ask what I've done wrong to break my Pico-8 install....<br /> I have this code that does a circle fill cross fade:</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 invcircfill(r,c) local r2=r*r color(c) for j=0,127 do local y=64-j local x=sqrt(max(r2-y*y)) rectfill(0,j,64-x,j) rectfill(64+x,j,127,j) 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>In the DRAW function I have this, that I also pilfered:</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>invcircfill(90*abs(cos(time()/4)),0)</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 bit obviously calls the function but I'm not sure how it works.<br /> It bounces in and out on a loop.</p> <p>Would someone WAY more advance than I, please explain what I should have instead of that call to make the circle either expand once or contract one.</p> <p>Thanks again</p> <p>Peej</p> https://www.lexaloffle.com/bbs/?tid=45257 https://www.lexaloffle.com/bbs/?tid=45257 Sat, 06 Nov 2021 00:17:39 UTC Visual Studio Code <p>Hello all.<br /> I have a problem suddenly with Visual Studio Code and I hope I've not broken something.</p> <p>I found a nice bit of code on the BBS that did a circular cross fade and copied it over to my project.</p> <p>When I run it through Visual Studio Code it says &quot;WARNING NO PERMANENT STORAGE&quot;</p> <p>Then the game runs.</p> <p>When I load PICO-8 it loads up fine and lets me load and run my game.</p> <p>Does anyone know what I've done wrong??</p> <p>I just hope it's not going to stop saving or just go ca-ca after so much work being put into it.</p> <p>Thanks for your time.</p> https://www.lexaloffle.com/bbs/?tid=45256 https://www.lexaloffle.com/bbs/?tid=45256 Fri, 05 Nov 2021 23:59:13 UTC Untderstanding If..Then..Else <p>Hi guys:<br /> This is kinda embarrassing but I'm not 100% sure how ELSE works.</p> <p>If an if condition is originally TRUE, does the ELSE say &quot;Well I'll do this is it's FALSE&quot;?</p> <p>c=&quot;ORANGE&quot;<br /> IF c=&quot;ORANGE&quot; then print &quot;YES&quot; (This is definitely true)<br /> ELSE print &quot;NO&quot; (Somewhere in the code, c changes to APPLE)</p> <hr /> <p>But what about OR comparisons?</p> <p>c=&quot;ORANGE&quot;<br /> IF c=&quot;PLUM&quot; OR c=&quot;GRAPE&quot; then then print &quot;YES&quot;<br /> ELSE print &quot;NO&quot; (It does this line because c is NEITHER PLUM or GRAPE)</p> <hr /> <p>I think that's correct so far. But I get a bit stuck on ELSEIF</p> <p>c=&quot;ORANGE&quot; b=&quot;APPLE&quot;<br /> IF c=&quot;PLUM&quot; OR c=&quot;GRAPE&quot; then then print &quot;YES&quot;<br /> ELSEIF b=&quot;APPLE&quot; print &quot;THIS LINE!&quot;</p> <p>Does the psudo code above confirm the fact that c is NOT PLUM or GRAPE but sees that b is APPLE so runs that and prints &quot;THIS LINE!&quot;</p> <p>It's hard to explain why I get stuck. I hope someone gets what I'm trying to ask.</p> <p>Cheers</p> https://www.lexaloffle.com/bbs/?tid=44976 https://www.lexaloffle.com/bbs/?tid=44976 Wed, 13 Oct 2021 22:07:07 UTC Simplify <p>Hello all.<br /> Can any of you clever folk make this code shorter?<br /> It's bugging the life out of me but I don't know how to make it shorter though it looks like it can be.<br /> Cheers.</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> --p.c= n / 2 + 0.5 ? if (p.t/p.die&lt;7/#p.c_table) p.c=4 if (p.t/p.die&lt;5/#p.c_table) p.c=3 if (p.t/p.die&lt;3/#p.c_table) p.c=2 if (p.t/p.die&lt;1/#p.c_table) p.c=1</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=44953 https://www.lexaloffle.com/bbs/?tid=44953 Mon, 11 Oct 2021 18:13:54 UTC Untitled <p>Hi guys.<br /> I just thought I'd share what I have achieved so far.<br /> Not much, I know, but it's slow progress.</p> <p>Arrows, left and right to run.<br /> Z to double jump/stomp on ground.<br /> X to jump</p> <p>I'm not overly happy with the bounce about that the bad guys to when they get ground stomped.<br /> Sometimes they bounce too high and long, other times, hardly at all.<br /> I have no idea how to fix that!</p> <p>The spider, finding the highest level through a gap, I'm quite pleased with.</p> <p>Have a looky, see what you think.</p> <p>Cheers</p> <p> <table><tr><td> <a href="/bbs/?pid=98064#p"> <img src="/bbs/thumbs/pico8_zukizuzomi-4.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=98064#p"> hyperwip #4</a><br><br> by <a href="/bbs/?uid=56501"> Peej</a> <br><br><br> <a href="/bbs/?pid=98064#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=44839 https://www.lexaloffle.com/bbs/?tid=44839 Thu, 30 Sep 2021 20:58:56 UTC X and Y problem <p>Hi guys.<br /> I have an enemy that moves towards the player.<br /> I have the usual set up with DX, DY, X, Y. Where X and Y are the co-ordinates of enemy, DX &amp; DY are the direction of movement.<br /> I thought it would be good to have it set up like this:</p> <p>e.dx and e.dy are the enemies dx and dy.<br /> e.x and e.y are the enemies x and y cords.</p> <p>plyr.x and plyr.y are the players co-ords...</p> <p>If the plyr.x MINUS the enemy.x is a positive sign in the result, move the dx 1 or right.<br /> If the plyr.x MINUS the enemy.x is a negative sign in the result, move the dx negative 1 or left.</p> <p>If the plyr.y, minus 2 (so the enemy is slightly higher) MINUS the enemy.y is a positive sign in the result, move the dy 1 or down.<br /> If the plyr.y, minus 2 (so the enemy is slightly higher) MINUS the enemy.y is a negative sign in the result, move the dy -1 or up.</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>e.dx=sgn(plyr.x-e.x) e.dy=sgn((plyr.y-2)-e.y)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>This works very well and I was pleased with myself for shortening the code.</p> <p>However, my problem is (especially on the y) that if the enemy and the player are the same y value, the enemy wiggles up and down and the sign of the maths goes -1,1,-1,1,-1,1,-1 etc...</p> <p>I seem to remember there's something I'm missing to stop the enemy 'vibrating' like this when the coodinates are the same but can't remember what it is.<br /> Would someone please help as I'm a bit lost.</p> <p>Cheers.</p> https://www.lexaloffle.com/bbs/?tid=44803 https://www.lexaloffle.com/bbs/?tid=44803 Tue, 28 Sep 2021 22:25:03 UTC Circular particle exp &amp; password <p>Hello all...<br /> Two things I want to ask about but don't think it'd justify two separate threads.</p> <p>1/ Can someone explain how to do a particle explosion thing that emits in a circular pattern?<br /> I've experimented with particles for dust etc. but thought it might be nice to have a pickup emit a circular particle system when picked up. I don't know how to work with the x and y for each particle.</p> <p>2/ Can someone point me to a tutorial or code, or whatever for those old school passcode systems for level/life/score saves. I wanted to have a system in their as a homage to games gone by that one would type in a 5 digit passcode and it would carry on the game where you left off. Like Bubble Bobble used to have.</p> <p>Thanks for your time.<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=44550 https://www.lexaloffle.com/bbs/?tid=44550 Tue, 07 Sep 2021 20:19:23 UTC Delete from a table <p>Me again, sorry.<br /> I have a table called ENEMY that holds... well enemies.<br /> Every thing works as want so far apart from deleting from the table.</p> <p>I have two enemies at the moment.<br /> Number 1 is a snake.<br /> Number 2 is a spider.</p> <p>Then I have this to kill them off:</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> for en=1,#enemy do -- this line below stops working if box_hit(enemy[en].x,enemy[en].y) then if enemy[en].mode==&quot;patrole&quot; then plyr.hit_enemy = true plyr.struck_by_x=enemy[en].x end if enemy[en].mode==&quot;dead&quot; then plyr.hit_enemy = false end if enemy[en].mode==&quot;pickup&quot; then plyr.hit_enemy = false score+=enemy[en].score del(enemy,enemy[en]) 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>If I kill the spider first, it works.<br /> If I kill the sname first it throws an error attempt to index field '?' a nil value.</p> <p>I put it down to the DEL line at the end.<br /> Does it look correct or is there more to deleting from a table than I know of?</p> <p>Many thanks<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=44348 https://www.lexaloffle.com/bbs/?tid=44348 Sun, 22 Aug 2021 22:13:48 UTC Map and screen boundries <p>Hello all...<br /> Would someone be kind enough to point me in the direction of where I should be looking to solve my screen boundary problem.</p> <p>I'm slowly working on a scrolling platform game and all's working quite well. I have bad guys that bounce about when they get hit. I wanted to have these bouncing guys hit and bounce back from the screen edge when they collide rather than the map edge. Much like having a wall all around the area you're currently looking at.</p> <p>I may be over thinking it but... when the screen scrolls to the left, for example, is the left most edge of the screen still 0 or is there some sort of display edge I should be looking into??</p> <p>Thanks in advance and I hope this makes sense.</p> <p>Cheers.<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=44325 https://www.lexaloffle.com/bbs/?tid=44325 Fri, 20 Aug 2021 21:59:29 UTC Maths problem. Calculating middle <p>Hello all...<br /> I have a maths problem.</p> <p>I have two points, t1 &amp; t2 that I want to find the centre of.<br /> t1 &amp; t2 are two point on the x axis.<br /> Another object's x approaches this middle point.<br /> I have this so far:</p> <p>if flr(self.x+3) == abs(self.t1-self.t2)/2+abs(self.t1)</p> <p>t1 minus t2 divided by 2 giving half the distance between the two, added on to t1.</p> <p>This works if t1 is smaller than t2.</p> <p>But it doesn't work if t2 is smaller than t1, because the the 'middle point' is off to the right of t2!!</p> <p>Can anyone suggest a better formula for getting the middle of two points regardless of which one is smaller?</p> <p>I'm stumped.</p> <p>Many thanks for your time and I hope this makes sense....</p> <p>Peej</p> https://www.lexaloffle.com/bbs/?tid=44182 https://www.lexaloffle.com/bbs/?tid=44182 Wed, 11 Aug 2021 20:48:31 UTC Saving token / characters <p>Hello all.<br /> I'm doing alright at the moment with the new Pico-8 and I'm typing away happily.<br /> One problem though.... I seem to be typing 'self' a LOT and using loads of valuable characters and/or tokens.</p> <p>Is there a simple way to cut back on the number of times I have to use 'self'?</p> <p>Its probably really complicated and I thought I was doing well...</p> <p>Many thanks in advance<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=43912 https://www.lexaloffle.com/bbs/?tid=43912 Wed, 21 Jul 2021 21:42:55 UTC Trying to understand tables <p>Hello all, again.<br /> I'm trying to get my head around tables.<br /> I thought it would be a good idea to store a table of the possible modes and enemy can be in, chase, pause, detect etc.<br /> So the enemy could only be in one mode at a time without all the if statements.</p> <p>I tried 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 add_new_enemy(x,y,type) add(enemy,{ mode={}, add(mode,{1,2,3}), x=x, y=y.... etc.</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Adding a table called 'mode' with values 1,2,3 (All in the name of experimentation.)</p> <p>Similar to the last problem I asked about, I'm trying to just print the first value of 'mode'.<br /> In the _draw I 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>print(enemy[1].mode[1])</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 that print NIL</p> <p>What am I doing wrong? is my table all wrong are is my print statement wrong?</p> <p>Many thanks<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=43865 https://www.lexaloffle.com/bbs/?tid=43865 Sat, 17 Jul 2021 22:16:33 UTC How do I get this variable out? <p>Embarrassing question but please be gentle. I'm very new to all this.<br /> I have this code: (Lower down there). It's a bit mock up really for this question.</p> <p>Lower down still in my code I'm working on a collision detection bit that needs, among other things, the value of x.<br /> As you can see, it's all referencing 'self' and I have NO IDEA how to get the x value from this line: </p> <p>spr(17,self.x,self.y,1,1,false)</p> <p>Would someone please help a noob out.</p> <p>Many thanks<br /> Peej</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 add_new_enemy() add(enemy,{ x=80, y=96, w=8, h=8, dx=rnd(2)-1, dy=rnd(2)-1, life=20, draw=function(self) spr(17,self.x,self.y,1,1,false) end, update=function(self) self.x+=self.dx self.y+=self.dy self.life-=1 if self.life&lt;0 then del(enemy,self) 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> https://www.lexaloffle.com/bbs/?tid=43824 https://www.lexaloffle.com/bbs/?tid=43824 Thu, 15 Jul 2021 00:15:22 UTC Is my particle code garbage? <p>Hello all.<br /> I'm brand new to all things Pico 8, having dabbled with programming since the 80s.<br /> I'm having LOTS of problems though.</p> <p>I added particles to my platform player.<br /> I saw a tutorial about adding objects and function within them, so I tried to change my particle system.<br /> It broke. The error says: Unclosed { but I can't find where I've gone wrong.<br /> I apologise if this isn't how to post code on this.<br /> Can someone help out, please. (This is trimmed down in the hope I don't over stay my welcome!)</p> <p>function _init()<br /> ....<br /> particle={}<br /> end</p> <p>function add_new_particle(x,y,die,dx,dy,grav,grow,shrink,r,c_table)<br /> add(particle,{<br /> x=x,<br /> y=y,<br /> t=0,<br /> die=die,<br /> dx=dx,<br /> dy=dy,<br /> grav=grav,<br /> grow=grow,<br /> shrink=shrink,<br /> r=r,<br /> c=0,<br /> c_table=c_table</p> <pre><code> draw=function(self) if self.r&lt;=1 then pset(self.x,self.y,self.c) else circfill(self.x,self.y,self.r,self.c) end end, update=function(self) self.x+=self.dx self.y+=self.dy if self.grav then self.dy+=.5 end if self.grow then self.r+=.1 end if self.shrink then self.r-=.2 end self.t+=1 if self.t&gt;self.die then del(particle,self) end if self.t/self.die &lt; 1/#self.c_table then self.c=self.c_table[1] elseif self.t/self.die &lt; 2/#self.c_table then self.c=self.c_table[2] elseif self.t/self.die &lt; 3/#self.c_table then self.c=self.c_table[3] else self.c=self.c_table[4] end end }) end function dust() add_new_particle(plyr.x,plyr.y,10+rnd(7),rnd(2)-1,rnd(.3)-.4,false,true,true,3,{4,4,5,5}) end function runs() add_new_particle(plyr.x,plyr.y,10+rnd(7),rnd(2)-1,rnd(1)-0.5,false,false,true,2,{4,4,5,5}) end</code></pre> <p>When the player lands on a platform, I have this: But it doesn't get this far.<br /> dust()<br /> sfx(0)</p> <p>I haven't even figured what to put in the _draw function yet.</p> <p>I hope this isn't too much to see what I'm trying to do and makes a bit of sense to someone.<br /> Thanks for your time.<br /> Peej</p> https://www.lexaloffle.com/bbs/?tid=43787 https://www.lexaloffle.com/bbs/?tid=43787 Mon, 12 Jul 2021 21:51:51 UTC