Dodalem mini fizyke

This commit is contained in:
knmarcin 2018-11-22 22:55:41 +01:00
parent 9984e8af4d
commit d1076fc4a2
2 changed files with 78 additions and 19 deletions

BIN
Pong

Binary file not shown.

81
Pong.go
View File

@ -23,11 +23,13 @@ var GameOver bool = false
var LastPressedKey rune var LastPressedKey rune
var BallX, BallY int var BallX, BallY int
var BallDirX, BallDirY int var BallDirX, BallDirY int
var GoesUP bool = true
var GoesLEFT bool = true
func main() { func main() {
SpawnEverything() SpawnEverything()
for !GameOver { for !GameOver {
Ball() TickBall()
} }
} }
@ -203,33 +205,90 @@ func Ball() {
func TickBall() { func TickBall() {
BallX = 4 BallX = 4
BallY = 14 BallY = 17
for !GameOver { for !GameOver {
if GoesUP { if GoesUP {
if BallX < 9 { if BallX > 0 {
BallX++ gameBoard[BallX][BallY] = " "
BallX--
gameBoard[BallX][BallY] = "o"
if GoesLEFT { if GoesLEFT {
gameBoard[BallX][BallY] = " "
BallY-- BallY--
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
} }
if Bally == 9 { if !GoesLEFT {
gameBoard[BallX][BallY]= " "
BallY++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
if BallX == 0 {
PrintBoard()
GoesUP = false GoesUP = false
} }
if BallY == 1 {
if gameBoard[BallX+1][BallY-1] == "|" {
GoesLEFT = false
} else {
fmt.Print("Game Over")
GameOver = true
}
}
if BallY == 29 {
GoesLEFT = true
}
}
} }
if !GoesUP { if !GoesUP {
if BallX > 1 { if BallX < 9 {
BallX-- gameBoard[BallX][BallY] = " "
if GoesLeft { BallX++
gameBoard[BallX][BallY] = "o"
PrintBoard()
if GoesLEFT {
gameBoard[BallX][BallY] = " "
BallY--
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1* time.Second)
}
if !GoesLEFT {
gameBoard[BallX][BallY] = " "
BallY++ BallY++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
if BallY == 1 {
if gameBoard[BallX][BallY -1] == "|" {
GoesLEFT = false
} else {
fmt.Print("Game Over")
GameOver = true
} }
} }
if BallY == 29 {
GoesLEFT = true
}
if BallX == 9 {
GoesUP = true
}
if BallY == 0 {
GoesLEFT = false
}
if BallY == 29 {
GoesLEFT = true
}
} }
} }
} }
} }