def drawPortalLines(self): ''' ''' already_drawn = [] for object in self.objects: if type(object) == GameObjects.Portal and object not in already_drawn and object.linked: already_drawn.append(object.linked) jngl.setColor(255, 0, 0, 180) jngl.drawLine(object.x+16, object.y+33, object.linked.x+16, object.linked.y+33)
def draw(self): jngl.setColor(255, 255, 255) x = self.x - self.width * (self.breathFactor - 1) / 2 y = self.y + self.height * (self.breathFactor - 1) xfactor = self.breathFactor yfactor = 1 + (1 - self.breathFactor) if self.xspeed >= 0: jngl.drawScaled(self.filenames[self.currentFile], x, y, xfactor, yfactor) else: jngl.drawScaled(self.filenames[self.currentFile], x + self.width, y, -xfactor, yfactor) if self.hasKey: jngl.draw(RESOURCEWORLD + "key.png", self.x, self.y - 20)
def draw(self): flash = int(jngl.getTime() * 300 % 200) if flash > 100: flash = 200 - flash red = self.red + flash green = self.green + flash blue = self.blue + flash if red > 255: red = 255 if blue > 255: blue = 255 if green > 255: green = 255 width = self.size height = self.size jngl.pushMatrix() jngl.translate(self.x, self.y) if self.exploding: jngl.setColor(red, green, blue, 255 - self.explodeTimeout) width -= self.explodeTimeout / 2 height -= self.explodeTimeout / 2 distance = self.explodeTimeout / 3 jngl.drawRect(-width / 6 - distance, -height / 6 - distance, width / 3, height / 3) jngl.drawRect(-width / 6 - distance, -height / 6 + distance, width / 3, height / 3) jngl.drawRect(-width / 6 + distance, -height / 6 + distance, width / 3, height / 3) jngl.drawRect(-width / 6 + distance, -height / 6 - distance, width / 3, height / 3) jngl.setFontColor(255, 255, 255, int(255 - self.explodeTimeout * 2.55)) jngl.print("{0: >+3}".format(self.score), -23, int(-15 - self.explodeTimeout / 5)) jngl.setFontColor(255, 255, 255, 255) else: jngl.setColor(255, 255, 255, 255) jngl.pushMatrix() jngl.rotate(jngl.getTime() * 50 % 360) jngl.drawRect(-width / 2, -height / 2, width, height) jngl.popMatrix() jngl.setColor(red, green, blue) jngl.pushMatrix() jngl.rotate(-jngl.getTime() * 50 % 360) jngl.drawRect(-width / 2, -height / 2, width, height) jngl.popMatrix() jngl.popMatrix()
def run(self): self.camera = 0 lastTime = jngl.getTime() needDraw = True timePerStep = 0.01 counter = 0 fps = 0 self.box = None self.port1 = None while jngl.running(): x = jngl.getMouseX() - self.camerax y = jngl.getMouseY() - self.cameray if self.gridEnabled: x = int(x / self.gridSize) * self.gridSize y = int(y / self.gridSize) * self.gridSize if self.box: x += self.gridSize y += self.gridSize if jngl.getTime() - lastTime > timePerStep: lastTime += timePerStep needDraw = True if jngl.keyDown("z"): if not self.zoom: self.camerax += self.windowWidth / 2 self.cameray += self.windowHeight / 2 self.zoom = True # self.gridEnabled = False self.scale = 0.5 elif self.zoom: self.zoom = False self.camerax -= self.windowWidth / 2 self.cameray -= self.windowHeight / 2 jngl.scale(self.scale) self.scale = 1 if jngl.keyPressed("s"): # and jngl.keyDown(jngl.key.ControlL): jngl.hideWindow() file = asksaveasfile(mode="wb", defaultextension=".slv", filetypes=[("Somyeol Level", "*.slv")]) if file != None: self.level.saveLevel(file) file.close() self.showWindow() if jngl.keyPressed("g"): self.toggleGrid() if jngl.keyPressed(jngl.key.ControlL) and jngl.keyPressed("n"): self.camerax = 0 self.cameray = 0 self.level = Map.Map() self.gridEnabled = True self.add10 = False self.scale = 1 self.zoom = False if jngl.keyPressed("l"): # and jngl.keyDown(jngl.key.ControlL): jngl.hideWindow() self.level.loadLevel() self.showWindow() if jngl.keyPressed("i"): self.addImage(x, y) if jngl.keyPressed("t"): jngl.hideWindow() from Game import Game game = Game() tempMap = copy.deepcopy(self.level) game.setMap(tempMap) game.enable_credits = False game.testmode = True game.run() jngl.hideWindow() self.showWindow() if jngl.keyPressed("m"): self.add10 = not self.add10 # Change the Placeable if jngl.mousePressed(jngl.mouse.Right) or jngl.keyPressed(jngl.key.PageUp): self.box = None self.port1 = None self.placeable_count += 1 if self.placeable_count >= len(self.placeable): self.placeable_count = 0 if jngl.keyPressed(jngl.key.PageDown): self.box = None self.port1 = None self.placeable_count -= 1 if self.placeable_count < 0: self.placeable_count = len(self.placeable) - 1 for i in range(len(self.quickselect) - 1): if jngl.keyPressed(self.quickselect[i]): self.box = None self.port1 = None self.placeable_count = i % (len(self.placeable)) if jngl.mousePressed(jngl.mouse.Middle) or jngl.keyPressed(jngl.key.Delete): obj = self.getObjectAt(x, y) lists = (self.level.somyeols, self.level.objects, self.level.images) for l in lists: if obj in l: l.remove(obj) if jngl.keyDown(jngl.key.ShiftL) or jngl.keyDown(jngl.key.ShiftR): if jngl.mouseDown(jngl.mouse.Left): self.moveObject(x, y) else: self.obj = None if jngl.mousePressed(jngl.mouse.Left): self.addObject(x, y) if jngl.keyDown(jngl.key.Right): self.camerax -= 4 if jngl.keyDown(jngl.key.Left): self.camerax += 4 if jngl.keyDown(jngl.key.Up): self.cameray += 4 if jngl.keyDown(jngl.key.Down): self.cameray -= 4 if ( self.cameray / self.scale + self.windowHeight ) * self.scale <= self.windowHeight: # Kamera immer über dem Boden? self.cameray = (self.windowHeight / self.scale - self.windowHeight) * self.scale if jngl.keyPressed(jngl.key.Escape): jngl.hideWindow() quit = tkMessageBox.askyesno("Close Editor?", "Do you really want to quit?") if quit: return self.showWindow() jngl.swapBuffers() elif needDraw: needDraw = False jngl.pushMatrix() jngl.translate(self.camerax, self.cameray) self.level.drawEditor() if not self.zoom: if not jngl.keyDown(jngl.key.ShiftL) and not jngl.keyDown(jngl.key.ShiftR): self.placeable[self.placeable_count](x, y).drawPreview() jngl.print(self.placeable[self.placeable_count](x, y).__str__(), x + 40, y) if self.add10: jngl.print("10x", x - 40, y + 10) if self.box: jngl.setColor(100, 100, 100, 100) if len(self.box) > 2: jngl.setColor(255, 100, 100, 100) jngl.drawRect(self.box[0], self.box[1], x - self.box[0], y - self.box[1]) elif self.port1: jngl.setColor(255, 50, 50, 100) jngl.drawLine(self.port1.x + 16, self.port1.y + 33, x + 16, y + 33) jngl.popMatrix() jngl.pushMatrix() jngl.translate(self.camerax % self.gridSize, self.cameray % self.gridSize) if self.gridEnabled and not self.zoom: jngl.setColor(0, 0, 0, 40) for x in range(0, self.windowWidth, self.gridSize): jngl.drawLine(x, -self.gridSize, x, self.windowHeight) for y in range(0, self.windowHeight, self.gridSize): jngl.drawLine(-self.gridSize, y, self.windowWidth, y) jngl.popMatrix() jngl.setFontColor(0, 0, 0, 200) if jngl.keyDown("h"): jngl.print( "L - load file\nS - save file\nI - insert image\nLeft Mouse Button - add object\nMiddle Mouse Button - remove object\nRight Mouse Button or Page Up/Down - change object to add\nShift + Left Mouse Button - Move object\nG - change grid size\nT - test level\nM - add 10 somyeols at once\nZ Zoom out\nCtrl+N New Level (deletes everything!)", 10, 10, ) else: jngl.print( "Press H to show help text. X = {0} Y = {1}".format(-self.camerax, self.cameray), 10, 10 ) jngl.print( "Somyeols: {0} Objects: {1}".format(len(self.level.somyeols), len(self.level.objects)), 10, 30 ) fps += jngl.getFPS() / 50 counter -= 1 if counter < 0: counter = 50 jngl.setTitle("Somyeol2D - LevelEditor {0} - FPS: {1}".format(self.version, int(fps))) fps = 0 jngl.swapBuffers() else: jngl.sleep(1)
def draw(self): jngl.setColor(200, 200, 200) jngl.drawRect(self.x, self.y, self.width, self.height)