Tryout Task Tutorial

Return to Showcase

Tryout Task Tutorial

Postby joshuabeti » Sun Mar 21, 2010 3:13 am

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?

http://www.youtube.com/watch?v=LR_lLQFH-qY
joshuabeti
 
Posts: 2
Joined: Wed Feb 03, 2010 5:54 am
Location: Shah Alam, Selangor, Malaysia

Postby Bradamante » Sun Mar 21, 2010 8:16 pm

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

Code: Select all
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:

Code: Select all
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
CustoMac (2013), Mac OS X.9 - MacBookPro (2007), Mac OS X.8.5
@ YouTube
User avatar
Bradamante
 
Posts: 306
Joined: Tue Nov 25, 2008 10:58 am
Location: Leipzig, Germany

Postby joshuabeti » Mon Mar 22, 2010 4:07 am

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

but some errors occured.... :(


Image

for the asteroid...I have edited 3 pictures

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

Image

Image

Image

Please help me Bradamante..I am so new with this...huhu
joshuabeti
 
Posts: 2
Joined: Wed Feb 03, 2010 5:54 am
Location: Shah Alam, Selangor, Malaysia

Postby tallmystcarpet » Mon Mar 22, 2010 6:03 am

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!

Code: Select all
my test=1
if myTest!= 2:
    if myTest==1:
        print 'myTest==1'
is a syntax that python will understand and compile without errors but:

Code: Select all
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 ;)
http://www.ibiblio.org/swaroopch/byteof ... on_120.pdf
User avatar
tallmystcarpet
 
Posts: 222
Joined: Sun Aug 30, 2009 8:53 pm

Postby Bradamante » Mon Mar 22, 2010 9:26 am

joshuabeti wrote:Please help me Bradamante..I am so new with this...huhu


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: http://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

Code: Select all
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:
Code: Select all
for i in range(10):
...     print i % 2


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

Code: Select all
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.

Code: Select all
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)
CustoMac (2013), Mac OS X.9 - MacBookPro (2007), Mac OS X.8.5
@ YouTube
User avatar
Bradamante
 
Posts: 306
Joined: Tue Nov 25, 2008 10:58 am
Location: Leipzig, Germany


Return to Showcase

Who is online

Users browsing this forum: Bing [Bot] and 1 guest