May-19-2020, 09:07 PM
Hey all,
I'm really new to Python, this is only really my 5th or 6th day using the language (or really any major language). When I was younger I used Scratch a lot so if I'm using the wrong terminology or I am being unclear I'm sorry I can clear things up if you would like me to:).
Right now this I'm trying to create a space-invaders-type clone, this is my first project without the direct help of a guide. So I want to have bullets come out of my plane sprite. I'm trying to figure out how to do two things really, one is to get a 'clone' of the bullet sprite to spawn at an x and y relative to the plane. I know how to use .blit((x, y)) but I can't figure out how to get a clone of the sprite to spawn in so I can have multiple bullets coming out of the plane. The next thing I want to figure out is how to get that new spawned clone of the sprite to keep going towards y = 0 and stopping either when it gets there or collides with the enemy(ies)
I've googled some guides and posts and I either can't figure out how it could apply to my project or I can't understand what is happening. I saw a lot of ideas including classes and lists and while I understand what lists are I don't see/understand how they apply here, I am also starting to understand the usefulness of classes but they still are a bit confusing to me.
Thanks for any help:)
I'm really new to Python, this is only really my 5th or 6th day using the language (or really any major language). When I was younger I used Scratch a lot so if I'm using the wrong terminology or I am being unclear I'm sorry I can clear things up if you would like me to:).
Right now this I'm trying to create a space-invaders-type clone, this is my first project without the direct help of a guide. So I want to have bullets come out of my plane sprite. I'm trying to figure out how to do two things really, one is to get a 'clone' of the bullet sprite to spawn at an x and y relative to the plane. I know how to use .blit((x, y)) but I can't figure out how to get a clone of the sprite to spawn in so I can have multiple bullets coming out of the plane. The next thing I want to figure out is how to get that new spawned clone of the sprite to keep going towards y = 0 and stopping either when it gets there or collides with the enemy(ies)
I've googled some guides and posts and I either can't figure out how it could apply to my project or I can't understand what is happening. I saw a lot of ideas including classes and lists and while I understand what lists are I don't see/understand how they apply here, I am also starting to understand the usefulness of classes but they still are a bit confusing to me.
Thanks for any help:)
# imports and initializations import pygame import random pygame.init() # game start running = True gametick = 100 px = 250 # player x and y py = 275 pvel = 25 # player velocity and bullet vel bvel = 40 mod = 1 clock = pygame.time.Clock() # window window_height = 600 window_width = 800 window = pygame.display.set_mode((window_width, window_height)) pygame.display.set_caption("Game") # sprite imports. playerImg = pygame.image.load("images\player.png") backgroundImg = pygame.image.load("images\Background.png") bulletImg = pygame.image.load("images\Bullet.png") # Definitions def player(px, py): window.blit(playerImg, (px, py)) pygame.transform.scale(playerImg, (10, 10)) def background(): window.blit(backgroundImg, (0, 0)) def borders(): global px if px <= 0: px = 0 elif px >= 704: px = 704 # Gameloop while running: clock.tick(30) # Stop command for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Showing sprites and background background() player(px, py) # bullets # nothing here yet # Controls keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: borders() px -= pvel * mod if keys[pygame.K_RIGHT]: borders() px += pvel * mod if keys[pygame.K_UP]: pass # this will be for the bullets pygame.display.update()