Ejemplo n.º 1
0
def getVisual(arr):
    exists = False
    for particle in visual_set_external:
        if particle.idObject == arr['idObject']:
            exists = True
    if not exists:
        visual_set_external.add(
            Particle(arr['updateSprite'],
                     Vector(arr['pos']['x'], arr['pos']['y']),
                     Vector(arr['vel']['x'],
                            arr['vel']['y']), arr['nextPosTime'],
                     Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                     arr['maxVel'], arr['maxRange'], arr['angle'],
                     arr['radius'], arr['spriteKey'], spriteDictionary,
                     arr['fps'], arr['removeOnVelocity0'],
                     arr['removeOnAnimationLoop'], arr['idObject'],
                     arr['numRows'], arr['numColumns'], arr['startRow'],
                     arr['startColumn'], arr['endRow'], arr['endColumn']))

    for particle in visual_set_external:
        if particle.idObject == arr['idObject']:
            particle.recieve(Vector(arr['nextPos']['x'],
                                    arr['nextPos']['y']), arr['nextPosTime'],
                             arr['maxVel'], arr['maxRange'], arr['angle'],
                             arr['updateSprite'], arr['spriteKey'], arr['fps'],
                             arr['numRows'], arr['numColumns'],
                             arr['startRow'], arr['startColumn'],
                             arr['endRow'], arr['endColumn'], arr['radius'],
                             spriteDictionary)
Ejemplo n.º 2
0
def randomGrass():
    width, height = int(config['MAP']['WIDTH']), int(config['MAP']['HEIGHT'])
    # Calculate some random grass values

    lightId = 1
    medId = 2
    darkId = 3

    for x in range(0, int(width / 512)+1):
        for y in range(0, int(height / 512)+1):
            winner = 0
            dh = random.randrange(80, 100) / 100
            dl = random.randrange(1, 30) / 100
            mh = random.randrange(60, 100) / 100
            ml = random.randrange(1, 50) / 100
            if y > (height / 512) * dh or y < (height / 512) * dl or x > (width / 512) * dh or x < (width / 512) * dl:
                grass = getRandomString('en_l1_gs_d_', 5)

            elif (y > (height / 512) * mh or y < (height / 512) * ml) or (
                    x > (width / 512) * mh or x < (width / 512) * ml):

                grass = getRandomString('en_l1_gs_m_', 5)
            else:

                grass = getRandomString('en_l1_gs_l_', 5)
            # Grass
            pos = Vector(x * 512, y * 512)

            env_l1_set.add(Particle(False, pos, Vector(0, 0), 0, pos, 0, 0, 0, 0,
                                    grass, spriteDictionary, 0.0001, False, False, getUid(), 1, 1, 1, 1, 1, 1))
Ejemplo n.º 3
0
class SpriteAnimator:
    def __init__(self, image):
        self.image = simpleguics2pygame.load_image(image)
        self.dimOriginal = Vector(self.image.get_width(),
                                  self.image.get_height())
        self.dimCamera = Vector(0, 0)

    def draw(self, canvas, cam, pos, numberColumns, numberRows, row, column,
             angle):
        ratio = cam.dimCanv.copy().divideVector(cam.dim)
        self.dimCamera = self.dimOriginal.copy().divideVector(
            Vector(numberColumns, numberRows)).multiplyVector(ratio)
        canLoc = pos.getP()

        imageCenter = Vector(
            (self.image.get_width() / numberColumns) * column -
            (self.image.get_width() / numberColumns) / 2,
            (self.image.get_height() / numberRows) * row -
            (self.image.get_height() / numberRows) / 2)

        imageDimention = Vector(self.image.get_width() / numberColumns,
                                self.image.get_height() / numberRows)

        canvas.draw_image(self.image,
                          imageCenter.getP(), imageDimention.getP(), canLoc,
                          self.dimCamera.getP(), angle)
Ejemplo n.º 4
0
def getWeapon(arr):
    exists = False
    for weapon in weapon_set_external:
        if weapon.idObject == arr['idObject']:
            exists = True

    if not exists:

        weapon_set_external.add(
            Weapon(Vector(arr['pos']['x'], arr['pos']['y']),
                   Vector(arr['vel']['x'],
                          arr['vel']['y']), arr['nextPosTime'],
                   Vector(arr['nextPos']['x'],
                          arr['nextPos']['y']), arr['maxVel'], arr['angle'],
                   arr['radius'], arr['spriteKey'], spriteDictionary,
                   arr['fps'], arr['idObject'], arr['numRows'],
                   arr['numColumns'], arr['startRow'], arr['startColumn'],
                   arr['endRow'], arr['endColumn'], arr['removeOnVelocity0'],
                   arr['removeOnAnimationLoop'], arr['damage']))

    for weapon in weapon_set_external:
        if weapon.idObject == arr['idObject']:

            weapon.recieve(Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                           arr['nextPosTime'], arr['maxVel'], arr['angle'],
                           arr['spriteKey'], arr['fps'], arr['numRows'],
                           arr['numColumns'], arr['startRow'],
                           arr['startColumn'], arr['endRow'], arr['endColumn'],
                           arr['radius'], spriteDictionary, arr['applied'])
Ejemplo n.º 5
0
    def checkIfReachedStop(self, nodeTraffic_dict, relation_dict, line_dict,
                           way_dict, node_dict):
        nextStop = node_dict[self.nextStop]
        pos = Vector(nextStop['x'], nextStop['y'])
        if self.currentNode == self.nextStop or (
                self.particle.pos.copy().distanceTo(pos) < 300 and
            (pos.copy().subtract(self.particle.pos)).dot(self.particle.vel) < 0
        ):
            self.stopIndex += 1
            self.send = True
            self.currentStop = self.nextStop
            # if in current remove, add yourself to

            if self.stopIndex < len(self.stop_list):
                self.nextStop = self.stop_list[self.stopIndex]
                nextStopDic = nodeTraffic_dict[self.nextStop]
                nextStopDic.update({self.idObject: self.particle})
            elif self.nextStop == self.stop_list[len(self.stop_list) - 1]:
                self.reachedEnd = True
                if self.line1Bool:
                    self.setLine(relation_dict, line_dict, way_dict, node_dict,
                                 self.line2)
                    self.line1Bool = False
                else:
                    self.setLine(relation_dict, line_dict, way_dict, node_dict,
                                 self.line1)
                    self.line1Bool = True
            self.particle.vel.multiply(0)
Ejemplo n.º 6
0
    def generatePoints(self,cam,sprite_dict,baseNode):
        self.updateZoomDistance(cam,baseNode)
        mpp=512 #size of image

        scaleFactor=self.getImageScaleFactor(self.zoom, getLatLongFromCoordinates(baseNode,cam.origin)[0])
        mpp*=scaleFactor
        key_dict={}
        remove_dict={}
        for x in range(int((cam.origin.getX()-cam.dim.getX())//mpp),int(((cam.origin.getX()+cam.dim.getX())//mpp)+1)):
            for y in range(int((cam.origin.getY()-cam.dim.getY())//mpp),int(((cam.origin.getY()+cam.dim.getY())//mpp)+1)):
                key=self.constructKey(x,y,self.zoom)
                directory=self.cwd+'/img/Map/'+key+'.png'
                if not key in sprite_dict:
                    point = getLatLongFromCoordinates(baseNode, Vector(x * mpp, y * mpp))
                    url = self.getUrl(point[0], point[1], self.zoom)
                    path=Path(directory)
                    image=0
                    if path.is_file():

                        image=simpleguics2pygame._load_local_image(directory)


                    elif not key in self.loadingKeys:
                        imgThread=threading.Thread(target=self.loadImage,args=(url,directory))
                        imgThread.start()
                        self.loadingKeys.update({key:key})


                    # if image in file load from file else load from simpleguics2 as bellow
                    # else load image from url and save to directory

                    if image != 0:
                        tile = SpriteAnimator(image, scaleFactor)
                        radius=256*scaleFactor
                        sprite_dict.update({key: tile})

                        mapTile = MapTile(Vector(x*mpp,y*mpp),self.zoom,key,sprite_dict,radius)
                        self.tile_dict.update({key: mapTile})

                elif key not in self.tile_dict:
                    radius = 256 * scaleFactor
                    mapTile = MapTile(Vector(x * mpp, y * mpp), self.zoom, key, sprite_dict,radius)
                    self.tile_dict.update({key:mapTile})
                key_dict.update({key:key})

        for key in self.tile_dict:
            if key not in key_dict:
                remove_dict.update({key:key})
        for key in remove_dict:
            self.tile_dict.pop(key)
Ejemplo n.º 7
0
    def draw(self, canvas, cam, node_dict):
        # line.drawNodeList(canvas, cam, node_dict, self.node_list)
        # line.drawNode(canvas,cam,node_dict,self.nextNode,'Green')
        # line.drawNode(canvas,cam,node_dict,self.nextStop,'Red')
        # self.particle.draw(canvas, cam)
        distance = cam.origin.copy().subtract(self.particle.pos)
        if distance.getX() < 0:
            distance.x *= -1
        if distance.getY() < 0:
            distance.y *= -1

        if distance.getX() < cam.dim.getX() and distance.getY() < cam.dim.getY(
        ):
            pos3 = self.particle.pos.copy().transformToCam(cam).getP()

            currentNode = node_dict[self.currentNode]
            nextNode = node_dict[self.nextNode]
            directVector = Vector(nextNode['x'], nextNode['y']).subtract(
                Vector(currentNode['x'], currentNode['y']))
            if directVector.length() != 0:
                directVector.normalize().negate()
                rad = self.particle.radius
                ratio = cam.ratioToCam()
                length = rad * ratio.getX()
                pos1 = directVector.copy().rotate(30)
                pos2 = directVector.copy().rotate(-30)
                pos1.multiply(length).add(self.particle.pos)
                pos2.multiply(length).add(self.particle.pos)

                canvas.draw_polygon([
                    pos1.transformToCam(cam).getP(),
                    pos2.transformToCam(cam).getP(), pos3
                ], 2, 'red', self.color)
Ejemplo n.º 8
0
    def fire(self, player, monster):
        # THIS IS ESSENTIALLY COPPIED FROM CLICK HANDLER AND IMPLEMENTED FOR MONSTER ONCE IT CHOOSES A TARGET :d, NO TIME TO MAKE IT NICER ON BOTH ENDS AND OPTIMIZE UNFORTUNATELY
        # SET MAGIC SPRITE ATTACK ANIMATION
        numRows, numCol, startRow, startCol, endRow, endCol, key = getRandomMagicWeapon(
            monster.magic)
        # SET MAGIC SPRITE WEAPON WITH The above
        precisionX = random.randrange(0, 90)
        precisionY = random.randrange(0, 90)
        precisionY -= 45
        precisionX -= 45
        pos = player.particle.pos.copy().add(Vector(precisionX, precisionY))
        radius = 0
        if monster.magic < 500:
            radius = 15
        if monster.magic < 1000 and radius == 0:
            radius = 20
        if monster.magic < 5000 and radius == 0:
            radius = 25
        if monster.magic < 20000 and radius == 0:
            radius = 30
        if monster.magic < 50000 and radius == 0:
            radius = 35
        if monster.magic > 50000 and radius == 0:
            radius = 40

        weapon = Weapon(pos, Vector(0, 0),
                        0, pos, 0, 0, radius, key, spriteDictionary, 20,
                        getUid(), numRows, numCol, startRow, startCol, endRow,
                        endCol, False, True, monster.magic)
        # BIND SPRITE TO MONSTER and MONSTER TO SPRITE to remember who kills who
        weapon.idPlayer = monster.idObject
        weapon_set.add(weapon)

        # SET MAGIC SPRITE CASTING ANIMATION USE PARTICLE CLASS ADD TO VISUAL SET
        # SHIFT ALL MAGIC SPRITES UP FOR MONSTER IF SMALL
        pos = monster.particle.pos.copy()
        if monster.particle.dim.getY() < 120:
            pos.y -= 30
        numRows, numCol, startRow, startCol, endRow, endCol, key = getRandomMagicCast(
            monster.magic)
        particle = Particle(True, pos, Vector(0, 0), 0, pos, 0, 0,
                            0, 0, key, spriteDictionary, 15, False, True,
                            getUid(), numRows, numCol, startRow, startCol,
                            endRow, endCol)
        visual_set.add(particle)

        monster.particle.vel.multiply(0)
        monster.particle.nextPosTime = time.time()
        monster.particle.nextPos = monster.particle.pos
        monster.hasFired = True
Ejemplo n.º 9
0
    def updatePosVel(self):
        if self.pos.copy().subtract(self.nextPos).dot(self.vel) > 0:
            self.vel.multiply(0)

        if self.pos != self.nextPos:
            x, y = self.pos.copy().distanceToVector(self.nextPos)
            dist = Vector(x, y)
            dist.negate()

            if self.nextPosTime - time.time() <= 0:
                self.pos = self.nextPos
            else:
                self.vel = dist.divide(self.nextPosTime - time.time())
                self.vel.multiply(time.time() - self.currentTime)
                self.pos.add(self.vel)
Ejemplo n.º 10
0
    def move(self):
        # for player in player_list:
        #     if playerId == player.idObject:
        #         pos = player.particle.pos.copy()
        self.currentTime=time.time()

        if self.moveUp==True :
            self.origin.add(Vector(0,-self.dim.getY()/self.moveSensitivity))
        if self.moveDown==True :
            self.origin.add(Vector(0,self.dim.getY()/self.moveSensitivity))

        if self.moveLeft == True :
            self.origin.add(Vector(-self.dim.getX()/self.moveSensitivity,0))
        if self.moveRight == True :
            self.origin.add(Vector(self.dim.getX()/self.moveSensitivity,0))
Ejemplo n.º 11
0
    def move(self,playerId,player_list):
        for player in player_list:
            if playerId == player.idObject:
                pos = player.particle.pos.copy()
        self.currentTime=time.time()

        if self.moveUp==True and GOD_MODE:
            self.origin.add(Vector(0,-self.moveSensitivity))
        if self.moveDown==True and GOD_MODE:
            self.origin.add(Vector(0,self.moveSensitivity))

        if self.moveLeft == True and GOD_MODE:
            self.origin.add(Vector(-self.moveSensitivity,0))
        if self.moveRight == True and GOD_MODE:
            self.origin.add(Vector(self.moveSensitivity,0))
Ejemplo n.º 12
0
class Camera:
    def __init__(self, origin, dim):
        self.idClass = 1
        self.idObject = uuid.uuid4()

        self.origin = origin
        self.dim = dim
        self.dimCanv=Vector(int(config['CANVAS']['CANVAS_WIDTH']),int(config['CANVAS']['CANVAS_HEIGHT']))
        self.zoomIn=False
        self.zoomOut=False
        self.moveLeft=False
        self.moveRight=False
        self.moveUp=False
        self.moveDown=False

        self.maxZoomDist=int(config['CAMERA']['CAM_MAX_ZOOM_DIST'])
        self.minZoomDist = int(config['CAMERA']['CAM_MIN_ZOOM_DIST'])
        self.moveSensitivity=int(config['CAMERA']['CAM_MOVE_SENSITIVITY'])
        self.zoomSensitivity=float(config['CAMERA']['CAM_ZOOM_SENSITIVITY'])
        self.currentTime=time.time()


    def move(self,playerId,player_list):
        for player in player_list:
            if playerId == player.idObject:
                pos = player.particle.pos.copy()
        self.currentTime=time.time()

        if self.moveUp==True and GOD_MODE:
            self.origin.add(Vector(0,-self.moveSensitivity))
        if self.moveDown==True and GOD_MODE:
            self.origin.add(Vector(0,self.moveSensitivity))

        if self.moveLeft == True and GOD_MODE:
            self.origin.add(Vector(-self.moveSensitivity,0))
        if self.moveRight == True and GOD_MODE:
            self.origin.add(Vector(self.moveSensitivity,0))


    def zoom(self):
        if self.zoomOut == True and ((self.dim.x<self.maxZoomDist and self.dim.y<self.maxZoomDist)or GOD_MODE):
            self.dim.add(self.dim.copy().multiply(self.zoomSensitivity))

        if self.zoomIn == True and ((self.dim.x>self.minZoomDist and self.dim.y>self.minZoomDist)or GOD_MODE):

                self.dim.add(self.dim.copy().multiply(-self.zoomSensitivity))

    def ratioToCam(self):
        return(self.dimCanv.copy().divideVector(self.dim))

    def ratioToCanv(self):
        return (self.dim.copy().divideVector(self.dimCanv))

    def get(self):
        return(self.origin, self.dim.x)

    def recieve(self,other):
        self.currentTime=other.currentTime
        self.origin=other.origin
        self.dim=other.dim
Ejemplo n.º 13
0
 def moveMonsters(self):
     # CHOOSE A RANDOM POINT WITHIN OPERATING RANGE OF MONSTER AND MOVE THE MONSTER TO THAT LOCATION IF THE VELOCITY IS 0 and not fierin
     if self.moveMonstersTime > 5:
         for monster in monster_set:
             num = random.randrange(1, 3)
             if num == 1 and not monster.hasFired and monster.particle.vel.getX(
             ) == 0 and monster.particle.vel.getY() == 0:
                 px = random.randrange(
                     int(monster.operationOrigin.getX() -
                         monster.operationRange.getX()),
                     int(monster.operationOrigin.getX() +
                         monster.operationRange.getX()))
                 py = random.randrange(
                     int(monster.operationOrigin.getY() -
                         monster.operationRange.getY()),
                     int(monster.operationOrigin.getY() +
                         monster.operationRange.getY()))
                 if px > MAP_WIDTH:
                     px = MAP_WIDTH
                 if px < 0:
                     px = 0
                 if py > MAP_HEIGHT:
                     py = MAP_HEIGHT
                 if py < 0:
                     py = 0
                 monster.particle.move(Vector(px, py))
         self.moveMonstersTime = 0
Ejemplo n.º 14
0
    def __init__(self, updateSprite, pos, vel, radius, angle, spriteKey, spriteDictionary, fps, removeOnVelocity0,
                 removeOnAnimationLoop, idObject, numRows, numColumns, startRow, startColumn, endRow, endColumn):

        self.idObject = idObject
        self.idClass = 2
        self.pos = pos
        self.vel = vel
        self.angle = angle
        self.updateSprite = updateSprite
        self.spriteKey = spriteKey

        if spriteKey != '':
            self.spriteSheet = SpriteSheet(spriteDictionary.get(self.spriteKey, 'elf_demo'), fps)

            self.spriteSheet.setRow(numRows, numColumns, startRow, startColumn, endRow, endColumn)
            self.dim = self.spriteSheet.animator.dimOriginal.copy().divideVector(
                Vector(self.spriteSheet.numColumns, self.spriteSheet.numRows))

        self.removeOnAnimationLoop = removeOnAnimationLoop
        self.removeOnVelocity0 = removeOnVelocity0

        self.radius = radius

        self.drawn = False
        if radius == 0:
            self.radius = self.dim.size() / 4

        self.currentTime = time.time()
Ejemplo n.º 15
0
    def __init__(self, maxVel, maxAcceleration, lineName1, lineName2,
                 relation_dict, line_dict, way_dict, node_dict, angle, radius,
                 spriteKey, spriteDictionary, spriteFps, idObject, numRows,
                 numColumns, startRow, startColumn, endRow, endColumn, color):

        self.line1 = lineName1
        self.line2 = lineName2
        self.line1Bool = True

        self.way_list = line_dict[
            self.line1]  #make sure this is a list of ways by id's
        wayId = self.way_list[0]
        way = way_dict[wayId]
        self.node_list = way['nodes']

        self.stop_list = line.getStopListFromLineName(relation_dict, way_dict,
                                                      self.line1)

        self.traverseForward = True

        self.reachedEnd = False
        self.wayIndex = 0
        self.nodeIndex = 1
        self.stopIndex = 0

        self.color = color
        self.send = True
        self.remove = False
        self.currentWay = self.way_list[self.wayIndex]
        self.currentStop = self.stop_list[self.stopIndex]
        self.nextStop = self.stop_list[self.stopIndex]
        self.currentNode = self.node_list[self.nodeIndex - 1]
        self.nextNode = self.node_list[self.nodeIndex]
        nodeCurrent = node_dict[self.currentNode]
        nodeNext = node_dict[self.nextNode]
        self.acceleration = 0
        self.maxVel = maxVel
        self.maxAcceleration = maxAcceleration

        vel = Vector(nodeNext['x'], nodeNext['y']).subtract(
            Vector(nodeCurrent['x'], nodeCurrent['y']))
        if vel.length() != 0:
            vel.normalize()

        self.directionVect = vel
        self.cooldown = nodeCurrent['delay']
        if self.maxVel == 50:
            self.cooldown = 10

        self.currentTime = time.time()
        self.idObject = idObject
        self.particle = Particle(True,
                                 Vector(nodeCurrent['x'], nodeCurrent['y']),
                                 Vector(0, 0), radius, angle, spriteKey,
                                 spriteDictionary, spriteFps, False, False,
                                 self.idObject, numRows, numColumns, startRow,
                                 startColumn, endRow, endColumn)
Ejemplo n.º 16
0
    def checkDecelForStop(self, node_dict):
        nextStop = node_dict[self.nextStop]
        distanceToStop = self.particle.pos.copy().distanceTo(
            Vector(nextStop['x'], nextStop['y']))
        distanceToDecel = self.particle.vel.copy().multiply(
            (self.particle.vel.length() / self.maxAcceleration)).length()

        if distanceToStop < distanceToDecel:
            self.acceleration = -self.maxAcceleration
Ejemplo n.º 17
0
    def updateVelocity(self, nodeTraffic_dict, relation_dict, line_dict,
                       way_dict, node_dict, simulation_speed):

        # check for condition of index incrementation
        self.checkIfReachedNode(way_dict, node_dict)

        currentVel = self.particle.vel.copy().length()
        nextNode = node_dict[self.nextNode]
        nextStop = node_dict[self.nextStop]
        if (Vector(nextNode['x'], nextNode['y']).subtract(
                self.particle.pos)).dot(self.particle.vel) < 0:
            currentVel *= -1
        if currentVel < nextNode['maxVel'] or nextNode == nextStop:
            self.acceleration = self.maxAcceleration

        elif currentVel > nextNode['maxVel'] and nextNode != nextStop:
            self.acceleration = -self.maxAcceleration

        else:
            self.acceleration = 0

        self.checkDecelForStop(node_dict)

        #second distance check with trains in the same stop location of the dictionary:
        stop = nodeTraffic_dict[self.nextStop]
        for id in stop:
            if id != self.idObject:
                particle = stop[id]
                velocityA = self.particle.vel.copy()
                velocityB = particle.vel.copy()
                if velocityA.dot(velocityB) > 0:
                    distanceToStop = self.particle.pos.copy().distanceTo(
                        particle.pos)
                    distanceToDecel = self.particle.vel.copy().multiply(
                        (self.particle.vel.length() /
                         self.maxAcceleration)).length()

                    if distanceToStop - 100 < distanceToDecel and self.particle.vel.copy(
                    ).dot(particle.pos.copy().subtract(self.particle.pos)) > 0:
                        self.acceleration = -self.maxAcceleration
                        if self.particle.vel.length() < 1:
                            self.acceleration = 0
                            self.particle.vel.multiply(0)

        #update velocity in relation to acceleration
        if self.currentNode == self.nextNode:
            self.incrementIndexes(way_dict, node_dict)
        if self.directionVect.length() != 0 and self.acceleration != 0:
            velToAdd = self.directionVect.copy().multiply(self.acceleration)
            velToAdd.multiply(
                (time.time() - self.currentTime) * simulation_speed)
            self.particle.vel.add(velToAdd)

        #check if reached stop
        self.checkIfReachedStop(nodeTraffic_dict, relation_dict, line_dict,
                                way_dict, node_dict)
Ejemplo n.º 18
0
    def __init__(self, origin, dim):
        self.idClass = 1
        self.idObject = uuid.uuid4()

        self.origin = origin
        self.dim = dim
        self.dimCanv=Vector(int(config['CANVAS']['CANVAS_WIDTH']),int(config['CANVAS']['CANVAS_HEIGHT']))
        self.zoomIn=False
        self.zoomOut=False
        self.moveLeft=False
        self.moveRight=False
        self.moveUp=False
        self.moveDown=False

        self.maxZoomDist=int(config['CAMERA']['CAM_MAX_ZOOM_DIST'])
        self.minZoomDist = int(config['CAMERA']['CAM_MIN_ZOOM_DIST'])
        self.moveSensitivity=int(config['CAMERA']['CAM_MOVE_SENSITIVITY'])
        self.zoomSensitivity=float(config['CAMERA']['CAM_ZOOM_SENSITIVITY'])
        self.currentTime=time.time()
Ejemplo n.º 19
0
    def incrementIndexes(self, way_dict, node_dict):
        self.currentNode = self.nextNode
        if (self.nodeIndex < len(self.node_list) - 1 and self.traverseForward
            ) or (self.nodeIndex > 0 and not self.traverseForward):  #next node
            if self.traverseForward:

                self.nodeIndex += 1
            else:
                self.nodeIndex -= 1
            self.nextNode = self.node_list[self.nodeIndex]
        elif (self.nodeIndex >= len(self.node_list) - 1
              and self.traverseForward) or (self.nodeIndex <= 0
                                            and not self.traverseForward):
            if self.wayIndex >= len(self.way_list) - 1:  #reached end
                self.reachedEnd = True
                self.nodeIndex = 1
                self.wayIndex = 0
            else:  #next way
                self.wayIndex += 1
                self.nodeIndex = 0
                self.currentWay = self.way_list[self.wayIndex]
                way = way_dict[self.currentWay]
                self.node_list = way['nodes']
                self.nextNode = self.node_list[self.nodeIndex]
                currentNode = node_dict[self.currentNode]
                nextNode = node_dict[self.nextNode]
                wayId = self.way_list[self.wayIndex]
                way = way_dict[wayId]
                nodeId = self.node_list[self.nodeIndex + 1]
                nextNextNode = node_dict[nodeId]
                if self.currentNode == self.nextNode:
                    self.traverseForward = True
                elif Vector(currentNode['x'], currentNode['y']).distanceTo(
                        Vector(nextNode['x'], nextNode['y'])) < Vector(
                            currentNode['x'], currentNode['y']).distanceTo(
                                Vector(nextNextNode['x'], nextNextNode['y'])):
                    self.traverseForward = True
                else:
                    self.traverseForward = False
                    self.nodeIndex = len(self.node_list) - 1
                    self.nextNode = self.node_list[self.nodeIndex]
Ejemplo n.º 20
0
    def spawnT1(
        self
    ):  # WITHIN 25% OF MAP CENTER, OPERATION RANGE OF 1000, ATTACK RANGE OF 500 t1, 1500,t2, 2500 t3? for lols
        # the following locations on the map X axis and y axis randomly:   \_________XXXXXX___________\
        pos = Vector(
            random.randint(int(MAP_WIDTH / 2 - MAP_WIDTH / 3),
                           int(MAP_WIDTH / 2 + MAP_WIDTH / 3)),
            random.randint(int(MAP_HEIGHT / 2 - MAP_HEIGHT / 3),
                           int(MAP_HEIGHT / 2 + MAP_HEIGHT / 3)))
        vel = Vector(0, 0)
        maxVel = 100  # why not

        aBack, numRows, numCol, startRow, startCol, endRow, endCol, key = getRandomMonster(
            1)
        monster = Monster(pos, vel, 0, pos, maxVel, 0, 50,
                          key, spriteDictionary, 15, getUid(), False,
                          Vector(0, 0), 1, numRows, numCol, startRow, startCol,
                          endRow, endCol, 1, aBack, False,
                          random.randrange(6000, 10000), pos.copy(),
                          pos.copy().normalize().multiply(1000), 200, 500)

        monster.setSpriteState(2)

        monster.totalLife = monster.life
        monster.magic = random.randrange(200, 1000)
        monster.range = random.randrange(200, 1000)
        monster_set.add(monster)
Ejemplo n.º 21
0
def getPlayer(arr):
    exists = False
    for player in player_list:

        if player.idObject == arr['idObject']:
            exists = True
    if not exists:

        player_list.append(
            Player(
                Vector(arr['pos']['x'], arr['pos']['y']),
                Vector(arr['vel']['x'], arr['vel']['y']), arr['nextPosTime'],
                Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                arr['maxVel'], arr['angle'], arr['radius'], arr['spriteKey'],
                spriteDictionary, arr['fps'], arr['idObject'], arr['hasFired'],
                Vector(arr['clickPosition']['x'],
                       arr['clickPosition']['y']), arr['spriteState'],
                arr['numRows'], arr['numColumns'], arr['startRow'],
                arr['startColumn'], arr['endRow'], arr['endColumn']))

    for player in player_list:
        if player.idObject == arr['idObject'] and arr['idObject'] != playerId:
            player.recieve(
                arr['hasFired'],
                Vector(arr['clickPosition']['x'], arr['clickPosition']['y']),
                Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                arr['nextPosTime'], arr['maxVel'], arr['maxRange'],
                arr['angle'], arr['updateSprite'], arr['spriteKey'],
                arr['fps'], arr['numRows'], arr['numColumns'], arr['startRow'],
                arr['startColumn'], arr['endRow'], arr['endColumn'],
                arr['radius'], spriteDictionary, arr['life'], arr['range'],
                arr['melee'], arr['magic'])
Ejemplo n.º 22
0
    def setLine(self, relation_dict, line_dict, way_dict, node_dict,
                line_name):
        self.way_list = line_dict[
            line_name]  # make sure this is a list of ways by id's
        wayId = self.way_list[0]
        way = way_dict[wayId]
        self.node_list = way['nodes']

        self.stop_list = line.getStopListFromLineName(relation_dict, way_dict,
                                                      line_name)
        self.reachedEnd = False

        self.wayIndex = 0
        self.nodeIndex = 1
        self.stopIndex = 0

        self.currentWay = self.way_list[self.wayIndex]
        self.currentStop = self.stop_list[self.stopIndex]
        self.nextStop = self.stop_list[self.stopIndex]
        self.currentNode = self.node_list[self.nodeIndex - 1]
        self.nextNode = self.node_list[self.nodeIndex]
        nodeCurrent = node_dict[self.currentNode]
        nodeNext = node_dict[self.nextNode]
        self.acceleration = 0

        vel = Vector(nodeNext['x'], nodeNext['y']).subtract(
            Vector(nodeCurrent['x'], nodeCurrent['y']))
        if vel.length() != 0:
            vel.normalize()
        self.directionVect = vel
        self.cooldown = nodeCurrent['delay']
        self.currentTime = time.time()
Ejemplo n.º 23
0
    def draw(self, canvas, cam, pos, numberColumns, numberRows, row, column, angle):
        ratio = cam.dimCanv.copy().divideVector(cam.dim)
        self.dimCamera = self.dimOriginal.copy().divideVector(Vector(numberColumns, numberRows)).multiplyVector(ratio)
        canLoc = pos.getP()

        imageCenter = Vector(
            (self.image.get_width() / numberColumns) * column - (self.image.get_width() / numberColumns) / 2,
            (self.image.get_height() / numberRows) * row - (self.image.get_height() / numberRows) / 2)

        imageDimention = Vector(self.image.get_width() / numberColumns, self.image.get_height() / numberRows)

        canvas.draw_image(self.image, imageCenter.getP(), imageDimention.getP(), canLoc, self.dimCamera.getP(), angle)
Ejemplo n.º 24
0
    def draw(self, canvas, cam):

        self.particle.draw(canvas, cam)
        if SHOW_MONSTER_THOUGHTS:
            ratio = cam.ratioToCam()

            percentage = -self.life / self.totalLife
            simplegui_lib_draw.draw_rect(
                canvas,
                self.particle.pos.copy().add(Vector(
                    0, -100)).transformToCam(cam).getP(),
                Vector(100, 20).multiplyVector(Vector(
                    percentage, 0.2)).multiplyVector(ratio).getP(),
                1,
                'Red',
                fill_color='red')

        if SHOW_MONSTER_THOUGHTS:
            ratio = cam.ratioToCam()

            radius1 = int(self.attackRange * ratio.getX())
            radius2 = int(self.followDistance * ratio.getX())
            canvas.draw_circle(
                self.particle.pos.copy().transformToCam(cam).getP(), radius1,
                1, 'Red')
            canvas.draw_circle(
                self.particle.pos.copy().transformToCam(cam).getP(), radius2,
                1, 'Pink')
            simplegui_lib_draw.draw_rect(
                canvas,
                self.operationOrigin.copy().transformToCam(cam).subtract(
                    self.operationRange.copy().multiplyVector(ratio)).getP(),
                self.operationRange.copy().add(
                    self.operationRange).multiplyVector(ratio).getP(),
                1,
                'White',
                fill_color=None)
Ejemplo n.º 25
0
    def spawnT3(
        self
    ):  # WITHIN 25% OF MAP CENTER, OPERATION RANGE OF 1000, ATTACK RANGE OF 500 t1, 1500,t2, 2500 t3? for lols

        topBand = Vector(random.randrange(0, int(MAP_WIDTH)),
                         random.randrange(0, int(MAP_HEIGHT *
                                                 0.15)))  # bottom 25% of map

        bottomBand = Vector(
            random.randrange(0, int(MAP_WIDTH)),
            random.randrange(int(MAP_HEIGHT * 0.85),
                             int(MAP_HEIGHT)))  # top 25% of map

        leftBand = Vector(random.randrange(0, int(MAP_WIDTH * 0.15)),
                          random.randrange(0,
                                           int(MAP_HEIGHT)))  # left 25% of map

        rightBand = Vector(
            random.randrange(int(MAP_WIDTH * 0.85), int(MAP_WIDTH)),
            random.randrange(0, int(MAP_HEIGHT)))  # right 25% of map

        num = random.randrange(0, 400)
        if num > 300:
            pos = topBand
        elif num > 200:
            pos = bottomBand
        elif num > 100:
            pos = leftBand
        else:
            pos = rightBand

        # the following locations on the map X axis and y axis randomly:   \XXXXX______________________XXXXX\
        vel = Vector(0, 0)
        maxVel = 200  # why not
        aBack, numRows, numCol, startRow, startCol, endRow, endCol, key = getRandomMonster(
            3)
        monster = Monster(pos, vel, 0, pos, maxVel, 0, 100,
                          key, spriteDictionary, 15, getUid(), False,
                          Vector(0, 0), 1, numRows, numCol, startRow, startCol,
                          endRow, endCol, 3, aBack, False,
                          random.randrange(500000, 1000000), pos.copy(),
                          pos.copy().normalize().multiply(1000), 500, 1000)
        monster.setSpriteState(2)

        monster.life = random.randrange(500000, 1000000)
        monster.totalLife = monster.life
        monster.magic = random.randrange(50000, 100000)

        monster.operationOrigin = pos.copy()

        monster_set.add(monster)
Ejemplo n.º 26
0
    def spawnT2(
        self
    ):  # WITHIN 25-75% OF MAP CENTER, OPERATION RANGE OF 3000, ATTACK RANGE OF 500 t1, 1500,t2, 2500 t3? for lols
        topBand = Vector(random.randrange(0, int(MAP_WIDTH)),
                         random.randrange(int(MAP_HEIGHT * 0.1),
                                          int(MAP_HEIGHT *
                                              0.25)))  # bottom 25% of map

        bottomBand = Vector(random.randrange(0, int(MAP_WIDTH)),
                            random.randrange(int(MAP_HEIGHT * 0.75),
                                             int(MAP_HEIGHT *
                                                 0.9)))  # top 25% of map

        leftBand = Vector(
            random.randrange(int(MAP_WIDTH * 0.1), int(MAP_WIDTH * 0.25)),
            random.randrange(0, int(MAP_HEIGHT)))  # left 25% of map

        rightBand = Vector(
            random.randrange(int(MAP_WIDTH * 0.75), int(MAP_WIDTH * 0.9)),
            random.randrange(0, int(MAP_HEIGHT)))  # right 25% of map

        num = random.randrange(0, 400)
        if num > 300:
            pos = topBand
        elif num > 200:
            pos = bottomBand
        elif num > 100:
            pos = leftBand
        else:
            pos = rightBand

        maxVel = 120  # why not
        vel = Vector(0, 0)

        aBack, numRows, numCol, startRow, startCol, endRow, endCol, key = getRandomMonster(
            2)
        monster = Monster(pos, vel, 0, pos, maxVel, 0, 75,
                          key, spriteDictionary, 15, getUid(), False,
                          Vector(0, 0), 1, numRows, numCol, startRow, startCol,
                          endRow, endCol, 2, aBack, False,
                          random.randrange(50000, 300000), pos.copy(),
                          pos.copy().normalize().multiply(1000), 300, 700)
        monster.setSpriteState(2)

        monster.totalLife = monster.life
        monster.magic = random.randrange(10000, 30000)
        monster.range = random.randrange(10000, 30000)

        monster_set.add(monster)
Ejemplo n.º 27
0
 def returnMonster(self, monster):
     px = random.randrange(
         int(monster.operationOrigin.getX() -
             monster.operationRange.getX()),
         int(monster.operationOrigin.getX() +
             monster.operationRange.getX()))
     py = random.randrange(
         int(monster.operationOrigin.getY() -
             monster.operationRange.getY()),
         int(monster.operationOrigin.getY() +
             monster.operationRange.getY()))
     if px > MAP_WIDTH:
         px = MAP_WIDTH
     if px < 0:
         px = 0
     if py > MAP_HEIGHT:
         py = MAP_HEIGHT
     if py < 0:
         py = 0
     monster.particle.move(Vector(px, py))
Ejemplo n.º 28
0
def getMonster(arr):
    exists = False
    for monster in monster_set_external:

        if monster.idObject == arr['idObject']:
            exists = True
    if not exists:
        monster_set_external.add(
            Monster(
                Vector(arr['pos']['x'], arr['pos']['y']),
                Vector(arr['vel']['x'], arr['vel']['y']), arr['nextPosTime'],
                Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                arr['maxVel'], arr['angle'], arr['radius'], arr['spriteKey'],
                spriteDictionary, arr['fps'], arr['idObject'], arr['hasFired'],
                Vector(arr['clickPosition']['x'],
                       arr['clickPosition']['y']), arr['spriteState'],
                arr['numRows'], arr['numColumns'], arr['startRow'],
                arr['startColumn'], arr['endRow'], arr['endColumn'],
                arr['tier'], arr['aBack'], arr['external'], arr['totalLife'],
                Vector(arr['operationOrigin']['x'],
                       arr['operationOrigin']['y']),
                Vector(arr['operationRange']['x'], arr['operationRange']['y']),
                arr['attackRange'], arr['followDistance']))

    for monster in monster_set_external:
        if monster.idObject == arr['idObject']:
            monster.recieve(
                arr['hasFired'],
                Vector(arr['clickPosition']['x'], arr['clickPosition']['y']),
                Vector(arr['nextPos']['x'], arr['nextPos']['y']),
                arr['nextPosTime'], arr['maxVel'], arr['maxRange'],
                arr['angle'], arr['updateSprite'], arr['spriteKey'],
                arr['fps'], arr['numRows'], arr['numColumns'], arr['startRow'],
                arr['startColumn'], arr['endRow'], arr['endColumn'],
                arr['radius'], spriteDictionary, arr['life'], arr['range'],
                arr['melee'], arr['magic'], arr['remove'])
Ejemplo n.º 29
0
 def __init__(self, image,scaleFactor):
     self.image = image
     self.dimOriginal = Vector(self.image.get_width(), self.image.get_height()).multiply(scaleFactor)
     self.dimCamera = Vector(0, 0)
Ejemplo n.º 30
0
 def __init__(self, image):
     self.image = simpleguics2pygame.load_image(image)
     self.dimOriginal = Vector(self.image.get_width(),
                               self.image.get_height())
     self.dimCamera = Vector(0, 0)