Free Friday 5-22-26

Today in class, I continued the space war game. I added allies and more enemies and scores.

This is the code for the ally.

class Ally(Sprite):
	def __init__(self, spriteshape, color, startx, starty):
		Sprite.__init__(self, spriteshape, color, startx, starty)
		self.speed = 8
		self.setheading(random.randint(0,360))

This is the code for the score

def show_status(self):
		self.pen.undo()
		msg = "Score: %s" %(self.score)
		self.pen.penup()
		self.pen.goto(-300, 310)
		self.pen.write(msg, font=("Arial", 16, "normal"))

This is the code for multiple enemies and allies.

enemies =[]
for i in range(6):
	enemies.append(Enemy("circle", "red", -100, 0))

allies =[]
for i in range(6):
	allies.append(Ally("square", "blue", 100, 0))

This is the code to increase the score.

game.score += 100
game.show_status()

This is the code to decrease the score.

game.score -= 50
game.show_status()	

CATEGORIES:

Tags:

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *