Compare commits
No commits in common. "fa37a4740b8eb88a1304e56dd762f3c85a91f700" and "f0ad3157f34e3c8216f9339337bfbe9a566912a1" have entirely different histories.
fa37a4740b
...
f0ad3157f3
10
game.go
10
game.go
@ -19,10 +19,10 @@ func gameinit() {
|
|||||||
// Quit the screen
|
// Quit the screen
|
||||||
quit(&game)
|
quit(&game)
|
||||||
|
|
||||||
// fmt.Println("\nDebug time: Trash")
|
fmt.Println("\nDebug time: Trash")
|
||||||
// for i, t := range game.trash {
|
for i, t := range game.trash {
|
||||||
// fmt.Println("Trash: ", i, t)
|
fmt.Println("Trash: ", i, t)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Give closure
|
// Give closure
|
||||||
if game.gameover == 1 {
|
if game.gameover == 1 {
|
||||||
@ -165,7 +165,7 @@ func (game *Game) keyboardProcessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func quit(game *Game) {
|
func quit(game *Game) {
|
||||||
// game.screen.Clear()
|
game.screen.Clear()
|
||||||
maybePanic := recover()
|
maybePanic := recover()
|
||||||
game.screen.Fini()
|
game.screen.Fini()
|
||||||
if maybePanic != nil {
|
if maybePanic != nil {
|
||||||
|
52
robots.go
52
robots.go
@ -43,28 +43,21 @@ func (game *Game) moveRobots() {
|
|||||||
// After all the moves, lets check if any of the rowboz collided with anything
|
// After all the moves, lets check if any of the rowboz collided with anything
|
||||||
for i, r := range game.robots {
|
for i, r := range game.robots {
|
||||||
|
|
||||||
// Hit a player? Game over!
|
// Check if it collides with anything.
|
||||||
if game.onPlayer(r) {
|
if game.onPlayer(r) {
|
||||||
game.gameover = 1
|
game.gameover = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Robots mingling? Trash!
|
if game.onRobot(i, r) || game.onTrash(r) {
|
||||||
if game.onRobot(i, r) {
|
|
||||||
|
|
||||||
// Delete robot
|
trash := r
|
||||||
|
|
||||||
|
// delete robot
|
||||||
game.deleteRobot(i)
|
game.deleteRobot(i)
|
||||||
|
|
||||||
// Create trash
|
// create trash
|
||||||
game.addTrash(r)
|
game.addTrash(trash)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hugging Trash? More trash!
|
|
||||||
if game.onTrash(r) {
|
|
||||||
|
|
||||||
// Delete robot
|
|
||||||
game.deleteRobot(i)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +65,9 @@ func (game *Game) moveRobots() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) onRobot(index int, pos Position) bool {
|
func (game *Game) onRobot(index int, pos Position) bool {
|
||||||
var found bool = false
|
var found bool
|
||||||
for i, r := range game.robots {
|
for i, r := range game.robots {
|
||||||
if index != i && pos == r {
|
if index != i && pos.x == r.x && pos.y == r.y {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,27 +77,16 @@ func (game *Game) onRobot(index int, pos Position) bool {
|
|||||||
// TODO: improve this
|
// TODO: improve this
|
||||||
func (game *Game) deleteRobot(robot int) {
|
func (game *Game) deleteRobot(robot int) {
|
||||||
|
|
||||||
// The following would work, if it wasn't for the fact you are iterating through an array,
|
var rowboz []Position
|
||||||
// and deleting elements form that same array. So deleting item #15 isn't going to work
|
|
||||||
// when the array has been reduced to 13 elements.
|
|
||||||
// if robot < len(game.robots) {
|
|
||||||
// game.robots = append(game.robots[:robot], game.robots[robot+1:]...)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// This isn't going to work for the same reason,
|
for i, r := range game.robots {
|
||||||
// and it adds the issue that random robots will get deleted.
|
if robot != i {
|
||||||
// var rowboz []Position
|
rowboz = append(rowboz, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// for i, r := range game.robots {
|
game.robots = nil
|
||||||
// if robot != i {
|
game.robots = rowboz
|
||||||
// rowboz = append(rowboz, r)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// game.robots = nil
|
|
||||||
// game.robots = rowboz
|
|
||||||
|
|
||||||
// Conclusion: I need to find a different way to do this properly while iterating to that same array.
|
|
||||||
|
|
||||||
game.player.score++
|
game.player.score++
|
||||||
|
|
||||||
|
2
trash.go
2
trash.go
@ -9,7 +9,7 @@ func (game *Game) drawTrash() {
|
|||||||
func (game *Game) onTrash(pos Position) bool {
|
func (game *Game) onTrash(pos Position) bool {
|
||||||
var found bool
|
var found bool
|
||||||
for _, t := range game.trash {
|
for _, t := range game.trash {
|
||||||
if t == pos {
|
if t.x == pos.x && t.y == pos.y {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user