This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
88 lines (67 loc) · 2.58 KB
/
objects.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pygame
import os
import library
import utils
import copy
class Player(pygame.sprite.Sprite):
GRAVITY = 0.7
JUMP_STR = 45 * GRAVITY
def __init__(self, x, screen_height, jump_key, image_str):
pygame.sprite.Sprite.__init__(self)
self.vel_y = 0
self.jump_key = jump_key
self.ground = 0.85 * screen_height
self.image = library.image_library[image_str]
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = self.ground - self.rect.h
def draw(self, screen):
screen.blit(self.image, (self.rect.x, self.rect.y))
def update(self, should_jump):
if should_jump and self.rect.y >= self.ground - self.rect.h:
self.vel_y -= Player.JUMP_STR
library.sound_library['jump'].play()
self.vel_y += min(Player.GRAVITY, self.ground - self.rect.y - self.rect.h)
if self.rect.y + self.vel_y < self.ground - self.rect.h:
self.rect.y += self.vel_y
else:
self.rect.y = self.ground - self.rect.h
self.vel_y = 0
class Background(pygame.sprite.Sprite):
VEL_X = 12
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(0, 0, 3840, 1080)
self.image1 = library.image_library['bg']
self.image2 = library.image_library['bg']
def draw(self, screen):
w = self.rect.w
x = self.rect.x
y = self.rect.y
screen.blit(self.image1, (-((x + w) % (2 * w) - w), y))
screen.blit(self.image2, (-(x % (2 * w) - w), y))
def update(self):
self.rect.x += Background.VEL_X
class Goose(pygame.sprite.Sprite):
VEL_X = -12
def __init__(self, x, screen_height):
pygame.sprite.Sprite.__init__(self)
self.image = library.image_library['goose']
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = 0.85 * screen_height - self.rect.h
self.hitbox = copy.copy(self.rect)
self.hitbox.w /= 2
def draw(self, screen):
screen.blit(self.image, (self.rect.x, self.rect.y))
def update(self):
self.rect.x += Goose.VEL_X
self.hitbox.x = self.rect.x
class StaticImage(pygame.sprite.Sprite):
def __init__(self, px, py, screen_width, screen_height, image_str):
self.image = library.image_library[image_str]
self.rect = self.image.get_rect()
self.rect.x = screen_width * px - self.rect.w / 2
self.rect.y = screen_height * py - self.rect.h / 2
def draw(self, screen):
screen.blit(self.image, (self.rect.x, self.rect.y))