Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as pg
- pg.init()
- win = pg.display.set_mode((1440, 800))
- pg.display.set_caption('Cubes Game')
- clock = pg.time.Clock()
- bg = pg.image.load('sprites/bg.png')
- walkRight = [pg.image.load('sprites/run1.png'),
- pg.image.load('sprites/run2.png'),
- pg.image.load('sprites/run3.png'),
- pg.image.load('sprites/run4.png'),
- pg.image.load('sprites/run5.png'),
- pg.image.load('sprites/run6.png'),
- pg.image.load('sprites/run7.png')]
- walkLeft =[pg.image.load('sprites/lrun1.png'),
- pg.image.load('sprites/lrun2.png'),
- pg.image.load('sprites/lrun3.png'),
- pg.image.load('sprites/lrun4.png'),
- pg.image.load('sprites/lrun5.png'),
- pg.image.load('sprites/lrun6.png'),
- pg.image.load('sprites/lrun7.png'),]
- playerStand = [pg.image.load('sprites/idle1.png'),
- pg.image.load('sprites/idle2.png'),
- pg.image.load('sprites/idle3.png'),
- pg.image.load('sprites/idle4.png'),
- pg.image.load('sprites/idle5.png'),
- pg.image.load('sprites/idle6.png'),
- pg.image.load('sprites/idle7.png'),]
- playerStandLeft = [pg.image.load('sprites/L_idle1.png'),
- pg.image.load('sprites/L_idle2.png'),
- pg.image.load('sprites/L_idle3.png'),
- pg.image.load('sprites/L_idle4.png'),
- pg.image.load('sprites/L_idle5.png'),
- pg.image.load('sprites/L_idle6.png'),
- pg.image.load('sprites/L_idle7.png'),]
- class player():
- def __init__(self, hp, x, y, widht, height, speed, isJump, jumpCount, left, right, stay, animCount, lastMove):
- self.hp = hp
- self.x = x
- self.y = y
- self.widht = widht
- self.height = height
- self.speed = speed
- self.isJump = isJump
- self.jumpCount = jumpCount
- self.left = left
- self.right = right
- self.stay = stay
- self.animCount = animCount
- self.lastMove = lastMove
- class shell():
- def __init__(self, x, y, radius, color, facing):
- self.x = x
- self.y = y
- self.radius = radius
- self.color = color
- self.facing = facing
- self.vel = 20 * facing
- def draw(self, win):
- pg.draw.circle(win, self.color, (self.x, self.y),self.radius)
- def drawWindow():
- global animCount
- win.blit(bg, (0,0))
- if animCount + 1 >= 35:
- animCount = 0
- if left:
- win.blit(walkLeft[animCount // 5], (x,y))
- animCount += 1
- elif right:
- win.blit(walkRight[animCount // 5], (x,y))
- animCount += 1
- elif stay:
- if lastMove == 'right':
- win.blit(playerStand [animCount // 5], (x,y))
- animCount += 1
- else:
- win.blit(playerStandLeft [animCount // 5], (x,y))
- animCount += 1
- for bullet in bullets:
- bullet.draw(win)
- pg.display.update()
- run = True
- bullets = []
- while run:
- clock.tick(35)
- for event in pg.event.get():
- if event.type == pg.QUIT:
- run = False
- for bullet in bullets:
- if bullet.x < 1440 and bullet.x > 0:
- bullet.x += bullet.vel
- else:
- bullets.pop(bullets.index(bullet))
- keys = pg.key.get_pressed()
- if keys[pg.K_f]:
- if lastMove == "right":
- facing = 1
- else:
- facing = -1
- if len(bullets) < 5:
- bullets.append(shell(round(x + widht // 2), round(y + height // 2), 5, (255,0,0), facing))
- if keys[pg.K_LEFT] and x > 1 or keys[pg.K_a] and x > 1:
- x -= speed
- left = True
- right = False
- stay = False
- lastMove = 'left'
- elif keys[pg.K_RIGHT] and x < 1380 or keys[pg.K_d] and x < 1380:
- x += speed
- left = False
- right = True
- stay = False
- lastMove = 'right'
- else:
- left = False
- right = False
- stay = True
- if not(isJump):
- if keys[pg.K_SPACE]:
- isJump = True
- else:
- if jumpCount >= -10:
- if jumpCount < 0:
- y += (jumpCount ** 2) / 2
- else:
- y -= (jumpCount ** 2) / 2
- jumpCount -= 1
- else:
- isJump = False
- jumpCount = 10
- drawWindow()
- pg.quit()
Add Comment
Please, Sign In to add comment