def setBlock(boxx, boxy):  #screen coords
    worldX, worldY = boxx + CameraBlocksX.get(), boxy + CameraBlocksY.get()
    blockType = SelectedBlockType.get()
    if blockType == 1:
        if (worldX, worldY) not in mainDict:
            WSet.add((worldX, worldY))
            mainDict[worldX, worldY] = WireBlock(
                boxx,
                boxy)  #send in screen coords to block object constructors
            mapWirePaths()  #wirePathMapping def here
    elif blockType == 2:  #left input transistor
        if (worldX, worldY) not in mainDict:
            TSet.add((worldX, worldY))
            mainDict[worldX, worldY] = TransistorBlock(LEFT, boxx, boxy, \
                LEFTSIDEX, LEFTSIDEY, UPSIDEX, UPSIDEY, RIGHTSIDEX, RIGHTSIDEY, DOWNSIDEX, DOWNSIDEY)
            mapWirePaths()  #wirePathMapping def here
    elif blockType == 3:  #right input transistor
        if (worldX, worldY) not in mainDict:
            TSet.add((worldX, worldY))
            mainDict[worldX, worldY] = TransistorBlock(RIGHT, boxx, boxy, \
                RIGHTSIDEX, RIGHTSIDEY, DOWNSIDEX, DOWNSIDEY, LEFTSIDEX, LEFTSIDEY, UPSIDEX, UPSIDEY)
            mapWirePaths()  #wirePathMapping def here
    elif blockType == 4:  #up input transistor
        if (worldX, worldY) not in mainDict:
            TSet.add((worldX, worldY))
            mainDict[worldX, worldY] = TransistorBlock(UP, boxx, boxy, \
                UPSIDEX, UPSIDEY, RIGHTSIDEX, RIGHTSIDEY, DOWNSIDEX, DOWNSIDEY, LEFTSIDEX, LEFTSIDEY)
            mapWirePaths()  #wirePathMapping def here
    elif blockType == 5:  #down input transistor
        if (worldX, worldY) not in mainDict:
            TSet.add((worldX, worldY))
            mainDict[worldX, worldY] = TransistorBlock(DOWN, boxx, boxy, \
                DOWNSIDEX, DOWNSIDEY, LEFTSIDEX, LEFTSIDEY, UPSIDEX, UPSIDEY, RIGHTSIDEX, RIGHTSIDEY)
            mapWirePaths()  #wirePathMapping def here
Beispiel #2
0
 def repositionOnScreen(self):  #screen coords
     if self.onScreen:
         self.left, self.top = leftTopCoordsOfBox(
             self.boxx - CameraBlocksX.get(),
             self.boxy - CameraBlocksY.get()
         )  #screen coords, world coords. world converted to screen
         self.blockLocSize = (self.left, self.top, BoxSize.get(),
                              BoxSize.get())  #screen coords
         self.drawBlock()
 def repositionOnScreen(self):  #screen coords
     if self.onScreen:
         self.left, self.top = leftTopCoordsOfBox(
             self.boxx - CameraBlocksX.get(),
             self.boxy - CameraBlocksY.get()
         )  #screen coords, world coords. world converted to screen
         #self.blockLocSize = (self.left - 1, self.top - 1, TOTALBoxSize.get(), TOTALBoxSize.get()) #screen coords
         self.blockLocSize = (self.left, self.top, BoxSize.get(),
                              BoxSize.get())  #screen coords
         if self.state:  # == True:
             self.drawBlock(TRANSISTORBLOCKON)
         else:
             self.drawBlock(TRANSISTORBLOCKOFF)
Beispiel #4
0
 def __init__(self, boxx, boxy):  #screen coords
     self.boxx, self.boxy = (
         boxx + CameraBlocksX.get(), boxy + CameraBlocksY.get()
     )  #world coords, screen coords. screen converted to world
     self.left, self.top = leftTopCoordsOfBox(boxx, boxy)  #screen coords
     self.inputBlockL = (LEFTSIDEX + self.boxx, self.boxy)  #world coords
     self.inputBlockR = (RIGHTSIDEX + self.boxx, self.boxy)  #world coords
     self.inputBlockU = (self.boxx, UPSIDEY + self.boxy)  #world coords
     self.inputBlockD = (self.boxx, DOWNSIDEY + self.boxy)  #world coords
     self.blockLocSize = (self.left, self.top, BoxSize.get(), BoxSize.get()
                          )  #screen coords
     self.onScreen = True
     self.processedThisTick = False
     self.state = OFF
     self.editCount = -1
     self.wirePathID = None  #must be set in edit
     self.drawBlock()
 def __init__(self, type, boxx, boxy, inputSideX, inputSideY, outputSideX1,
              outputSideY1, outputSideX2, outputSideY2, outputSideX3,
              outputSideY3):  #screen coords
     self.boxx, self.boxy = (
         boxx + CameraBlocksX.get(), boxy + CameraBlocksY.get()
     )  #world coords, screen coords. screen converted to world
     self.left, self.top = leftTopCoordsOfBox(boxx, boxy)  #screen coords
     self.inputBlock = (inputSideX + self.boxx, inputSideY + self.boxy
                        )  #world coords
     self.outputBlock1 = (outputSideX1 + self.boxx, outputSideY1 + self.boxy
                          )  #world coords
     self.outputBlock2 = (outputSideX2 + self.boxx, outputSideY2 + self.boxy
                          )  #world coords
     self.outputBlock3 = (outputSideX3 + self.boxx, outputSideY3 + self.boxy
                          )  #world coords
     self.blockLocSize = (self.left, self.top, BoxSize.get(), BoxSize.get()
                          )  #screen coords
     self.onScreen = True  #set to false if block is outside camera view
     self.previousState = None
     self.state = OFF
     self.wirePathIDs = set()
def deleteBlock(boxx, boxy):  #screen coords
    worldX, worldY = boxx + CameraBlocksX.get(), boxy + CameraBlocksY.get()
    if (worldX, worldY) in mainDict:
        if (worldX, worldY) in TSet:
            transistorsPaths = mainDict[worldX, worldY].getWirePaths()
            for path in transistorsPaths:
                wirePathDict[path].remTrans((worldX, worldY))
                if wirePathDict[path].getTransTotal() == 0:
                    wirePathDict[path].turnOff()
            TSet.remove((worldX, worldY))
        else:
            try:  #if no key don't worry, this is for orphaned wirepaths (wirepaths with no transistor outputs attached)
                wirePathDict[mainDict[worldX,
                                      worldY].getWirePathID()].turnOff()
                WireBlock.setWireBlockDeleted(True)
            except KeyError:
                pass
            WSet.remove((worldX, worldY))
        del mainDict[worldX, worldY]
        left, top = leftTopCoordsOfBox(boxx, boxy)  #screen coords
        #drawRect(EMPTYBLOCKBORDER, (left - 1, top - 1, TOTALBoxSize.get(), TOTALBoxSize.get())) #clears yellow edge left from transistor, prevents haveing to redraw background
        drawRect(EMPTYBLOCK, (left, top, BoxSize.get(), BoxSize.get()))
        mapWirePaths()  #wirePathMapping def here
Beispiel #7
0
def checkOnScreen(loc):  #checks if block is on screen
    return (loc[0] >= CameraBlocksX.get() and loc[0] <= CameraBlocksX.get() + BoardWidth.get() - 1) and \
            (loc[1] >= CameraBlocksY.get() and loc[1] <= CameraBlocksY.get() + BoardHeight.get() - 1 - (TOPBAR / BoxSize.get()))