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.

97
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,36 +205,93 @@ 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] = " "
if GoesLEFT {
BallY--
}
if Bally == 9 {
GoesUP = false
}
}
if !GoesUP {
if BallX > 1 {
BallX-- BallX--
if GoesLeft { gameBoard[BallX][BallY] = "o"
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 BallX == 0 {
PrintBoard()
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 BallX < 9 {
gameBoard[BallX][BallY] = " "
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++
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
}
}
} }
} }
} }
}
func Parallelize(functions ...func()) { func Parallelize(functions ...func()) {
var waitGroup sync.WaitGroup var waitGroup sync.WaitGroup