supercurses [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=75425 Using vectors for 1000 entity movement <p>Hello,</p> <p>I have a feeling I don't fully understand vectors. I am thinking of the optimal way to handle the updating of a large number of entities for something like a Vampire Survivors game. Right now, in my testing, parallel arrays appears to have the lowest impact on CPU. 1000 mobs move towards the player and cpu is 0.601, metatables go up to 0.823</p> <p>I tried vectors this morning and my cpu stat is 1.4.</p> <p>Vectors are a bit new to me and I'm wondering if I going about this the right way.</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() mobs={} player={} player.v = vec(240, 130) for i=1, 1000 do local spawn_radius = max(470, 270) / 2 + 50 local player_x, player_y = player.v:get(0, 2) local spawn_x = player_x local spawn_y = player_y local angle = rnd(1) local x = spawn_x + spawn_radius * cos(angle) local y = spawn_y + spawn_radius * sin(angle) v = vec(x, y) add(mobs,{v=v,spd=rnd(0.5)}) end end function _update() for mob in all(mobs) do -- Calculate direction vector (from mob to player) local direction = vec(0, 0) -- Get mob and player positions local mob_x, mob_y = mob.v:get(0, 2) local player_x, player_y = player.v:get(0, 2) -- Create direction vector direction = vec(player_x - mob_x, player_y - mob_y) -- Normalize the direction (make it length 1) local mag = direction:magnitude() if mag &gt; 0 then direction = direction:div(mag) mob.v = mob.v:add(direction:mul(mob.spd)) end end end function _draw() cls() for mob in all(mobs) do local x, y = mob.v:get(0, 2) spr(1, x, y) end print(stat(1), 0, 0, 8) 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=148311 https://www.lexaloffle.com/bbs/?tid=148311 Tue, 08 Apr 2025 08:35:23 UTC Simulating top-down ball rotation <p>Hello,</p> <p>I am simulating a ball being dragged around by a player. I'd like to create some animation to simulate that the ball is rotating (top-down view). I am trying to do that with a light source on top of the ball but I can't quite get it working correctly.</p> <p>Looking for advice or some pointers to good tutorials on this subject. </p> <p>Thanks in advance</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() player = {x=64, y=64} end function _update() local move_x, move_y = 0, 0 if btn(0) then move_x = -1 end if btn(1) then move_x = 1 end if btn(2) then move_y = -1 end if btn(3) then move_y = 1 end -- update player position and animation if move_x != 0 or move_y != 0 then player.x += move_x player.y += move_y end update_ball() end function _draw() cls() rectfill(player.x, player.y, player.x+8, player.y+8, 8) draw_ball() end --ball ball = {x=80, y=80, vx=0, vy=0, length=24, friction=0.9, mass=5, pull_force=0.2} ball.hitbox = {2,2,6,6} ball.name = &quot;ball&quot; ball.radius = 5 -- in ball initialization ball.light_pos = {x = ball.x, y = ball.y} function distance(x1, y1, x2, y2) return sqrt((x2-x1)^2 + (y2-y1)^2) end function update_ball() local dx = ball.x - player.x local dy = ball.y - player.y local dist = distance(ball.x, ball.y, player.x, player.y) if dist &gt; ball.length then local angle = atan2(dx, dy) local pull_strength = (dist - ball.length) * ball.pull_force ball.vx -= cos(angle) * pull_strength ball.vy -= sin(angle) * pull_strength end ball.vx *= ball.friction ball.vy *= ball.friction ball.x += ball.vx ball.y += ball.vy if ball.vx != 0 or ball.vy != 0 then local move_dir_x = ball.vx &gt; 0 and 1 or (ball.vx &lt; 0 and -1 or 0) local move_dir_y = ball.vy &gt; 0 and 1 or (ball.vy &lt; 0 and -1 or 0) ball.light_pos.x += move_dir_x * 0.5 ball.light_pos.y += move_dir_y * 0.5 -- check if light has reached ball edge local light_dist = distance(ball.x, ball.y, ball.light_pos.x, ball.light_pos.y) if light_dist &gt;= ball.radius+1 then -- move light along the direction of movement ball.rolled_under = true ball.roll_under_timer = ball.roll_under_frames -- reposition light on opposite side of ball and continue moving ball.light_pos.x = ball.x - move_dir_x * ball.radius ball.light_pos.y = ball.y - move_dir_y * ball.radius -- immediately continue moving in the same direction ball.light_pos.x += move_dir_x * 0.5 ball.light_pos.y += move_dir_y * 0.5 end end end function draw_ball() line(player.x+4, player.y+4, ball.x, ball.y, 13) circfill(ball.x, ball.y, 5, 1) -- light spot circfill(ball.light_pos.x, ball.light_pos.y, 1, 7) 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=145781 https://www.lexaloffle.com/bbs/?tid=145781 Thu, 28 Nov 2024 10:57:30 UTC How to know what Lua is supported and isn't? <p>In the following code, everything works apart from table.sort(). How would I know that?</p> <p>Also, the only keyword highlighted in the code editor is &quot;sub&quot;</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> s = &quot;hello world&quot; i, j = string.find(s, &quot;hello&quot;) print(i..&quot;:&quot;..j) print(string.sub(s, i, j)) print(string.find(s, &quot;world&quot;)) local t = {} table.insert(t, 1) table.insert(t, 24) for i=1, #t do print(t[i]) end table.sort(t)</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=144442 https://www.lexaloffle.com/bbs/?tid=144442 Fri, 27 Sep 2024 08:08:58 UTC Separation of model / view <p>Hello,</p> <p>I'm a beginner programmer, trying to figure out good practice. To be honest, I get a lot of joy out of refactoring code even though I know it's more important to create something of value. Seems to give my brain comfort.</p> <p>I've been creating a card game and realised that one of my challenges is that I have a card object that has some game logic associated with it but I'm also mixing up a bunch of presentation information on that card. It's getting messy.</p> <p>Which got me thinking about trying to separate concerns. Wondering what the community's view is on an approach like below?</p> <p>The general idea here is that a card needs to know nothing about its presentation (but is linked to its presentation). It's a bidirectional link, a card_view is related to its card.</p> <p>Obviously, in a game where there are not a lot of objects, this might be overkill.</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() renderer = Renderer:new() animator = Animator:new() deck = {} x_offset, y_offset, i = 0, 0, 0 for i=1, 10 do local card = Card:new(i, &quot;Hearts&quot;) local card_view = CardView:new{ card=card, x=15, y=200, target_x=15+x_offset, target_y=106} card.view = card_view renderer:add_drawable(card_view) animator:add_moveable(card_view) add(deck, card) x_offset+=38 end end function _update() if btnp(5) and i&lt;#deck then deck[#deck-i].view.moving = true i+=1 end animator:animate_entities() end function _draw() cls(27) renderer:draw_entities() end Card = {} Card.__index = Card function Card:new(rank, suit) local self = setmetatable({}, CardView) self.name = &quot;Card&quot; self.rank = rank self.suit = suit self.view = nil return self end function Card:update() --lots of game logic to go here end CardView = {} CardView.__index = CardView function CardView:new(options) local self = setmetatable({}, CardView) self.name = &quot;Card View&quot; self.card = options.card self.x = options.x self.y = options.y self.start_x = options.x self.start_y = options.y self.target_x = options.target_x self.target_y = options.target_y self.sp = 1 self.moving = false return self end function CardView:_dist(x1, y1, x2, y2) return sqrt((x2 - x1)^2 + (y2 - y1)^2) end function CardView:update() if self.moving then local dx = self.target_x - self.x local dy = self.target_y - self.y local remaining_distance = sqrt(dx*dx + dy*dy) local total_distance = self:_dist(self.start_x, self.start_y, self.target_x, self.target_y) local traveled_distance = total_distance - remaining_distance if remaining_distance &gt; 1 then local progress = traveled_distance / total_distance -- Move the self self.x += dx * 0.2 self.y += dy * 0.2 -- Check if 85% of the journey is complete if progress &gt;= 0.85 and not self.revealed then self.sp = 2 self.revealed = true end else self.x = self.target_x self.y = self.target_y self.moving = false end end end function CardView:draw() spr(self.sp, self.x, self.y) if self.revealed then print(self.card.suit, self.x+2, self.y+4, 8) print(self.card.rank, self.x+2, self.y+12, 8) end end Renderer = {} Renderer.__index = Renderer function Renderer:new() local self = setmetatable({}, Renderer) self.drawables = {} return self end function Renderer:add_drawable(drawable, zIndex) if type(drawable.draw) ~= &quot;function&quot; then error(&quot;No draw function for &quot;..drawable.name) end drawable.zIndex = zIndex or 0 -- Default to 0 if no zIndex is provided local index = #self.drawables + 1 -- Find the correct position to insert based on zIndex for i=1,#self.drawables do if self.drawables[i].zIndex &gt; drawable.zIndex then index = i break end end -- Insert drawable at the found position for i = #self.drawables + 1, index + 1, -1 do self.drawables[i] = self.drawables[i-1] end self.drawables[index] = drawable end function Renderer:draw_entities() for _, drawable in ipairs(self.drawables) do if type(drawable.draw) ~= &quot;function&quot; then error(&quot;No draw function for &quot;..drawable.name) end drawable:draw() end end Animator = {} Animator.__index = Animator function Animator:new() local self = setmetatable({}, Animator) self.moveables = {} return self end function Animator:add_moveable(moveable) add(self.moveables, moveable) end function Animator:animate_entities() for _, moveable in ipairs(self.moveables) do moveable:update() 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=143972 https://www.lexaloffle.com/bbs/?tid=143972 Sat, 31 Aug 2024 15:02:51 UTC WIP Slay the Spire style pathing map <p>Hello, </p> <p>I've been working on trying to produce a randomly generated map like in Slay the Spire.</p> <p>I used the rules documented here to generate the map:</p> <p><a href="https://steamcommunity.com/sharedfiles/filedetails/?id=2830078257">https://steamcommunity.com/sharedfiles/filedetails/?id=2830078257</a></p> <p>(not convinced these are the whole rules but it's good enough for now)</p> <p>The map is a 7 x 15 grid.<br /> 6 paths are drawn through the grid, the first two paths must be at different starting points, others are random (which gives the branching effect)<br /> Events are placed on the grid as per the weightings specified.<br /> Some rules are obeyed to prevent certain events from appearing in certain places (for example, 2 rest sites in a row are not allowed)<br /> I added some jittering to give the map rendering a more organic look.</p> <p>Controls </p> <p>1) You can scroll up and down the map with the up and down keys.<br /> 2) Hit left and right to select an originating path. Press X to lock in the selection.<br /> 3) Press up to move up that selected path.<br /> 4) While you have a path selected, press left and right to move between valid branches of the path.</p> <p>Seems to be working, although it's an awful lot of code, I need to look for some optimisations next.</p> <p>Any comments, or suggestions welcome.</p> <p> <table><tr><td> <a href="/bbs/?pid=152642#p"> <img src="/bbs/thumbs/pico8_yuzuhutuba-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=152642#p"> yuzuhutuba</a><br><br> by <a href="/bbs/?uid=75425"> supercurses</a> <br><br><br> <a href="/bbs/?pid=152642#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=143664 https://www.lexaloffle.com/bbs/?tid=143664 Wed, 14 Aug 2024 17:47:17 UTC Minit Survivors WIP <p>Very much WIP using some of the graphical style/themes from Mint in a Vampire Survivors style game.</p> <p>WIP has:</p> <ul> <li>2 characters with different modifiers</li> <li>6 weapons and 1 passive item. weapons and passives have level upgrade modifiers</li> <li>A wave spawner (but it spawns the same stuff every wave - need more mob types)</li> <li>Boss mobs drop a chest that will drop a random upgrade to an item in your inventory</li> <li>Standard mobs drop xp, hitting the target xp for the level triggers a shop where you are offered 3 items (with some weighting towards items you already own)</li> </ul> <p>&quot;O&quot; button does everything.</p> <p>TODO:</p> <ul> <li>refactor for performance, I think I can improve collision handling</li> <li>a proper map, thinking an infinite map like vampire survivors</li> <li>scaling of mobs with XP</li> <li>more items</li> <li>more enemy types</li> <li>probably refactor how I am doing classes, it's getting messy.</li> <li>bugs, probably lots of them</li> <li>everything else</li> </ul> <p> <table><tr><td> <a href="/bbs/?pid=147772#p"> <img src="/bbs/thumbs/pico64_diphwezu-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=147772#p"> diphwezu</a><br><br> by <a href="/bbs/?uid=75425"> supercurses</a> <br><br><br> <a href="/bbs/?pid=147772#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=142080 https://www.lexaloffle.com/bbs/?tid=142080 Thu, 02 May 2024 13:30:30 UTC Have an object circle around a moving player <p>Hello, I have this code that circles an object around the player position.</p> <p>It works well if the player stands still, but if the player moves the trajectory of the object goes a bit wonky. it sort of stops, or looks like it wants to go in the other direction for a bit.</p> <p>How can I make it smoothly rotate around the player?</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> local player = self.game_context.player local orbit_radius = 40 -- Distance from player to orbiting projectile local orbit_speed = self.speed -- Normalized speed of orbit; consider this as fraction of a circle per frame for p in all(self.projectiles) do p.angle += orbit_speed if (p.angle &gt; 360) p.angle = 0 p.x = player.x + (player.attributes.w / 2) + orbit_radius * cos(p.angle/360) p.y = player.y + (player.attributes.h / 2) + orbit_radius * sin(p.angle/360) -- Handle projectile duration and collision p.duration -= 1 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=142046 https://www.lexaloffle.com/bbs/?tid=142046 Tue, 30 Apr 2024 15:18:19 UTC Problems importing a sprite sheet <p>Hello,</p> <p>I feel like I am being a bit thick this morning.</p> <p>I have a 128 x 128 sprite sheet as a .png.</p> <p>I've tried importpng and the pictron exporter from asesprite. both exhibit the same behaviour, when I paste from the clipboard the whole image fills sprite 0 and sets its size to 128 x 128, I'm expecting the image to start at sprite 0 and fill outwards. Am I missing something obvious?</p> <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/75425/SCR-20240429-jwtd.png" alt="" /> <p>thanks in advance</p> https://www.lexaloffle.com/bbs/?tid=142024 https://www.lexaloffle.com/bbs/?tid=142024 Mon, 29 Apr 2024 09:35:30 UTC Referencing tables before they are created <p>Hello, considering the following:</p> <p>Trying to remake Vampire Survivors and a fun project<br /> I have a character class<br /> Characters have effects that are applied to a target. In this example my target = player<br /> I have a character that is an instance of that class. Let's call him &quot;Antonio&quot;<br /> I have a &quot;run&quot;, Antonio is copied into run.player<br /> I set player to be run.player</p> <p>My problem is that I have to initiate the character class and Antonio before I create &quot;player&quot;. But player is not yet created so player referenced on the character class is nil.</p> <p>I hope this makes sense, I have a workaround but it feels clunky and I'm wondering if there are other solutions.</p> <p>Here is my code before the workaround:</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> character = {} character.__index = character function character:new(name) local o = setmetatable({}, character) o.name = name o.x = 0 o.y = 0 o.sp_scale = 1 o.w = 16 o.h = 16 o.effects = effects o.original_invincibility_frames = 10 o.invincibility_frames = 0 o.max_health = 100 o.health = 20 o.recovery = 0 o.armor = 0 o.move_speed = 1 o.might = 1 o.weapon_projectile_speed = 0 o.weapon_duration = 0 o.weapon_area = 0 o.weapon_cooldown = 0 o.weapon_projectiles_amount = 0 o.revival = 0 o.magnet = 0 o.luck = 0 o.growth = 0 o.greed = 0 o.curse = 0 o.reroll = 0 o.skip = 0 o.banish = 0 return o end function character:set_effects(effects) self.effects = effects end function character:apply_effects(level) local effects = self.effects for _, effect in pairs(effects) do if level % effect.level_increment == 0 and level &lt;= effect.max_level_increment then local target = effect.target if effect.mode == &quot;percent&quot; then target[effect.stat] += (target[effect.stat] or 0) * effect.value else target[effect.stat] = (target[effect.stat] or 0) + effect.value end end end end antonio = character:new(&quot;antonio&quot;) antonio.recovery = 0.5 antonio:set_effects( { { description=&quot;Gains 10% Might every 2 Levels&quot;, stat = &quot;might&quot;, value = 1, target = player, -- here is the problem, player doesn't exist level_increment = 2, max_level_increment = 10, mode = &quot;percent&quot; }, { description=&quot;Gains 0.5 Recovery every 1 level&quot;, stat = &quot;recovery&quot;, value = 0.5, target = player, level_increment = 1, max_level_increment = 5 } } ) function _init() t = 0 run = {} run.player = {} run.level = 1 add(run.player, deepcopy(antonio)) player = run.player[1] end function _update() if t % 60 == 0 then player.health += player.recovery end if btnp(4) then run.level += 1 player:apply_effects(run.level) end t += 1 end function _draw() local y = 0 cls(0) for entry in all(run.player) do for k, v in pairs(entry) do if type(v) == &quot;number&quot; then print(k..&quot;:&quot;..v, 0, y) y += 8 end end end local y = 0 print(&quot;Level: &quot;..run.level, 240, y) end function deepcopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in next, orig, nil do copy[deepcopy(orig_key)] = deepcopy(orig_value) end setmetatable(copy, getmetatable(orig)) else -- for numbers, strings, booleans, etc copy = orig end return copy 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>And here is my code with the workaround, in short, once player is created I go and apply player as the target of the effects: player:update_effects_target(player)</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>character = {} character.__index = character function character:new(name) local o = setmetatable({}, character) o.name = name o.x = 0 o.y = 0 o.sp_scale = 1 o.w = 16 o.h = 16 o.effects = effects o.original_invincibility_frames = 10 o.invincibility_frames = 0 o.max_health = 100 o.health = 20 o.recovery = 0 o.armor = 0 o.move_speed = 1 o.might = 1 o.weapon_projectile_speed = 0 o.weapon_duration = 0 o.weapon_area = 0 o.weapon_cooldown = 0 o.weapon_projectiles_amount = 0 o.revival = 0 o.magnet = 0 o.luck = 0 o.growth = 0 o.greed = 0 o.curse = 0 o.reroll = 0 o.skip = 0 o.banish = 0 return o end function character:set_effects(effects) self.effects = effects end function character:update_effects_target(target) for _, effect in pairs(self.effects) do effect.target = target end end function character:apply_effects(level) local effects = self.effects for _, effect in pairs(effects) do if level % effect.level_increment == 0 and level &lt;= effect.max_level_increment then local target = effect.target if effect.mode == &quot;percent&quot; then target[effect.stat] += (target[effect.stat] or 0) * effect.value else target[effect.stat] = (target[effect.stat] or 0) + effect.value end end end end antonio = character:new(&quot;antonio&quot;) antonio.recovery = 0.5 antonio:set_effects( { { description=&quot;Gains 10% Might every 2 Levels&quot;, stat = &quot;might&quot;, value = 1, target = player, -- here is the problem, player doesn't exist level_increment = 2, max_level_increment = 10, mode = &quot;percent&quot; }, { description=&quot;Gains 0.5 Recovery every 1 level&quot;, stat = &quot;recovery&quot;, value = 0.5, target = player, level_increment = 1, max_level_increment = 5 } } ) function _init() t = 0 run = {} run.player = {} run.level = 1 add(run.player, deepcopy(antonio)) player = run.player[1] player:update_effects_target(player) end function _update() if t % 60 == 0 then player.health += player.recovery end if btnp(4) then run.level += 1 player:apply_effects(run.level) end t += 1 end function _draw() local y = 0 cls(0) for entry in all(run.player) do for k, v in pairs(entry) do if type(v) == &quot;number&quot; then print(k..&quot;:&quot;..v, 0, y) y += 8 end end end local y = 0 print(&quot;Level: &quot;..run.level, 240, y) end function deepcopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in next, orig, nil do copy[deepcopy(orig_key)] = deepcopy(orig_value) end setmetatable(copy, getmetatable(orig)) else -- for numbers, strings, booleans, etc copy = orig end return copy 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=141922 https://www.lexaloffle.com/bbs/?tid=141922 Wed, 24 Apr 2024 10:32:02 UTC Grid based partitioning for collision detection <p>Hello,</p> <p>For fun, I'm building a Vampire Survivors style game. There will be a lot of mobs on screen, so I've built a grid partitioning system and each weapon only checks for collisions with mobs nearby.</p> <p>The grid size is 30, so that's a 16 x 9 grid. </p> <p>My question is this, currently, I'm initialising the grid on every frame and re-populating all the mob positions into their grids.</p> <p>Should I move to initialising just once and updating mob positions in the grid on every frame? I'm not sure whether that will actually be quicker because I will have to delete the mob from one grid position and add it to another.</p> <p>Also, that seems hard to implement :-)</p> <p>Thanks in advance</p> <p>Russ</p> <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/75425/SCR-20240417-pabq.png" alt="" /> https://www.lexaloffle.com/bbs/?tid=141783 https://www.lexaloffle.com/bbs/?tid=141783 Wed, 17 Apr 2024 15:45:15 UTC Knuckle Dice v1.3 <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/75425/matrixv1_1_1.png" alt="" /> <p> <table><tr><td> <a href="/bbs/?pid=126787#p"> <img src="/bbs/thumbs/pico8_rikazogoye-3.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=126787#p"> Knuckle Dice v1.3</a><br><br> by <a href="/bbs/?uid=75425"> supercurses</a> <br><br><br> <a href="/bbs/?pid=126787#p"> [Click to Play]</a> </td></tr></table> </p> <h1>Knuckle Dice v1.3</h1> <p>Knuckle Dice is an attempt to recreate Knuckle Bones from Cult of the Lamb. This is my first programming project ever so there's no AI yet - it's two player only to begin with.</p> <p>In the future I will try to add:</p> <ul> <li>CPU AI (DONE)</li> <li>I want to experiment with perfect information. In other words, remove the randomness and tell the player exactly what the opponent is about to play.</li> </ul> <p>Controls</p> <ul> <li>z to start/restart</li> <li>x to play a dice</li> </ul> <p>Rules/Game Logic</p> <ul> <li>Maximum 3 dice in one column</li> <li>Playing a die in a column that matches dice in the opposing player's column removes all instances of that dice</li> <li>When nine dice are played by either player the game ends</li> </ul> <p>Scoring</p> <ul> <li>You receive points equivalent to the die played multiplied by the number of instances of that dice. (e.g a 5 played twice in one column will give you twenty points - 2*(5+5)</li> <li>The player with the most points wins</li> </ul> <p>v1.1 Updates</p> <ul> <li>Changed GFX to more of a 1bit style</li> </ul> <p>v1.3 Updates</p> <ul> <li>Now it's a single player game with some rudimentary AI for P2</li> </ul> https://www.lexaloffle.com/bbs/?tid=51916 https://www.lexaloffle.com/bbs/?tid=51916 Wed, 08 Mar 2023 16:14:07 UTC