# Help on a pong style game

**URL:** <https://forum.makecode.com/t/help-on-a-pong-style-game/30016>\
**Category:** Help\
**Tags:** game\
**Created:** [August 7, 2024, 10:50pm UTC](https://forum.makecode.com/t/help-on-a-pong-style-game/30016 "2024-08-07T22:50:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tochaeluz](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@tochaeluz](https://forum.makecode.com/u/tochaeluz)\
**Post date:** [August 7, 2024, 10:50pm UTC](https://forum.makecode.com/t/help-on-a-pong-style-game/30016/1 "2024-08-07T22:50:53Z")

</div>

Hello everyone,

I am working on a Pong-style game in MakeCode Arcade and everything was functioning perfectly until I added a tilemap. After integrating the tilemap, the functions `recriarBolaAoAtingirEspacoDoAdversario` (recreateBallUponHittingOpponentArea) and `rebaterAoSairDaTelaNaVertical` (bounceUponLeavingVerticalScreen) stopped working. I suspect that the issue might be related to how the coordinates are handled with the tilemap.

Here’s a brief overview of my setup:

- On start, I set the tilemap and create the players and the ball.
- The game loop continuously checks for certain conditions such as rebounding the ball when it touches the player or the screen edges.
- The functions `recriarBolaAoAtingirEspacoDoAdversario` and `rebaterAoSairDaTelaNaVertical` were functioning correctly before the tilemap was added.

Since adding the tilemap, these functions are no longer behaving as expected. I believe the tilemap might be changing the coordinate system, but I’m not sure how to adjust my code to account for this.

Could anyone provide insights or suggestions on how to resolve this issue?

Thank you for your help!

![arcade-Projeto-Base---SpaceBall---Aula (1)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/f/6/f6040d0255207380b93a2a484f23a91732d1756d.png)

---

<div class="post-metadata">

**Author:** ![NeoStreak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neostreak/32/27498_2.png) [@NeoStreak](https://forum.makecode.com/u/NeoStreak)\
**Post date:** [August 7, 2024, 11:35pm UTC](https://forum.makecode.com/t/help-on-a-pong-style-game/30016/2 "2024-08-07T23:35:30Z")

</div>

Maybe change forever to on game update?

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 8, 2024, 2:04am UTC](https://forum.makecode.com/t/help-on-a-pong-style-game/30016/3 "2024-08-08T02:04:26Z")

</div>

When you switch to using a tilemap, you create a “world” that sprites are not able to leave. Without the tilemap, sprites are able to leave the screen.

In `recriarBolaAoAtingirEspacoDoAdversario()`, you test `if bola.x < 0`, which will never be true with a tile map. (The ball can never leave the screen.) Try `if bola.left = 0` instead. Similarly, test for `if bola.right = screen.width` instead. (Just to make sure I catch the event correctly, I used \<= and \>= operators instead of just =.)

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/c/8/c893079cbb16843f9ab19305701e6804fa85e6a4.png)

Make those changes, and your game should start working the way you are expecting.

Let us know if you still need more help. Nice work! Looks great!

---

<div class="post-metadata">

**Author:** ![tochaeluz](https://avatars.discourse-cdn.com/v4/letter/t/a9a28c/32.png) [@tochaeluz](https://forum.makecode.com/u/tochaeluz)\
**Post date:** [August 8, 2024, 5:06pm UTC](https://forum.makecode.com/t/help-on-a-pong-style-game/30016/4 "2024-08-08T17:06:33Z")

</div>

Hello again,

Thank you for the help! The function `recriarBolaAoAtingirEspacoDoAdversario()` is now working perfectly after the changes. However, I’m still having trouble with the function `rebaterAoSairDaTelaNaVertical()`.

I tried to adjust the conditions similarly by using `top` and `bottom`, but it didn’t resolve the issue. Here is the relevant part of the code:

blocks

```auto
function rebaterAoSairDaTelaNaVertical() {
    if (bola.top <= 0 || bola.bottom >= screen.height) {
        bola.vy = -bola.vy
        music.knock.play()
    }
}

```

Despite these changes, the ball doesn’t bounce back when it reaches the top or bottom of the screen. Could you please provide further guidance on how to correctly handle this with the tilemap?

Thank you again for your assistance!
