def animate(): pbge.update() # using the XY mouse position to move the cube mx = -5 + pbge.mouseX * 10 my = 5 - pbge.mouseY * 10 pbge.moveTo(pbge.mycube, mx, my, 0) pbge.moveTo(pbge.myspot, mx * 0.3, my * 0.3, 7)
def animate(): pbge.update() pbge.color += pbge.way # inverting way once the color is 0 or 255 if (pbge.color == 0 or pbge.color == 255): pbge.way *= -1 pbge.changeColor(pbge.mycube, pbge.color, 0, 0) pbge.moveTo(pbge.mysphere, 0, 0, pbge.color / 127)
def animate(): pbge.update() pbge.color += pbge.way # inverting way once the color is 0 or 255 if ( pbge.color == 0 or pbge.color == 255 ): pbge.way *= -1 pbge.changeColor( pbge.mycube, pbge.color,0,0 ) pbge.moveTo( pbge.mysphere, 0,0, pbge.color / 127 )
def animate(): pbge.update() # keyboard interactions # use 'f' for faster and 's' for slower # done only once when the key is pressed if (pbge.keyPressed('f')): pbge.speed *= 2 pbge.moveTo(pbge.myspot, 0, 0, 7 + pbge.speed * 10) if (pbge.keyPressed('s')): pbge.speed *= 0.5 pbge.moveTo(pbge.myspot, 0, 0, 7 + pbge.speed * 10) # use 'r' to reset the cube position if (pbge.keyPressed('r')): pbge.moveTo(pbge.mycube, 0, 0, 0) # use the arrows to move the cube if (pbge.keyActive(pbge.ARROW_UP)): pbge.move(pbge.mycube, 0, pbge.speed, 0) if (pbge.keyActive(pbge.ARROW_DOWN)): pbge.move(pbge.mycube, 0, -pbge.speed, 0) if (pbge.keyActive(pbge.ARROW_LEFT)): pbge.move(pbge.mycube, -pbge.speed, 0, 0) if (pbge.keyActive(pbge.ARROW_RIGHT)): pbge.move(pbge.mycube, pbge.speed, 0, 0)
def animate(): pbge.update() # keyboard interactions # use 'f' for faster and 's' for slower # done only once when the key is pressed if ( pbge.keyPressed( 'f' ) ): pbge.speed *= 2 pbge.moveTo( pbge.myspot, 0, 0, 7 + pbge.speed * 10 ) if ( pbge.keyPressed( 's' ) ): pbge.speed *= 0.5 pbge.moveTo( pbge.myspot, 0, 0, 7 + pbge.speed * 10 ) # use 'r' to reset the cube position if ( pbge.keyPressed( 'r' ) ): pbge.moveTo( pbge.mycube, 0, 0, 0 ) # use the arrows to move the cube if ( pbge.keyActive( pbge.ARROW_UP ) ): pbge.move( pbge.mycube, 0, pbge.speed, 0 ) if ( pbge.keyActive( pbge.ARROW_DOWN ) ): pbge.move( pbge.mycube, 0, -pbge.speed, 0 ) if ( pbge.keyActive( pbge.ARROW_LEFT ) ): pbge.move( pbge.mycube, -pbge.speed, 0, 0 ) if ( pbge.keyActive( pbge.ARROW_RIGHT ) ): pbge.move( pbge.mycube, pbge.speed, 0, 0 )
def init(): scene = bge.logic.getCurrentScene() scene.post_draw = [animate] pbge.configure() # getting the reference of the created objects # for further modifications myplane = pbge.createPlane( -2,0,0 ) mycube = pbge.createCube( 0,2,0 ) mysphere = pbge.createSphere( 0,-2,0 ) mycylinder = pbge.createCylinder( 2,0,0 ) #let's place a spot myspot = pbge.createSpot( 0,0,7 ) # all objects are created, # let's change the position: pbge.moveTo( myplane, 0,0,-3 ) # let's change the size: pbge.scale( myplane, 10 ) pbge.scaleZ( mycube, 3 ) # let's change the orientation: pbge.rotateX( mycylinder, 15 )