Pong: How does the paddle know where the ball will hit?

后端 未结 7 2064
旧巷少年郎
旧巷少年郎 2021-02-05 04:16

After implementing Pacman and Snake I\'m implementing the next very very classic game: Pong.

The implementation is really simple, but I just have one little problem rema

7条回答
  •  悲&欢浪女
    2021-02-05 05:17

    I'm not sure what the 'official' way to do this is, but I've always just used (pseudocode)

    if (ball is above paddle) {
        move paddle up
    }
    if (ball is below paddle) {
        move paddle down
    }
    

    Then I gave the paddle a slightly varying speed that was slow enough that it couldn't always keep up with the ball. Kind of crude, but it works.

    This thread also has some interesting ideas you might want to look at: http://www.gamedev.net/community/forums/topic.asp?topic_id=439576

提交回复
热议问题