Log In  


So, I'm fairly new to Pico 8 (8 days in, lol), and I have some minimal experience with python. I watched a tutorial video on how to place enemy sprites using a placeholder sprite and then replacing it with the sprite intended for that location. It seems that I can get the appropriate sprite to display, but not in the correct location. I'm sure this has something to do with my for() loop to determine the current x,y of the sprite, but I can't seem to see it. This is what I have so far.

Cart #dudijabaj-0 | 2024-07-28 | Code ▽ | Embed ▽ | No License



Taking a look at the code you use to add enemies by map tiles:

function spawn_enemies()
 --add enemies to map screen
 for x=0,15 do
  for y=0,15 do
   if (mget(x,y)==8) add(e_layout,enemies[1])
   if (mget(x,y)==24) add(e_layout,enemies[2])
   if (mget(x,y)==40) add(e_layout,enemies[4])
   if (mget(x,y)==56) add(e_layout,enemies[3])
   for i in all(e_layout) do
    i.x=(x*8)
    i.y=(y*8)
   end
  end
 end
end

Because the loop setting the coordinates (for i in all(e_layout) do) is nested within the loops for all x,y, this inner loop is running 16*16 (256) times over and using the x,y values from the outer loops (the last run of each will always =15, eventually setting all enemy x and y coordinates to (120,120) by the end of these outer loops).

Instead, you'll want to set the enemy's x,y once during the same iteration of the outer loops as they are added, so you can use those x,y iterators from the loops (*8) to set the enemy coords in px.



[Please log in to post a comment]