Hello,
I'm trying to learn Python, (i have 2.5.4) by writing a snake game, but I'm stuck. Some integers change into floats and keep changing randomly, at least from my perspective :)
The problem is that Snake.spawnPoint
gets changed by Cam.move()
print Snake.spawnPoint # first time, this returns '[25, 20]' ,which is good.
Cam.Move()
print Snake.spawnPoint # after the method, the value is '[26.0, 21.0]', and that's bad
After that, they just drift around.
And this is the method: (it has nothing to do with the spawnPoint
def Move(self):
self.vel[0]+=(self.target[0]-self.cen[0])*self.k
self.vel[1]+=(self.target[1]-self.cen[1])*self.k
if self.vel[0] > self.friction: self.vel[0]-= self.friction
elif self.vel[0] < self.friction: self.vel[0]+= self.friction
else: self.vel[0] = 0
if self.vel[1] > self.friction: self.vel[1]-= self.friction
elif self.vel[1] < self.friction: self.vel[1]+= self.friction
else: self.vel[1]=0
self.cen[0]+=self.vel[0]
self.cen[1]+=self.vel[1]
The spawnPoint
is a constant that I append to the snake's body when he spawns. I like it to be a list because it have the snake's body made of lists, and the rendering method uses index()
to do stuff.
The code doesn't seem to fit here, so i zipped it. Can someone take a look at it? Thanks http://www.mediafire.com/?zdcx5s93q9hxz4o