3

Cart #43609 | 2017-08-25 | Code ▽ | License: CC4-BY-NC-SA
3

This cartridge is an exploration about 'how to show things to the player'.
Arrow keys to move, [O] button (usually Z/W key on qwerty/azerty keyboard) to change the view mode.
Sometime, I just make pico stuffs for the pleasure to scratch my head... :-)

P#43610 2017-08-25 12:51 ( Edited 2017-08-27 11:45)

:: Felice

Is it basically raycasting with limited depth?

P#43614 2017-08-25 13:52 ( Edited 2017-08-25 17:52)
:: Felice

I was looking at the code and wanted to share some information about Lua that I think is awesome.

Lua's boolean operators can return non-boolean results:

• a or b will return a if it is not nil or false, otherwise b.

• a and b will return a if it is nil or false, otherwise b.

Notice they simply return one of the inputs, rather than coercing the result into a boolean. They only return a boolean if the returned input is a boolean.

If you know C/C++, then you're probably familiar with the ?: operator, which does what your iif() does. You can simulate that with AND/OR:

a ? b : c == a and b or c

Therefore, you can replace iif() with less code that's more readable (to me):

 ```function iif(c,t,f) return c and t or f end ```

Or, instead of calling v=iif(c,t,f), simply inline the v=c and t or f logic at the call site.

As an aside, this is great for optional arguments:

 ```function error(s,c) color(c or 8) -- supplied color or red if not supplied print(s) end ```

Sorry for the long post, but when I found out Lua worked this way, it made me happy, so I wanted to pass on the knowledge. :)

P#43615 2017-08-25 14:16 ( Edited 2017-08-25 18:26)
:: jihem

> Is it basically raycasting with limited depth?
I made a function to draw each pixel of a line (Bresemham). I have shown a sample of use at the picoscope 2017. It's a basic raycasting without optimization. This has been used as tutorial (for young and less young peoples).

> a ? b : c == a and b or c
Yes, it's a good tip for pico8 but... You'd better not take the habit to use it because with compiled languages (*) you may have no control of the order of the evaluation. So if, a,b and c are functions : b() can be called first, rather than a(), to evaluate the and operator. I fell into this trap (for the + operator) : http://monkeycoder.co.nz/forums/topic/rval-eval-order/

So take care... This tip can be language and/or platform specific...
;-)

Thanks for the advice. It's very kind to help other people.

(*) c++ 11 respects the order for 'and', 'or' and '?'.

P#43631 2017-08-26 03:44 ( Edited 2017-08-26 08:01)
:: Felice

Oh absolutely, that tip was very specific to Lua.

A good language will do it the same way, though not as conveniently if the types are not dynamic.

C/C++ does boolean short-circuiting pretty well. I've often done this sort of thing:

 ```if (s!=nullptr && s->blah) { // ... } ```

Because I know evaluation will stop before s->blah if s==nullptr.

Unfortunately, C/C++ boolean logic results are coerced to true/false, so the nifty default-value trick wouldn't work:

 ```color( c || 8 ); ```

That'd just pass true, always. Probably give a compiler warning, in fact, e.g. "boolean expression is const."

P#43632 2017-08-26 04:23 ( Edited 2017-08-26 08:29)
:: jihem

Yes

Nice to meet you. I like the catridge you made with the boing ball like the Amiga demo.
I like what you have done with pico8 and the way you do it.

Mine is @wdwave

Have a good day
jihem

P#43634 2017-08-26 06:44 ( Edited 2017-08-26 10:46)
:: Felice

I don't really use twitter. The format frustrates me. :) I avoid social media in general. I just hover over forums that interest me.

I should point out that someone else made the majority of that Boing demo. All I did was tweak a few things and the sfx to make it as faithful as possible, since I loved my Amiga back in the day and I always thought the Boing demo was amazing. Now I know they were cheating, but it's still amazing for being clever. :) Anyway, I wouldn't want to take credit for something I didn't do.

P#43638 2017-08-26 11:30 ( Edited 2017-08-26 15:31)

I like it... You could easily turn it into a proper "Bat Simulator" by (1) removing the ability to "turn on the light" and (2) having a moving target (say a juicy moth ;-) that you must chase while avoiding obstacles.

P#43672 2017-08-27 07:45 ( Edited 2017-08-27 11:45)