Log In  

Hello! I'm new to PICO-8 and I'm currently struggling to make a table which my "levels", which has enemies in them. The method I tried :

function make_enemy(x,y)
 a={}
 a.x=x
 a.y=y

 return a
end

function draw_enemy(en)
 circfill(en.x, en.y, 3, 8)
end

enemy1=make_enemy(0,0)
enemy2=make_enemy(120,120)

mapcount=1
maps={
 {enemy1},
 {enemy2},
 {enemy1, enemy2}
}

function _draw()
 foreach(maps[mapcount], draw_enemy)
end

This doesn't seem to work for me.

Could anyone suggest a more reliable way?

P#49696 2018-02-26 00:47 ( Edited 2018-02-27 00:05)

:: Felice

It seems to work for me.

You default to map #1, which only has enemy1 in it.

You create enemy1 at 0,0.

When drawing an enemy, you draw a 3-radius circle.

When I run it, I see the bottom-right corner of the circle drawn at 0,0:

The only thing you seem to be missing is clearing the screen with cls() before you draw your objects. I suspect you just didn't notice your success up in the corner because you still had all the existing cruft on your screen.

To my eye, you're doing it right. :)


Layout tip:

You can initialize a table while creating it, and return it inline:

function make_enemy(x,y)
  return {
    x=x,
    y=y
  }
end
P#49698 2018-02-26 01:13 ( Edited 2018-02-26 06:16)
:: Felice

You know...

I thought about it for a bit, and I thought of a much more efficient form of make_enemy():

function make_enemy(x,y)
  twitter:post("I think "..x.." is better than "..y.."!")
end

I just don't think there's any quicker way to do it.

.

.

.

Sorry... ;)

P#49699 2018-02-26 03:19 ( Edited 2018-02-26 08:19)

I tried your method and it is super fast! Do you have efficient way to remove those enemies? I’m suffering from a buffer overflow and del() doesn’t seem to work? ;)

P#49729 2018-02-26 16:03 ( Edited 2018-02-26 21:03)
:: Felice

I don't think the API comes with a call to do that. Maybe ask zep to add one. ;)

P#49736 2018-02-26 19:05 ( Edited 2018-02-27 00:05)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-09-17 04:15 | 0.023s | 2097k | Q:21