Example #1
0
class Player(Entity):
    orect = pygame.Rect(10, 2, 12, 28)
    kconv = {
        pygame.K_w: (0, -1),
        pygame.K_s: (0, 1),
        pygame.K_a: (-1, 0),
        pygame.K_d: (1, 0)
    }
    enemy = False
    bombs = 1
    rng = 2
    pen = False
    dy = 1
    iconv = {
        (0, -1): img2("Men/Man2u"),
        (0, 1): img2("Men/Man2"),
        (1, 0): img2("Men/Man2r"),
        (-1, 0): img2("Men/Man2l")
    }
    ms = 2
    akey = pygame.K_UP
    rd = False
    detonate = False

    def update(self, world, events):
        if self.hidden:
            self.hidden = False
        if self.detonate:
            self.detonate = False
        if world.akey == self.akey:
            keys = pygame.key.get_pressed()
            for k, v in self.kconv.iteritems():
                if keys[k] and self.move(v[0], v[1], self.ms, world):
                    break
            for e in events:
                if e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE and self.bombs:
                    for e in world.get_ents(self.x, self.y):
                        if e.name == "Bomb":
                            break
                    else:
                        world.e.append(
                            Bomb(iround((self.x * 32 + self.xoff) / 32.0),
                                 iround((self.y * 32 + self.yoff) / 32.0),
                                 self.rng, self))
                        self.bombs -= 1
                elif e.type == pygame.KEYDOWN and e.key == pygame.K_LSHIFT and self.rd:
                    self.detonate = True
        if not self.moving:
            tile = world.t[self.x][self.y]
            if tile == 2:
                world.done = True
            elif tile == 8:
                world.done = True
                world.exitcode = "SECRET"
            elif tile == 9:
                world.done = True
                world.exitcode = "WARP"

    def get_img(self):
        return self.iconv[(self.dx, self.dy)]
Example #2
0
class FatPlayer(Player):
    orect = pygame.Rect(8, 2, 16, 28)
    rng = 2
    bombs = 2
    ms = 1.5
    pen = True
    sticky = True
    iconv = {(0, -1): img2("Men/FManu"), (0, 1): img2("Men/FMan"), (1, 0): img2("Men/FManr"),
             (-1, 0): img2("Men/FManl")}
Example #3
0
class Player(Entity):
    orect = pygame.Rect(10, 2, 12, 28)
    enemy = False
    bombs = 1
    rng = 2
    pen = False
    dy = 1
    iconv = {(0, -1): img2("Men/Man2u"), (0, 1): img2("Men/Man2"), (1, 0): img2("Men/Man2r"),
             (-1, 0): img2("Men/Man2l")}
    ms = 2
    akey = pygame.K_UP
    rd = False
    detonate = False

    def __init__(self, x, y, c):
        self.place(x, y)
        self.c = c

    def update(self, world, events):
        if self.detonate:
            self.detonate = False
        for d in self.c.get_dirs():
            if self.move(d[0], d[1], self.ms, world):
                break
        bpress = self.c.get_buttons(events)
        if bpress[0] and self.bombs:
            for e in world.get_ents(self.x,self.y):
                if e.name=="Bomb":
                    break
            else:
                world.e.append(
                    Bomb(iround((self.x * 32 + self.xoff) / 32.0), iround((self.y * 32 + self.yoff) / 32.0),
                         self.rng,
                         self))
                self.bombs -= 1
        if bpress[1] and self.rd:
            self.detonate = True
        elif bpress[1] and not self.rd:
            self.altbomb(world)
        if not self.moving:
            tile = world.t[self.x][self.y]
            if tile == 2:
                world.done = True
            elif tile == 8:
                world.done = True
                world.exitcode = "SECRET"
            elif tile == 9:
                world.done = True
                world.exitcode = "WARP"

    def altbomb(self, world):
        pass

    def get_img(self):
        return self.iconv[(self.dx, self.dy)]
Example #4
0
class SmallPlayer(Player):
    orect = pygame.Rect(12, 4, 8, 24)
    rng = 1
    ms = 4
    iconv = {
        (0, -1): img2("Men/SManu"),
        (0, 1): img2("Men/SMan"),
        (1, 0): img2("Men/SManr"),
        (-1, 0): img2("Men/SManl")
    }
    akey = pygame.K_DOWN
Example #5
0
class ThinPlayer(Player):
    orect = pygame.Rect(12, 2, 8, 28)
    rng = 3
    rd = True
    akey = pygame.K_RIGHT
    iconv = {
        (0, -1): img2("Men/TManu"),
        (0, 1): img2("Men/TMan"),
        (1, 0): img2("Men/TManr"),
        (-1, 0): img2("Men/TManl")
    }
Example #6
0
class BombPlus(Entity):
    enemy = False
    img = img2("ExBomb")
    powerup = True

    def collect(self, p):
        p.bombs += 1
Example #7
0
class Penetrating(Entity):
    enemy = False
    img = img2("Pen")
    powerup = True

    def collect(self, p):
        p.pen = True
Example #8
0
class Bomb(Entity):
    enemy = False
    timer = 120
    img = img2("Bomb")
    darkresist = True
    name = "Bomb"

    def __init__(self, x, y, r, p=False):
        self.x = x
        self.y = y
        self.p = p
        self.r = r
        self.pen = p and p.pen
        self.rd = p and p.rd

    def update(self, world, events):
        if self.rd:
            if self.p.detonate or self.timer == 1:
                world.create_exp(self.x, self.y, self.r, self.pen)
                world.e.remove(self)
                self.p.bombs += 1
        else:
            self.timer -= 1
            if self.timer == 0:
                world.create_exp(self.x, self.y, self.r, self.pen)
                world.e.remove(self)
                if self.p:
                    self.p.bombs += 1
            elif self.timer <= 30:
                self.xoff = randint(-2, 2)
                self.yoff = randint(-2, 2)
Example #9
0
class Fireball(Entity):
    img = img2("Fireball")
    orect = pygame.Rect(10, 10, 12, 12)
    solid = False
    darkresist = True

    def __init__(self, x, y, ang, spd):
        while ang < pi:
            ang += 2 * pi
        while ang > pi:
            ang -= 2 * pi
        self.place(x, y)
        self.ang = ang
        self.ax = x * 32
        self.ay = y * 32
        self.dx = spd * math.cos(ang)
        self.dy = spd * math.sin(ang)
        self.spd = spd

    def update(self, world, events):
        self.ax += self.dx
        self.ay += self.dy
        self.aplace(self.ax, self.ay)
        if not world.inworld(self.x, self.y) or world.o[self.x][self.y]:
            world.e.remove(self)
Example #10
0
class NullPower(Entity):
    enemy = False
    img = img2("Null")
    powerup = True

    def collect(self, p):
        p.bombs = 0
        p.rng = 0
        p.pen = False
Example #11
0
class SokoBlock(Entity):
    enemy = False
    img = img2("SokoBlok")
    pushable = True
    name = "Sokoblock"

    def update(self, world, events):
        if not self.moving:
            if world.get_t(self.x, self.y) == 4:
                world.t[self.x][self.y] = 5
                world.e.remove(self)
Example #12
0
class Explosion(Entity):
    img = img2("Exp")
    pimg = img2("ExpPen")
    orect = pygame.Rect(6, 6, 20, 20)
    life = 20
    denemy = True
    darkresist = True

    def __init__(self, x, y, pen):
        self.place(x, y)
        self.pen = pen

    def update(self, world, events):
        self.xoff = randint(-1, 1)
        self.yoff = randint(-1, 1)
        self.life -= 1
        if self.life == 0:
            world.e.remove(self)

    def get_img(self):
        return self.pimg if self.pen else self.img
Example #13
0
class SokoBlokSlippy(SokoBlock):
    img = img2("SokoBlokIce")

    def update(self, world, events):
        if not self.moving:
            if world.get_t(self.x, self.y) == 4:
                world.t[self.x][self.y] = 5
                world.e.remove(self)
            if self.dx != 0 or self.dy != 0:
                if not self.move(self.dx, self.dy, self.speed, world):
                    self.dx = 0
                    self.dy = 0
Example #14
0
class FireballLauncher(Entity):
    img = img2("FireballL1")
    aimg = img2("FireballL2")
    enemy = False
    fireballclass = Fireball
    speed = 3

    def __init__(self, x, y):
        self.place(x, y)
        self.tonext = randint(120, 240)

    def update(self, world, events):
        if self.tonext:
            self.tonext -= 1
        else:
            self.tonext = randint(120, 240)
            np = world.get_p(self.x, self.y)
            ang = math.atan2(np.y * 32 + np.yoff - self.y * 32 - self.yoff,
                             np.x * 32 + np.xoff - self.x * 32 - self.xoff)
            world.e.append(self.fireballclass(self.x, self.y, ang, self.speed))

    def get_img(self):
        return self.img if self.tonext > 30 else self.aimg
Example #15
0
class HomingFireball(Fireball):
    img = img2("HFireball")

    def update(self, world, events):
        self.ax += self.dx
        self.ay += self.dy
        self.aplace(self.ax, self.ay)
        if not world.inworld(self.x, self.y) or world.o[self.x][self.y]:
            world.e.remove(self)
        np = world.get_p(self.x, self.y)
        tang = math.atan2(np.y * 32 + np.yoff - self.y * 32 - self.yoff,
                          np.x * 32 + np.xoff - self.x * 32 - self.xoff)
        tdiff = math.fmod(tang - self.ang + pi, tau) - pi
        if right > tdiff > 0:
            self.ang += 0.02
        elif 0 > tdiff > -right:
            self.ang -= 0.02
        self.dx = self.spd * math.cos(self.ang)
        self.dy = self.spd * math.sin(self.ang)
Example #16
0
class CannonBall(Entity):
    img = img2("CannonBall")
    orect = pygame.Rect(10, 10, 12, 12)

    def __init__(self, x, y, dx):
        self.dx = dx
        self.place(x, y)
        self.js = True

    def update(self, world, events):
        if not self.moving:
            if not self.js and world.inworld(
                    self.x, self.y) and world.o[self.x][self.y]:
                world.e.remove(self)
            elif world.inworld(self.x, self.y):
                self.move(self.dx, 0, 4, world, True)
            else:
                world.e.remove(self)
            if self.js:
                self.js = False
Example #17
0
from Img import img2
worlds=[[{"g":img2("Ice")},((209,248,255),(170,236,255)),"chipdisko"],[{"g":img2("Sand")},((209,248,255),(173,162,17)),"Desert"]]
castle=[{"g":img2("CastleBrick")},((100,100,100),(255,0,0)),"Flags"]
Example #18
0
class SokoBlockGoo(SokoBlock):
    img = img2("SokoBlokGoo")
    sticky = True
Example #19
0
class HFireballLauncher(FireballLauncher):
    fireballclass = HomingFireball
    aimg = img2("FireballL3")