def line(self, start, end, color=(255, 255, 255)): start -= self.camera end -= self.camera start += Vec2((SCREEN_WIDTH - 300) / 2, (SCREEN_HEIGHT - 200) / 2) end += Vec2((SCREEN_WIDTH - 300) / 2, (SCREEN_HEIGHT - 200) / 2) pygame.draw.line(self.screen, color, (start.x, start.y), (end.x, end.y), 3)
def __init__(self, parentPos, pos): self.parentPos = Vec2(0, 0) self.pos = Vec2(0, 0) self.truePos = Vec2(0, 0) self.parentPos = parentPos self.pos = pos
def subdivide_rect(rect): center = rect.center() north_west = Rect2(Vec2(rect.min.x, center.y), Vec2(center.x, rect.max.y)) north_east = Rect2(center, rect.max) south_west = Rect2(rect.min, center) south_east = Rect2(Vec2(center.x, rect.min.y), Vec2(rect.max.x, center.y)) return (north_west, north_east, south_west, south_east)
def randomGrid_square(grid, scale=1.0, randomishness=1.0): step = scale / grid centroids = [] for i in range(grid): for j in range(grid): p = Vec2(i, j) * step + Vec2(rand(), rand()) * step * randomishness centroids.append(p) return centroids
def move(self): rad = self.rotation * 6.283185 / 360 dx, dy = sin(rad), cos(rad) self.forward = Vec2(dx, -dy) self.right = Vec2(dy, dx) self.position += self.forward * self.accel * SPEED + self.right * self.straif * STRAIF self.rotation += self.turn * SPIN self.drawable.position = self.position self.drawable.rotation = self.rotation
def move(self, game): #print(self.startRange, self.halfRange, self.endRange) #print(game.currentLevel.character.hitBox.pos) #print(self.hitBox.vel.x) #print(self.hitBox.pos) #print(self.startPos) if self.hitBox.pos.x > self.halfRange: self.hitBox.vel = Vec2(-160, -135) if self.hitBox.pos.x < self.halfRange and self.hitBox.pos.x > self.endRange: self.hitBox.vel = Vec2(-160, 135)
def __init__(self, pos, size, startRange, endRange): pos *= 24 pos.y -= 8 size *= 24 self.hitBox = HitBox(pos, Vec2(55, 55), False, Layer("deadly"), Vec2(100, 0)) self.hitBox.onCollide(self.hitRemove, Layer("player")) self.hitRemove == False self.startRange = pos.x + startRange * 24 self.endRange = pos.x + endRange * 24 self.frame = 0 self.mainScreen = pygame.display.get_surface() #self.enemy = [ #pygame.image.load("Graphics/EnemyGraphics/observer/AnimationRechts/observerRight1.png").convert_alpha(), #pygame.image.load("Graphics/EnemyGraphics/observer/AnimationLinks/observerLeft1.png").convert_alpha()] self.img = 0 #lädt Grafiken des Gegners self.LaufAnimationGoblin = [ pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame1.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame2.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame3.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame4.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame5.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame6.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame7.png" ), (70, 55)), pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/Goblin/GoblinFrames/runRight/frame8.png" ), (70, 55)) ]
def __init__(self, parentPos, pos, imageNames): self.state = 0 self.images = [] self.size = Vec2(0, 0) self.onClick = None super().__init__(parentPos, pos) #loading images for i in imageNames: image = pygame.image.load(i) self.size = Vec2(image.get_size()) self.images.append(image)
def draw(self, img, pos, isgui=False): if isgui: self.screen.blit(img, (pos.x, pos.y)) else: pos -= self.camera pos += Vec2((SCREEN_WIDTH - 300) / 2, (SCREEN_HEIGHT - 200) / 2) img_size = Vec2(img.get_width(), img.get_height()) v1 = pos + img_size v2 = Vec2(SCREEN_WIDTH - 300, SCREEN_HEIGHT - 200) + img_size / 2 if v1.x < 0 or v1.y < 0 or pos.x > v2.x or pos.y > v2.y: return pos -= Vec2(img.get_width() / 2, img.get_height() / 2) self.screen.blit(img, (pos.x, pos.y))
def __init__(self, size, background): self.position = Vec2() self.size = size self.background = background self.surface = pygame.Surface(self.size.values) self.mainScreen = pygame.display.get_surface() self.surface.fill(self.background)
def __init__(self, parent, pos, radius, mass): self._parent = parent self._totalForce = Vec2(0, 0) self._p = pos self._v = Vec2(0, 0) self._speed = self._v.getMagnitude() self._a = Vec2(0, 0) self._radius = radius self._m = mass self.color = "red" self.circle = None self._draw()
def draw(self, renderer): if self.route: dir = self.target.get_coords() - self.pos angle = math.degrees(Vec2(dir.y, dir.x).getAngle()) + 180 renderer.draw(pygame.transform.rotate(rocketImg, angle), self.pos) else: renderer.draw(rocketImg, self.pos)
def point_set_bounding_box(points): minx = float('inf') miny = float('inf') maxx = float('-inf') maxy = float('-inf') for x, y in points: if x < minx: minx = x if x > maxx: maxx = x if y < miny: miny = y if y > maxy: maxy = y return Rect2(Vec2(minx, miny), Vec2(maxx, maxy))
def clickedPlanet(mouseVec): for planet in planets: planet_screen_pos = planet.get_coords() - renderer.camera planet_screen_pos += Vec2((SCREEN_WIDTH - 300) / 2, (SCREEN_HEIGHT - 200) / 2) diff = mouseVec - planet_screen_pos if diff.getLen() <= 128 * planet.size: return planet return None
def getStart(self): returnValue = libpanda._inPgRdzl6Bh(self.this) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None return returnObject
def getEnd(self): returnValue = libpanda._inPgRdzFrB0(self.this) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None return returnObject
def createVoroMan(boundingBox, grid, randomishness=1.0, seed=None): pMin, pMax = boundingBox size = Vec2(pMax) - Vec2(pMin) if seed: save = True else: seed = iRand(0, maxint) print 'seed:', seed save = False random_seed(seed) centroids = randomGrid_square(grid, WindowSize, randomishness) tooSmall = size.x / grid / TOOSMALL print 'tooSmall:', tooSmall polies = VoroMan( centroids, boundingBox, tooSmall ) # bounding box not really implemented yet. Only size is used. fp = "%i_%i.pickle" % (grid, seed) if save: pickle.dump(polies, open(fp, "wb")) return polies
def getFilmOffset(self): returnValue = libpanda._inPMAKPb8t_(self.this) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None return returnObject return
def draw(self, renderer): renderer.draw(self.img, self.pos) self.nametext.absDraw(renderer) if self.ownage: scale = self.size * 128 castleVec = Vec2(scale * math.sin(math.radians(self.castleAngle)), scale * math.cos(math.radians(self.castleAngle))) renderer.draw(pygame.transform.rotate(castleImg, self.castleAngle), self.pos - castleVec)
def __init__(self, parentPos, pos, backgroundName): self.background = None self.size = Vec2(0, 0) self.children = [] super().__init__(parentPos, pos) self.background = pygame.image.load(backgroundName)
def __init__(self, pos, size): pos *= 24 size *= 24 self.hitBox = HitBox(pos, Vec2(55, 50), True, Layer("solid")) self.mainScreen = pygame.display.get_surface() self.img = 0 self.cannonGraphic = pygame.transform.scale( pygame.image.load( "Graphics/EnemyGraphics/cannon/cannonTransFlipped.png"), (70, 55))
def interpolate(self, parameter1): returnValue = libpanda._inPgRdzPI7a(self.this, parameter1) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject
def __overloaded___sub___ptrConstLPoint2f_ptrConstLPoint2f(self, other): returnValue = libpanda._inPUZN3ZCqi(self.this, other.this) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject return
def _calculateFrictionalForce(self, fn): # la force de frottement n'a d'effet que si la boule est en mouvement if self._speed != 0: uk = 0.03 Fk = fn * uk frictionalForceDirection = self._v.normalize() * -1 Fk = frictionalForceDirection * Fk return Fk else: return Vec2(0, 0)
def getValue(self): returnValue = libpanda._inPgRdzZ__N(self.this) import Vec2 returnObject = Vec2.Vec2(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject
def _calculateTotalForce(self): totalForce = Vec2(0, 0) # Force normale Fn = self._m * 9.81 # Force de frottement Fk = self._calculateFrictionalForce(Fn) totalForce += Fk return totalForce
def CreatePolies(): setrecursionlimit(10000) #shader = sf.Shader.from_file(None, '../data/db2.frag' ) #states = sf.RenderStates(shader=shader) pMin = -WindowSize, -WindowSize pMax = WindowSize, WindowSize boundingBox = pMin, pMax polies = loadVoroMan(grid, seed) if seed else None if not polies: polies = createVoroMan(boundingBox, grid, randomishness, seed) pMin, pMax = Vec2(boundingBox[0]), Vec2(boundingBox[1]) pScale = pMax - pMin polies = [SFPoly(poly, pMin, pScale) for poly in polies] for p in polies: p.interlink(polies) return polies
def __init__(self, name, pos, type, size, population, ownage): self.name = name self.pos = pos self.type = type self.size = size self.population = population self.ownage = ownage if self.name == None: self.name = random.choice(names) if self.type == None: self.type = self.generate_type(types) if self.size == None: self.size = random.uniform(0.1, 0.7) if self.ownage == None: self.ownage = False self.nametext = TextObject(Vec2(0, 0), pos + Vec2(0, 140) * self.size, Vec2(100, 100), self.name) self.resources = {"Food": 0, "Wood": 0, "Iron": 0} self.maxResources = { "Food": 1000, "Wood": 1000, "Iron": 1000, "Population": 1000 } self.production = {"Food": 3, "Wood": 3, "Iron": 3} for type in types: self.resources[type] = 0 if self.name == "Earth": self.resources['Food'] = 100 img = PlanetImgs[types.index(self.type)] self.img = pygame.transform.scale(img, (int( img.get_width() * self.size), int(img.get_height() * self.size))) self.timer = 0 self.castleAngle = random.randint(-20, 20)
def rayRayIntersectPoint(a1, a2, b1, b2): #print a1,a2,b1,b2 x1_, y1_ = a1 x2_, y2_ = a2 x3_, y3_ = b1 x4_, y4_ = b2 # Make sure the lines aren't parallel if ((y2_ - y1_) / (x2_ - x1_) != (y4_ - y3_) / (x4_ - x3_)): d = (((x2_ - x1_) * (y4_ - y3_)) - (y2_ - y1_) * (x4_ - x3_)) if (d != 0): r = (((y1_ - y3_) * (x4_ - x3_)) - (x1_ - x3_) * (y4_ - y3_)) / d s = (((y1_ - y3_) * (x2_ - x1_)) - (x1_ - x3_) * (y2_ - y1_)) / d if (r >= 0) and (s >= 0): return Vec2(x1_ + r * (x2_ - x1_), y1_ + r * (y2_ - y1_))
def update_dashboard(selection): if(isinstance(selection, Planet)): tradeWindow.setPos(Vec2(1000, 10500)) planetWindow.setPos(Vec2(0, 500)) planet_name.setText(selection.name) planet_population.setText("~POP~ %i" % selection.population) planet_food.setText("~FOOD~ %i" % selection.resources['Food']) planet_wood.setText("~WOOD~ %i" % selection.resources['Wood']) planet_iron.setText("~IRON~ %i" % selection.resources['Iron']) elif isinstance(selection, Traderoute): tradeWindow.setPos(Vec2(0, 500)) planetWindow.setPos(Vec2(10000, 10000)) #Getting the info from the path resType = selection.cargo planets = selection.path tradePlanetNames[0].setText(planets[0].name) tradePlanetNames[1].setText(planets[1].name) #abcd tradeTransferText[0].setText(RESOURCE_TO_IMAGE[selection.cargo[0]] + " >>>>") tradeTransferText[1].setText("<<<< " + RESOURCE_TO_IMAGE[selection.cargo[1]])