Source

Fat x Fast / FatxFast / objects / triggers.py


# This file is part of FatxFast.
#
#    FatxFast is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FatxFast is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FatxFast.  If not, see <http://www.gnu.org/licenses/>.

# Versioning based on: 
# http://en.wikipedia.org/wiki/Versioning#Designating_development_stage
__author__ = "dryatu (c) 2013"
__version__ = "1.2.4"


from FatxFast.objects import buffs, entity

# Trigger ids 10-49
COFFEE_ID = 10
WARP_ID = 11
TRIGGER_ID = 13
END_ID = 14
START_ID = 15

# ID RANGES
TRIGGER_RANGE = range(10, 50)

class Trigger(entity.GameEntity):
   
    def __init__(self, **kwargs):
        kwargs["invisible"] = kwargs.get("invisible", 1)
        super(Trigger, self).__init__(colorkey="blue", **kwargs)

    def process(self, entity):
        pass

class WarpTrigger(Trigger):
    
    def __init__(self, **kwargs):
        super(WarpTrigger, self).__init__(**kwargs)
        self.dest_x = int(kwargs.get("dest_x", 0))
        self.dest_y = int(kwargs.get("dest_y", 0))
        self.entity_id = WARP_ID
        self._debuff_duration = 750

    def process(self, entity):
        can_warp = True
        for buff in entity.buffs:
            if isinstance(buff, buffs.WarpDebuff):
                can_warp = False
                break
        if can_warp:
            entity.set_speed(0,0)
            entity.set_position((self.dest_x, self.dest_y))
            entity.buffs.add(buffs.WarpDebuff(entity, self._debuff_duration))
            return True
    

class StartTrigger(Trigger):
    
    def __init__(self, **kwargs):
        super(StartTrigger, self).__init__(**kwargs)
        self.entity_id = START_ID

class EndTrigger(Trigger):
    
    def __init__(self, **kwargs):
        super(EndTrigger, self).__init__(**kwargs)
        self.entity_id = END_ID

    def process(self, entity):
        super(EndTrigger, self).process(entity)
        return True
    
class CoffeeTrigger(Trigger):

    def __init__(self, **kwargs):
        super(CoffeeTrigger, self).__init__(imagename="coffee.png", 
            **kwargs)
        self.entity_id = COFFEE_ID
        self.invisible = 0
        self._coffee_duration = 7500

    def process(self, entity):
        entity.points += 1024
        buff = buffs.SpeedBuff(entity, self._coffee_duration)
        buff.name = "speedbuff"+str(id(buff))
        buff.trigger()
        entity.buffs.add(buff)


TRIGGER_CLASSES = {
    COFFEE_ID: CoffeeTrigger,
    WARP_ID: WarpTrigger,
    END_ID: EndTrigger,
    START_ID: StartTrigger}