python - Adding a falling object -
# import pygame library python import pygame,sys #this next line imports pygame sound system pygame.mixer.init() # loads 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") # allows play song have loaded sound.play() #this allows grab inputs keyboard or mouse presses pygame.locals import * # line limits number of frames (60) # if computer speeds faster, still able play # helps prevent burning phone battery clock = pygame.time.clock() #this initiates pygame pygame.init() #set colors black = (0,0,0) white = (255,255,255) red = (255,0,0) green = (0,255,0) blue = (0,0, 255) #creating size of our game screen size = width, height = 700,700 black = 0,0,0 screen = pygame.display.set_mode((800,600)) # set title of window pygame.display.set_caption('dinosaur madness') pygame.mouse.set_visible(0) #makes mouse invisible on screen # adding 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 screen each loop x,y = pygame.mouse.get_pos() screen.blit(dinosaur,(x-dinosaur.get_width()/2, dinosaur_top)) event in pygame.event.get(): if event.type==pygame.quit: sys.exit() elif event.type == keydown , event.key == k_escape: sys.exit() elif event.type == keydown , event.key == k_q: sys.exit() #this allows user end game #by clicking on x @ top, escape, or q elif event.type ==mousebuttondown: roar.play() # when mouse button pressed, roar sound play shoot_y = 520 shoot_x = x elif event.type == keydown , event.key==k_space: pygame.image.save(screen,"screenshot.png") #this save screen shots of our screen file if shoot_y > 0: screen.blit(shoot,(shoot_x,shoot_y)) shoot_y -= 10 pygame.display.update()
i want add falling ice cubes. object dinosaur shoot them before hits bottom. if hits bottom, player loses. how go this. new pygame. want add code , not sure how it.
Comments
Post a Comment