File: objsmoke.py

package info (click to toggle)
solarwolf 1.5%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,656 kB
  • sloc: python: 5,353; ansic: 159; makefile: 102; pascal: 50; sh: 27
file content (58 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (3)
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
#explosion class

import random, math
import pygame
from pygame.locals import *
import game, gfx


images = []


def load_game_resources():
    global images
    images = gfx.animstrip(gfx.load('smoke.png'))
    if gfx.surface.get_bytesize()>1: #16 or 32bit
        i = 1
        for img in images:
            img.set_alpha((1.8-math.log(i))*40, RLEACCEL)
            i += 1



class Smoke:
    def __init__(self, pos):
        self.clocks = 0
        self.rect = images[0].get_rect()
        self.rect.center = pos
        offset = random.randint(-7,7), random.randint(-7,7)
        self.rect = self.rect.move(offset)
        self.lastrect = self.rect
        self.dead = 0
        self.drift = random.randint(-1, 1), random.randint(-1, 1)
        self.speed = random.randint(2, 4)
        self.current = 0
        self.life = random.randint(12, 20)

    def erase(self, background):
        r = background(self.rect)
        if self.dead:
            gfx.dirty(r.inflate(1, 2))

    def draw(self, gfx):
        frame = min(self.clocks // 5, 3)
        img = images[frame]
        r = gfx.surface.blit(img, self.rect)
        gfx.dirty(r.inflate(1, 2))

    def tick(self, speedadjust):
        self.current += 1
        if self.current >= self.speed:
            self.current = 0
            self.rect = self.rect.move(self.drift)

        self.clocks += 1
        if self.clocks >= self.life:
            self.dead = 1