Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import *
- from sys import exit
- from math import *
- from random import randint
- #Background
- bg = './images/bg.png'
- #Graphics player
- still = './images/player/still.gif'
- walk = './images/player/walk.gif'
- kick = './images/player/kick.gif'
- punch = './images/player/punch.gif'
- duck = './images/player/duck.gif'
- special1 = './images/player/special.png'
- jumpy = './images/player/jump.gif'
- #graphics npc
- enemy_still = './images/npc/estill.gif'
- #create screen
- screen = pygame.display.set_mode((400, 254), 0, 32)
- pygame.display.set_caption('MK Game')
- #initate pygame
- pygame.init()
- #game graphic load
- background = pygame.image.load(bg).convert()
- #character graphic load
- stillpro = pygame.image.load(still).convert()
- walkpro = pygame.image.load(walk).convert()
- kickpro = pygame.image.load(kick).convert()
- punch1 = pygame.image.load(punch).convert()
- duckpro = pygame.image.load(duck).convert()
- special = pygame.image.load(special1).convert()
- jump = pygame.image.load(jumpy).convert()
- #character flip
- stillflip = pygame.transform.flip(stillpro, 1, 0)
- specialflip = pygame.transform.flip(special, 1, 0)
- walkflip = pygame.transform.flip(walkpro, 1, 0)
- kickflip = pygame.transform.flip(kickpro, 1, 0)
- punchflip = pygame.transform.flip(punch1, 1, 0)
- duckflip = pygame.transform.flip(duckpro, 1, 0)
- jumpflip = pygame.transform.flip(jump, 1, 0)
- #npc graphic load
- estill = pygame.image.load(enemy_still).convert()
- #npc flip
- eflipstill = pygame.transform.flip(estill, 1, 0)
- #sprite will change depending on wich key is pressed
- sprite = stillpro
- ducky = stillpro
- duckflipy = stillflip
- esprite = estill
- spriteflip = stillflip
- #player location variables
- x, y = 0, 80
- move_x, move_y = 0, 0
- airtime = 0
- #player variables
- phealth = 100
- ppower = 0
- speed = 5
- #enemy location variables
- ex, ey = 140, 80
- #enemy variables
- ehealth = 100
- epower = 0
- espeed = 5
- #time keeping
- clock = pygame.time.Clock()
- while True:
- #Error checks
- #player hit test
- xplus = x + 88
- rangey = range(x, xplus)
- xneg = x - 40
- negrangey = range(xneg, x)
- #enemy hit test
- explus = ex + 88
- rangey = range(ex, explus)
- exneg = ex - 40
- enegrangey = range(exneg, ex)
- #time handling
- time_passed = clock.tick(60)
- time_passed_seconds = time_passed / 1000.
- ptime = time_passed_seconds #passed time short handed
- #npc facing
- if ex > x:
- esprite = eflipstill
- elif ex < x:
- esprite = estill
- #npc test brain
- move = randint(1,2)
- if ex > x and move == 1:
- ex = ex - espeed
- elif ex < x and move == 1:
- ex = ex + espeed
- #Keycommands start
- for event in pygame.event.get():
- if event.type == QUIT:
- exit()
- # Get keydown commands
- if event.type == KEYDOWN:
- if event.key == K_LEFT:
- move_x = -speed - 1
- if sprite != duckpro:
- if sprite != kickpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump:
- sprite = walkpro
- spriteflip = walkflip
- if event.key == K_RIGHT:
- move_x = speed + 1
- if sprite != duckpro:
- if sprite != kickpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump:
- sprite = walkpro
- spriteflip = walkflip
- if event.key == K_a:
- if x < ex:
- if ex in rangey:
- ehealth -=10
- print 'enemy health', ehealth,'player power', ppower
- ppower += 20
- elif x > ex:
- if ex in negrangey:
- ehealth -= 10
- print 'enemy health', ehealth,'player power', ppower
- ppower += 20
- sprite = kickpro
- spriteflip = kickflip
- if event.key == K_d:
- if x < ex:
- if ex in rangey:
- ehealth -=10
- print 'enemy health', ehealth,'player power', ppower
- ppower += 20
- elif x > ex:
- if ex in negrangey:
- ehealth -= 10
- print 'enemy health', ehealth,'player power', ppower
- ppower += 20
- sprite = punch1
- spriteflip = punchflip
- if event.key == K_DOWN:
- ducky = duckpro
- duckyflip = duckflip
- spriteflip = duckflip
- sprite = duckpro
- y = 115
- if event.key == K_s and ppower >= 50:
- if x < ex:
- if ex in rangey:
- ehealth -=10
- print 'enemy health', ehealth,'player power', ppower
- elif x > ex:
- if ex in negrangey:
- ehealth -= 10
- print 'enemy health', ehealth,'player power', ppower
- sprite = special
- spriteflip = specialflip
- ppower -= 50
- if event.key == K_UP and y > 30 and airtime <= 0:
- sprite = jump
- spriteflip = jumpflip
- while (y > 30):
- y = y - 1
- airtime = airtime + 1
- if y == 30 and airtime >= 5:
- y = y + 50
- airtime = 0
- break
- #Get key up commands
- elif event.type == KEYUP:
- if event.key == K_LEFT:
- move_x = 0
- if sprite != duckpro:
- if sprite != kickpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump:
- sprite = stillpro
- spriteflip = stillflip
- if event.key == K_RIGHT:
- move_x = 0
- if sprite != duckpro:
- if sprite != kickpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump:
- sprite = stillpro
- spriteflip = stillflip
- if event.key == K_a:
- sprite = stillpro
- spriteflip = stillflip
- if event.key == K_d:
- sprite = stillpro
- spriteflip = stillflip
- if event.key == K_DOWN:
- sprite = stillpro
- spriteflip = stillflip
- ducky = stillpro
- y = 80
- if event.key == K_s:
- sprite = stillpro
- spriteflip = stillflip
- if event.key == K_UP or airtime >= 1:
- while(y < 80):
- y = y + 1
- airtime = 0
- sprite = stillpro
- spriteflip = stillflip
- #spare error fixing if's I.E Graphics being in wrong place after multiple key press
- print airtime
- if x < 0:
- x = 0
- if x > 350:
- x = 350
- if y < 0:
- y = 80
- if y > 80 and sprite != duckpro:
- y = 80
- if y == 80 and sprite == duckpro:
- y = 115
- if x > ex:
- if ducky == duckpro:
- if sprite != kickpro:
- if sprite != walkpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump :
- sprite = duckpro
- y = 115
- if duckflipy == duckflip:
- if sprite != kickpro:
- if sprite != walkpro:
- if sprite != punch1:
- if sprite != special:
- if sprite != jump :
- spriteflip = duckflip
- y = 115
- #print x, y, ptime
- x+= move_x
- y+= move_y
- screen.fill((0,0,0))
- screen.blit(background, (0,0))
- #print player sprites to screen
- if x < ex:
- if sprite == stillpro:
- screen.blit(stillpro, (x, y))
- if sprite == walkpro:
- screen.blit(walkpro, (x, y))
- if sprite == special:
- screen.blit(special, (x, y))
- if sprite == kickpro:
- screen.blit(kickpro, (x, y))
- if sprite == punch1:
- screen.blit(punch1, (x, y))
- if sprite == duckpro:
- screen.blit(duckpro, (x, y))
- if sprite == jump:
- screen.blit(jump, (x, y))
- if x > ex:
- if spriteflip == stillflip:
- screen.blit(stillflip, (x, y))
- if spriteflip == walkflip:
- screen.blit(walkflip, (x, y))
- if spriteflip == specialflip:
- screen.blit(specialflip, (x, y))
- if spriteflip == kickflip:
- screen.blit(kickflip, (x, y))
- if spriteflip == punchflip:
- screen.blit(punchflip, (x, y))
- if spriteflip == jumpflip:
- screen.blit(jumpflip, (x, y))
- if spriteflip == duckflip:
- screen.blit(duckflip, (x, y))
- #enemy sprites to screen
- screen.blit(esprite,(ex, ey))
- #check if health is good
- if ehealth <= 0:
- print 'Game Over! player wins!'
- exit()
- elif phealth <= 0:
- print 'Game Over! Enemy wins!'
- exit()
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement