# \[SOLVED\] Reflective Shield - Python

**URL:** <https://discourse.codecombat.com/t/solved-reflective-shield-python/31776>\
**Category:** Level Help\
**Created:** [January 13, 2022, 1:13pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776 "2022-01-13T13:13:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 13, 2022, 1:13pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/1 "2022-01-13T13:13:45Z")

</div>

The problem that I am facing is with dealing damage to Nalfar. I tried all the numbers from 0.1 through 0.8 for “z” in the reflect method, no use. I successfully reflect it towards him, but zero damage.

[Link to level](https://codecombat.com/play/level/reflective-shield?) (sub)  
Here is my code:

```python
# Use hero.reflect() to reflect back Nalfar's projectiles!

while True:
    enemy = hero.findNearestEnemy()
    missile = hero.findEnemyMissiles()[0]
    direction = Vector.normalize(Vector.subtract(enemy.pos, hero.pos))
    if missile and hero.distanceTo(missile) < 5:
        hero.reflect(Vector(direction.x, direction.y, 0.5))

```

---

<div class="post-metadata">

**Author:** ![Anonym](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/anonym/32/47546_2.png) [@Anonym](https://discourse.codecombat.com/u/Anonym)\
**Post date:** [January 13, 2022, 1:38pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/2 "2022-01-13T13:38:37Z")

</div>

sadly this level is not loading for me ☹

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/2/d/2d1ffc1f4ad9a7f378879bfddffda0ee428494ee.jpeg)

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 13, 2022, 1:40pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/3 "2022-01-13T13:40:53Z")

</div>

okay … maybe you can try using Illia if you have her, because the level is made to use her reflect ability … and thanks for trying to help

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 13, 2022, 9:38pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/4 "2022-01-13T21:38:27Z")

</div>

> [@Aya](#):
>
> ```python
> enemy = hero.findNearestEnemy()
> missile = hero.findEnemyMissiles()[0]
> 
> ```

Don’t need to find the nearest enemy. Find all missiles, it should return an array. Use a for loop to run through the missiles array and check is a missile exists before reflecting it. You don’t need to check the distance.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 14, 2022, 6:30am UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/5 "2022-01-14T06:30:52Z")

</div>

But what should I fill in the reflect?

That’s the code for now:

```python
while True:
    missiles = hero.findEnemyMissiles()
    for missile in missiles:
        if missile:
            hero.reflect(Vector(x, y, z))

```

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 14, 2022, 11:49am UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/6 "2022-01-14T11:49:04Z")

</div>

```python
hero.reflect(Vector(direction.x, direction.y, 1.9))

```

It’s what you had except the z value is different.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 14, 2022, 4:54pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/7 "2022-01-14T16:54:40Z")

</div>

It sends it too high. more than 0.8 is too high, less that 0.2 is too low, what’s in between hits Nalfar but does no damage

```python
while True:
    enemy = hero.findNearestEnemy()
    missiles = hero.findEnemyMissiles()
    direction = Vector.normalize(Vector.subtract(enemy.pos, hero.pos))
    for missile in missiles:
        if missile:
            hero.reflect(Vector(direction.x, direction.y, 1.9))

```

(nearest enemy is to find direction, which is for reflect, i dunno what else to do)

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 14, 2022, 5:03pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/8 "2022-01-14T17:03:34Z")

</div>

> [@Aya](#):
>
> ```python
> while True:
> missiles = hero.findEnemyMissiles()
> for missile in missiles:
> if missile:
> hero.reflect(Vector(x, y, z))
> 
> ```

You have this already but you need to add this line of code right before the reflect statement:

```python
direction = Vector.subtract(missile.pos, hero.pos)

```

You don’t need to use enemy in your code, because enemy is irrelevant. For reflect reflect direction.x and direction.y and experiment with z values.

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 14, 2022, 5:08pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/9 "2022-01-14T17:08:33Z")

</div>

Ah okay, will do (20chars)

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [January 14, 2022, 5:11pm UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/10 "2022-01-14T17:11:24Z")

</div>

It worked, i didn’t need to change the z value from 1.9  
Thank you @abc

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [January 15, 2022, 5:12am UTC](https://discourse.codecombat.com/t/solved-reflective-shield-python/31776/11 "2022-01-15T05:12:00Z")

</div>

Closed on January 15, 2022, 5:12am UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
