Ejemplo n.º 1
0
    def __init__(self, x, y, actions, unitParent):
        from models import Troop
        if issubclass(type(unitParent), Troop):
            image = os.path.join("images", "menus", "unit_action_menu.png")
            # x = x - ACTIONMENU_X_OFFSET
            # y = y - ACTIONMENU_Y_OFFSET
        # elif type(unitParent) == SpoofedBuilding:
        #     image = os.path.join("images", "menus", "spoofed_building_action_menu.png")
        else:
            image = os.path.join("images", "menus", "building_action_menu.png")
        super(ActionMenu, self).__init__(image)
        self.position = euclid.Vector2(x, y)
        self.actionNames = actions
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.actionList = []
        self.unitParent = unitParent

        if issubclass(type(unitParent), Troop):
            self.slots = [euclid.Vector2(x - 43, y),
                          euclid.Vector2(x + 0, y),
                          euclid.Vector2(x + 43, y)]  # HOW MANY SLOTS SHOULD TROOPS HAVE? 3?
        else:
            self.slots = [euclid.Vector2(x + 50, y - 0),
                          euclid.Vector2(x - 50, y - 0),
                          euclid.Vector2(x - 0, y - 50),
                          euclid.Vector2(x - 0, y + 50),
                          euclid.Vector2(x + 35.11, y - 35.11),
                          euclid.Vector2(x + 35.11, y + 35.11),
                          euclid.Vector2(x - 35.11, y - 35.11),
                          euclid.Vector2(x - 35.11, y + 35.11)]

        # (Easily Changed)
        self.make_action_buttons()
Ejemplo n.º 2
0
 def __init__(self, x, y):
     super(BuildingsDetailsButton, self).__init__(
         os.path.join("images", "instructions",
                      "building_details_button.png"))
     self.position = x, y
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
Ejemplo n.º 3
0
 def __init__(self,x,y):
     super(SettingsMenuSprite, self).__init__(os.path.join("images",
                                                "maps", "minimap_bg.png"))
     self.position = euclid.Vector2(x,y)
     self.opacity = 255
     self.scale = 0.6
     self.cshape = aabb_to_aa_rect(self.get_AABB())
Ejemplo n.º 4
0
 def __init__(self, hotkeys, x, y):
     super(HotkeysMenu, self).__init__(os.path.join("images",
                                                "maps", "minimap_bg.png"))
     self.hotkeys = hotkeys
     self.position = euclid.Vector2(float(x), float(y))
     self.opacity = 255
     self.scale = 0.6
     self.cshape = aabb_to_aa_rect(self.get_AABB())
Ejemplo n.º 5
0
 def __init__(self, x, y, isVisible=True):
     super(SurrenderButton, self).__init__(os.path.join(
         "images", "maps", "surrender.png"))
     self.visible = isVisible
     self.position = euclid.Vector2(x, y)
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
     self.scale = 0.2  # Arbitrary
Ejemplo n.º 6
0
 def __init__(self, stickyNoteParent):
     super(TutorialXButton, self).__init__(os.path.join("images", "tutorial", "x.png"))
     x = stickyNoteParent.position[0] + 84
     y = stickyNoteParent.position[1] + 112
     self.position = euclid.Vector2(x, y)
     self.stickyNoteParent = stickyNoteParent
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
Ejemplo n.º 7
0
    def __init__(self, x, y):
        super(ToggleMusicButton, self).__init__(os.path.join(
            "images", "maps", "music.png"))
        self.visible = True
        self.scale = 1

        self.position = euclid.Vector2(x,y)
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position
Ejemplo n.º 8
0
 def __init__(self, x, y, text):
     super(ToggleTutorialButton, self).__init__(text=text,font_name='Rabiohead',font_size=24)
     self.visible = True
     self.scale = 1
     width = 50
     height = 20
     self.rect = rect.Rect(x - width/2, - height/2, x + width/2, x + height/2)
     self.position = euclid.Vector2(x,y)
     self.cshape = aabb_to_aa_rect(self.rect)
     self.cshape.center = self.position
Ejemplo n.º 9
0
    def __init__(self, col, row, vid, asID, visibilityState=0, pid=0,image=None):
        if not image:
            super(Vertex, self).__init__(os.path.join("images", "maps",
                                                  "vertex.png"))
        else:
            super(Vertex, self).__init__(image) #init core

        self.position = euclid.Vector2(col * CELL_SIZE, row * CELL_SIZE)
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position
        self.visibilityState = visibilityState

        self.pid = pid  # pid of the human player

        self.numOfSlots = NUM_OF_SLOTS

        self.slotPositions = []

        self.edges = []
            # array of edge objects attached to this vertex. key is edgeNum,
            # val is Edge object.

        self.building = None

        self.vid = vid

        self.asID = asID

        self.asCircle = None

        self.adjacentVertices = []

        self.actionMenuSlots = get_action_menu_slots(4, self.position[0], self.position[1])
        self.borderVertices = defaultdict(list)
        # This will contain all of the Vertices that this vertex is connected to
        # that are in a different AS. k: asID v: list of vertices in that AS
        self.emptySlots = []
        self.emptyTroopSlots = {}

        self.transTroopSlots = {}  # for booking slots while unit is moving
        #value is a tuple of index,slot

        self.troopSlots = {}

        self.buildingSlot = None

        self.opacity = visibilityState * 255

        # for Djiskstra
        self.heapItem = None
Ejemplo n.º 10
0
 def __init__(self, ASes, numMapCols, numMapRows, edges, player):
     super(MiniMap, self).__init__(os.path.join("images",
                                                "maps", "minimap_bg.png"))
     self.edges = edges
     self.minimapBuildings = {}
     self.minimapTroops = {}
     self.opacity = 255
     self.scale = 0.6
     self.mapCellWidth = numMapCols * CELL_SIZE
     self.mapCellHeight = numMapRows * CELL_SIZE
     self.ASes = ASes
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.player = player
     self.setup()
Ejemplo n.º 11
0
    def __init__(self, image, curVertex, health=0, pid=0, speed=0, power=0, attackRange=0, buildTime=1):

        fullImagePath = os.path.join("images", "troops", image)

        super(Troop, self).__init__(fullImagePath, curVertex, health, pid=pid, buildTime=buildTime)


        self.initialHealth = health

        self.playerIndicator = Sprite(os.path.join("images","troops", "player.png"))
        self.playerIndicator.color = PLAYER_COLORS[self.pid]
        self.playerIndicator.opacity = 0
        self.add(self.playerIndicator,z=-1)

        
        if not curVertex.add_troop(self):
            self.slotIndex = -1
            return

        self.position = curVertex.troopSlots[self.slotIndex].position
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position

        self.power = power

        # keep track of the destination while troop is moving
        self.destVertex = None

        self.speed = float(speed) * TEST_SPEEDUP

        self.attackRange = attackRange

        self.scale = UNIT_SCALE_NORMAL

        # the target sets this flag to False once it's died
        self.shouldAttack = set() # A set containing the enemies that this thing should attack (when empty we should stop attacking)

        self.is_attacking = False

        self.attackingPath = []

        self.packets = []

        self.targetVid = -1

        self.sourceVid = -1

        for i in range(4):
            self.packets.append(Packet(self.position))
Ejemplo n.º 12
0
    def __init__(self, image, curVertex, health=0, pid=0, buildTime=1):
        fullImagePath = os.path.join("images", "buildings", image)
        super(Building, self).__init__(fullImagePath, curVertex, health, pid, buildTime=buildTime)

        # flag to check if unit is busy doing something
        self.isBusy = False
        self.initialHealth = health

        
        if not curVertex.add_building(self):
            self.slotIndex = -1
            return

        if type(self) == CPU:
            self.position = curVertex.position  
        else:
            self.position = euclid.Vector2(curVertex.buildingSlot.position[0], curVertex.buildingSlot.position[1] + 10)
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position
Ejemplo n.º 13
0
    def __init__(self, image, curVertex, health=0, pid=0, buildTime=1):
        fullImagePath = os.path.join("images", "buildings", image)
        super(Building, self).__init__(fullImagePath,
                                       curVertex,
                                       health,
                                       pid,
                                       buildTime=buildTime)

        # flag to check if unit is busy doing something
        self.isBusy = False
        self.initialHealth = health

        if not curVertex.add_building(self):
            self.slotIndex = -1
            return

        if type(self) == CPU:
            self.position = curVertex.position
        else:
            self.position = euclid.Vector2(
                curVertex.buildingSlot.position[0],
                curVertex.buildingSlot.position[1] + 10)
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position
Ejemplo n.º 14
0
	def __init__(self,x,y):
		super(BackButton, self).__init__(os.path.join("images", "instructions", "back_button.png"))
		self.position = x,y
		self.cshape = aabb_to_aa_rect(self.get_AABB())
		self.cshape.center = self.position
Ejemplo n.º 15
0
 def __init__(self, x, y):
     super(UtilityTroopDetailsButton, self).__init__(
         os.path.join("images", "instructions", "utility_troop_button.png"))
     self.position = x, y
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
Ejemplo n.º 16
0
 def __init__(self, x, y):
     super(TechTreeButton, self).__init__(
         os.path.join("images", "instructions", "tech_tree_button.png"))
     self.position = x, y
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
Ejemplo n.º 17
0
 def __init__(self, x, y):
     super(BackButtonUD, self).__init__(
         os.path.join("images", "instructions", "back_button.png"))
     self.position = x, y
     self.cshape = aabb_to_aa_rect(self.get_AABB())
     self.cshape.center = self.position
Ejemplo n.º 18
0
    def __init__(self,
                 image,
                 curVertex,
                 health=0,
                 pid=0,
                 speed=0,
                 power=0,
                 attackRange=0,
                 buildTime=1):

        fullImagePath = os.path.join("images", "troops", image)

        super(Troop, self).__init__(fullImagePath,
                                    curVertex,
                                    health,
                                    pid=pid,
                                    buildTime=buildTime)

        self.initialHealth = health

        self.playerIndicator = Sprite(
            os.path.join("images", "troops", "player.png"))
        self.playerIndicator.color = PLAYER_COLORS[self.pid]
        self.playerIndicator.opacity = 0
        self.add(self.playerIndicator, z=-1)

        if not curVertex.add_troop(self):
            self.slotIndex = -1
            return

        self.position = curVertex.troopSlots[self.slotIndex].position
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.cshape.center = self.position

        self.power = power

        # keep track of the destination while troop is moving
        self.destVertex = None

        self.speed = float(speed) * TEST_SPEEDUP

        self.attackRange = attackRange

        self.scale = UNIT_SCALE_NORMAL

        # the target sets this flag to False once it's died
        self.shouldAttack = set(
        )  # A set containing the enemies that this thing should attack (when empty we should stop attacking)

        self.is_attacking = False

        self.attackingPath = []

        self.packets = []

        self.targetVid = -1

        self.sourceVid = -1

        for i in range(4):
            self.packets.append(Packet(self.position))
Ejemplo n.º 19
0
	def __init__(self,x,y):
		super(UnitDetailsButton, self).__init__(os.path.join("images", "instructions", "unit_description_button.png"))
		self.position = x,y
		self.cshape = aabb_to_aa_rect(self.get_AABB())
		self.cshape.center = self.position
Ejemplo n.º 20
0
	def __init__(self,x,y):
		super(UtilityTroopDetailsButton, self).__init__(os.path.join("images", "instructions", "utility_troop_button.png"))
		self.position = x,y
		self.cshape = aabb_to_aa_rect(self.get_AABB())
		self.cshape.center = self.position
Ejemplo n.º 21
0
    def __init__(self, x, y, name, unitParent):
        fontSize = 8
        self.is_text = False

        try:
            image = os.path.join("images", "menus", BUTTON_DICTIONARY[name])
        except:
            image = os.path.join("images", "menus", "unit_action_button.png")
            self.is_text = True
        textOffsetX = 13
        textOffsetY = -5
        super(ActionButton, self).__init__(image)

        # Calculate action time in number of seconds. We could also add this
        # info to the name (or to self.actionList some other way)
        self.actionTime = {
            "DEL": 3,
            "TPING": 8,
            "TCONS": 15,
            "BDB": 10,
            "BCPU": 20
        }.get(name, None)

        decryptType = ""
        if name == "Decrypt":
            decryptType = str(unitParent.originalType.__class__.__name__)
    
        self.buttonName = {
            "TPing":"Create Ping",
            "TAPTGet":"Create APT-Get",
            "TDOS":"Create DOS",
            "TInstaller":"Create Installer",
            "TSQLInjection":"Create SQLInjection",
            "TDNSPoison":"Create DNSPoison",
            "THandshake":"Create Handshake",
            "TSpoof":"Create Spoof",
            "TBufferOverflow":"Create Buffer Overflow",
            "BDB":"Install Database",
            "BCPU":"Program FPGA",
            "BDatabase":"Install Database",
            "BAlgorithmFactory":"Allocate Algorithms",
            "BSoftwareUpdater":"Download Software Updater",
            "BFirewall":"Enable Firewall",
            "BRSA":"Write RSA",
            "BHandshake":"Build Handshake",
            "BDNSPoison":"Build DNS Poison",
            "BSpoofedBuilding": "Build Spoofed Building",
            "UPingOfDeath":"Upgrade to Ping of Death",
            "UNMap":"Upgrade to NMap",
            "USinkhole":"Upgrade to Sinkhole",
            "RPortScanner":"Port Scanner",
            "RHandshake":"Research Handshake",
            "RBigData":"Research Big Data",
            "RAdvancedAlgorithms":"Research Advanced Algorithms",
            "RPingResearch": "Advanced Ping",
            "RNetworkTopology": "Research Network Topology",
            "RFPGA":"Research FPGA",
            "RRSA":"Research RSA",
            "ROverclocking":"Research Overclocking",
            "ROverflow":"Research Overflow",
            "DSpoof":"Spoofed Building",
            "Attack":"Attack",
            "Shake":"Shake",
            "Encrypt":"Encrypt",
            "Decrypt":"Decrypt To " + decryptType,
            "GenKey":"Generate Key",
            "Ping":"Execute Ping",
            "NMap":"Perform NMap"
        }.get(name, []) # Determine the name to display on the button

        if self.buttonName == []:
            quit()

        self.position = euclid.Vector2(x, y)
        self.text = Label(self.buttonName, position=(
        x - textOffsetX, y - textOffsetY), color=(50, 50, 116, 255), font_size=fontSize, multiline = True, font_name='Rabiohead', width=ACTION_BUTTON_WIDTH - 5)
        self.name = name
        self.cshape = aabb_to_aa_rect(self.get_AABB())
        self.unitParent = unitParent