[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: Creating several instances of same image
Grant Morganryuuguu wrote:
Also you could use a Numeric array. I like them for 2d structures
import Numeric
x=3
y=4
aliens = Numeric.resize(Alien(),(x,y))
for i in range(x)
for j in range(y)
aliens[i,j] = Alien((LEFT + i * DISTANCE, TOP + j * DISTANCE))
I find it easier to visualize what the code is doing when I can use
[i,j] type syntax. Also you can use slices to find left most and
right most alien which you will need.
i like it! It's like a nice Numeric Mini - Tutorial...
so
Numeric.resize(Alien(),(x,y))
gives me an (Numeric) Array for items of type Alien() (class object
reference) with size x*y ...
aliens[i,j]=Alien()
puts something in it
and
myAlien = aliens[1,1]
gives the reference back to me?
that's teh cool! It's so much easier than i thought, time to rewrite
some of my stuff... using lists, on the other hand, forces you to think
about what you do in terms of necessary / unnecessary accesses for speed
reasons...
Daniel