Commit 1cbd39df authored by santiaago's avatar santiaago
Browse files

add hasBody2 func

parent 49ac8090
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -586,21 +586,9 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size
			}

			lowBodyIndex := 7
			if invader.height > 5 {
				// add more body if height > 5
				if hasLowBody(invader, squares, lowBodyIndex, xQ, yQ) {
					fill = draw.FillFromRGBA(colorMap[xQ])
				}
				lowBodyIndex++
			}

			if invader.height > 6 {
				// add more body if height > 6
				if hasLowBody2(invader, squares, lowBodyIndex, xQ, yQ) {
			if hasBody2(invader, &lowBodyIndex, squares, xQ, yQ) {
				fill = draw.FillFromRGBA(colorMap[xQ])
			}
				lowBodyIndex++
			}

			if hasArmOrExtension2(invader, lowBodyIndex, squares, xQ, yQ) {
				fill = draw.FillFromRGBA(colorMap[xQ])
@@ -616,6 +604,24 @@ func SpaceInvaders(w http.ResponseWriter, key string, colors []color.RGBA, size
	canvas.End()
}

func hasBody2(invader invader, lowBodyIndex *int, squares, xQ, yQ int) (result bool) {
	if invader.height > 5 {
		if hasLowBody(invader, squares, *lowBodyIndex, xQ, yQ) {
			result = true
		}
		*lowBodyIndex++
	}

	if invader.height > 6 {
		if hasLowBody2(invader, squares, *lowBodyIndex, xQ, yQ) {
			result = true
		}
		*lowBodyIndex++
	}
	return result

}

func hasLegOrFoot(invader invader, lowBodyIndex, xQ, yQ int) bool {
	if yQ == lowBodyIndex || yQ == lowBodyIndex+1 {
		if hasLeg(invader, lowBodyIndex, xQ, yQ) {