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 7877473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:22:52+00:00 2026-06-03T03:22:52+00:00

I have created a pygame, the object of the game is to avoid the

  • 0

I have created a pygame, the object of the game is to avoid the balls moving around the screen (random)

ballpic = pygame.image.load('ball.png').convert_alpha()

I have a level function:

def levels(score):
 global enemies
 global velocity
 enemies = enemies
 velocity = velocity

#level one 
if score >= 500:
  enemies = 6
  velocity = 2

#level two
if score >= 1000:
  enemies = 6
  velocity = 2
  #....And so on

Game with indentation: ///Expired/

if I try to do that I get this error:

Traceback (most recent call last):
 File "C:\Users\MO\Desktop\Twerk\twerk-bck.py", line 252, in <module>
  game()
File "C:\Users\MO\Desktop\Twerk\twerk-bck.py", line 199, in game
 positionx[i]=positionx[i]+positionxmove[i]
IndexError: list index out of range

I understand I need to append new values to the lists to expand them by 3 more entries. what I’m trying to achieve is to add more balls to the screen score hits certain figure. But I don’t have any idea how I can do that ?

Thank you

  • 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-03T03:22:54+00:00Added an answer on June 3, 2026 at 3:22 am

    You initialize positionx and friends at line 134 before the main loop at 147. Then you call levels(score) inside the loop, which updates the enemies count but doesn’t actually allocate more space in positionx for the extra enemies. levels() should be responsible for resizing the arrays when it increases the enemy count.

    As Lattyware commented, using objects for each enemy would be a much better design. Generally if you’re keeping any kind of parallel arrays like positionx and positiony, you should replace them with an array of objects. Then all your different loops over range(enemies) would be replaced by one big loop like:

    for enemy in enemies:
        enemy.update(globalGameState)
    

    where globalGameState is one or more variables keeping track of stuff like the mouse position that is the same for all enemies.

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

Sidebar

Related Questions

I have created Pygame, which has objects (balls) which randomly move around the screen
Have created simple Ajax enabled contact forms before that have around 12 fields -
have created REST service using servicestack and in post request I have return object
I have image.I am trying to load a button on it.The image I'm loading
I am trying to create a pacman game with pygame but I have run
I have created a function that loops a folder and retrieves each image file
I have created a simple score system for my pygame. but it's pausing the
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and

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.