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)
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)
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)
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
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)