# This import the pygame library into Python
import pygame,sys

#This next line imports the pygame sound system
pygame.mixer.init()
# this loads the sound
sound = pygame.mixer.Sound("C:/Music/pygamenew/Music2/Jurassic_Park_-_quot_Main_Theme_quot_John_Williams.wav")
roar = pygame.mixer.Sound("C:/Music/pygamenew/Music2/Dinosaur Roar-SoundBible.com-605392672.wav")
# this allows us to play the song we have loaded
sound.play()

#This allows us to grab inputs from keyboard or mouse presses
from pygame.locals import *

# This line limits the number of frames (60)
# If computer speeds get faster, you will still be able to play
# This also helps to prevent burning your phone battery
clock = pygame.time.Clock()

#This initiates the pygame
pygame.init()

#Set up the colors
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0, 255)

#creating the size of our game screen
size = width, height = 700,700
BLACK = 0,0,0
screen = pygame.display.set_mode((800,600))


# Set the title of the window
pygame.display.set_caption('Dinosaur Madness')

pygame.mouse.set_visible(0) #Makes mouse invisible on screen

# adding an image
dinosaur = pygame.image.load("C:/Music/img_buddy1.png")
dinosaur = pygame.transform.scale(dinosaur,(75,75)) 

dinosaur.set_colorkey(WHITE)
dinosaur_top=screen.get_height() - dinosaur.get_height()
dinosaur_left=screen.get_width()/2 - dinosaur.get_width()/2
screen.blit(dinosaur,(dinosaur_left,dinosaur_top))
shoot = pygame.image.load("C:/Music/animated-fire.gif")
shoot = pygame.transform.scale(shoot,(20,20))
shoot.set_colorkey(WHITE)
shoot_y = 0

while True:
    clock.tick(60)
    screen.fill((BLUE))  #clears out the screen each loop


    x,y = pygame.mouse.get_pos()
    screen.blit(dinosaur,(x-dinosaur.get_width()/2, dinosaur_top))

    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            sys.exit()
        elif event.type == KEYDOWN and event.key == K_q:
            sys.exit()
        #this allows the user to end the game
        #by clicking on the x at the top, escape, or q
        elif event.type ==MOUSEBUTTONDOWN:
            roar.play() # when a mouse button is pressed, a roar sound will play
            shoot_y = 520
            shoot_x = x

        elif event.type == KEYDOWN and event.key==K_SPACE:
            pygame.image.save(screen,"screenshot.png")
            #this will save screen shots of our screen to a file



    if shoot_y > 0:
        screen.blit(shoot,(shoot_x,shoot_y))
        shoot_y -= 10
    pygame.display.update()

我要添加下落的冰块。 恐龙的目标是在它们撞到底部之前将它们射击。 如果触底,玩家将输。 我该怎么做。 我是pygame的新手。 我想添加到我的代码中,但我不确定该怎么做。

  ask by user3479481 translate from so

本文未有回复,本站智能推荐: