0

I'm new to python/pygame and I'm trying to make a game. Basically it is a space ship floating around in space(it will be a scrolling background) pointing towards the mouse/crosshair. on clicking it will shoot bullets. there will be flying enemies which need AI and clinging enemies which need AI. Also liquids need to "flow." Collision detection for running into walls/bullets,enemies/floor. And lastly I will need a menu GUI (if i used gui in the right context.)

But right now, i would like to move the background (or for now the sprite) with keyboard controls. also how do I do a stretched image for the background?

This is what i've got:

import pygame, random, sys, time
pygame.init()
SIZE = [1000, 1000]
screen = pygame.display.set_mode(SIZE)
crosshair = pygame.image.load('crosshair.jpg')
player = pygame.image.load('spaceship.jpg')
pygame.display.set_caption("Solar Warfare")
WHITE = [255, 255, 255]
mouse_pos = []
spaceshipX = 0
spaceshipY = 0
done = False
pygame.mouse.set_visible(False)

while not done:
        for event in pygame.event.get():
                if event.type == pygame.MOUSEMOTION:
                        mouse_pos = pygame.mouse.get_pos([])
                        screen.blit(crosshair, (mouse_pos[0], mouse_pos[1]))
                        pygame.display.flip()#What is the other way to
                        #update the screen?
                if event.type == pygame.QUIT:
                        done = True                        
                if event.type == pygame.K_RIGHT:
                        spaceshipX += 1
        screen.fill(WHITE)
        screen.blit(player, (spaceshipX, spaceshipY))
        screen.blit(crosshair, (mouse_pos))
        pygame.display.flip()

pygame.quit()

I would like to add a scrolling background. I also need AI for the enemies, but thats later. Same with the Main Menu and levels and bosses/features etc... I talk alot XD

Indigo2003
  • 27
  • 11
  • "But right now, i would like to move the background (or for now the sprite) with keyboard controls." I don't see any attempt to read or use keyboard input in your posted code. What have you tried so far for keyboard controls, or for displaying any sort of background that could then be made to move? – Tom Dalton Mar 10 '16 at 23:53
  • @Tom I've been trying to respond with code in the comment for like 20 minutes. I give up. I'll just update the code in the question. – Indigo2003 Mar 12 '16 at 23:29
  • @Tom Also, my sprites don't have a transparent background. How do I change that? – Indigo2003 Mar 12 '16 at 23:39
  • `screen.blit(spaceship, (spaceshipY, spaceshipY))` - you are using `spaceshipY` for both the X and the Y position of the spaceship. – Tom Dalton Mar 14 '16 at 11:59
  • also see http://stackoverflow.com/questions/13059092/transparent-sprites-in-pygame ref the transparency. – Tom Dalton Mar 14 '16 at 11:59
  • @Tom thanks so much! Do you know how to rotate an image and make a stretched image? – Indigo2003 Mar 14 '16 at 16:17
  • @tom wait it still dodesnt work. I'll add the updated script. also can you vote up my question please? – Indigo2003 Mar 14 '16 at 16:24
  • @TomDalton Can you give me a working example with a crosshair and a moving sprite? – Indigo2003 Mar 16 '16 at 00:22
  • 1
    Sorry, stack overflow isn't a code writing service. Maybe you should start with a simpler game? Have you looked at any of the pygame demo games? – Tom Dalton Mar 16 '16 at 00:28
  • @TomDalton yes but i can't figure out how to download the source code for one – Indigo2003 Mar 16 '16 at 19:12
  • @TomDalton the one most similar to mine is called "Space Pirates Mission" – Indigo2003 Mar 17 '16 at 16:57

0 Answers0