adabot.py
1 # SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import pygame, sys 6 from pygame.locals import * 7 8 class adabot(): 9 image = '' 10 x = 0 11 y = 0 12 ll = 0 # left limit 13 rl = 0 # right limit 14 direction = 'right' 15 16 def __init__(self, x, y, ll, rl): 17 self.image = pygame.image.load('adabot.png') 18 self.image = self.image.convert_alpha() 19 self.x = x 20 self.y = y 21 self.ll = ll 22 self.rl = rl 23 24 def update(self): 25 if (self.direction == 'right'): 26 self.x += 5 27 else: 28 self.x -= 5 29 30 if (self.x > self.rl or self.x < self.ll): 31 self.direction = 'right' if self.direction == 'left' else 'left'