All pastes #829723 Raw Edit

Vermischtes

public text v1 · immutable
#829723 ·published 2007-12-23 12:30 UTC
rendered paste body
import pygame, ode
from pygame.locals import *

class Cow(pygame.sprite.Sprite):
    def __init__(self, screen, surface, world, x, y):
        pygame.sprite.Sprite.__init__(self)
        
        # pygame Sprite
        self.screen = screen
        self.image = surface
        self.rect = self.image.get_rect()
        
        # coords
        self.x = x
        self.cy = y
        self.y = self.screen.get_height() - self.cy
        
        # pyode
        self.world = world
        self.body = ode.Body(world)
        self.mass = ode.Mass()
        
        self.mass.setBox(800, self.image.get_width(), self.image.get_height(), 1)
        self.mass.mass = 75
        self.body.setMass(self.mass)
        
        self.body.setPosition((self.x, self.cy, 0))
        self.rect.move_ip(self.x, self.y)
        
    def update(self):
        oldx = self.x
        oldcy = self.cy
        oldy = self.y
             
        cx, cy, cz = self.body.getPosition()
        
        self.x = cx
        self.cy = cy
        self.y = self.screen.get_height() - self.cy
        
        self.rect.move_ip(self.x -oldx, self.y - oldy)