Changeset 390:93f13f7d97f2


Ignore:
Timestamp:
04/09/11 14:18:08 (12 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Message:

Initial fire rate-limiting

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/constants.py

    r356 r390  
    1818DOUBLE_TAP_TIME = 0.15
    1919
     20RECHARGE_TIME = 1
     21
    2022# Layer defination
    2123class Layers(object):
     
    2931class FoxHud(object):
    3032    TEXT = pygame.Color(255, 255, 255, 196)
    31     HEALTH_BACKGROUND = pygame.Color(128, 64, 0, 128)
    32     HEALTH_FOREGROUND = pygame.Color(255, 64, 0, 196)
    33     HEALTH_HEIGHT = 160
    34     HEALTH_WIDTH = 20
    3533
    3634    BG_ALPHA = 120
     
    5553    TAILS_HEIGHT = 8 * TAIL_OFFSET
    5654
     55    HEALTH_BACKGROUND = pygame.Color(128, 64, 0, 128)
     56    HEALTH_FOREGROUND = pygame.Color(255, 64, 0, 196)
     57    HEALTH_HEIGHT = 160
     58    HEALTH_WIDTH = 20
     59
     60    RECHARGE_BACKGROUND = pygame.Color(64, 128, 0, 128)
     61    RECHARGE_FOREGROUND = pygame.Color(64, 255, 0, 196)
     62    RECHARGE_TOP = 220
     63    RECHARGE_WIDTH = 50
     64    RECHARGE_HEIGHT = 15
     65
     66    SCROLL_TOP = 240
     67    TOFU_TOP = 270
  • skaapsteker/levelscene.py

    r383 r390  
    200200        fox_hud = constants.FoxHud
    201201
    202         # Draw the health bar
    203         health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200
    204         bar = pygame.Rect(0, 0, constants.FoxHud.HEALTH_WIDTH, constants.FoxHud.HEALTH_HEIGHT)
    205         bar.bottomleft = health_bottom
    206         pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_BACKGROUND, bar)
    207         bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(max(0, fox.cur_health))/fox.max_health)
    208         bar.bottomleft = health_bottom
    209         pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar)
    210202        # Inventory bg
    211203        bgsurf = pygame.Surface((fox_hud.INVENTORY_SIZE + 2 * 8,
     
    230222                inv_pos.top += (fox_hud.INVENTORY_SIZE - inv_pos.height) / 2
    231223            self._level_surface.blit(self._player.inventory_image, inv_pos)
     224
    232225        # Tail bg
    233226        bgsurf = pygame.Surface((self._tail.get_size()[0] + 2 * fox_hud.BG_MARGIN,
     
    247240            self._level_surface.blit(self._tail, tail_pos)
    248241
     242        # Draw the health bar
     243        health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200
     244        bar = pygame.Rect(0, 0, fox_hud.HEALTH_WIDTH, fox_hud.HEALTH_HEIGHT)
     245        bar.bottomleft = health_bottom
     246        pygame.draw.rect(self._level_surface, fox_hud.HEALTH_BACKGROUND, bar)
     247        bar.height = int(fox_hud.HEALTH_HEIGHT * float(max(0, fox.cur_health))/fox.max_health)
     248        bar.bottomleft = health_bottom
     249        pygame.draw.rect(self._level_surface, fox_hud.HEALTH_FOREGROUND, bar)
     250
     251        # Draw fire recharge bar
     252        recharge = pygame.Rect(self._clip_rect.right - 55,
     253                               self._clip_rect.top + fox_hud.RECHARGE_TOP,
     254                               fox_hud.RECHARGE_WIDTH, fox_hud.RECHARGE_HEIGHT)
     255        pygame.draw.rect(self._level_surface, fox_hud.RECHARGE_BACKGROUND, recharge)
     256        recharge.width = int(fox_hud.RECHARGE_WIDTH * self._player.recharge_level())
     257        pygame.draw.rect(self._level_surface, fox_hud.RECHARGE_FOREGROUND, recharge)
     258
    249259        # Draw scroll count
    250 
    251         pos = self._clip_rect.right - 20, self._clip_rect.top + 225
     260        pos = self._clip_rect.right - 20, self._clip_rect.top + fox_hud.SCROLL_TOP + 5
    252261        count = Text("%s" % len(fox.scrolls), pos)
    253262        count.draw(self._level_surface)
    254         pos = self._clip_rect.right - 55, self._clip_rect.top + 220
     263        pos = self._clip_rect.right - 55, self._clip_rect.top + fox_hud.SCROLL_TOP
    255264        self._level_surface.blit(self._scroll, pos)
    256265
    257266        # Draw tofu count
    258         pos = self._clip_rect.right - 20, self._clip_rect.top + 255
     267        pos = self._clip_rect.right - 20, self._clip_rect.top + fox_hud.TOFU_TOP + 5
    259268        count = Text("%s" % fox.tofu, pos)
    260269        count.draw(self._level_surface)
    261         pos = self._clip_rect.right - 55, self._clip_rect.top + 250
     270        pos = self._clip_rect.right - 55, self._clip_rect.top + fox_hud.TOFU_TOP
    262271        self._level_surface.blit(self._tofu, pos)
    263 
    264272
    265273
  • skaapsteker/sprites/player.py

    r381 r390  
    77from ..sprites.projectiles import Fireball, Lightning
    88from ..physics import Sprite
    9 from ..constants import Layers, FoxHud, DOUBLE_TAP_TIME
     9from ..constants import Layers, FoxHud, DOUBLE_TAP_TIME, RECHARGE_TIME
    1010from ..data import get_files, load_image
    1111from ..engine import PlayerDied, AddSpriteEvent
     
    3030        self._animation_frame = 0.0
    3131        self._last_time = time.time()
     32        self._last_fired = time.time()
    3233        # State flags and such
    3334        self.attacking = 0
     
    300301
    301302    def action_fire1(self):
     303        if not self.check_fire_rate():
     304            return
    302305        if "fireball" not in self._me.tails:
    303306            self._bite_attack()
     
    306309
    307310    def action_fire2(self):
     311        if not self.check_fire_rate():
     312            return
    308313        if "lightning" not in self._me.tails:
    309314            self._bite_attack()
    310315        else:
    311316            self._lightning_attack()
     317
     318    def check_fire_rate(self):
     319        if self.recharge_level() < 1:
     320            return False
     321        self._last_fired = time.time()
     322        return True
     323
     324    def recharge_level(self):
     325        return min((time.time() - self._last_fired) / RECHARGE_TIME, 1)
    312326
    313327    def _get_action(self):
Note: See TracChangeset for help on using the changeset viewer.