def update(self): dt=self.time.deltaTime() self.__timer+=dt if(self.__gameover): self.__score.position=Vector2(7*math.sin(self.__timer*2),0) else: if(len(self.__level)==0 and len(self.__levelinstances)==0): print("--------------------") print("--CONGRATULATIONS!--") print("--------------------") print("YOU ARE THE WINRAR!!") print("--------------------") self.__score.sendMessage("addScore",self.getPlayer().getComponent("PlanePlayerControl").lives()*500) self.__gameover=True if(self.__level is not None): while(len(self.__level)>0 and self.__level[0][0][1]<self.__timer*10): entry=self.__level.pop(0) pos=entry[0] node=entry[1] #print(node.name()) go=None if(node.name().find("plane_small")==0): go=self.createEnemySimple("plane_evil01","s",Vector2(pos[0],9.9),Vector2(node.evalParm("velx"),node.evalParm("vely")),node.evalParm("sinAmp"),node.evalParm("sinFreq"),node.evalParm("sinOffset"),destroyCallback=self.explosion) elif(node.name().find("plane_big")==0): go=self.createEnemySimple("plane_evil02","m",Vector2(pos[0],9.9),Vector2(node.evalParm("velx"),node.evalParm("vely")),node.evalParm("sinAmp"),node.evalParm("sinFreq"),node.evalParm("sinOffset"),node.evalParm("lives"),node.evalParm("shooting"),node.evalParm("shootRowCount"),node.evalParm("projectilesCount"),node.evalParm("spreadHalfangle"),node.evalParm("shootRowDelay"),node.evalParm("shootReloadTime"),node.evalParm("shootAngle"),self.bigExplosion) elif(node.name().find("plane_boss_type1")==0): go=self.createBoss(Vector2(pos[0],9.9)) if(go is not None): self.__levelinstances.append(go) if(len(self.__neds)>0): needsort=False if(random.random()<0.7*dt): self.__clouds.append(self.__genCloud(1,20,1,20,1,10)) needsort=True if(random.random()<0.35*dt): self.__clouds.append(self.__genCloud(2,4,2,4.5,1,1.25)) needsort=True if(needsort): self.__clouds.sort(key=lambda x:x[4],reverse=True) shapelist=[] removelist=[] for cloud in self.__clouds: cloud[0]+=self.__globalVel[0]*dt/cloud[4] cloud[1]+=self.__globalVel[1]*dt/cloud[4] if(cloud[1]+cloud[3]*0.5 < -10): removelist.append(cloud) else: clr=cloud[5] shapelist.append(hou.NetworkShapeBox(hou.BoundingRect(cloud[0]-cloud[2]*0.5,cloud[1]-cloud[3]*0.5,cloud[0]+cloud[2]*0.5,cloud[1]+cloud[3]*0.5),color=hou.Color((clr,clr,clr)),alpha=0.9,screen_space=False)) for item in removelist: self.__clouds.remove(item) for ne in self.__neds: ne.setShapes(shapelist) self.__playerCached=None #to update in case player was killed or shit
def applyToEditor(self, editor): rect = hou.BoundingRect(this.cursor.position + this.cursor.half_extent, this.cursor.position - this.cursor.half_extent) pickbox = hou.NetworkShapeBox(rect, hou.ui.colorFromName('GraphPickFill'), alpha=0.3, fill=True, screen_space=False) self.shapes.append(pickbox) super(EditorUpdates, self).applyToEditor(editor)
def center_on_item(item, panel = hou.ui.curDesktop()): network_editor = panel.paneTabOfType(hou.paneTabType.NetworkEditor) h_item = hou.nodeBySessionId(int(item.data().get("session_id"))) if h_item is None: return if item.data().get("category") == "stickynote": h_item = hou.stickyNoteBySessionId(int(item.data().get("session_id"))) network_editor.cd(h_item.parent().path()) h_pos = h_item.position() bounds = hou.BoundingRect() bounds.setTo(hou.Vector4(h_pos[0]+1,h_pos[1]-8,h_pos[0]+8,h_pos[1]+8)) h_item.setSelected(True, True, True) network_editor.setVisibleBounds(bounds, transition_time=.05, set_center_when_scale_rejected=True)
def screenShot(): """take a screen shot of the current viewport at the current frame""" help(screenShot) import hou import toolutils import os #selected node nodeSelect = hou.selectedNodes() path = hou.expandString("$HIP") frame = hou.expandString("$F") frame = int(frame) black = hou.Color((0, 0, 0)) #name check there is a node selected if len(nodeSelect) < 1: print("!!! error: select a node !!!") else: for node in nodeSelect: name = node.name() node.setColor(black) #Get the current Desktop desktop = hou.ui.curDesktop() # Get the scene viewer scene = toolutils.sceneViewer() flipbook_options = scene.flipbookSettings().stash() # set frame range flipbook_options.frameRange((frame, frame)) #set output path root = "{1}/{2}/{0}/".format(name, path, "screenShot") if os.path.exists(root): listPath = os.listdir(root) inc = len(listPath) inc = int(inc) outputPath = "{}{}.{:04d}.jpg".format(root, name, inc) else: os.makedirs(root) inc = 0 outputPath = "{}{}.{:04d}.jpg".format(root, name, inc) #set flipbook current path flipbook_options.output(outputPath) #run flipbook scene.flipbook(scene.curViewport(), flipbook_options) # reload image print(outputPath) editor = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor) image = hou.NetworkImage() image.setPath(outputPath) image.setRect(hou.BoundingRect(0, 0, 5, 5)) image.setRelativeToPath(node.path()) editor.setBackgroundImages([image])
def _redraw(self, uievent, pending_actions): autoscroll.startAutoScroll(self, uievent, [self]) # FIXME doesn't work pos1 = uievent.editor.posToScreen(self._cursor.position) pos2 = uievent.editor.posToScreen(self._drag_cursor.position) rect = hou.BoundingRect(pos1, pos2) pickbox = hou.NetworkShapeBox(rect, hou.ui.colorFromName('GraphPickFill'), alpha=0.3, fill=True, screen_space=True) pickboxborder = hou.NetworkShapeBox( rect, hou.ui.colorFromName('GraphPickFill'), alpha=0.8, fill=False, screen_space=True) self.editor_updates.setOverlayShapes([pickbox, pickboxborder]) items = uievent.editor.networkItemsInBox(pos1, pos2, for_select=True) items = BoxPickHandler.getItemsInBox(items) uievent.editor.setPreSelectedItems(items)
def handleEventCoroutine(): visiblebounds = hou.BoundingRect() halfsize = utils.getNewNodeHalfSize() minsize = min(halfsize.x(), halfsize.y()) maxsize = max(halfsize.x(), halfsize.y()) inputnames = ('input', 'multiinput', 'dotinput') outputnames = ('output', 'indirectinputoutput', 'dotoutput') alignrects = [] shapes = [] nodecenter = None locatedconn = None locatedinput = None locatedoutput = None handler = None editor = None olddefaultcursor = None while True: uievent = yield if editor is None: editor = uievent.editor olddefaultcursor = editor.defaultCursor() if handler is not None: handler = sendEventToHandler(handler, uievent, shapes) if handler is None: editor.setDefaultCursor(olddefaultcursor) continue newvisiblebounds = editor.visibleBounds() if visiblebounds != newvisiblebounds: alignrects = editor.allVisibleRects([]) visiblebounds = newvisiblebounds if (isinstance(uievent, KeyboardEvent) or \ isinstance(uievent, MouseEvent)): if nodecenter is None: nodecenter = uievent.mousepos nodecenter = editor.posFromScreen(nodecenter) # Check for a wire to drop the node on, if that pref is enabled. # Don't update the target on a mouse up event. We want to keep # the located/selected target from the last mouse event, since the # selected value gets cleared on the mouseup event. if prefs.allowDropOnWire(editor) and uievent.eventtype != 'mouseup': target = None if isinstance(uievent, MouseEvent) and \ uievent.selected.item is not None: target = uievent.selected elif uievent.located.item is not None: target = uievent.located locatedconn = None locatedinput = None locatedoutput = None if target is not None: if isinstance(target.item, hou.NodeConnection): locatedconn = target elif target.name in inputnames: locatedinput = target elif target.name in outputnames: locatedoutput = target if locatedconn is None and \ locatedinput is None and \ locatedoutput is None: editor.setDefaultCursor(None) else: editor.setDefaultCursor(utils.theCursorDragDropOn) if isinstance(uievent, KeyboardEvent): if uievent.eventtype.endswith('keyhit') and \ display.setKeyPrompt(editor, uievent.key, 'h.pane.wsheet.cancel', uievent.eventtype): break if uievent.eventtype.endswith('keyhit') and \ display.setKeyPrompt(editor, uievent.key, 'h.pane.wsheet.add_op', uievent.eventtype): # Indicate that the keyboard event should be sent again, which # will allow it to be handled by the parent context (and open # up the tab menu). editor.handleCurrentKeyboardEvent(True) break elif uievent.eventtype == 'keyhit' and uievent.key == 'Enter': editor.eventContextData()['pos'] = nodecenter - halfsize setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break elif uievent.eventtype == 'keyhit' and uievent.key == 'Shift+Enter': editor.eventContextData()['pos'] = None setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break elif isinstance(uievent, MouseEvent): if uievent.eventtype == 'mousewheel': view.scaleWithMouseWheel(uievent) elif uievent.eventtype == 'mousedown': if uievent.selected.name.startswith('overview'): handler = base.OverviewMouseHandler(uievent) elif base.isPanEvent(uievent): handler = base.ViewPanHandler(uievent) elif base.isScaleEvent(uievent): handler = base.ViewScaleHandler(uievent) if handler is not None: editor.setDefaultCursor(olddefaultcursor) handler = sendEventToHandler(handler, uievent, shapes) elif uievent.eventtype == 'mouseup': editor.eventContextData()['pos'] = nodecenter - halfsize setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break else: nodecenter = uievent.mousepos nodecenter = editor.posFromScreen(nodecenter) category = editor.pwd().childTypeCategory() # If we are showing a preview of the node shape, we need to # pass a large square to ensure the shape draws at the # expected size. if prefs.showNodeShapes(editor) and \ category != hou.vopNodeTypeCategory(): halfmaxsize = hou.Vector2(maxsize, maxsize) rect = hou.BoundingRect(nodecenter - halfmaxsize, nodecenter + halfmaxsize) else: rect = hou.BoundingRect(nodecenter - halfsize, nodecenter + halfsize) snapresult = snap.snap(editor, None, rect, alignrects) if snapresult.isValid(): nodecenter += snapresult.delta() rect.translate(snapresult.delta()) ''' if prefs.showNodeShapes(editor): nodeshape = '' nodetypename = editor.eventContextData()['nodetypename'] if category is not None: nodetype = category.nodeType(nodetypename) if nodetype is not None: nodeshape = nodetype.defaultShape() shapes = [hou.NetworkShapeNodeShape(rect, nodeshape, hou.ui.colorFromName('GraphPreSelection'), 0.5, True, False)] else: shapes = [hou.NetworkShapeBox(rect, hou.ui.colorFromName('GraphPreSelection'), 0.5, True, False)]''' shapes = snapresult.shapes(editor) shapes.extend(buildPendingWires(editor, nodecenter, locatedconn, locatedinput, locatedoutput)) editor.setOverlayShapes(shapes) if editor is not None: editor.setDefaultCursor(olddefaultcursor) editor.setOverlayShapes([]) editor.popEventContext()