diff --git a/bf.go b/bf.go index 2499ee3..c6704c3 100644 --- a/bf.go +++ b/bf.go @@ -74,10 +74,7 @@ func drawPaint() { func drawSquares() { for index, element := range squares { - if debug { - fmt.Println(index, element.X) - } - + debugLog(debug, fmt.Sprintln(index, element.X)) rl.DrawRectangleV(element, rl.Vector2{X: float32(squareSize), Y: float32(squareSize)}, rl.LightGray) } } @@ -93,25 +90,17 @@ func moveBall() { if rl.IsKeyDown(rl.KeyS) { speed += 2 } - if rl.IsKeyDown(rl.KeyRight) { - if !checkCollision(rl.Vector2{X: ballpos.X + float32(speed), Y: ballpos.Y}) { - ballpos.X = ballpos.X + float32(speed) - } + if rl.IsKeyDown(rl.KeyRight) && !checkCollision(rl.Vector2{X: ballpos.X + float32(speed), Y: ballpos.Y}) { + ballpos.X = ballpos.X + float32(speed) } - if rl.IsKeyDown(rl.KeyLeft) { - if !checkCollision(rl.Vector2{X: ballpos.X - float32(speed), Y: ballpos.Y}) { - ballpos.X = ballpos.X - float32(speed) - } + if rl.IsKeyDown(rl.KeyLeft) && !checkCollision(rl.Vector2{X: ballpos.X - float32(speed), Y: ballpos.Y}) { + ballpos.X = ballpos.X - float32(speed) } - if rl.IsKeyDown(rl.KeyUp) { - if !checkCollision(rl.Vector2{X: ballpos.X, Y: ballpos.Y - float32(speed)}) { + if rl.IsKeyDown(rl.KeyUp) && !checkCollision(rl.Vector2{X: ballpos.X, Y: ballpos.Y - float32(speed)}) { ballpos.Y = ballpos.Y - float32(speed) - } } - if rl.IsKeyDown(rl.KeyDown) { - if !checkCollision(rl.Vector2{X: ballpos.X, Y: ballpos.Y + float32(speed)}) { - ballpos.Y = ballpos.Y + float32(speed) - } + if rl.IsKeyDown(rl.KeyDown) && !checkCollision(rl.Vector2{X: ballpos.X, Y: ballpos.Y + float32(speed)}) { + ballpos.Y = ballpos.Y + float32(speed) } } diff --git a/debughandler.go b/debughandler.go new file mode 100644 index 0000000..f1c9a3e --- /dev/null +++ b/debughandler.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func debugLog(debug bool, print string) { + if debug { + fmt.Println(print) + } +} + +/* +TODO: add other debuging code here so it's be more simple to read bf.go +*/