Log In  

Demo of a missile seeking behavior and a nice flame/smoke effect. Not sure what I would use it for. Code is pretty clean and easy to follow. Toggle random target pos and mouse control with X key.

Uses some code for timers in my snippets repo https://github.com/unstoppablecarl/pico-8-snippets

v2

Cart #52336 | 2018-05-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

v1
Cart #52283 | 2018-05-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

P#52284 2018-05-02 12:20 ( Edited 2018-05-05 17:19)

:: Felice

That is a fantastic plume effect, even disregarding the fact that it's done with a limited, fixed palette. I am jaw-on-floor impressed with that.

The seeking is nice as well.

P#52287 2018-05-02 13:09 ( Edited 2018-05-02 17:09)

Indeed very nice (60 fps mode really shines here).

Edit: ouch! 38% cpu for a single missile - need to find a GPU for Pico ;)

Note: I usual, you can shave a lot of cpu cycle by replacing:

for x in all(xxx) do
...

by:

for _,x in pairs(xxx) do
-- or
for i=1,#xxx do
 local x=xxx[i]
 ...

For this cart, cpu goes from 50% to 38%

P#52299 2018-05-02 16:34 ( Edited 2018-05-02 20:36)

Why is pairs() so much better than all() ?

P#52306 2018-05-02 22:21 ( Edited 2018-05-03 02:21)
:: Felice

Because pairs() is internal to lua, it's able to iterate over the internal hash maps that Lua uses for tables. On the other hand, all() is an iterator written in actual lua and costs about 20x more cycles per iteration.

The tradeoff is that pairs() does not guarantee an ordered traversal, but all() does, which is why it needs some extra wrapper logic.

P#52307 2018-05-03 01:04 ( Edited 2018-05-03 05:04)

In this case I would need to use all() for the draw calls right?? They need to be in order to look right.

P#52314 2018-05-03 07:51 ( Edited 2018-05-03 11:51)
:: Felice

Are they in a sequentially-indexed array? If so, you'd be better off using a numeric for:

 for i=1,#particles do
  particles[i]:update()
 end

This has only a few cycles of overhead, 1 for the loop iteration and (I think) a couple for the array indexing. This, versus 20 for the all() iterator.

You seem to be using add/del to manage your array, so they should be sequentially-numbered.

P#52324 2018-05-03 10:08 ( Edited 2018-05-03 14:08)

just adding to what Felice said:

If I'm not mistaken, the only unique advantage of all() is that you can safely del() items in a table while iterating with it. (besides the token advantage over other loops which is sometimes what matters :p)

nice rocket exhaust btw! :D

P#52338 2018-05-03 16:04 ( Edited 2018-05-03 20:05)

nope - pairs can be iterated while doing adds & dels (doing that all over the place in my particle systems!)

P#52340 2018-05-03 16:57 ( Edited 2018-05-03 20:57)
:: Felice

Agreed, pairs() isn't a sequential iterator, so messing with the sequence won't cause problems.

P#52349 2018-05-03 19:50 ( Edited 2018-05-03 23:50)

ohhhhh got it. wow I don't know why I never realized that XD

actually I think it was probably because the manual specifically notes that you can del() items while using all() and a loong time ago I must have misinterpreted that as saying it was like a distinguishing feature and therefore the primary reason for its existence :p

but I guess the small character-count (and single return value which further contributes to that) is really the biggest distinguishing feature of all()

anyway, sorry to derail the thread

P#52351 2018-05-03 22:27 ( Edited 2018-05-04 02:27)

I thought so too. strange that it is something to be avoided.

P#52415 2018-05-05 13:19 ( Edited 2018-05-05 17:19)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-09-26 02:36 | 0.026s | 2097k | Q:54