Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from Player import player
- from Enemy import enemy
- from projectile import projectile
- pygame.init()
- score = 0
- kills = 0
- win = pygame.display.set_mode((500, 480))
- keys = pygame.key.get_pressed()
- pygame.display.set_caption("First Game")
- bg = pygame.image.load('Game/bg.jpg')
- char = pygame.image.load('Game/standing.png')
- clock = pygame.time.Clock()
- def redrawGameWindow():
- win.blit(bg, (0, 0))
- text = font.render('Score: ' + str(score), 1, (0,0,0))
- win.blit(text, (390,10))
- man.draw(win)
- goblin.draw(win)
- for bullet in bullets:
- bullet.draw(win)
- pygame.display.update()
- # mainloop
- man = player(200, 410, 64, 64)
- goblin = enemy(100, 410, 64, 64, 300)
- shootLoop = 0
- font = pygame.font.SysFont('comicsans', 30, True, False)
- bullets = []
- run = True
- while run:
- clock.tick(27)
- if man.isDead:
- run = False
- print("You lost the game ;(")
- if goblin.visible:
- if man.hitbox[1] < goblin.hitbox[1] + goblin.hitbox[3] and man.hitbox[1] + man.hitbox[3] > goblin.hitbox[1]:
- if man.hitbox[0] + man.hitbox[2] > goblin.hitbox[0] and man.hitbox[0] < goblin.hitbox[0] + goblin.hitbox[2]:
- man.hit()
- score -= 2
- man.health -= 2
- if shootLoop > 0:
- shootLoop+=1
- if shootLoop > 3:
- shootLoop = 0
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- for bullet in bullets:
- if goblin.visible:
- if bullet.y - bullet.radius < goblin.hitbox[1] + goblin.hitbox[3] and bullet.y + bullet.radius > goblin.hitbox[1]:
- if bullet.x + bullet.radius > goblin.hitbox[0] and bullet.x - bullet.radius < goblin.hitbox[0] + goblin.hitbox[2]:
- goblin.hit()
- score += 1
- if goblin.visible:
- bullets.pop(bullets.index(bullet))
- if bullet.x < 500 and bullet.x > 0:
- bullet.x += bullet.vel
- else:
- bullets.pop(bullets.index(bullet))
- if keys[pygame.K_SPACE] and shootLoop == 0:
- if man.left:
- facing = -1
- else:
- facing = 1
- if len(bullets) < 5:
- bullets.append(
- projectile(round(man.x + man.width // 2), round(man.y + man.height // 2), 6, (0, 0, 0), facing))
- shootLoop = 1
- if keys[pygame.K_LEFT] and man.x > man.vel:
- man.x -= man.vel
- man.left = True
- man.right = False
- man.standing = False
- elif keys[pygame.K_RIGHT] and man.x < 500 - man.width - man.vel:
- man.x += man.vel
- man.right = True
- man.left = False
- man.standing = False
- else:
- man.standing = True
- man.walkCount = 0
- if not (man.isJump):
- if keys[pygame.K_UP]:
- man.isJump = True
- man.right = False
- man.left = False
- man.walkCount = 0
- else:
- if man.jumpCount >= -10:
- neg = 1
- if man.jumpCount < 0:
- neg = -1
- man.y -= (man.jumpCount ** 2) * 0.5 * neg
- man.jumpCount -= 1
- else:
- man.isJump = False
- man.jumpCount = 10
- man.jumpCount = 10
- redrawGameWindow()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement