Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as pg
- pg.init()
- winHeight=600
- winWidth = 1020
- x=10
- y=560
- size = 37
- bg = pg.image.load("scenes/Background/bg.png")
- walkList = [pg.image.load("player/Run/run-00.png"),pg.image.load("player/Run/run-01.png"),pg.image.load("player/Run/run-02.png"),pg.image.load("player/Run/run-03.png"),pg.image.load("player/Run/run-04.png"),pg.image.load("player/Run/run-05.png")]
- char = pg.image.load("player/idle/idle-00.png")
- vel = 3
- win = pg.display.set_mode((winWidth,winHeight))
- pg.display.set_caption("SMAS 'EM By IKEA KID")
- run = True
- jumCount = 7
- isJump = False
- AnimationCounter = 0
- def Animation():
- direction = win.blit(walkList[AnimationCounter], (x, y))
- if pg.event == pg.K_LEFT:
- return direction
- elif pg.event == pg.K_RIGHT:
- direction=pg.transform.flip(direction,False,True)
- return direction
- def RedrawWindow():
- global AnimationCounter
- win.blit(bg, (0,0))
- if AnimationCounter +1 >= 6:
- AnimationCounter = 0
- if walk:
- Animation()
- AnimationCounter += 1
- elif not walk:
- win.blit(char,(x,y))
- pg.display.update()
- while run:
- pg.time.delay(15)
- for event in pg.event.get():
- if event.type == pg.QUIT:
- run = False
- keys = pg.key.get_pressed()
- if keys[pg.K_LEFT] and x > vel:
- x -= vel
- walk = True
- elif keys[pg.K_RIGHT] and x+size < winWidth-vel:
- x += vel
- walk = True
- flip = True
- else:
- AnimationCounter = 0
- walk = False
- if not(isJump):
- if keys[pg.K_SPACE]:
- isJump = True
- else:
- if jumCount >= -7:
- neg = 1
- if jumCount < 0:
- neg = -1
- y -= (jumCount**2)*0.5*neg
- jumCount-=0.5
- else:
- isJump = False
- jumCount = 7
- RedrawWindow()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement