Sneaking Demo

It’s like a proof of concept and some exts. Not fully in blocks (yet).

  1. FoV (distance and walls)

  1. Patrolling enemies

More details later.

Cheers

8 Likes

The second example with the moving enemy where it even takes into account walls blocking the view is incredible! Great job!

1 Like

For anyone interested, a simply illustration of the basic idea behind sensing with wall is here:

Sprite A can see sprite B if:
a) distance between A and B is less than or equal to range of sensing;
AND
b) there’s no wall between

For a), distance can be calculated by square root of (deltaX^2 + deltaY^2)

For b), consider the following,


in which,

  1. finding the critical points requires some geometric calculation (similar triangles, tan/arctan)
  2. tilemap ext is useful for checking if a certain tile is wall

An interactive demo is here, the line between the sprites is drawn and critical lat/long tiles are colored (lats are purple, longs are red).

Try moving sprites and changing range parameter (set to 128, full screen)

After that, on the shoulder of @richard, the shader ext is useful for showing enemy alert range for player.

4 Likes

I did something else. I had done this by finding the absolute value of the differences in x, to see if it was withing a difference range.

This gives me an error message.

oops, can you post the error here?

Does not want to show anything, so I don’t know. It just won’t run

demo.sight doesn’t work. error:
Line 39: Property ‘toggleTestingTiles’ does not exist on type ‘typeof sight’.

:joy: toogleTestingTiles() was a debugging function and was not exported in the current version. Exported and tagged a version v0.0.2

for some reason this is super confusing
can you explain how I can use this?

To use the detecting instruction
image
an extension is needed.

Try to import the extension by clicking ‘Extensions’

then, paste the extension url “https://github.com/felixtsu/pxt-sight” then hit Enter,

after clicking the extension, the instruction can be dragged from ‘Sprite Sight’ group

sprite , otherSprite are the sprites under detection, following a number indicating the range of sight.

1 Like

Can I ask what the boolean does?

1 Like

I’m in javascript, and I know what everything is but I just don’t know how to use them in the correct order.

The conditional returns true when distance between sprite and othersprite in less than range and there’s no wall between, otherwise false.

Like this?

1 Like