Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- #Window display for pygame with caption
- win = pygame.display.set_mode((800,600))
- pygame.display.set_caption("Derpes Herp")
- #Names for things
- walkRight = [pygame.image.load("walk1R.png"), pygame.image.load("walk2R.png"), pygame.image.load("walk3R.png")]
- walkLeft = [pygame.image.load("walk1L.png"), pygame.image.load("walk2L.png"), pygame.image.load("walkL3.png")]
- bg = pygame.image.load("bg.png")
- char = pygame.image.load("orgbob.png")
- #Name for fps controller
- clock = pygame.time.Clock()
- ## Had index errors without this counter
- class player(object):
- def __init__(self,x,y,width,height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.vel = 5
- self.isJump = False
- self.left = False
- self.right = False
- self.walkCount = 0
- self.jumpCount = 10
- self.standing = True
- self.attackCount = 0
- self.attack = False
- ##draw is just the name given for this function so I know its "drawing"
- ##Also if walkCount is 9 or reset I think might be backwards
- def draw(self, win):
- if self.walkCount + 1 >= 9 :
- self.walkCount = 0
- ## Controls walk frames using walkCounter as an index
- if not(self.standing):
- if self.left:
- win.blit(walkLeft[self.walkCount//3], (self.x,self.y))
- self.walkCount += 1
- elif self.right:
- win.blit(walkRight[self.walkCount//3], (self.x,self.y))
- self.walkCount +=1
- else:
- if self.right:
- win.blit(walkRight[0], (self.x, self.y))
- else:
- win.blit(walkRight[0], (self.x, self.y))
- ##a simple punch without the whole animation atm(self, x ,y ,width, height):
- class attacks(object):
- def __init__(self,x,y,width,height):
- attacks.attack = [pygame.image.load("atk1.png"), pygame.image.load("atk2.png"), pygame.image.load("atk3.png")]
- def draw(self, win):
- attacks.attack()
- if self.attackCount +1 >= 9:
- self. attackCount = 0
- if not (attacks.attack):
- if attacks.attack:
- win.blit(attack[0],[self.attackCount//3], self.x, self.y)
- self.attackCount += 1
- ## attempt of punch on screen
- class enemy(object):
- walkRight = [pygame.image.load("enwalkR.png")]
- walkLeft = [pygame.image.load("enwalkL.png")]
- def __init__(self, x, y, width, height, end):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.path = [x, end]
- self.walkCount = 0
- self.vel = 3
- def draw(self, win):
- self.move()
- if self.walkCount + 1 >= 3:
- self.walkCount = 0
- if self.vel > 0:
- win.blit(self.walkRight[self.walkCount//3], (self.x,self.y))
- self.walkCount += 1
- else:
- win.blit(self.walkLeft[self.walkCount//3], (self.x,self.y))
- self.walkCount += 1
- def move(self):
- if self.vel > 0:
- if self.x < self.path[1] + self.vel:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.x += self.vel
- self.walkCount = 0
- else:
- if self.x > self.path[0] - self.vel:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.x += self.vel
- self.walkCount = 0
- def redrawGameWindow():
- global walkCount
- global attack
- win.blit(bg, (0, 0))
- bob.draw(win)
- jerk.draw(win)
- pygame.display.update()
- #While true
- #This calls the classes created
- bob = player(100, 200, 128, 128)
- jerk = enemy(500, 200, 164, 100, 600)
- run = True
- while run:
- clock.tick(30)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- keys = pygame.key.get_pressed()
- #attempting to make this into a bool that changes the value
- if keys[pygame.K_SPACE]:
- bob.attack = True
- bob.left = False
- bob.right = False
- if keys[pygame.K_LEFT] and bob.x > bob.vel:
- bob.x -= bob.vel
- bob.left = True
- bob.right = False
- bob.standing = False
- elif keys[pygame.K_RIGHT] and bob.x < 800 - bob.width - bob.vel:
- bob.x += bob.vel
- bob.right = True
- bob.left = False
- bob.standing = False
- else:
- bob.standing = True
- bob.walkCount = 0
- if not(bob.isJump):
- if keys[pygame.K_UP]:
- bob.isJump = True
- bob.right = False
- bob.left = False
- bob.walkCount = 0
- else:
- if bob.jumpCount >= -10:
- neg = 1
- if bob.jumpCount < 0:
- neg = -1
- bob.y -= (bob.jumpCount ** 2) * 0.5 * neg
- bob.jumpCount -= 1
- else:
- bob.isJump = False
- bob.jumpCount = 10
- redrawGameWindow()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement