File: blob.py

package info (click to toggle)
whichwayisup 0.7.9-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: python: 2,372; sh: 3; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 2,297 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'''Blob. Jumps when the player jumps, and damages the player and dies when it hits the player.'''

import pygame
import random

from pygame.locals import *

from locals import *

import data

from object import DynamicObject
from sound import play_sound
from animation import Animation
from particle import Particle

class Blob(DynamicObject):

  def __init__(self, screen, x, y, player):
    DynamicObject.__init__(self, screen, x, y, 10, True, True)
    self.animations["default"] = Animation("blob", "standing")
    self.animations["dying"] = Animation("blob", "dying")
    self.animations["jumping"] = Animation("blob", "jumping")
    self.animations["falling"] = Animation("blob", "falling")
    self.image = self.animations[self.current_animation].update_and_get_image()
    self.rect = self.image.get_rect()
    self.rect.centerx = int(self.x)
    self.rect.centery = int(self.y)
    self.jump_queue = False
    self.itemclass = "blob"
    self.player = player
    return

  def update(self, level = None):
    DynamicObject.update(self, level)

    blood = []

    if not self.active:
      return blood

    if self.on_ground:
      if self.current_animation != "dying":
        self.current_animation = "default"
      if self.jump_queue:
        self.true_jump()
        count = 0
        while (count < 5):
          count += 1
          blood.append(Particle(self.screen, 10, self.rect.centerx + random.uniform(-7, 7), self.rect.bottom, 0.0, -0.5, 0.3, level.dust_color, 4))
    else:
      self.dy = self.dy - BLOB_AIR_JUMP
      if self.dy > 0 and self.current_animation == "jumping":
        self.current_animation = "default"
      if self.dy > 2 and self.current_animation == "default":
        self.current_animation = "falling"
      self.jump_queue = False

    if self.current_animation != "dying" and self.rect.colliderect(self.player.rect):
      self.die()
      blood = self.player.take_damage(BLOB_DAMAGE)

    return blood

  def true_jump(self):
    if self.on_ground and self.current_animation != "dying":
      self.current_animation = "jumping"
      self.jump_queue = False
      self.dy = -BLOB_JUMP_ACC

  def jump(self):
    if self.active:
      self.jump_queue = True
    return