添加下落的对象

时间:2014-04-21 03:28:09

标签: python pygame

# 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的新手。我想添加到我的代码中,我不知道该怎么做。

0 个答案:

没有答案