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?
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 |
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... ;)
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? ;)
I don't think the API comes with a call to do that. Maybe ask zep to add one. ;)
[Please log in to post a comment]