Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:58:04+00:00 2026-06-04T03:58:04+00:00

I’m a beginner programmer and my first language is Python 2.7, I’m trying to

  • 0

I’m a beginner programmer and my first language is Python 2.7, I’m trying to make a space invader type game but i want to have multiple bullets at once and cant find a way to do that. so i made my own way here is my code ill explain more after you see it

        if event.type ==pygame.KEYDOWN and event.key==K_SPACE:
            if m < 5:
                m+=1

            if m==1:
                m1a=1
                m1x=ls

            if m==2:
                m2a=1
                m2x=ls

            if m==3:
                m3a=1
                m3x=ls

            if m==4:
                m4a=1
                m4x=ls

            if m==5:
                m5a=1
                m5x=ls

            print m
#missle 1
    if m1a==1:
        screen.blit(rship,(m1x,m1))
        if m1>=0:
            m1-=1
        else:
            m-=1
            m1a=0
            m1=460
#missle 2
    if m2a==1:
        screen.blit(rship,(m2x,m2))
        if m2>=0:
            m2-=1
        else:
            m-=1
            m2a=0
            m2=460
#missle 3
    if m3a==1:
        screen.blit(rship,(m3x,m3))
        if m3>=0:
            m3-=1
        else:
            m-=1
            m3a=0
            m3=460
#missle 4
    if m4a==1:
        screen.blit(rship,(m4x,m4))
        if m4>=0:
            m4-=1
        else:
            m-=1
            m4a=0
            m4=460
#missle 5
    if m5a==1:
        screen.blit(rship,(m5x,m5))
        if m5>=0:
            m5-=1
        else:
            m-=1
            m5a=0
            m5=460

I’m sure its laughably noobish but I’m just learning but the problem is the first and second missile are fine its the third and beyond that get messed up. when you fire the third it moves the second over the where your shooting from and then if you fir again the code wont go back down to 1 it stays at 2 and gets even more glitches. If you need me to try and explain it better I gladly will. Just trying to Learn.

Full code here: pastebin.com/FnPaME6N

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:58:06+00:00Added an answer on June 4, 2026 at 3:58 am

    Here is some working code, but I wouldn’t call it great.

    import pygame
    import math
    from pygame.locals import *
    background_colour = (122, 100, 155)
    (width, height) = (500, 500)
    
    pygame.init()
    
    #ship = pygame.image.load('lolol.jpeg')\
    rship = pygame.image.load('js.jpg')
    mis = pygame.image.load('lot.jpg')
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption('A.N.T.O.N.I.A.')
    screen.fill(background_colour)
    pygame.display.flip()
    running = True
    
    MAX_MISSILES = 5
    
    ls = 250  # Horizontal ship location
    
    LEFT = False
    RIGHT = False
    
    def move(ls, RIGHT, LEFT):
        '''Moves the ship 3 pixels to the left or right.
    
        Only moves if just one direction key is down, and not both.
        Also, will not move if the ship is at either horizontal screen edge.
    
        ls is the ship location.
    
        '''
        if LEFT and not RIGHT:
            if ls >= 10:
                ls -= 3
        elif RIGHT and not LEFT:
            if ls <= 440:
                ls += 3
        return ls
    
    def fire_missile(ls, missiles):
        '''Fire a missile, as long as we are not at the maximum number.
    
        We use a list to hold our missile locations.
    
        '''
        if len(missiles) >= MAX_MISSILES:
            return
        else:
            missiles.append((ls, 460))
    
    def draw_missiles(missiles):
        '''Draw all the missiles.'''
        if missiles:
            for missile in missiles:
                screen.blit(mis, (missile))
    
    def move_missiles(missiles):
        '''If there are any missiles, move them up 1 pixel, and append
        them to the newlist.  The new list will replace the old list.
    
        '''
        if missiles:
            newmissiles = []
            for missile in missiles:
                # Do not append the missile to the new list if it is going
                # off the screen
                if missile[1] > 0:
                    newmissiles.append((missile[0], missile[1] - 1))
            return newmissiles
        else:
            return missiles
    
    missiles = []
    
    while running:
        screen.blit(rship, (ls, 450))
        pygame.display.flip()
        screen.fill(background_colour)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                running = False
            if event.type == pygame.KEYDOWN and event.key == K_ESCAPE:
                # You can now quit with the escape key.
                pygame.quit()
                running = False
            if event.type == pygame.KEYDOWN and event.key == K_LEFT:
                LEFT = True
            # LEFT is True untli you let up in the LEFT key
            if event.type == pygame.KEYUP and event.key == K_LEFT:
                LEFT = False
            if event.type == pygame.KEYDOWN and event.key == K_RIGHT:
                RIGHT = True
            if event.type == pygame.KEYUP and event.key == K_RIGHT:
                RIGHT = False
            if event.type == pygame.KEYDOWN and event.key == K_SPACE:
                fire_missile(ls, missiles)
        ls = move(ls, RIGHT, LEFT)
        draw_missiles(missiles)
        missiles = move_missiles(missiles)
    

    Any time you find yourself making variables with numbers in them, it’s a code smell, and means you probably should use a different data type.

    As has been suggested, you’ll probably want to look into the sprite and group modules, but this will at least do what you were trying to do so far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.