Пример #1
0
class Projectile(Item):
    """ Represents a banana projectile launch by the monkey.
    @ivar visual: Graphical object containing data and transformations
    @type visual: C{L{VisualObject}}
    """

    feature = "projectile"

    def __init__(self, id):
        """ Projectile itemp constructor. """
        Item.__init__(self, id)
        self.visual = VisualObject(os.path.join("data", "banana.png"))
        self.registerEvent("projectile")

    def evt_projectile_move(self, x, y):
        """ Projectile move event handler.
        @param event: Event with "projectile_move" type.
        @type event: C{L{common.simple_event.Event}}
        """
        self.visual.move(x, y)

    def evt_projectile_hitGround(self, x, y):
        """ Projectile hit ground event handler.
        @param event: Event with "projectile_hit_ground" type.
        @type event: C{L{common.simple_event.Event}}
        """
        print "[DISPLAY] Hit ground"
        # TODO: Graphic effect

    def evt_projectile_activate(self, state):
        """ Projectile activate event handler.
        @param event: Event with "projectile_activate" type.
        @type event: C{L{common.simple_event.Event}}
        """
        self.visual.setVisibility(state == 1)
Пример #2
0
class Projectile(Item):
    """ Represents a banana projectile launch by the monkey.
    @ivar visual: Graphical object containing data and transformations
    @type visual: C{L{VisualObject}}
    """
    
    feature = "projectile"
    
    def __init__(self, id):
        """ Projectile itemp constructor. """
        Item.__init__(self, id)
        self.visual = VisualObject(os.path.join("data", "banana.png"))
        self.registerEvent("projectile")
        
    def evt_projectile_move(self, x, y):
        """ Projectile move event handler.
        @param event: Event with "projectile_move" type.
        @type event: C{L{common.simple_event.Event}}
        """
        self.visual.move(x, y)
        
    def evt_projectile_hitGround(self, x, y):
        """ Projectile hit ground event handler.
        @param event: Event with "projectile_hit_ground" type.
        @type event: C{L{common.simple_event.Event}}
        """
        print "[DISPLAY] Hit ground"
        # TODO: Graphic effect
        
    def evt_projectile_activate(self, state):
        """ Projectile activate event handler.
        @param event: Event with "projectile_activate" type.
        @type event: C{L{common.simple_event.Event}}
        """
        self.visual.setVisibility(state == 1)
Пример #3
0
 def __init__(self):
     """ Sun item constructor. """
     Item.__init__(self)
     self.__visual1 = VisualObject(os.path.join("data", "sun.png"))
     self.__visual2 = VisualObject(os.path.join("data", "sun2.png"))
     self.__visual1.move (300,10)
     self.__visual2.move (300,10)
     self.visual = self.__visual1
     self.registerEvent("projectile")
     self.registerEvent("game")
Пример #4
0
 def __init__(self, id):
     """ Character item constructor.
     @param id:  Server item id.
     @type id: C{int}
     @param name: Character name.
     @type name: C{str}
     """
     Item.__init__(self, id)
     self.__x = None
     self.__y = None
     self.__id = id
     self.__name = "unamed%s" %id
     self.visual = VisualObject(os.path.join("data", "gorilla.png"))
     self.active = False
     self.registerEvent("character")
Пример #5
0
class Sun(Item):
    """ Represents a smiling sun which makes "oh" when collided.
    @ivar visual: Graphical object containing data and transformations
    @type visual: C{L{VisualObject}}
    @ivar __visual1: Visual with the smiling sun image.
    @type __visual1: C{L{VisualObject}}
    @ivar __visual2: Visual with the "oh"-ing sun image.
    @type __visual2: C{L{VisualObject}}
    """
    
    feature = "sun"
    
    def __init__(self):
        """ Sun item constructor. """
        Item.__init__(self)
        self.__visual1 = VisualObject(os.path.join("data", "sun.png"))
        self.__visual2 = VisualObject(os.path.join("data", "sun2.png"))
        self.__visual1.move (300,10)
        self.__visual2.move (300,10)
        self.visual = self.__visual1
        self.registerEvent("projectile")
        self.registerEvent("game")
        
    def evt_game_nextTurn(self):
        """ Next turn event handler.
        @param event: Event with "game_next_turn" type.
        @type event: C{L{common.simple_event.Event}}
        """
        self.resetHit()
        
    def evt_projectile_move(self, x, y):
        """ Projectile move event handler.
        @param event: Event with "projectile_move" type.
        @type event: C{L{common.simple_event.Event}}
        """
        if self.visual == self.__visual2: return
        projectile_rect = pygame.Rect([x,y,10,10]) # TODO: Incorrect projectile size!
        if self.visual.rect.colliderect(projectile_rect):
            self.hit()
    
    def resetHit(self):
        """ Shows back the smiling sun. """
        self.visual = self.__visual1
    
    def hit(self):
        """ Shows the sun which makes "oh". """
        self.visual = self.__visual2
Пример #6
0
class Character(Item):
    """ Represents a monkey character controlled by the player.
    @ivar visual: Graphical object containing data and transformations
    @type visual: C{L{VisualObject}}
    @ivar __x: Item abscisse.
    @type __x: C{int}
    @ivar __y: Item ordonnee.
    @type __y: C{int}
    @ivar __id: Server item id.
    @type __id: C{int}
    @ivar __name: Name of the player controlling the character (as known by the server).
    @type __name: C{str}
    """
    feature = "character"
    
    def __init__(self, id):
        """ Character item constructor.
        @param id:  Server item id.
        @type id: C{int}
        @param name: Character name.
        @type name: C{str}
        """
        Item.__init__(self, id)
        self.__x = None
        self.__y = None
        self.__id = id
        self.__name = "unamed%s" %id
        self.visual = VisualObject(os.path.join("data", "gorilla.png"))
        self.active = False
        self.registerEvent("character")
        
    def evt_character_move(self, id, x, y):
        """ Character move event handler.
        @param event: Event with "character_move" type.
        @type event: C{L{common.simple_event.Event}}
        """
        if self.__id != id: return
        self.__x = x
        self.__y = y
        self.visual.move(self.__x, self.__y)
    
    def eventPerformed(self, event):
        if event.event == "move":
            raise Exception(event)
    
    def evt_character_name(self, id, name):
        self.__name = name
Пример #7
0
 def __init__(self, id):
     """ Projectile itemp constructor. """
     Item.__init__(self, id)
     self.visual = VisualObject(os.path.join("data", "banana.png"))
     self.registerEvent("projectile")
Пример #8
0
 def __init__(self, id):
     """ Projectile itemp constructor. """
     Item.__init__(self, id)
     self.visual = VisualObject(os.path.join("data", "banana.png"))
     self.registerEvent("projectile")