# Sneaking Demo

**URL:** https://forum.makecode.com/t/sneaking-demo/4961
**Category:** Arcade
**Tags:** game
**Created:** [December 12, 2020, 12:52am UTC](https://forum.makecode.com/t/sneaking-demo/4961 "2020-12-12T00:52:51Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [December 12, 2020, 12:52am UTC](https://forum.makecode.com/t/sneaking-demo/4961/1 "2020-12-12T00:52:51Z")

</div>

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

> **[sneaking.demo](https://arcade.makecode.com/97022-62922-00013-89813)**
>
> 用❤️创造，Microsoft MakeCode Arcade出品。

1. FoV (distance and walls)  
 ![pz0j6-nl3mk](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e527a7a54e549a614ff349ccdadb12a2e4081fa8.gif)

 ![hpcbo-hpk1z](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/ad197286cf0a93222cdfe06b0c60b1edbb5b5d4f.gif)

> **[felixtsu/pxt-sight](https://github.com/felixtsu/pxt-sight)**
>
> MakeCode 项目. Contribute to felixtsu/pxt-sight development by creating an account on GitHub.

1. Patrolling enemies

> **[felixtsu/pxt-waypoint-ext](https://github.com/felixtsu/pxt-waypoint-ext)**
>
> A MakeCode project. Contribute to felixtsu/pxt-waypoint-ext development by creating an account on GitHub.

More details later.

Cheers

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [December 12, 2020, 1:28am UTC](https://forum.makecode.com/t/sneaking-demo/4961/2 "2020-12-12T01:28:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [December 12, 2020, 2:48am UTC](https://forum.makecode.com/t/sneaking-demo/4961/3 "2020-12-12T02:48:06Z")

</div>

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,

 ![Image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/1287f63793fd218ef814202eda01ad0bf02c4121.jpeg)  
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).

> **[demo.sight](https://arcade.makecode.com/03708-34411-82502-44363)**
>
> 用❤️创造，Microsoft MakeCode Arcade出品。

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

After that, on the shoulder of @richard, [the shader ext](https://forum.makecode.com/t/shader-extension/4860) is useful for showing enemy alert range for player.

---

<div class="post-metadata">

### Author: ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)
#### Post date: [December 19, 2020, 4:41am UTC](https://forum.makecode.com/t/sneaking-demo/4961/4 "2020-12-19T04:41:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)
#### Post date: [December 19, 2020, 5:19pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/5 "2020-12-19T17:19:51Z")

</div>

This gives me an error message.

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [December 20, 2020, 12:19am UTC](https://forum.makecode.com/t/sneaking-demo/4961/6 "2020-12-20T00:19:01Z")

</div>

oops, can you post the error here?

---

<div class="post-metadata">

### Author: ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)
#### Post date: [December 20, 2020, 3:13am UTC](https://forum.makecode.com/t/sneaking-demo/4961/7 "2020-12-20T03:13:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MasterOfTheYeets](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@MasterOfTheYeets](https://forum.makecode.com/u/MasterOfTheYeets)
#### Post date: [February 3, 2021, 4:24pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/8 "2021-02-03T16:24:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [February 4, 2021, 1:07am UTC](https://forum.makecode.com/t/sneaking-demo/4961/9 "2021-02-04T01:07:19Z")

</div>

> [@MasterOfTheYeets](#):
>
> toggleTestingTiles

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

> **[demo.sight](https://arcade.makecode.com/05238-50967-53731-56569)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![brandodon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brandodon/32/3625_2.png) [@brandodon](https://forum.makecode.com/u/brandodon)
#### Post date: [March 24, 2021, 1:49am UTC](https://forum.makecode.com/t/sneaking-demo/4961/10 "2021-03-24T01:49:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [March 26, 2021, 3:33pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/11 "2021-03-26T15:33:52Z")

</div>

To use the detecting instruction  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/8b21863b09cc2923529d3a676cd7ea6c8d89a98b.png)  
an extension is needed.

Try to import the extension by clicking ‘Extensions’

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/1d0cb984a9ad780cb1e58b2a588b33e9c74220e2.png)

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/ef08e5e99576596a01a4661ff655d0fe0e9c1215.png)

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/779dd90a2a98b38a8e79113ca5e657996c4196c8.png)

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

---

<div class="post-metadata">

### Author: ![Agent\_14](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/agent_14/32/17567_2.png) [@Agent\_14](https://forum.makecode.com/u/Agent_14)
#### Post date: [March 26, 2021, 4:20pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/12 "2021-03-26T16:20:12Z")

</div>

Can I ask what the boolean does?

---

<div class="post-metadata">

### Author: ![brandodon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brandodon/32/3625_2.png) [@brandodon](https://forum.makecode.com/u/brandodon)
#### Post date: [March 26, 2021, 7:04pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/13 "2021-03-26T19:04:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [March 27, 2021, 2:23am UTC](https://forum.makecode.com/t/sneaking-demo/4961/14 "2021-03-27T02:23:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)
#### Post date: [March 27, 2021, 2:23am UTC](https://forum.makecode.com/t/sneaking-demo/4961/15 "2021-03-27T02:23:27Z")

</div>

> [@brandodon](#):
>
> the

Like this?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/adbd95fcefb23b3bf470520807ae4177cc97f60b.png)

---

<div class="post-metadata">

### Author: ![Stickman4269](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/stickman4269/32/23582_2.png) [@Stickman4269](https://forum.makecode.com/u/Stickman4269)
#### Post date: [January 5, 2025, 8:16pm UTC](https://forum.makecode.com/t/sneaking-demo/4961/16 "2025-01-05T20:16:47Z")

</div>

I’m trying to use the directional version but in a demo I made it only works under specific circumstances like whether or not I’m moving clockwise, but then it swaps directions sometimes.

> **[Sight Test](https://arcade.makecode.com/S19608-68174-27810-91665)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.
