Free Friday 5/1/26

Today in class, I started a space war game.

This is the code that sets the animations speed to the maximum, changes the background color, hides the default turtle, saves memory, and speeds up drawing.

turtle.fd(0)
turtle.speed(0)
turtle.bgcolor("black")
turtle.ht()
turtle.setundobuffer(1)
turtle.tracer(1)

This is the code that moves the player

def move(self):
        self.fd(self.speed) 

This is the code that gets the player that to move up, down, left, and right.

def turn_left(self):
        self.lt(45)     

    def turn_right(self):
        self.lt(45)

    def accelerate(self):
        self.speed += 1 

    def decelerate(self):
        self.speed -= 1                  

This is the code for the player.

    player = Player("triangle", "white", 0, 0)

This is the code for the keys that gets the player to move.

turtle.onkey(player.turn_left, "Left")
turtle.onkey(player.turn_right, "Right")
turtle.onkey(player.accelerate, "Up")
turtle.onkey(player.decelerate, "Down")

CATEGORIES:

Tags:

No Responses

Leave a Reply

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