-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackgroundSarah.py
90 lines (81 loc) · 3.43 KB
/
backgroundSarah.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
88
89
90
# scrolling background for game
import pygame
from pygame.locals import *
import os
import sys
import math
pygame.init()
screen = pygame.display.set_mode((800, 600))
W, H = 800, 447
win = pygame.display.set_mode((W,H))
pygame.display.set_caption('Side Scroller')
bg = pygame.image.load(os.path.join('images','bg.png')).convert()
# bg = pygame.image.load('evening_1.jpg').convert()
screen.fill((0,0,0))
bgX = 0
bgX2 = bg.get_width()
clock = pygame.time.Clock()
class player(object):
run = [pygame.image.load(os.path.join('images', str(x) + '.png')) for x in range(8,16)]
jump = [pygame.image.load(os.path.join('images', str(x) + '.png')) for x in range(1,8)]
slide = [pygame.image.load(os.path.join('images', 'S1.png')),pygame.image.load(os.path.join('images', 'S2.png')),pygame.image.load(os.path.join('images', 'S2.png')),pygame.image.load(os.path.join('images', 'S2.png')), pygame.image.load(os.path.join('images', 'S2.png')),pygame.image.load(os.path.join('images', 'S2.png')), pygame.image.load(os.path.join('images', 'S2.png')), pygame.image.load(os.path.join('images', 'S2.png')), pygame.image.load(os.path.join('images', 'S3.png')), pygame.image.load(os.path.join('images', 'S4.png')), pygame.image.load(os.path.join('images', 'S5.png'))]
jumpList = [1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4]
def __init__(self, x, y, width, height):
self.x = x
self.y = y
self.width = width
self.height = height
self.jumping = False
self.sliding = False
self.slideCount = 0
self.jumpCount = 0
self.runCount = 0
self.slideUp = False
def draw(self, win):
if self.jumping:
self.y -= self.jumpList[self.jumpCount] * 1.2
win.blit(self.jump[self.jumpCount//18], (self.x,self.y))
self.jumpCount += 1
if self.jumpCount > 108:
self.jumpCount = 0
self.jumping = False
self.runCount = 0
elif self.sliding or self.slideUp:
if self.slideCount < 20:
self.y += 1
elif self.slideCount == 80:
self.y -= 19
self.sliding = False
self.slideUp = True
if self.slideCount >= 110:
self.slideCount = 0
self.slideUp = False
self.runCount = 0
win.blit(self.slide[self.slideCount//10], (self.x,self.y))
self.slideCount += 1
else:
if self.runCount > 42:
self.runCount = 0
win.blit(self.run[self.runCount//6], (self.x,self.y))
self.runCount += 1
def redrawwindow():
win.blit(bg,(bgx,0))
win.blit(bg,(bgx2,0))
pygame.display.update()
run = True
speed = 30 # NEW
while run:
clock.tick(speed) # NEW
bgX -= 1.4 # Move both background images back
bgX2 -= 1.4
if bgX < bg.get_width() * -1: # If our bg is at the -width then reset its position
bgX = bg.get_width()
if bgX2 < bg.get_width() * -1:
bgX2 = bg.get_width()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
quit()
screen.blit(bg,(bgX2,0))
pygame.display.update()