Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

Bricks

Python Source icon bricks.py — Python Source, 6 KB (6321 bytes)

Dateiinhalt

from visual import *

defaultheight = 1
defaultlength = 0.85
win = materials.texture(data=materials.loadTGA("win"),mapping = "sign")

##--Brick--##
class Brick(frame):
    def __init__(self, color_, posN = (0, 0, 0)):
        frame.__init__(self)
        self.brick = box(frame = self, pos = posN, height = defaultheight, length = defaultlength, width = 0.15, color = color_)
        self.c = color_
        self.p = posN
    def getGraphics(self, posN = (0, 0, 0)):
        return self.brick
    def move(self, vs):
        self.pos += vs
    def hit(self):
        if not(hasattr(brickLight, 'brick')):
            self.brick = box(frame = self, pos = self.p, height = defaultheight, length = defaultlength, width = 0.15, color = self.c)
        self.brick.visible = False
        del self.brick
    def destroy(self):
        self.brick.visible = False
        del self.brick
##--Brick--#


##--object1--##
class brickLight(Brick):
    def __init__(self, posN = (0,0,0)):
        Brick.__init__(self, color.yellow, posN)
##--object1--##


##--object2--##
class brickMedium(Brick):
    def __init__(self, posN = (0,0,0)):
        Brick.__init__(self, color.orange, posN)
    def hit(self):
        if not(hasattr(brickLight, 'brick')):
            self.brick = box(frame = self, pos = self.p, height = defaultheight, length = defaultlength, width = 0.15, color = self.c)
        self.brick.visible = False
        del self.brick
        self.brick = brickLight()
##--object2--##


##--object3--##
class brickHeavy(Brick):
    def __init__(self, posN = (0,0,0)):
        Brick.__init__(self, color.red, posN)
    def hit(self):
        if not(hasattr(brickLight, 'brick')):
            self.brick = box(frame = self, pos = self.p, height = defaultheight, length = defaultlength, width = 0.15, color = self.c)
        self.brick.visible = False
        del self.brick
        self.brick = brickMedium()
##--object3--##


##--object4 (GOAL)--##
class brickWin(Brick):
    def __init__(self, posN = (0,0,0)):
        frame.__init__(self)
        self.brick = box (frame = self, pos = posN, height = defaultheight, length = defaultlength, width = 0.15, color = color.green)
        self.hit_ = 4
    def hit(self):
        self.hit_ -= 1
        print(str(self.hit_))
        if self.hit_ == 3:
            self.brick.color = color.blue
        elif self.hit_ == 2:
            self.brick.color = color.magenta
        elif self.hit_ == 1:
            self.brick.color = color.white
        elif self.hit_ == 0:
            print("you won")
            self.winbox = box(frame = self, pos = (-5, -5, 1), height = 20, length = 20, width = 20, color = color.green)
            print(str(self.winbox.pos.x))
            #self.brick.visible = False
            #del self.brick
##--object4--##


class brickNew(frame):
    def __init__(self, posN, color, win_, hits_, world):
        frame.__init__(self)
        self.brick = box (frame = self, pos = posN, height = defaultheight, length = defaultlength, width = 0.15, color = color)
        self.win = win_
        self.hits = hits_
        self.x_ = posN[0]
        self.y_ = posN[1]
        self.w = world
    def hit(self):
        if(self.hits > 0):
            self.hits -= 1

        if(self.win):
            if self.hits == 3:
                self.brick.color = color.blue
            elif self.hits == 2:
                self.brick.color = color.magenta
            elif self.hits == 1:
                self.brick.color = color.white
            elif self.hits == 0:
                self.winbox = box(frame = self, axis = (0, 0, 1), pos = (0, 0, 1), height = 10, length = 10, width = 10, material=win)
                self.winbox.rotate(angle = pi, axis = (0, 0, 1), origin = self.winbox.pos)
                self.w.bricklist.remove(self)
                self.brick.visible = False
                del self.brick
        else:
            if self.hits == 2:
                self.brick.color = color.orange
            elif self.hits == 1:
                self.brick.color = color.yellow
            elif self.hits == 0:
                self.w.bricklist.remove(self)
                self.brick.visible = False
                del self.brick

##--world--##
class world():
    def __init__(self):
        self.height = 7.15 # 7.65
        self.width = 12 # 14.125
        # self.distance = 0.0833333333333333333334
        self.d = 0.5
        self.d2 = 2.25
        self.bricklist = []
        self.count = 0
    def worldgen(self):
        for y in range(14):
            brickw =(defaultlength + self.d)
            for x in range(2):
                #self.bricklist.append(brickLight((x * brickw - self.d2 - (6 * brickw), y * (0.6 + self.d) - self.height, 0)))
                self.bricklist.append(brickNew((x * brickw * 0.8 - self.d2 - (4 * brickw * 0.8), y * (0.6 + self.d) - self.height, 0), color.yellow, False, 1, self))
                self.count += 1
            for x in range(2):
                #self.bricklist.append(brickMedium((x * brickw - self.d2 - (3 * brickw), y * (0.6 + self.d) - self.height, 0)))
                self.bricklist.append(brickNew((x * brickw * 0.8 - self.d2 - (2 * brickw * 0.8), y * (0.6 + self.d) - self.height, 0), color.orange, False, 2, self))
                self.count += 1
            for x in range(2):
                #self.bricklist.append(brickHeavy((x * brickw - self.d2, y * (0.6 + self.d) - self.height, 0)))
                self.bricklist.append(brickNew((x * brickw * 0.8 - self.d2, y * (0.6 + self.d) - self.height, 0), color.red, False, 3, self))
                self.count += 1
        for y in range(6):
            self.bricklist.append(brickNew((brickw * 0.8 - self.d2 + (brickw * 0.8), y * (0.6 + self.d) - self.height, 0), color.red, False, 3, self))#mitte oben
            self.bricklist.append(brickNew((brickw * 0.8 - self.d2 + (brickw * 0.8), y * (0.6 + self.d) + 1.65, 0), color.red, False, 3, self))#mitte unten
        for y in range (14):
            for x in range (2):
                self.bricklist.append(brickNew((x * brickw * 0.8 - self.d2 + (3 * brickw * 0.8), y * (0.6 + self.d) - self.height, 0), color.red, False, 3, self))
        #self.bricklist.append(brickWin())
        self.bricklist.append(brickNew((-0.1, 0, 0), color.green, True, 4, self))
        self.count += 1
##--world--##




Funktionsleiste