AndyGFX [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=14190 Picolunky (level generator) <p> <table><tr><td> <a href="/bbs/?pid=26303#p"> <img src="/bbs/thumbs/pico26378.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=26303#p"> Picolunky 0.6</a><br><br> by <a href="/bbs/?uid=14190"> AndyGFX</a> <br><br><br> <a href="/bbs/?pid=26303#p"> [Click to Play]</a> </td></tr></table> </p> <p><strong>Update: </strong></p> <p>added function fixstages to TMap class, for prevent unreachable platforms from pattern in stage. Implementation is very simple and you can extend method as you wich. Currently is checked only &quot;platform&quot; tile id. </p> <p><strong>Method:</strong></p> <p>From generated POI point is created connection to free edge in stage and remove platform tiles between connected stages if exist.</p> <p> <table><tr><td> <a href="/bbs/?pid=26303#p"> <img src="/bbs/thumbs/pico26301.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=26303#p"> Picolunky 0.5</a><br><br> by <a href="/bbs/?uid=14190"> AndyGFX</a> <br><br><br> <a href="/bbs/?pid=26303#p"> [Click to Play]</a> </td></tr></table> </p> <p>This example show procedural level building combined from two method:<br /> 1) maze generator - for wall<br /> 2) predefined pattern - for stages (platform, ladder, obstacles, ...)</p> <p>Every room is created from 2x2 stage, and stage is defined in sprite as template, where color index = tile id descibed in data structure:</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> self.template[0] = {name=&quot;empty&quot; ,color=1,tile=self.starttile+0,probability=1.0} self.template[1] = {name=&quot;wall&quot; ,color=2,tile=self.starttile+1,probability=1.0} self.template[2] = {name=&quot;platform&quot; ,color=3,tile=self.starttile+2,probability=1.0} self.template[3] = {name=&quot;breakable&quot;,color=4,tile=self.starttile+3,probability=0.5} self.template[4] = {name=&quot;obstacle&quot; ,color=5,tile=self.starttile+4,probability=0.5} self.template[5] = {name=&quot;ladder&quot; ,color=6,tile=self.starttile+5,probability=1.0} self.template[6] = {name=&quot;item&quot; ,color=7,tile=self.starttile+6,probability=0.5} self.template[7] = {name=&quot;exit&quot; ,color=8,tile=self.starttile+7,probability=1.0} self.template[8] = {name=&quot;hazard&quot; ,color=9,tile=self.starttile+8,probability=1.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>Maze is generated in stages count and walls are implemebted as wall to stage.</p> <p><strong>Control</strong><br /> [z] = generate new maze with wall<br /> [x] = generate new order of patterns in stages<br /> arrow=scroll map</p> https://www.lexaloffle.com/bbs/?tid=3985 https://www.lexaloffle.com/bbs/?tid=3985 Tue, 02 Aug 2016 05:19:33 UTC Marching squares <p> <table><tr><td> <a href="/bbs/?pid=25739#p"> <img src="/bbs/thumbs/pico25738.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=25739#p"> Marching squares</a><br><br> by <a href="/bbs/?uid=14190"> AndyGFX</a> <br><br><br> <a href="/bbs/?pid=25739#p"> [Click to Play]</a> </td></tr></table> </p> <p>Hi</p> <p>here is my next cartridge which is combination of my previous <a href="https://www.lexaloffle.com/bbs/?tid=3883">Cellular automata class</a> and Marching squares technique for generate procedural platform or top-down levels.</p> <p>Control:<br /> [z] tileset type #1<br /> [x] tileset type #2<br /> [arrows] scroll map</p> <p><em>Note: source code is't optimized for tokens for now</em></p> <p>AndyGFX</p> https://www.lexaloffle.com/bbs/?tid=3905 https://www.lexaloffle.com/bbs/?tid=3905 Fri, 22 Jul 2016 18:05:56 UTC Cellular automata <p> <table><tr><td> <a href="/bbs/?pid=25620#p"> <img src="/bbs/thumbs/pico25628.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=25620#p"> Cellular automata class</a><br><br> by <a href="/bbs/?uid=14190"> AndyGFX</a> <br><br><br> <a href="/bbs/?pid=25620#p"> [Click to Play]</a> </td></tr></table> </p> <p> <table><tr><td> <a href="/bbs/?pid=25620#p"> <img src="/bbs/thumbs/pico25619.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=25620#p"> Cellular automata</a><br><br> by <a href="/bbs/?uid=14190"> AndyGFX</a> <br><br><br> <a href="/bbs/?pid=25620#p"> [Click to Play]</a> </td></tr></table> </p> <p>Hellou, </p> <p>I think this is a very useful for everyone, who want create procedural maps.</p> <p><em>Press Z key few times for smooth 'caves'.</em></p> <p>EDIT: example is now as class.</p> <p>How to:</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> ... cave = TCellular:New() cave:Generate(128,116,0.6,4,5,5) ... function DrawMap() for xm=1,cave._w do for ym=1,cave._h do if (cave:Map(xm,ym)==0) pset(xm,ym,0) if (cave:Map(xm,ym)==1) pset(xm,ym,7) 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>AndyGFX.</p> https://www.lexaloffle.com/bbs/?tid=3883 https://www.lexaloffle.com/bbs/?tid=3883 Wed, 20 Jul 2016 10:40:44 UTC Actors and Actor as class ... <p>Hi,</p> <p>here is example how to write lua code more as OOP using metatable and user defined callbacks for update and draw per actor.</p> <p>Note: Plane sprite is created as sprite 2x1 on sprite id 1 and 2.</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> -- Actors+Actor CLASSes -- andygfx - cubesteam - 2016 -- Define TActors container class --------------------------------------------- TActors = {} -- TActors CONSTRUCTOR function TActors:New() o = { list={} } setmetatable(o, self) self.__index = self return o end -- TActors methods ------------------------------------------------------------ -- add actor to Actors list function TActors:Add(actor) add(self.list,actor) end -- delete actor from Actors list function TActors:Del(actor) del(self.list,actor) end -- return count of actors in list function TActors:Count() return #self.list end -- call user defined update method on all actors in list function TActors:Update() for a in all(self.list) do if a.enable then a:update() end end end -- call user defined draw method on all actors in list function TActors:Draw() for a in all(self.list) do if a.enable then a:draw() end end end -- Define TActor class -------------------------------------------------------- TActor = {} -- TActor CONSTRUCTOR --------------------------------------------------------- function TActor:New() o = { name=&quot;actor&quot;, enable=true, visible=true, x = 0, y = 0, _x = 0, _y = 0, sprite = 0, sx = 1, sy = 1, dx = 0, dy = 0, update = function() end, draw = function() end } setmetatable(o, self) self.__index = self return o end -- METHODS -- set actor fields function TActor:Set(name,sprID,x,y,w,h,dx,dy) self.name=name self.sprite=sprID self.x=x self.y=y self._x=x self._y=y self.sx=w self.sy=h self.dx=dx self.dy=dy end -- set actor update and draw callback function TActor:SetCallback(fncUpdate,fncDraw) self.update = fncUpdate self.draw = fncDraw end -- respawn acgtor to start position function TActor:Respawn() self.x=self._x self.y=self._y end -- pico8 callbacks ------------------------------------------------------------ function _init() end function _update() Actors:Update() end function _draw() cls() Actors:Draw() end -- TEST ACTORS ---------------------------------------------------------------- -- create Actors container Actors=TActors:New() -- user defined UPDATE callback for actor function UpdatePlane(self) self.x+=self.dx self.y+=self.dy if self.x&gt;128 then self:Respawn() end end -- user defined DRAW callback fro actor function DrawPlane(self) spr(self.sprite,self.x,self.y,self.sx,self.sy) end -- create actor#1 plane1 = TActor:New() plane1:Set(&quot;plane1&quot;,1,10,20,2,1,1,0) plane1:SetCallback(UpdatePlane,DrawPlane) Actors:Add(plane1) -- create actor#2 plane2 = TActor:New() plane2:Set(&quot;plane2&quot;,1,10,35,2,1,2,0) plane2:SetCallback(UpdatePlane,DrawPlane) Actors:Add(plane2) -- create actor#3 plane3 = TActor:New() plane3:Set(&quot;plane3&quot;,1,10,50,2,1,3,0) plane3:SetCallback(UpdatePlane,DrawPlane) Actors:Add(plane3) </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=3847 https://www.lexaloffle.com/bbs/?tid=3847 Sat, 16 Jul 2016 12:20:17 UTC