class Mover(Actor): def __init__(self, x, y, im, rotspeed): super().__init__(im, (x, y)) self.pos = (x, y) self.im = im self.rotspeed = rotspeed self.angle = 90 self.location = PVector(x, y) self.velocity = PVector(0, 0) self.topspeed = 10 def update(self): mouse_x, mouse_y = pygame.mouse.get_pos() mouse = PVector(mouse_x, mouse_y) dir = mouse - self.location dir.normalize() dir.mult(0.5) self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) self.pos = (self.location.x, self.location.y) self.angle += self.rotspeed def bounce(self): if (self.location.x > WIDTH - RADIUS) or (self.location.x < RADIUS): self.velocity.x *= -1 if (self.location.y > HEIGHT - RADIUS) or (self.location.y < RADIUS): self.velocity.y *= -1
class Mover(object): def __init__(self, x, y, r): self.location = PVector(x, y) self.velocity = PVector(0, 0) self.radius = r self.topspeed = 10 def display(self): screen.draw.filled_circle((self.location.x, self.location.y), self.radius, (255, 0, 0)) screen.draw.circle((self.location.x, self.location.y), self.radius, (0, 0, 0)) def update(self): self.acceleration = PVector.random2D() # self.acceleration.mult(0.5) self.acceleration.mult(random.uniform(0.0, 2.0)) self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) def check_edges(self): if (self.location.x > WIDTH - RADIUS): self.location.x = WIDTH - RADIUS self.velocity.x *= -1 elif (self.location.x < RADIUS): self.location.x = RADIUS self.velocity.x *= -1 if (self.location.y > HEIGHT - RADIUS): self.location.y = HEIGHT - RADIUS self.velocity.y *= -1 elif (self.location.y < RADIUS): self.location.y = RADIUS self.velocity.y *= -1
class Mover(): def __init__(self): self.radius = 16 # Position, Velocity, and Acceleration self.position = PVector(WIDTH / 2, HEIGHT / 2) self.velocity = PVector(0, 0) self.acceleration = PVector(0.001, -0.01) # Maximalgeschwindigkeit self.topspeed = 10 # Farbe self.color = (239, 242, 63) def draw(self): arcade.draw_circle_filled(self.position.x, self.position.y, self.radius, self.color) arcade.draw_circle_outline(self.position.x, self.position.y, self.radius, arcade.color.BLACK) def update(self): self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.position.add(self.velocity) if (self.position.x >= WIDTH + self.radius): self.position.x = -self.radius elif (self.position.x <= -self.radius): self.position.x = WIDTH - self.radius if (self.position.y >= HEIGHT + self.radius): self.position.y = -self.radius elif (self.position.y <= -self.radius): self.position.y = HEIGHT - self.radius
class Rocket(Actor): def __init__(self, x, y, im): super().__init__(im, (x, y)) self.pos = (x, y) self.im = im self.location = PVector(x, y) self.velocity = PVector(0, 0) self.frame = 0 self.angle = 90 self.topspeed = 10 def update(self): mouse_x, mouse_y = pygame.mouse.get_pos() mouse = PVector(mouse_x, mouse_y) dir = mouse - self.location dir.normalize() dir.mult(0.5) self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) self.pos = (self.location.x, self.location.y) # self.angle = self.angle_to((mouse_x, mouse_y)) self.angle = -self.velocity.heading() * (180 / math.pi) def make_animation(self): if self.frame <= 5: self.image = "ship1" elif self.frame <= 10: self.image = "ship2" elif self.frame <= 15: self.image = "ship3" elif self.frame <= 20: self.image = "ship4" if self.frame >= 20: self.frame = 0 self.frame += 1 def check_edges(self): if (self.location.x > WIDTH - RADIUS): self.location.x = RADIUS elif (self.location.x < RADIUS): self.location.x = WIDTH - RADIUS if (self.location.y > HEIGHT - RADIUS): self.location.y = RADIUS elif (self.location.y < RADIUS): self.location.y = HEIGHT - RADIUS
class Mover(): def __init__(self): self.radius = random.randrange(10, 20) self.mouse = PVector(200, 200) # Position und Velocity x = random.randrange(self.radius, WIDTH - self.radius) y = random.randrange(self.radius, HEIGHT - self.radius) self.position = PVector(x, y) v_x = random.randrange(-10, 10) v_y = random.randrange(-10, 10) self.velocity = PVector(v_x, v_y) # Maximalgeschwindigkeit self.topspeed = 10 # Farbe self.color = random.choice(colorlist) def draw(self): arcade.draw_circle_filled(self.position.x, self.position.y, self.radius, self.color) arcade.draw_circle_outline(self.position.x, self.position.y, self.radius, arcade.color.BLACK) def update(self): dir = self.mouse - self.position dir.normalize() dir.mult(0.5) self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.position.add(self.velocity) if (self.position.x >= WIDTH + self.radius): self.position.x = -self.radius elif (self.position.x <= -self.radius): self.position.x = WIDTH - self.radius if (self.position.y >= HEIGHT + self.radius): self.position.y = -self.radius elif (self.position.y <= -self.radius): self.position.y = HEIGHT - self.radius
class Mover(object): def __init__(self): self.location = PVector(randint(0, HEIGHT), randint(0, WIDTH)) self.velocity = PVector(0, 0) self.topspeed = randint(6, 12) self.radius = randint(8, 24) self.color = choice(colorlist) def display(self): screen.draw.filled_circle((self.location.x, self.location.y), self.radius, self.color) screen.draw.circle((self.location.x, self.location.y), self.radius, (0, 0, 0)) def update(self): mouse_x, mouse_y = pygame.mouse.get_pos() mouse = PVector(mouse_x, mouse_y) dir = mouse - self.location dir.normalize() dir.mult(0.5) self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) def check_edges(self): if (self.location.x > WIDTH - self.radius): self.location.x = WIDTH - self.radius self.velocity.x *= -1 elif (self.location.x < self.radius): self.location.x = self.radius self.velocity.x *= -1 if (self.location.y > HEIGHT - self.radius): self.location.y = HEIGHT - self.radius self.velocity.y *= -1 elif (self.location.y < self.radius): self.location.y = self.radius self.velocity.y *= -1
class Mover(Actor): def __init__(self, x, y, im, rotspeed): super().__init__(im, (x, y)) self.pos = (x, y) self.im = im self.rotspeed = rotspeed self.angle = 90 self.location = PVector(x, y) self.velocity = PVector(random.uniform(-2, 2), random.uniform(-2, 2)) # self.acceleration = PVector(-0.001, 0.01) self.topspeed = 10 def update(self): self.acceleration = PVector.random2D() self.acceleration.mult(0.5) # self.acceleration.mult(random.uniform(0, 2)) self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) self.pos = (self.location.x, self.location.y) self.angle += self.rotspeed def check_edges(self): if (self.location.x > WIDTH - RADIUS): self.location.x = RADIUS elif (self.location.x < RADIUS): self.location.x = WIDTH - RADIUS if (self.location.y > HEIGHT - RADIUS): self.location.y = RADIUS elif (self.location.y < RADIUS): self.location.y = HEIGHT - RADIUS def bounce(self): if (self.location.x > WIDTH - RADIUS) or (self.location.x < RADIUS): self.velocity.x *= -1 if (self.location.y > HEIGHT - RADIUS) or (self.location.y < RADIUS): self.velocity.y *= -1
class Mover(): def __init__(self): self.radius = 16 self.mouse = PVector(200, 200) # Position und Velocity self.position = PVector(WIDTH / 2, HEIGHT / 2) self.velocity = PVector(0, 0) # Maximalgeschwindigkeit self.topspeed = 10 # Farbe self.color = (239, 242, 63) def draw(self): arcade.draw_circle_filled(self.position.x, self.position.y, self.radius, self.color) arcade.draw_circle_outline(self.position.x, self.position.y, self.radius, arcade.color.BLACK) def update(self): # Richtung dir = self.mouse - self.position dir.normalize() dir.mult(0.5) # Acceleration self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.position.add(self.velocity) if (self.position.x >= WIDTH + self.radius): self.position.x = -self.radius elif (self.position.x <= -self.radius): self.position.x = WIDTH - self.radius if (self.position.y >= HEIGHT + self.radius): self.position.y = -self.radius elif (self.position.y <= -self.radius): self.position.y = HEIGHT - self.radius
class Mover(object): def __init__(self, x, y, r): self.location = PVector(x, y) self.velocity = PVector(0, 0) self.radius = r self.topspeed = 10 def display(self): screen.draw.filled_circle((self.location.x, self.location.y), self.radius, (255, 0, 0)) screen.draw.circle((self.location.x, self.location.y), self.radius, (0, 0, 0)) def update(self): mouse_x, mouse_y = pygame.mouse.get_pos() mouse = PVector(mouse_x, mouse_y) dir = mouse - self.location dir.normalize() dir.mult(0.5) self.acceleration = dir self.velocity.add(self.acceleration) self.velocity.limit(self.topspeed) self.location.add(self.velocity) def check_edges(self): if (self.location.x > WIDTH - RADIUS): self.location.x = WIDTH - RADIUS self.velocity.x *= -1 elif (self.location.x < RADIUS): self.location.x = RADIUS self.velocity.x *= -1 if (self.location.y > HEIGHT - RADIUS): self.location.y = HEIGHT - RADIUS self.velocity.y *= -1 elif (self.location.y < RADIUS): self.location.y = RADIUS self.velocity.y *= -1