Port 2 Controller Input (buttons always registered as "pressed")

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Port 2 Controller Input (buttons always registered as "pressed")

Post by Pokun »

Maybe the parent/child sprite view is a bit confusing.
Just think of the metasprite as an object. You have 3 objects in Pong: left paddle (p1), right paddle (p2) and a ball. So you would have variables for p1_x, p1_y, p1_speed, p2_x, p2_y, p2_speed, ball_x, ball_y ball_speed_x and ball_speed_y or something like that. In your logic you process the physics solely based on these values as well as on the width and height of each of the objects (which you have in constants or more variables) to make movement and collisions work correctly. When you move a paddle up you don't move any sprites up, just decrement the paddle's current Y-position value and that's it.

Then in a separate routine you do sprite updates for all objects. Here you just draw each sprite based on their current positions and the sprite part. So p1 top paddle sprite is drawn at coordinate (p1_x, p1_y) while p1 bottom part is drawn at coordinate (p1_x, p1_y+8) and so on.

Now the logic code is totally separate from the sprite update code. The sprites are just part of the visual representation of the game. Even if you comment out the whole sprite update routine, the game should still work and be fully playable, only that you won't be able to see where the ball and paddles are (blind-Pong!), but the ball should bounce correctly on walls and paddles and the score should increment correctly whenever you score a point.
Post Reply