Tryout Task Tutorial


#1

Guys, I need helps with Python programming, I am trying to make a simple prototype game with the tutorial (manuals provided by Panda3D.org)
Tutorial: TASK TUTORIAL
Mission: Only shoot the LETTERS, if player shoot the NUMBERS, player will lose
Problems: How do I make my mission possible, anyone can help me with the Programming?

youtube.com/watch?v=LR_lLQFH-qY


#2

One way is to use tags for that, or do you do that already?

def spawnAsteroids(self):
    for i in range(10):
        asteroid = loadObject("asteroid" + str(randint(1,3)), scale = AST_INIT_SCALE)
        if someCondition:
              	asteroid.setTag("isLetter", 1)
        else:
             asteroid.setTag("isLetter", 0)
        self.asteroids.append(asteroid)

Then when you check the collision of the bullet with the asteroid:

if (collision check code from the sample) and self.asteroid[i].getTag("isLetter") == 1:
        self.setExpires(bullet, 0)       #Schedule the bullet for removal
        self.asteroidHit(i)      #Handle the hit

#3

for the someCondition: I did try to change it to
if (self.asteroid[1] and self.asteroid[2])

but some errors occured… :frowning:

for the asteroid…I have edited 3 pictures

These are my astroid (I have fixed the LETTERS n NUMBERS:

Please help me Bradamante…I am so new with this…huhu


#4

I don’t think you’re in the good section of the forum… Someone will certainly move it to the right place.
The error message you got is because your code is not indented correctly. Python take care of the indentation of the code!

my test=1
if myTest!= 2:
    if myTest==1:
        print 'myTest==1'

is a syntax that python will understand and compile without errors but:

my test=1
if myTest!= 2:
if myTest==1:
print 'myTest==1'

will generate the errors you got.

Your error is detected at line 381 so have look at line 380 where the indentation error might be!

Some doctors created free medecines that I used to take two or three pages before sleeping :wink:
ibiblio.org/swaroopch/byteof … on_120.pdf


#5
  1. I think you have to learn a bit more about Python. I have used Will McCugan’s “Beginning Game Development with Python and Pygame: From Novice to Professional” for example. Also check the Python docs: docs.python.org/

  2. If you want to show error messages on the forum, do not make a screenshot. Instead, copy the text from the console to the forums using [ code ] tags.

  3. You have edited the graphics, but Panda does not know about that. Panda does not magically read pictures. You have to use text some way, for example tags.
    About the spawnAsteroids function. You are using

for i in range(10)

which creates the numbers 0 to 9. Let’s say you want to have 50% of the elements to be letters, 50% to be numbers. You can use the modulo % operator for that.
The modulo operator checks if number1 divided by number2 produces a remainder, like: 2/2 = 0, no rest, 3/2 = 1, has a remainder.

For example:

for i in range(10):
...     print i % 2

will print: 0,1,0,1,0,1,0,1,0,1.

for i in range(10):
...     print i % 3

will print: 0,1,2,0,1,2,0,1,2,0. You could use that to create three classes of objects instead of two.

def spawnAsteroids(self):
    for i in range(10):
        asteroid = loadObject("asteroid" + str(randint(1,3)), scale = AST_INIT_SCALE)
        if i % 2 == 0:
            asteroid.setTag("isLetter", 1)
        else:
            asteroid.setTag("isLetter", 0)
        self.asteroids.append(asteroid)