Log In  

Cart #sazewewawa-0 | 2020-07-16 | Code ▽ | Embed ▽ | No License
1

Press O to move towards the white dot, press X to shoot from the red dot.

I had an idea for a game where you would press a button to accelerate in one direction and press another button to shoot in the opposite direction as you automatically rotate. It ended up being a lot less fun to play than I thought it would be, but there might be some potential here if I flesh it out a bit.

I also ran into some weird runtime errors that I couldn't quite figure out. At first I thought it might be crashing because of the exact position that the bullet hits the target, but I think it might actually be bullets getting removed from the master table of bullets and their indexes getting all janked up. I'll probably have to rewrite the way the table is handled in order to stop this from happening.

P#79398 2020-07-16 04:32 ( Edited 2020-07-16 04:37)

Interesting control mechanism - it feels like a game jam restriction 'only two buttons' or the recent 'out of control'.

Re: I also ran into some weird runtime errors ...

I don't think the runtime error I ran into was your bullets table. I could be wrong but, looking at this:

 for t=#target,1,-1 do
  for i=#bullets,1,-1 do
   if mid(target[t].x-2,bullets[i].x,target[t].x+9)==bullets[i].x
   and mid(target[t].y-2,bullets[i].y,target[t].y+9)==bullets[i].y
   then
    kill_target(t)
    del(bullets,bullets[i])
   end
  end
 end

I think it's because you kill off your target in the inner loop.

Minimal case error reproduction:

  • two bullets, one target
  • fire first bullet to miss but still be on screen
  • fire second bullet to hit, and hit before other goes off screen
--variable tracking of code
--not usable code

--inner loop:

if target[1] etc bullet[2] etc
kill_target[1]

--function kill_target(1)
 score+=1
 del(target,target[1])
--return control to loop

 del(bullets,bullets[2])
-- there is one bullets left, bullet[1]

--next iteration of inner loop

if target[1] etc bullet[1] etc

--target[1] does not exist --> crash

Edit:

You could try break in the inner loop.

Pre-edit I mentioned a probably unnecessary technique of marking the target for destruction. Here I think break will be enough. Click show to see my previous suggestion anyway:

I'm guessing that if you just mark the target to be destroyed in the inner loop, then destroy it in the outer loop, this particular crash should be resolved.

Untested code, but maybe something like:

 for t=#target,1,-1 do
  local kill=false
  for i=#bullets,1,-1 do
   if mid(target[t].x-2,bullets[i].x,target[t].x+9)==bullets[i].x
   and mid(target[t].y-2,bullets[i].y,target[t].y+9)==bullets[i].y
   then
    kill=true
    del(bullets,bullets[i])
   end
  end
  if (kill) kill_target(t)
 end

All guesswork; I could be wrong with the above (but hopefully not).

P#79420 2020-07-16 16:28 ( Edited 2020-07-17 06:17)

[Please log in to post a comment]