Source

Fat x Fast / FatxFast / objects / player.py

Full commit

# 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.character import Character
from FatxFast.objects.buffs import COFFEE_BUFF_ID
import pygame

class Player(Character):
    
    def __init__(self, worldmap, **kwargs):
        super(Player, self).__init__(worldmap, **kwargs)
        self.points = 0
        self.maps_left = 0
        self._turbo = 1
        self.items = {}
        self._turboing = False

    def add_item(self, item):
        self.items[item.name] = item

    def _consume_turbo(self, amount):
        if not self._turboing:
            return False
        if self._turbo > 0:
            self._turbo -= amount
        if self._turbo <= 0:
            self._turbo = 0
            self.stop_turbo()

    def get_item(self, itemname):
        return self.items[itemname]

    def get_turbo(self):
        return self._turbo

    def remove_and_kill_buffs(self):
        for buff in self.buffs:
            buff.kill()

    def remove_item(self, itemname):
        if itemname in self.items:
            del self.items[itemname]

    def turbo(self):
        self._turboing = True
        self.physics.maxspeed = self.physics.get_default_maxspeed()*1.5

    def set_turbo(self, amount):
        if amount > 1:
            amount = 1
        self._turbo = amount

    def stop_turbo(self):
        self._turboing = False
        self.physics.maxspeed = self.physics.get_default_maxspeed()

    def update(self, dt):
        self._consume_turbo(0.0005*dt)
        super(Player, self).update(dt)
        self.stop_turbo()