Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, pygame.mixer, random, sys
- from pygame.locals import *
- pygame.init()
- screen = pygame.display.set_mode((640, 480))
- clock = pygame.time.Clock()
- pygame.mouse.set_visible(False)
- hero = pygame.image.load("Images/hero.png")
- bill = pygame.image.load("Images/bill.png")
- gameover = pygame.image.load("Images/gameover.png")
- bullet = pygame.image.load("Images/bullet.png")
- cursor = pygame.image.load("Images/cursor.png")
- pausescreen = pygame.image.load("Images/paused.png")
- pygame.mixer.music.load("Sounds/makaimura.mp3")
- pygame.mixer.music.set_volume(0.5)
- pygame.mixer.music.play(loops = -1, start = 0.0)
- shot_sound = pygame.mixer.Sound("Sounds/shot.wav")
- death_sound = pygame.mixer.Sound("Sounds/death.wav")
- hero_y = 304 # hero y axis
- hero_x = 228 # hero x axis
- bill_x = random.randint(0, 480)
- bill_y = random.randint(0, 640)
- moveup = False
- movedown = False
- moveright = False
- moveleft = False
- death_sound_played = False
- dead = False
- shot = False
- paused = False
- bill_hp = 100
- rate = 60
- shotmoves = 0
- while True:
- clock.tick(rate)
- cursor_x, cursor_y = pygame.mouse.get_pos()
- screen.fill((255, 255, 255))
- if shotmoves == 60:
- shot = False
- shotmoves = 0
- if not paused:
- if moveup:
- hero_x -= 1
- if movedown:
- hero_x += 1
- if moveright:
- hero_y += 1
- if moveleft:
- hero_y -= 1
- if hero_x < -10:
- hero_x = 470
- elif hero_x > 480:
- hero_x = 0
- if hero_y < -10:
- hero_y = 630
- elif hero_y > 640:
- hero_y = 0
- if bill_x > hero_x:
- bill_x -= 0.9
- elif bill_x < hero_x:
- bill_x += 0.9
- if bill_y > hero_y:
- bill_y -= 0.9
- elif bill_y < hero_y:
- bill_y += 0.9
- if round(bill_y) in range(hero_y - 6, hero_y + 6) and round(bill_x) in range(hero_x - 6, hero_x + 6) and bill_hp > 0:
- dead = True
- screen.blit(hero, (hero_y, hero_x))
- if bill_hp > 0:
- screen.blit(bill, (bill_y, bill_x))
- if shot and not paused:
- if bill_hp > 0:
- if round(shot_y) in range(round(bill_y), round(bill_y + 20)) and round(shot_x) in range(round(bill_x), round(bill_x + 28)):
- bill_hp -= 1
- shot = False
- shotmoves = 0
- dif_x = target_y - shot_x
- dif_y = target_x - shot_y
- shot_x += dif_x / 24
- shot_y += dif_y / 24
- shotmoves += 1
- if shot:
- screen.blit(bullet, (shot_y, shot_x))
- if dead:
- pygame.mixer.music.pause()
- pygame.mixer.music.rewind()
- if not death_sound_played:
- death_sound.play()
- death_sound_played = True
- screen.fill((255, 255, 255))
- screen.blit(gameover, (0, 0))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- elif event.type == KEYDOWN and event.key == K_RETURN:
- hero_y = 304 # hero y axis
- hero_x = 228 # hero x axis
- bill_x = random.randint(0, 480)
- bill_y = random.randint(0, 640)
- moveup = False
- movedown = False
- moveright = False
- moveleft = False
- shot = False
- death_sound_played = False
- rate = 60
- bill_hp = 100
- pygame.mixer.music.unpause()
- dead = False
- if paused:
- screen.blit(pausescreen, (0, 0))
- screen.blit(cursor, (cursor_x - 8, cursor_y - 8))
- pygame.display.update()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- elif event.type == KEYDOWN and event.key == K_RETURN:
- if paused:
- paused = False
- elif not paused:
- paused = True
- elif event.type == MOUSEBUTTONDOWN and not paused:
- shot_sound.play()
- target_x, target_y = pygame.mouse.get_pos()
- shot_x, shot_y = hero_x + 6, hero_y + 8
- shotmoves = 0
- shot = True
- elif event.type == KEYDOWN and not paused:
- if event.key == K_UP or event.key == K_w:
- moveup = True
- elif event.key == K_DOWN or event.key == K_s:
- movedown = True
- elif event.key == K_RIGHT or event.key == K_d:
- moveright = True
- elif event.key == K_LEFT or event.key == K_a:
- moveleft = True
- if event.key == K_SPACE:
- rate = 150
- elif event.type == KEYUP:
- if event.key == K_UP or event.key == K_w:
- moveup = False
- elif event.key == K_DOWN or event.key == K_s:
- movedown = False
- elif event.key == K_RIGHT or event.key == K_d:
- moveright = False
- elif event.key == K_LEFT or event.key == K_a:
- moveleft = False
- if event.key == K_SPACE:
- rate = 60
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement