func (p *Pong) Update(s Screen, keys Keys) {
	// Update Ball position
	p.ball.x = p.ball.x + p.ball.speed*p.ball.xVel
	p.ball.y = p.ball.y + p.ball.speed*p.ball.yVel

	// Check Colisions

	// Walls
	if (p.ball.y + p.ball.h) >= s.Height() {
		p.ball.yVel = -1
	}

	if p.ball.y <= 0 {
		p.ball.yVel = 1
	}

	// Computer
	if (p.ball.x+p.ball.w) >= p.computer.x &&
		(p.ball.y+p.ball.h/2) >= p.computer.y &&
		(p.ball.y) <= (p.computer.y+p.computer.h) {

		p.ball.xVel = -1
	}

	// Player
	if p.ball.x <= (p.player.x+p.player.w) &&
		(p.ball.y+p.ball.h/2) >= p.player.y &&
		p.ball.y <= (p.player.y+p.player.h) {

		p.ball.xVel = 1
	}

	// Dumb Computer AI
	// Middle of the screen
	if p.ball.x > s.Width()/2 {
		if p.ball.y < (p.computer.y + p.ball.h) {
			if p.computer.y >= 0 {
				p.computer.Up()
			}
		} else {
			if p.computer.y <= s.Height()-p.computer.h {
				p.computer.Down()
			}
		}
	}

	// Points

	if p.ball.x > p.computer.x {
		p.player.points++

		p.reset(s)
	}

	if p.ball.x <= 0 {
		p.computer.points++

		p.reset(s)
	}

	// Keyboard
	if keys.IsDown(keyUp) {
		if p.player.y >= 0 {
			p.player.Up()
		}
	}

	if keys.IsDown(keyDown) {
		if p.player.y <= s.Height()-p.player.h {
			p.player.Down()
		}
	}
}
// Update, Check colisions and update the game state
Update, Check colisions and update the game state
// Update Check colisions and update the game state
func (p *Pong) Update(s Screen, keys Keys) {
	p.ball.x = p.ball.x + p.ball.speed*p.ball.xVel
	p.ball.y = p.ball.y + p.ball.speed*p.ball.yVel
	if (p.ball.y + p.ball.h) >= s.Height() {
		p.ball.yVel = -1
	}
	if p.ball.y <= 0 {
		p.ball.yVel = 1
	}
	if (p.ball.x+p.ball.w) >= p.computer.x &&
		(p.ball.y+p.ball.h/2) >= p.computer.y &&
		(p.ball.y) <= (p.computer.y+p.computer.h) {
		p.ball.xVel = -1
	}
	if p.ball.x <= (p.player.x+p.player.w) &&
		(p.ball.y+p.ball.h/2) >= p.player.y &&
		p.ball.y <= (p.player.y+p.player.h) {
		p.ball.xVel = 1
	}
	if p.ball.x > s.Width()/2 {
		if p.ball.y < (p.computer.y + p.ball.h) {
			if p.computer.y >= 0 {
				p.computer.Up()
			}
		} else {
			if p.computer.y <= s.Height()-p.computer.h {
				p.computer.Down()
			}
		}
	}
	if p.ball.x > p.computer.x {
		p.player.points++
		p.reset(s)
	}
	if p.ball.x <= 0 {
		p.computer.points++
		p.reset(s)
	}
	if keys.IsDown(keyUp) {
		if p.player.y >= 0 {
			p.player.Up()
		}
	}
	if keys.IsDown(keyDown) {
		if p.player.y <= s.Height()-p.player.h {
			p.player.Down()
		}
	}
}
func ( p * Pong ) Update ( s Screen , keys Keys ) { p . ball . x = p . ball . x + p . ball . speed * p . ball . xVel p . ball . y = p . ball . y + p . ball . speed * p . ball . yVel if ( p . ball . y + p . ball . h ) >= s . Height ( ) { p . ball . yVel = - 1 } if p . ball . y <= 0 { p . ball . yVel = 1 } if ( p . ball . x + p . ball . w ) >= p . computer . x && ( p . ball . y + p . ball . h / 2 ) >= p . computer . y && ( p . ball . y ) <= ( p . computer . y + p . computer . h ) { p . ball . xVel = - 1 } if p . ball . x <= ( p . player . x + p . player . w ) && ( p . ball . y + p . ball . h / 2 ) >= p . player . y && p . ball . y <= ( p . player . y + p . player . h ) { p . ball . xVel = 1 } if p . ball . x > s . Width ( ) / 2 { if p . ball . y < ( p . computer . y + p . ball . h ) { if p . computer . y >= 0 { p . computer . Up ( ) } } else { if p . computer . y <= s . Height ( ) - p . computer . h { p . computer . Down ( ) } } } if p . ball . x > p . computer . x { p . player . points ++ p . reset ( s ) } if p . ball . x <= 0 { p . computer . points ++ p . reset ( s ) } if keys . IsDown ( keyUp ) { if p . player . y >= 0 { p . player . Up ( ) } } if keys . IsDown ( keyDown ) { if p . player . y <= s . Height ( ) - p . player . h { p . player . Down ( ) } } }
Update, Check colisions and update the game state
Update Check colisions and update the game state
// Update Ball position // Check Colisions // Walls // Computer // Player // Dumb Computer AI // Middle of the screen // Points // Keyboard