coches arriba abajo python

def setup():

    size(600, 400)

    global myCar1, myCar2


    myCar1 = Car(color(51), 450, 100, 5)

    myCar2 = Car(color(151), 150, 50, -2)


def draw():

    background(255)

    

    myCar1.move()

    myCar1.display()

    

    myCar2.move()

    myCar2.display()


class Car:

    def __init__(self, c, xpos, ypos, yspeed):

        self.c = c

        self.xpos = xpos

        self.ypos = ypos

        self.yspeed = yspeed


    def display(self):

        stroke(0)

        fill(self.c)

        rectMode(CENTER)

        rect(self.xpos, self.ypos, 20, 10)


    def move(self):

        self.ypos += self.yspeed


        if self.ypos > height and self.yspeed > 0:

            self.ypos = 0

        if self.ypos < 0 and self.yspeed < 0:

            self.ypos = 350


Comentarios

Entradas populares de este blog

5)Peligros de red

Coches que se chocan con una bola