Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice, randrange
- from time import time
- from actor import Actor, Arena
- class Rover(Actor):
- def __init__(self, arena, pos):
- self._x, self._y = pos
- self._w, self._h = 32, 23
- self._speed = 2
- self._dx, self._dy = 0, 0
- self._lives = 3
- self._last_collision = 0
- self._arena = arena
- arena.add(self)
- def move(self):
- arena_w, arena_h = self._arena.size()
- self._y += self._dy
- if self._y < 0:
- self._y = 0
- elif self._y > arena_h - self._h:
- self._y = arena_h - self._h
- self._x += self._dx
- if self._x < 0:
- self._x = 0
- elif self._x > arena_w - self._w:
- self._x = arena_w - self._w
- def go_left(self, go: bool):
- if go:
- self._dx = -self._speed
- elif self._dx < 0:
- self._dx = 0
- def go_right(self, go: bool):
- if go:
- self._dx = self._speed
- elif self._dx > 0:
- self._dx = 0
- def go_up(self, go: bool):
- if go:
- self._dy = -self._speed
- elif self._dy < 0:
- self._dy = self._speed +0.4
- def go_down(self, go: bool):
- if go:
- self._dy = self._speed
- elif self._dy > 0:
- self._dy = self._speed +0.4
- def lives(self) -> int:
- return self._lives
- def collide(self, other):
- if time() - self._last_collision < 2:
- return
- self._last_collision = time()
- if isinstance(other, Ghost):
- self._lives = 0
- elif isinstance(other, Ball):
- self._lives -= 1
- def position(self):
- return self._x, self._y, self._w, self._h
- def symbol(self):
- return 212, 158, self._w, self._h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement