def __init__(self, speed): super(Bird, self).__init__() # fly images to animation self.fly = ["./image/bird_0.png", "./image/bird_1.png"] self.fly_ani = Animate(self.fly, 36, 36) # image, width, height self.surf = self.fly_ani.animate(1) self.rect = self.surf.get_rect(left=SCREEN_WIDTH, bottom=GROUND - (random.randint(0, 2) * 40)) self.speed = 5 + speed self.index = 0
def __init__(self): super(Dinosaur, self).__init__() # inherit pygame.sprite.Sprite # self position self.x = 200 self.y = GROUND / 2 # jump images to animation self.run = [ "./image/dinosaur_0.png", "./image/dinosaur_1.png", "./image/dinosaur_2.png" ] self.run_ani = Animate(self.run, 50, 50) # image, width, height # squat images to animation self.squat = ["./image/dinosaur_-1.png", "./image/dinosaur_-2.png"] self.squat_ani = Animate(self.squat, 70, 30) # image, width, height # dead self.dead = ["./image/dinosaur_3.png"] self.dead_ani = Animate(self.dead, 50, 50) # physic attributes self.grav = 0.7 self.vel = 0 # self squat state for contact detection self.squat = False # time counter self.index = 0 # initial animation state self.surf = self.run_ani.animate(0) self.rect = self.surf.get_rect(center=(self.x, 0), bottom=GROUND)
def __init__(self, game_map, screen): super().__init__() self.game_map = game_map self.screen = screen self.width = 16 self.height = 8 self.image = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.rect = self.image.get_rect() self.rect.x = 410 self.rect.y = 300 self.pos = self.rect self.animation = Animate(screen, self) self.animation_counter = self.animation_step = 0 self.counter = 0 self.group = pygame.sprite.Group() self.current_sprite = self.image self.current_sprites = [ self.images.sprite_dict['down'][1] for x in range(2) ] self.wield = None self.inventory = Inventory()
class Bird(pygame.sprite.Sprite): def __init__(self, speed): super(Bird, self).__init__() # fly images to animation self.fly = ["./image/bird_0.png", "./image/bird_1.png"] self.fly_ani = Animate(self.fly, 36, 36) # image, width, height self.surf = self.fly_ani.animate(1) self.rect = self.surf.get_rect(left=SCREEN_WIDTH, bottom=GROUND - (random.randint(0, 2) * 40)) self.speed = 5 + speed self.index = 0 def update(self): self.rect.move_ip(-self.speed, 0) self.surf = self.fly_ani.animate(int(self.index / 10) % 2) self.index += 1 self.index %= 1000 if self.rect.right < 0: self.kill() # clean
class Dinosaur(pygame.sprite.Sprite): def __init__(self): super(Dinosaur, self).__init__() # inherit pygame.sprite.Sprite # self position self.x = 200 self.y = GROUND / 2 # jump images to animation self.run = [ "./image/dinosaur_0.png", "./image/dinosaur_1.png", "./image/dinosaur_2.png" ] self.run_ani = Animate(self.run, 50, 50) # image, width, height # squat images to animation self.squat = ["./image/dinosaur_-1.png", "./image/dinosaur_-2.png"] self.squat_ani = Animate(self.squat, 70, 30) # image, width, height # dead self.dead = ["./image/dinosaur_3.png"] self.dead_ani = Animate(self.dead, 50, 50) # physic attributes self.grav = 0.7 self.vel = 0 # self squat state for contact detection self.squat = False # time counter self.index = 0 # initial animation state self.surf = self.run_ani.animate(0) self.rect = self.surf.get_rect(center=(self.x, 0), bottom=GROUND) # dinosaur move def update(self, pressed_key): # for contact detection self.squat = False if self.rect.bottom >= GROUND: self.vel = 0 self.surf = self.run_ani.animate(int(self.index) % 3) self.rect = self.surf.get_rect(center=(self.x, 0), bottom=GROUND) # animation control elif self.rect.bottom != GROUND: self.vel = self.vel + self.grav self.surf = self.run_ani.animate(0) if pressed_key[K_DOWN]: if self.rect.bottom < GROUND: self.vel = 10 else: self.surf = self.squat_ani.animate(int(self.index / 1.8) % 2) self.rect = self.surf.get_rect(center=(self.x, 0), bottom=GROUND) self.vel = 0 self.squat = True # contact detection elif pressed_key[K_SPACE] or pressed_key[K_UP]: if self.vel > 0: # if falling don't jump self.vel = self.vel elif self.vel > -6 and self.vel < 0: self.vel = self.vel elif self.rect.bottom > GROUND - 70: self.vel = -7 elif self.vel == 0 and self.rect.bottom == GROUND - 70: self.vel = -12 self.surf = self.run_ani.animate(0) self.rect.move_ip(0, self.vel) # animation flip self.index += 0.3 self.index %= 6 def die(self): self.surf = self.dead_ani.animate(0) if self.rect.bottom == GROUND: self.rect = self.surf.get_rect(center=(self.x, 0), bottom=GROUND)
'depth': bod_depth, 'height': bod_height, 'cm': body_cm } wheel_params = { 'mass': wheel_mass, 'radius': wheel_rad, 'height': wheel_height, 'cm': wheel_cms, 'axis': wheel_axes } earth_rad = 6371 #km sat_alt = earth_rad + 300 vol_pos = (-6, 0) sat_pos0 = (6, 0) #number of iterations that the controller's cpu can run att_update = 0.01 time_sf = 10 w0 = [0, 0, 0] q0 = [1, 0, 0, 0] rate = 18 #frames/calculations per second controller = Controller(rate, body_params, q0=[1, 0, 0, 0], w0=[0, 0, 0]) anim_obj = Animate(controller, time_sf, real=False) #plt.waitforbuttonpress() #anim_obj.cid = anim_obj.orbit_fig.canvas.mpl_connect('button_press_event', anim_obj.onclick) #anim_obj.get_point() my_anim = anim_obj.make_animation() plt.show()
import dlib import numpy as np from animation import Animate import os predictor_path = "./shape_predictor_68_face_landmarks.dat" detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(predictor_path) cam = cv2.VideoCapture(0) root_dir = "./patches" patches = [os.path.join(root_dir, path) for path in os.listdir(root_dir)] animate = Animate(patches) fourcc = cv2.VideoWriter_fourcc(*'MP4V') source_h = int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT)) source_w = int(cam.get(cv2.CAP_PROP_FRAME_WIDTH)) writer = cv2.VideoWriter('output.mp4', fourcc, 10.0, (source_w, source_h)) while (cam.isOpened()): ret, img = cam.read() if ret: dets = detector(img[..., [2, 1, 0]], 1) if len(dets) < 1: continue d = dets[0] shape = predictor(img[..., [2, 1, 0]], d) points = np.empty((4, 2), dtype=int) for i, ix in enumerate([18, 25, 5, 11]): points[i][0], points[i][1] = shape.part(ix).x, shape.part(ix).y
class Player(Character): images = PlayerImages("m_blonde_sprites.png") spritesheet = images.sprite_list def __init__(self, game_map, screen): super().__init__() self.game_map = game_map self.screen = screen self.width = 16 self.height = 8 self.image = pygame.Surface([self.width, self.height], pygame.SRCALPHA, 32) self.rect = self.image.get_rect() self.rect.x = 410 self.rect.y = 300 self.pos = self.rect self.animation = Animate(screen, self) self.animation_counter = self.animation_step = 0 self.counter = 0 self.group = pygame.sprite.Group() self.current_sprite = self.image self.current_sprites = [ self.images.sprite_dict['down'][1] for x in range(2) ] self.wield = None self.inventory = Inventory() def update(self): self.animation.update() self.rect.x += self.change_x self.rect.y += self.change_y self.collisions() def collisions(self): collisions = pygame.sprite.spritecollide(self, self.game_map.object_group, False) for obj in collisions: if self.change_x > 0: self.rect.right = obj.rect.left self.stop() elif self.change_x < 0: self.rect.left = obj.rect.right self.stop() elif self.change_y > 0: self.rect.bottom = obj.rect.top self.stop() elif self.change_y < 0: self.rect.top = obj.rect.bottom self.stop() wood = pygame.sprite.spritecollide(self, self.game_map.crafting_group, False) for obj in wood: col = pygame.sprite.collide_rect(self, obj) if col: self.inventory.add_to_inv(obj) obj.pick_up() def move_left(self): super().move_left() self.current_sprites = self.images.sprite_dict['left'] def move_right(self): super().move_right() self.current_sprites = self.images.sprite_dict['right'] def move_up(self): super().move_up() self.current_sprites = self.images.sprite_dict['up'] def move_down(self): super().move_down() self.current_sprites = self.images.sprite_dict['down'] def stop(self): super().stop() self.current_sprites = [self.current_sprites[1] for x in range(2)] def mine(self): self.wield = w.PickAxe(self.pos) def chop(self): self.wield = w.Axe(self.pos) def till(self): pass