Esempio n. 1
0
 def update(self):
     #Calculates turning effect of each motor and uses them to make a turn
     averagespeed = float((self.motors[0].speed + self.motors[1].speed))/2
     self.velocity = norm(self.box.axis)*averagespeed/RATE
     moment0 = float(self.motors[0].speed)
     moment1 = float(-self.motors[1].speed)
     self.totalmoment = (moment0 + moment1)/RATE
     #Check for collisions with walls
     for wall in walllist:
         if collisiondetection.collisiondetect(wall,self.box):
             if wall == walllist[0]:
                 self.box.pos += (0.2,0,0)
             elif wall == walllist[1]:
                 self.box.pos += (-0.2,0,0)
             elif wall == walllist[2]:  
                 self.box.pos += (0,0,0.2)
             elif wall == walllist[3]:
                 self.box.pos += (0,0,-0.2)
             self.velocity=(0,0,0)
             self.totalmoment=0     
     #check for collisions with tokens
     for token in token_list:
         if collisiondetection.collisiondetect(self.box,token.box):
             #check if tokens are touching walls
             self.wall_token_collision(token) 
             #check if tokens are touching other tokens
             self.token_token_collision(token)
             if self.velocity != (0,0,0):
                 token.box.pos += self.velocity*1.5
                 for things in token.markers:
                     things.marker.pos += self.velocity*1.5
             if self.totalmoment != 0:
                 token.box.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                 token.box.pos -= 0.03*vector(self.box.axis.z,0,-self.box.axis.x)
                 for things in token.markers:
                     things.marker.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                     things.marker.pos -= 0.03*vector(self.box.axis.z,0,-self.box.axis.x)
                     things.marker.pos += self.velocity*1.5
             if self.totalmoment != 0:
                 token.box.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                 token.box.pos -= 0.1*vector(self.box.axis.z,0,-self.box.axis.x)
                 for things in token.markers:
                     things.marker.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                     things.marker.pos -= 0.1*vector(self.box.axis.z,0,-self.box.axis.x)                        
     self.box.pos += self.velocity
     self.box.rotate(angle=self.totalmoment/RATE, axis = (0,1,0), origin = self.box.pos)
Esempio n. 2
0
 def token_token_collision(self,token):
     temp_token_list = token_list[:]
     temp_token_list.remove(token)
     for othertoken in temp_token_list:
         if self.velocity != (0,0,0):
             if collisiondetection.collisiondetect(token.box,othertoken.box):
                 self.wall_token_collision(othertoken)
                 if self.velocity!=(0,0,0):
                     othertoken.box.pos += self.velocity*1.5
                     for things in othertoken.markers:
                         things.marker.pos += self.velocity*1.5
             if self.totalmoment != 0:
                 othertoken.box.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                 othertoken.box.pos -= 0.03*vector(self.box.axis.z,0,-self.box.axis.x)
                 for things in othertoken.markers:
                     things.marker.rotate(angle=(self.totalmoment/RATE), axis = (0,1,0), origin=self.box.pos)
                     things.marker.pos -= 0.03*vector(self.box.axis.z,0,-self.box.axis.x)
                 self.wall_token_collision(othertoken)
Esempio n. 3
0
 def wall_token_collision(self,token):
         for wall in walllist:
             if collisiondetection.collisiondetect(wall,token.box):
                 if wall == walllist[0]:
                     token.box.pos += (0.1,0,0)
                     self.box.pos += (0.2,0,0)
                     for things in token.markers:
                         things.marker.pos += (0.1,0,0)
                 elif wall == walllist[1]:
                     token.box.pos += (-0.1,0,0)
                     self.box.pos += (-0.2,0,0)
                     for things in token.markers:
                         things.marker.pos += (-0.1,0,0)
                     token.box.pos += (0,0,0.1)
                     self.box.pos += (0,0,0.2)
                     for things in token.markers:
                         things.marker.pos += (0,0,0.1)
                 elif wall == walllist[3]:
                     token.box.pos += (0,0,-0.1)
                     self.box.pos += (0,0,-0.2)
                     for things in token.markers:
                         things.marker.pos += (0,0,-0.1)
                 self.velocity=(0,0,0)
                 self.totalmoment=0