Help on a pong style game

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)

1 Like

Maybe change forever to on game update?

1 Like

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

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!

1 Like

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

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!

1 Like