Jan-24-2018, 01:47 PM
import pygame, random, math pygame.init() # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption("My Game") clock = pygame.time.Clock() Ship = pygame.image.load("galaga-nemco.png") Shipright = pygame.image.load("galaga-nemco-right.png") Shipleft = pygame.image.load("galaga-nemco-left.png") ShipDown = pygame.image.load("galaga-nemco-down.png") Background_Image = pygame.image.load("swagbackground.png") LaserBeam = pygame.image.load("laserbeam.png") current = Ship Laser = pygame.mixer.Sound("laser5.ogg") pygame.mixer.music.load('DST-TowerDefenseTheme.ogg') pygame.mixer.music.set_endevent(pygame.constants.USEREVENT) pygame.mixer.music.play() rect_change_x = 0 rect_change_y = 0 ship_x = 50 ship_y = 50 leftedge = 349 rightedge = 700 bottom = 500 top = 0 done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif ship_y >= 500: ship_y = 460 elif ship_y <= 340: ship_y = 390 elif ship_x >= 700: ship_x = 640 elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: rect_change_x = -3 current = Shipleft elif event.key == pygame.K_RIGHT: rect_change_x = 3 current = Shipright elif event.key == pygame.K_UP: rect_change_y = -3 elif event.key == pygame.K_DOWN: current = ShipDown rect_change_y = 3 elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: rect_change_x = 0 current = Ship elif event.key == pygame.K_UP or event.key == pygame.K_DOWN: rect_change_y = 0 current = Ship elif event.type == pygame.MOUSEBUTTONDOWN: Laser.play() ship_x += rect_change_x ship_y += rect_change_y screen.blit(Background_Image, (0, 0)) screen.blit(current, (ship_x, ship_y)) pygame.display.flip() clock.tick(60) pygame.quit()My question is, how can I make LaserBeam come out of ship. (Like a laser shooting out of a space ship)