Beispiel #1
0
    def __init__(self, manager, weapon, source_position, destination_position):
        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)

        self.manager = manager

        self.weapon = weapon
        self.weapon.duration = float(
            self.weapon.duration)  # ensure we are using floats
        self.padding = self.weapon.width

        self.source_position = source_position
        self.destination_position = destination_position

        self.idle_image = pygame.surface.Surface((0, 0))
        self.image = self.idle_image
        self.rect = pygame.rect.Rect(self.source_position[0],
                                     self.source_position[1],
                                     self.image.get_width(),
                                     self.image.get_height())

        self.framecount = 0
        self.frameskip = 2

        # Prerender the laser
        self.draw_laser()

        # Start animation
        self.current_pulse = 0
        self.image = self.laser_image
        self.rect = self.laser_rect
        self.timestamp = pygame.time.get_ticks()
        self.state = self.states.animating

        self.emit(constants.EVENT_ENTITY_WAIT, self)
Beispiel #2
0
 def __init__(self, name):
     BaseObject.__init__(self)
     self.name = name
     # The object should be able to listen to 'ping' and 'pong'
     # events.
     self._signals["ping"] = []
     self._signals["pong"] = []
Beispiel #3
0
    def __init__ (self):
        Accessible.__init__ (self)
        BaseObject.__init__ (self)
        pygame.sprite.Sprite.__init__ (self)

        self._x = 0
        self._y = 0
        self._width = 0   # Guaranteed sizes for the widget, see also 
        self._height = 0  # the size attribute and set_size () method.
        
        self._image = None
        self._rect = None
        self._eventarea = None

        self._style = None
        self._index = 0
        self._state = STATE_NORMAL
        self._focus = False
        self._sensitive = True

        self._controls = []
        self.parent = None
        self._newdepth = 0
        self._depth = 0
        self._dirty = True
    
        # Signals, the widget listens to by default
        self._signals[SIG_FOCUS] = []
Beispiel #4
0
 def __init__ (self, re):
     BaseObject.__init__ (self)
     # Remember to set _signals before setting the manager!
     self._signals[COMMAND] = []
     self.connect_signal (COMMAND, self.processCommand)
     self.manager = re.active_layer[2]
     self.renderer = re
     
     # self.frame is the main widget for this class.
     self.frame = VFrame (Label ("Enter login information"))
     # labels on the left, entry fields on the right.
     self.table = Table (3, 3)
     self.table.set_column_align (0, ALIGN_RIGHT)
     self.table.set_column_align (1, ALIGN_LEFT)
     self.table.add_child (0, 0, Label ("Server:"))
     self.table.add_child (1, 0, Label ("Port:"))
     self.table.add_child (2, 0, Label ("Username:"******"Connect")
     self.button.connect_signal (SIG_MOUSEDOWN, self.sendConnect)
     self.frame.add_child (self.button)
     
     # Set the frame roughly in the middle.
     self.frame.topleft = (190, 70)
Beispiel #5
0
 def __init__ (self, re):
     BaseObject.__init__ (self)
     # Remember to set _signals before setting the manager!
     self._signals[SIG_REC] = []
     self.connect_signal (SIG_REC, self.addText)
     self._signals[COMMAND] = []
     self.connect_signal (COMMAND, self.processCommand)
     self.manager = re.active_layer[2]
     self.renderer = re
     
     # self.table is the main widget for this class
     self.table = Table(2,2)
     
     self.chatframe = VFrame (Label ("Chat Window"))
     self.chatwindow = ScrolledList (520, 240)
     self.chatwindow.selectionmode = SELECTION_NONE
     self.chatframe.add_child (self.chatwindow)
     
     self.entryFrame = VFrame ()
     self.entry = Entry ()
     self.entry.minsize = (520, 24)
     self.entry.connect_signal ("input", self.sendText)
     self.entryFrame.add_child (self.entry)
     
     self.table.add_child (0, 0, self.chatframe)
     self.table.add_child (1, 0, self.entryFrame)
 def __init__ (self, manager, weapon, source_position, destination_position):
     BaseObject.__init__(self)
     pygame.sprite.Sprite.__init__(self)
     
     self.manager = manager
     
     self.weapon = weapon
     self.weapon.duration = float(self.weapon.duration) # ensure we are using floats
     self.padding = self.weapon.width
     
     self.source_position = source_position
     self.destination_position = destination_position
     
     self.idle_image = pygame.surface.Surface((0,0))
     self.image = self.idle_image
     self.rect = pygame.rect.Rect(
         self.source_position[0], self.source_position[1], self.image.get_width(), self.image.get_height())
     
     self.framecount = 0
     self.frameskip = 2
     
     # Prerender the laser
     self.draw_laser()
     
     # Start animation
     self.current_pulse = 0
     self.image = self.laser_image
     self.rect = self.laser_rect
     self.timestamp = pygame.time.get_ticks()
     self.state = self.states.animating
     
     self.emit(constants.EVENT_ENTITY_WAIT, self)
 def __init__ (self, manager, side, reference, name, model, weapon=None, weapon_points=[]):
     
     BaseObject.__init__(self)
     pygame.sprite.Sprite.__init__(self)
     
     self._signals[constants.EVENT_ENTITY_FIRE] = []
     self._signals[constants.EVENT_ENTITY_DAMAGE] = []
     self._signals[constants.EVENT_ENTITY_DEATH] = []
     
     self._signals[constants.EVENT_ANIMATION_DAMAGE_COMPLETE] = []
     
     self.manager = manager
     
     self.side = side
     self.reference = reference
     self.name = name
     self.weapon = weapon
     self.weapon_points = weapon_points
     
     self.damage_animation_queue = []
     
     self.death_duration = 1500.0
     
     self.image = pygame.image.load(model)
     self.rect = pygame.rect.Rect(0, 0, self.image.get_width(), self.image.get_height())
     self.state = self.states.idle
     
     self.framecount = 0
     self.frameskip = 3
 def __init__ (self, manager, font_path='./fonts/'):
     BaseObject.__init__(self)
     pygame.sprite.Sprite.__init__(self)
     
     if SummaryScreen.font == None:
         # Bitstream Vera Sans Mono
         SummaryScreen.font = pygame.font.Font(font_path+'VeraMoBd.ttf', 12)
         
     # Basically a duplication of damage animation - damage animation should probably be derived from this
     self.manager = manager
Beispiel #9
0
    def __init__(self, manager, font_path='./fonts/'):
        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)

        if SummaryScreen.font == None:
            # Bitstream Vera Sans Mono
            SummaryScreen.font = pygame.font.Font(font_path + 'VeraMoBd.ttf',
                                                  12)

        # Basically a duplication of damage animation - damage animation should probably be derived from this
        self.manager = manager
 def __init__ (self):
     BaseObject.__init__(self)
     
     self._signals[constants.EVENT_BATTLE_START] = []
     self._signals[constants.EVENT_VIEW_READY] = []
     
     self.entity_list = {}
     
     # Store the current round
     self.round = 0
     self.round_list = []
     self.round_timestamp = None
    def __init__(self):
        BaseObject.__init__(self)

        self._signals[constants.EVENT_BATTLE_START] = []
        self._signals[constants.EVENT_VIEW_READY] = []

        self.entity_list = {}

        # Store the current round
        self.round = 0
        self.round_list = []
        self.round_timestamp = None
    def __init__ (self, display_surface):
        BaseObject.__init__(self)
        
        # Set up list of signals to listen for
        for signal in (constants.EVENT_ROUND_START,
                        constants.EVENT_MESSAGE,
                        constants.EVENT_ENTITY_NEW,
                        constants.EVENT_ENTITY_WAIT,
                        constants.EVENT_ENTITY_READY,
                        constants.EVENT_BATTLE_START,
                        constants.EVENT_ANIMATION_LASER,
                        constants.EVENT_ANIMATION_DAMAGE):
            self._signals[signal] = []
        
        # Initialize the display
        self.display_surface = display_surface
        
        # Create a background surface
        background_color = (0,0,0)
        self.background_surface = pygame.surface.Surface((self.display_surface.get_width(), self.display_surface.get_height()))
        self.background_surface.fill(background_color)
        
        # Create starfield background
        star_count = 200
        utility.static_starfield(self.background_surface, star_count)

        # Blit the background surface to the display surface
        self.display_surface.blit(self.background_surface, (0,0))
    
        # Update the whole display
        pygame.display.flip()
        
        # Sprite group for drawing all messages
        self.message_group = pygame.sprite.RenderUpdates()
        
        # Sprite group for drawing all entities
        self.entity_group = pygame.sprite.RenderUpdates()
        
        # Sprite group for drawing all entities
        self.weapon_group = pygame.sprite.RenderUpdates()
        
        # Sprite group for damage animations
        self.damage_group = pygame.sprite.RenderUpdates()
        
        self.battle_active = False
        
        self.round_timestamp = None
        self.round_delay = 1500 # Should come from config file
        
        # Number of objects who have requested we wait for them before ending the round
        self.waiting_counter = 0

        self.state = BattleView.states.ready
    def __init__(self, display_surface):
        BaseObject.__init__(self)

        # Set up list of signals to listen for
        for signal in (constants.EVENT_ROUND_START, constants.EVENT_MESSAGE,
                       constants.EVENT_ENTITY_NEW, constants.EVENT_ENTITY_WAIT,
                       constants.EVENT_ENTITY_READY,
                       constants.EVENT_BATTLE_START,
                       constants.EVENT_ANIMATION_LASER,
                       constants.EVENT_ANIMATION_DAMAGE):
            self._signals[signal] = []

        # Initialize the display
        self.display_surface = display_surface

        # Create a background surface
        background_color = (0, 0, 0)
        self.background_surface = pygame.surface.Surface(
            (self.display_surface.get_width(),
             self.display_surface.get_height()))
        self.background_surface.fill(background_color)

        # Create starfield background
        star_count = 200
        utility.static_starfield(self.background_surface, star_count)

        # Blit the background surface to the display surface
        self.display_surface.blit(self.background_surface, (0, 0))

        # Update the whole display
        pygame.display.flip()

        # Sprite group for drawing all messages
        self.message_group = pygame.sprite.RenderUpdates()

        # Sprite group for drawing all entities
        self.entity_group = pygame.sprite.RenderUpdates()

        # Sprite group for drawing all entities
        self.weapon_group = pygame.sprite.RenderUpdates()

        # Sprite group for damage animations
        self.damage_group = pygame.sprite.RenderUpdates()

        self.battle_active = False

        self.round_timestamp = None
        self.round_delay = 1500  # Should come from config file

        # Number of objects who have requested we wait for them before ending the round
        self.waiting_counter = 0

        self.state = BattleView.states.ready
    def __init__(self,
                 manager,
                 damage_amount,
                 position,
                 animation_duration=0,
                 wait_duration=0,
                 font_path='./fonts/'):
        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)

        if DamageAnimation.font == None:
            # Bitstream Vera Sans Mono
            DamageAnimation.font = pygame.font.Font(font_path + 'VeraMoBd.ttf',
                                                    18)

        if manager:
            self.manager = manager

        self.x = position[0]
        self.y = position[1]

        shadow_offset = 3
        text = DamageAnimation.font.render(str(int(damage_amount)), False,
                                           (255, 0, 0)).convert()
        shadow = DamageAnimation.font.render(str(int(damage_amount)), False,
                                             (50, 50, 50)).convert()
        self.display_image = pygame.surface.Surface(
            (text.get_width() + shadow_offset,
             text.get_height() + shadow_offset), 0, 32).convert_alpha()
        self.display_image.fill((0, 0, 0, 0))
        self.display_image.blit(shadow, (shadow_offset, shadow_offset))
        self.display_image.blit(text, (0, 0))
        self.idle_image = pygame.surface.Surface((0, 0))
        self.image = self.idle_image
        self.rect = pygame.rect.Rect(self.x, self.y, self.image.get_width(),
                                     self.image.get_height())

        self.wait_duration = wait_duration
        self.duration = float(animation_duration)

        # Record of original alpha for blending
        self.original_alpha = pygame.surfarray.array_alpha(self.display_image)

        self.state = self.states.waiting
        self.timestamp = pygame.time.get_ticks()

        self.emit(constants.EVENT_ENTITY_WAIT, self)
Beispiel #15
0
 def __init__ (self, re):
     """
     The Jumping Button game. When the button is clicked, it emits a
     SCORE event, which is picked up by the network controller. It
     listens for a REPORT event and updates the score display with
     the value given by the server.
     """
     BaseObject.__init__ (self)
     self._signals[REPORT] = []
     self.connect_signal (REPORT, self.adjustScore)
     self.manager = re.active_layer[2]
     
     # create gui elements
     self.btn = self.drawButton ((20, 20))
     self.scoreLabel = Label ("Current score: ")
     re.add_widget (self.btn)
     re.add_widget (self.scoreLabel)
    def __init__ (self):
        BaseObject.__init__ (self)
        sprite.Sprite.__init__ (self)

        # Guaranteed sizes for the widget, see also the minsize/maxsize
        # attributes and set_*_size () methods.
        self._minwidth = 0
        self._minheight = 0
        self._maxwidth = 0
        self._maxheight = 0

        self._indexable = None
        
        self._image = None
        self._rect = Rect (0, 0, 0, 0)
        self._oldrect = Rect (0, 0, 0, 0)

        self._opacity = 255
        self._style = None
        self._index = 0
        self._state = STATE_NORMAL
        self._focus = False
        self._entered = False
        self._sensitive = True

        self._controls = []
        self._depth = 0
        self._dirty = True
        self._lock = 0

        self._bg = None

        self.parent = None
        
        # Accessibility.
        self._tooltip = None
        
        # Signals, the widget listens to by default
        self._signals[SIG_FOCUSED] = []
        self._signals[SIG_ENTER] = []
        self._signals[SIG_LEAVE] = []
        self._signals[SIG_DESTROYED] = []
Beispiel #17
0
    def __init__(self):
        BaseObject.__init__(self)
        sprite.Sprite.__init__(self)

        # Guaranteed sizes for the widget, see also the minsize/maxsize
        # attributes and set_*_size () methods.
        self._minwidth = 0
        self._minheight = 0
        self._maxwidth = 0
        self._maxheight = 0

        self._indexable = None

        self._image = None
        self._rect = Rect(0, 0, 0, 0)
        self._oldrect = Rect(0, 0, 0, 0)

        self._opacity = 255
        self._style = None
        self._index = 0
        self._state = STATE_NORMAL
        self._focus = False
        self._entered = False
        self._sensitive = True

        self._controls = []
        self._depth = 0
        self._dirty = True
        self._lock = 0

        self._bg = None

        self.parent = None

        # Accessibility.
        self._tooltip = None

        # Signals, the widget listens to by default
        self._signals[SIG_FOCUSED] = []
        self._signals[SIG_ENTER] = []
        self._signals[SIG_LEAVE] = []
        self._signals[SIG_DESTROYED] = []
Beispiel #18
0
 def __init__ (self, re):
     """
     The network controller. Can call remote PB methods, and because
     it inherits from pb.Referenceable, can also contain remote
     methods callable by the server.
     
     Make sure you set the internal _signals before setting the
     manager, otherwise the signals won't get connected to the event
     manager.
     """
     BaseObject.__init__ (self)
     self._signals[SCORE] = []
     self.connect_signal (SCORE, self.add_one)
     self.manager = re.active_layer[2]
     
     # Set up twisted connection.
     self.factory = pb.PBClientFactory ()
     d = self.factory.getRootObject ()
     d.addCallback (self.setRoot)
     reactor.connectTCP ('localhost', 8008, self.factory)
     self.root = None
    def __init__ (self, manager, message, display_duration=3500, font_path='./fonts/'):
        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)
        
        if Message.font == None:
            # Bitstream Vera Sans Mono
            Message.font = pygame.font.Font(font_path+'VeraMoBd.ttf', 12)
            
        # Increment the number of messages being displayed
        if Message.message_count == None:
            Message.message_count = 0
        else:
            Message.message_count += 1
            
        # Basically a duplication of damage animation - damage animation should probably be derived from this
        self.manager = manager
        
        shadow_offset = 3
        text = Message.font.render(message, True, (200,200,200)).convert_alpha()
        shadow = Message.font.render(message, True, (50,50,50)).convert_alpha()
        
        self.image = pygame.surface.Surface(
            (text.get_width() + shadow_offset,  text.get_height() + shadow_offset), 0, 32).convert_alpha()
        self.image.fill((0,0,0,0))
        self.image.blit(shadow, (shadow_offset, shadow_offset))
        self.image.blit(text, (0, 0))
        
        display_geometery = pygame.display.get_surface().get_rect()
        x = (display_geometery.width - self.image.get_width()) / 2
        y = (display_geometery.height - self.image.get_height()) / 2 + (self.image.get_height() * (Message.message_count-1))
        
        self.rect = pygame.rect.Rect(x, y, self.image.get_width(), self.image.get_height())
        
        self.display_duration = float(display_duration)        
        self.state = self.states.displaying
        
        self.timestamp = pygame.time.get_ticks()

        self.emit(constants.EVENT_ENTITY_WAIT, 0)
    def __init__(self,
                 manager,
                 side,
                 reference,
                 name,
                 model,
                 weapon=None,
                 weapon_points=[]):

        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)

        self._signals[constants.EVENT_ENTITY_FIRE] = []
        self._signals[constants.EVENT_ENTITY_DAMAGE] = []
        self._signals[constants.EVENT_ENTITY_DEATH] = []

        self._signals[constants.EVENT_ANIMATION_DAMAGE_COMPLETE] = []

        self.manager = manager

        self.side = side
        self.reference = reference
        self.name = name
        self.weapon = weapon
        self.weapon_points = weapon_points

        self.damage_animation_queue = []

        self.death_duration = 1500.0

        self.image = pygame.image.load(model)
        self.rect = pygame.rect.Rect(0, 0, self.image.get_width(),
                                     self.image.get_height())
        self.state = self.states.idle

        self.framecount = 0
        self.frameskip = 3
    def __init__ (self, manager, damage_amount, position, animation_duration=0, wait_duration=0, font_path='./fonts/'):
        BaseObject.__init__(self)
        pygame.sprite.Sprite.__init__(self)
        
        if DamageAnimation.font == None:
            # Bitstream Vera Sans Mono
            DamageAnimation.font = pygame.font.Font(font_path+'VeraMoBd.ttf', 18)
        
        if manager:
            self.manager = manager
        
        self.x = position[0]
        self.y = position[1]
        
        shadow_offset = 3
        text = DamageAnimation.font.render(str(int(damage_amount)), False, (255,0,0)).convert()
        shadow = DamageAnimation.font.render(str(int(damage_amount)), False, (50,50,50)).convert()
        self.display_image = pygame.surface.Surface(
            (text.get_width() + shadow_offset,  text.get_height() + shadow_offset), 0, 32).convert_alpha()
        self.display_image.fill((0,0,0,0))
        self.display_image.blit(shadow, (shadow_offset, shadow_offset))
        self.display_image.blit(text, (0, 0))
        self.idle_image = pygame.surface.Surface((0,0))
        self.image = self.idle_image
        self.rect = pygame.rect.Rect(self.x, self.y, self.image.get_width(), self.image.get_height())

        self.wait_duration = wait_duration
        self.duration = float(animation_duration)
        
        # Record of original alpha for blending
        self.original_alpha = pygame.surfarray.array_alpha(self.display_image)
        
        self.state = self.states.waiting
        self.timestamp = pygame.time.get_ticks()

        self.emit(constants.EVENT_ENTITY_WAIT, self)
 def __init__ (self, name):
     BaseObject.__init__(self)
     self._signals[EVENT_ENTITY_MOVE] = []
     self.name = name
Beispiel #23
0
 def __init__(self):
     BaseObject.__init__(self)
 def __init__ (self):
     BaseObject.__init__(self)
     self._signals[EVENT_ENTITY_NEW] = []
     self.entity_list = []
 def __init__ (self):
     BaseObject.__init__(self)
Beispiel #26
0
 def __init__(self, name):
     BaseObject.__init__(self)
     self._signals[EVENT_ENTITY_MOVE] = []
     self.name = name
Beispiel #27
0
 def __init__(self):
     BaseObject.__init__(self)
     self._signals[EVENT_ENTITY_NEW] = []
     self.entity_list = []