コード例 #1
0
ファイル: levelgen.py プロジェクト: nojan1/closeQuarters
    def placeCor(self, start, end, joinUp = False):
        angle, distance = getAngleDistance(start, end)
        angle = int(math.degrees(angle))
        if angle < 0:
            angle += 360

        angleIndex = int((angle % 360) / 90) 
        increments = [(1,0), (0,1), (-1,0), (0,-1)]

        increment = increments[int(angleIndex)]

        if joinUp:
            start = ( start[0] + int((increment[0] * -1) * (CORTHICKNESS / 2)), start[1] + int((increment[1] * -1) * (CORTHICKNESS / 2)) )
            distance = getAngleDistance(start, end)[1]

        iMin = int((CORTHICKNESS / 2) * -1)
        iMax = int(CORTHICKNESS / 2)
        for i in range(iMin, iMax + 1):
            sX = start[0] + (i * increment[1])
            sY = start[1] + (i * increment[0])

            for z in range(int(distance)):
                x = sX + (z * increment[0])
                y = sY + (z * increment[1])
                try:
                    if self.mapGrid[x][y] != "?": 
                        self.mapGrid[x][y] = "#"
                except:
                    print("Out of bounds %i,%i" % (x,y))
コード例 #2
0
ファイル: mob.py プロジェクト: nojan1/closeQuarters
    def onActivation(self, game, tickCount):
        if self.hasActivated:
            return

        self.hasActivated = True
        if self.hasSeenPlayer:
            self.animEnable = True
            #Find path and attack!
            newPos = self.ai.findPath(self, game)
            if newPos:
                attackRect = Rect(newPos, self.size)
                attackRect.move_ip(ATTACKTHRESHOLD / 2, ATTACKTHRESHOLD / 2)
                attackRect.inflate_ip(ATTACKTHRESHOLD, ATTACKTHRESHOLD)

                if game.player.getRect().colliderect( attackRect ):
                    #Attack player
                    if tickCount - self.lastAttack > 500:
                        game.handlePlayerDamage(self.damage)
                        self.lastAttack = tickCount
                else:
                    self.facingAngle = geometry.getAngleDistance(self.pos, newPos)[0]
                    self.pos = newPos

                    if len(self.imageIndexesTable) != 0:
                        #Switch to another set of textures depending on current angle
                        slices = 360.0 / len(self.imageIndexesTable)
                        angle = math.degrees(self.facingAngle)
                        index = int(round(angle / slices)) % len(self.imageIndexesTable)
                
                        self.imageIndexes = self.imageIndexesTable[index]

            else:
                self.animEnable = False
        else:
            self.hasSeenPlayer = self.ai.canSeePlayer(self, game) != False
コード例 #3
0
ファイル: levelgen.py プロジェクト: nojan1/closeQuarters
    def makeCor(self):
        #Generate corridors
        for r, w in self.roomInfo:
            distance = -1
            nearest = []
            for r2, w2 in self.roomInfo:
                if r2 == r:
                    continue

                angle, newDistance = getAngleDistance(w, w2)
                if distance == -1 or newDistance < distance:
                    distance = newDistance
                    nearest = (r2, w2)

            #Only needs one coridor?
            #roomInfo.remove( (r2, w2) )

            #print("Needs to make coridor between %s and %s" % (w, nearest[1]))
            if math.degrees(angle) % 90 == 0:
                #print(" - Direct line detected, using simple algoritm")
                self.placeCor(w, nearest[1])
            else:
                #print(" - Needs to bend the line")
                if abs(w[0] - nearest[1][0]) < abs(w[1] - nearest[1][1]):
                    #Bend for X
                    self.placeCor(w,(w[0], nearest[1][1]))
                    self.placeCor((w[0], nearest[1][1]), nearest[1], True)
                else:
                    #Bend for Y
                    self.placeCor(w, (nearest[1][0], w[1]))
                    self.placeCor((nearest[1][0], w[1]), nearest[1], True)
コード例 #4
0
ファイル: levelgen.py プロジェクト: nojan1/closeQuarters
    def makeSpecials(self):
        #Add mobs and pickups
        for i in range(random.randint(MOBMIN, MOBMAX)):
            pos = (-1,-1)
            while pos == (-1,-1) or self.mapGrid[pos[0]][pos[1]] != "#" or getAngleDistance(self.playerPos, pos)[1] < MOBTOPLAYERTHRESHOLD:
                pos = ( random.randint(2, WORLDSIZE[0] - 1), random.randint(2, WORLDSIZE[1] - 1) )

            if random.randint(0,100) > 90:
                #place pickup
                char = list(["L", "R", "H"])[random.randint(0,2)]
            else:
                char = list(["Z", "Z", "S"])[random.randint(0,2)]
    
            self.mapGrid[pos[0]][pos[1]] = char        
コード例 #5
0
ファイル: ai.py プロジェクト: nojan1/closeQuarters
    def findPath(self, mob, game):
        #Return valid move on a path leading to player
        destination = game.player.getRect()
        source = mob.getRect()
        destination.size = source.size

        path = self.canSeePlayer(mob, game)
        if path:
            #Direct line of sight to player... no need to find a path
            x = int(math.cos(path[0]) * mob.speed) + source.x
            y = int(math.sin(path[0]) * mob.speed) + source.y
            return (x,y)
        else:
            #Go into search mode (Not implemented)
            initialAngle = getAngleDistance(source.center, destination.center)[0] - math.radians(90)
            return self.search(source, destination, game, initialAngle)
コード例 #6
0
ファイル: ai.py プロジェクト: nojan1/closeQuarters
    def isClearLine(self, source, destination, game, mobsBlockLOS = True):
        #Return False or (angle, distance)
        x1, y1 = source
        x2, y2 = destination
        angle, distance = getAngleDistance(source, destination)

        increment = 0
        while increment <= (distance - (TILESIZE[0] / 2)):
            increment += TILESIZE[0] / 2.0
            
            x = int(math.cos(angle) * increment) + x1
            y = int(math.sin(angle) * increment) + y1

            rectToCheck = Rect((x,y), (TILESIZE[0] / 2, TILESIZE[1] / 2))

            if (not game.getMap().isAllowedPosition(rectToCheck)) or (mobsBlockLOS and game.getMap().mobPresent(rectToCheck)):
                return False
                
        return (angle, distance)