Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithin P authored and nithinputhenveettil committed Mar 6, 2020
1 parent b848673 commit 98ec3bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

__debug_bin

.vscode/
.vscode/

pong-game-golang
46 changes: 23 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@ const (
)

const (
enterKey = 257
leftArrowKey = 263
enterKey = 257
leftArrowKey = 263
rightArrowKey = 262
)

const (
width int32 = 1000
height int32 = 600
ballSpeed int32 = 8
ballRadius int32 = 25
hitBarSpeed int32 = 14
hitBarLength int32 = 100
hitBarHeight int32 = 25
gameName string = "Nithins's Pong Game!"
width = 1000
height = 600
ballSpeed = 8
ballRadius = 25
hitBarSpeed = 14
hitBarLength = 100
hitBarHeight = 25
gameName = "Nithins's Pong Game!"
)

var (
score int
gameOver bool
hitBarLeft int32
screenSize [2]int32
ballCentreY int32
ballCentreX int32
hitBarLeft int
screenSize [2]int
ballCentreY int
ballCentreX int
ballDirection direction
accelerateLeft bool
accelerateRight bool
)

func resetGame() {
rand.Seed(time.Now().Unix())
screenSize = [2]int32{width, height}
hitBarLeft = screenSize[0]/2 - int32(hitBarLength)/2
screenSize = [2]int{width, height}
hitBarLeft = screenSize[0]/2 - hitBarLength/2
ballCentreY = 150
ballCentreX = rand.Int31n(screenSize[0]-200) + 100
ballCentreX = rand.Intn(screenSize[0]-200) + 100
ballDirection = upLeft
accelerateLeft = false
accelerateRight = false
Expand All @@ -60,16 +60,16 @@ func resetGame() {
}

func drawBall() {
rl.DrawCircle(ballCentreX, ballCentreY, float32(ballRadius), rl.Red)
rl.DrawCircle(int32(ballCentreX), int32(ballCentreY), float32(ballRadius), rl.Red)
}

func drawHitBar() {
rl.DrawRectangle(hitBarLeft, (screenSize[1] - hitBarHeight), hitBarLength, hitBarHeight, rl.Blue)
rl.DrawRectangle(int32(hitBarLeft), int32(screenSize[1]-hitBarHeight), int32(hitBarLength), int32(hitBarHeight), rl.Blue)
}

func litsenKeyboardEvents() {
if rl.IsKeyDown(enterKey) {
if (gameOver) {
if gameOver {
resetGame()
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func moveBall() {
ballCentreX -= ballSpeed
ballCentreY += ballSpeed
} else {
score += 1
score++
ballDirection = upLeft
}
} else if ballCentreY+ballSpeed >= screenSize[1] {
Expand All @@ -138,7 +138,7 @@ func moveBall() {
ballCentreX += ballSpeed
ballCentreY += ballSpeed
} else {
score += 1
score++
ballDirection = upRight
}
} else if ballCentreY+ballSpeed >= screenSize[1] {
Expand Down Expand Up @@ -169,7 +169,7 @@ func moveHitBar() {

func main() {
resetGame()
rl.InitWindow(screenSize[0], screenSize[1], gameName)
rl.InitWindow(int32(screenSize[0]), int32(screenSize[1]), gameName)
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if !gameOver {
Expand Down

0 comments on commit 98ec3bc

Please sign in to comment.