Beispiel #1
0
 def __init__(self, x = 0, y = 0, dir = 32, team = 1, bmstore = None):
     if dir < 16:
         imgname = 'base_left.gif'
     elif dir < 48:
         imgname = 'base_down.gif'
     elif dir < 80:
         imgname = 'base_right.gif'
     elif dir < 112:
         imgname = 'base_up.gif'
     else:
         imgname = 'base_left.gif'
     MapObject.__init__(self, x, y, 35 * 64, 35 * 64, bmstore[imgname])
     self.dir = dir
     self.team = team
 def __init__(self, x=0, y=0, dir=32, team=1, bmstore=None):
     if dir < 16:
         imgname = 'base_left.gif'
     elif dir < 48:
         imgname = 'base_down.gif'
     elif dir < 80:
         imgname = 'base_right.gif'
     elif dir < 112:
         imgname = 'base_up.gif'
     else:
         imgname = 'base_left.gif'
     MapObject.__init__(self, x, y, 35 * 64, 35 * 64, bmstore[imgname])
     self.dir = dir
     self.team = team
    def checkEvent(self, canvas, me):
        b = self.getBounds()
        p = me.point
        pl = self.polygon
        THRESHOLD = 9 / canvas.scale**2

        larger = Rectangle(b.x - 20 * 64, b.y - 20 * 64, b.width + 40 * 64,
                           b.height + 40 * 64)
        wraps = canvas.wrapOffsets(larger, p)
        if len(wraps) == 0:
            return 0

        if me.button == 1:
            for i in range(len(pl.points)):
                point = pl.points[i]
                if canvas.wrapdist2(p, point) < THRESHOLD:
                    if canvas.isErase():
                        if self.polygon.npoints > 3:
                            self.removePoint(i)
                            canvas.repaint()
                            canvas.saveUndo()
                    else:
                        canvas.setCanvasEventHandler(
                            PolygonPointMoveHandler(self, me, i,
                                                    canvas.wrap(p, point)))
                    return 1

        if not canvas.isErase():
            for wrap in wraps:
                for i in range(pl.npoints):
                    p1 = pl.points[i - 1]
                    p2 = pl.points[i]
                    if ptSeqDistSq(p1.x, p1.y, p2.x, p2.y, p.x + wrap[0],
                                   p.y + wrap[1]) < THRESHOLD:
                        if me.button == 1:
                            self.insertPoint(i, p)
                            canvas.setCanvasEventHandler(
                                PolygonPointMoveHandler(self, me, i, wrap))
                            return 1

        # MapObject's move handler needs x and y. Would be nicer to trap
        # their access and return appropriate values then...
        self.x = self.polygon.points[0].x
        self.y = self.polygon.points[0].y
        return MapObject.checkEvent(self, canvas, me)
    def checkEvent(self, canvas, me):
        b = self.getBounds()
        p = me.point
        pl = self.polygon
        THRESHOLD = 9 / canvas.scale**2

        larger = Rectangle(b.x - 20 * 64, b.y - 20 * 64,
                           b.width + 40 * 64, b.height + 40 * 64)
        wraps = canvas.wrapOffsets(larger, p)
        if len(wraps) == 0:
            return 0

        if me.button == 1:
            for i in range(len(pl.points)):
                point = pl.points[i]
                if canvas.wrapdist2(p, point) < THRESHOLD:
                    if canvas.isErase():
                        if self.polygon.npoints > 3:
                            self.removePoint(i)
                            canvas.repaint()
                            canvas.saveUndo()
                    else:
                        canvas.setCanvasEventHandler(PolygonPointMoveHandler(
                            self, me, i, canvas.wrap(p, point)))
                    return 1

        if not canvas.isErase():
            for wrap in wraps:
                for i in range(pl.npoints):
                    p1 = pl.points[i - 1]
                    p2 = pl.points[i]
                    if ptSeqDistSq(p1.x, p1.y, p2.x, p2.y, p.x + wrap[0],
                                   p.y + wrap[1]) < THRESHOLD:
                        if me.button == 1:
                            self.insertPoint(i, p)
                            canvas.setCanvasEventHandler(PolygonPointMoveHandler(
                                self, me, i, wrap))
                            return 1

        # MapObject's move handler needs x and y. Would be nicer to trap
        # their access and return appropriate values then...
        self.x = self.polygon.points[0].x
        self.y = self.polygon.points[0].y
        return MapObject.checkEvent(self, canvas, me)
    def __init__(self, imagePath, x, y, world, colorkey=None,
                 description = 'No information available.',
                 movable = False, owner='tmp',blendPath=None,
                 entityID = None):
        """
        Set up an Entity with an image loaded from the filepath
        specified by imagePath, an absolute x and y position in a given
        world, and a default description.  The image is loaded with
        an optional alpha colorkey.
        
        @param IDcounter: class counter which increments for every
        entity which is created, giving each entity a unique id
        
        @param entityID: unique id given to each Entity when
        instantiated
        
        @param world: L{World} object in which the Entity exists
        @type world: L{World}
        
        @param description: string description of the entity
        
        @param options: dictionary mapping string keys to callbacks.
        Intended to be used for displaying a popup menu.  When an
        item is selected, its callback will execute.
        @type options: dict
        
        @param maxHealth: maximum health of the Entity
        @param curHealth: current health of the Entity
        
        @param size: radius of collision (not currently implemented)
        @param status: current status of the Entity.  Found in Locals.
        
        """
        self.world = world
        
        # Prevents entities from being initialized off of the grid
        self.worldSize = self.world.grid.getCartGridDimensions()
        x = x%self.worldSize[0]
        y = y%self.worldSize[1]
        
        MapObject.__init__(self, imagePath, x, y, colorkey, blendPath=blendPath,
            owner=owner)
        
        # MAYBE FIXME - ADDED WED, APR 20 TO TRY TO FIX OBJ PLACEMENT
        self.rect.center = (x,y)
        
        #self.owner = owner
        
        # adds the entity to the provided world
        self.entityID = entityID
        
        # sets entityID if entityID is None
        self.world.addEntity(self,entityID)

        # First initialization of description
        self.description = description
        self.realCenter=self.rect.center
        
        self.movable = movable
        
        self.maxHealth = 100
        self.curHealth = self.maxHealth
        self.size = 100 #radius of collision
        self.status = Locals.IDLE
        self.time = pygame.time.get_ticks()
        self.timePrev = 0
        self.timePassed = self.time-self.timePrev
        self.selected = False
        self.blocking = False
        self.drawOffset=(0,0)#?

        #Image variables related to orientation
        self.imageCount = 1
        self.imageNum = None

        self.focused = False

        self.healthBar = HealthBar(self)
        
        self.regenRate = 0
        self._regenHealth = 0
        self.inventory=None
 def __init__(self, x = 0, y = 0, bmstore = None):
     MapObject.__init__(self, x, y, 35 * 64, 35 * 64,
                        bmstore["checkpoint.gif"])
Beispiel #7
0
 def __init__(self, x = 0, y = 0, bmstore = None):
     MapObject.__init__(self, x, y, 35 * 64, 35 * 64, bmstore['fuel.gif'])
 def __init__(self, x=0, y=0, team=1, bmstore=None):
     MapObject.__init__(self, x, y, 21 * 64, 21 * 64, bmstore["ball.gif"])
     self.team = team
Beispiel #9
0
 def __init__(self, x = 0, y = 0, team = 1, bmstore = None):
     MapObject.__init__(self, x, y, 21 * 64, 21 * 64, bmstore["ball.gif"])
     self.team = team
Beispiel #10
0
 def __init__(self, x=0, y=0, bmstore=None):
     MapObject.__init__(self, x, y, 35 * 64, 35 * 64, bmstore['fuel.gif'])