-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
71 lines (54 loc) · 1.89 KB
/
Copy pathplayer.py
File metadata and controls
71 lines (54 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pygame
import random
import time
import sys
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.images = []
self.image = pygame.image.load("sprites/sprite_bee0.png")
self.images.append(pygame.image.load("sprites/sprite_bee0.png"))
self.images.append(pygame.image.load("sprites/sprite_bee1.png"))
self.images.append(pygame.image.load("sprites/sprite_bee2.png"))
self.images.append(pygame.image.load("sprites/sprite_bee3.png"))
self.images.append(pygame.image.load("sprites/sprite_bee4.png"))
self.index = 0
self.image = self.images[self.index]
self.rect = self.image.get_rect()
self.rect.center = (160, 600)
self.direction = pygame.math.Vector2()
self.speed = 10
# Game Information
self.pollen = 0
def input(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
self.direction.y = -1
elif keys[pygame.K_DOWN]:
self.direction.y = 1
else:
self.direction.y = 0
if keys[pygame.K_RIGHT]:
self.direction.x = 1
elif keys[pygame.K_LEFT]:
self.direction.x = -1
else:
self.direction.x = 0
def move(self):
pass
def draw(self, surface):
surface.blit(self.image, self.rect)
def update_flower_pollen(self):
self.pollen += 1
def update_hive_pollen(self):
self.pollen -= 1
def update(self):
self.input()
self.rect.center += self.direction * self.speed
self.index += 1
# if the index is larger than the total images
if self.index >= len(self.images):
# we will make the index to 0 again
self.index = 0
# finally we will update the image that will be displayed
self.image = self.images[self.index]