zm += dz * 0.5 ym += dy * 0.5 if (xm < -490 or xm > 490 or zm < -490 or zm > 490): fly = True #reached the edge of the maze! if not (mx == omx and my == omy and oxm == xm and ozm == zm): CAMERA.reset() CAMERA.rotate(tilt, 0, 0) CAMERA.rotate(0, rot, 0) CAMERA.position((xm, ym, zm)) omx = mx omy = my oxm = xm ozm = zm myecube.position(xm, ym, zm) myecube.draw() mymap.draw() mytrees1.draw() raspberry.draw() monst.draw() # monster movement mDy -= gravity mDelx, mDelz = mSx - xm, mSz - zm #distance from monster mDist = math.sqrt(mDelx**2 + mDelz**2) mDx = -0.1 * mDelx / mDist mDz = -0.1 * mDelz / mDist monst.rotateIncY(100.0 / mDist) if mDist > 100: #far away so teleport it nearer mSx, mSz = xm + 100 * random.random() - 50, zm + 100 * random.random( ) - 50
mymouse = Mouse() mymouse.start() omx=mymouse.x omy=mymouse.y # Display scene and rotate cuboid while 1: display.clear() mtrx.identity() mtrx.rotate(tilt, 0, 0) mtrx.rotate(0, rot, 0) mtrx.translate(xm,ym,zm) myecube.draw(ectex,xm,ym,zm) mymap.draw(mountimg1) mygrass.drawAll(grassimg) mytrees1.drawAll(tree2img) mytrees2.drawAll(tree1img) mytrees3.drawAll(hb2img) mx=mymouse.x my=mymouse.y #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: rot += (mx-omx)*0.2 tilt -= (my-omy)*0.2 omx=mx omy=my
avhgt = 2.0 xm=0.0 zm=0.0 ym = avhgt omx, omy = mymouse.position() CAMERA = Camera.instance() while DISPLAY.loop_running(): CAMERA.reset() CAMERA.rotate(tilt, 0, 0) CAMERA.rotate(0, rot, 0) CAMERA.position((xm, ym, zm)) mymodel.draw() myecube.draw() mx, my = mymouse.position() rot -= (mx-omx)*0.8 tilt += (my-omy)*0.8 omx=mx omy=my #Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 119: #key W xm -= math.sin(math.radians(rot)) zm += math.cos(math.radians(rot)) elif k == 115: #kry S
mymouse.start() mtrx = Matrix() omx = mymouse.x omy = mymouse.y # Display scene and rotate cuboid while 1: display.clear() mtrx.identity() mtrx.rotate(tilt, 0, 0) mtrx.rotate(0, rot, 0) #Utility.translatef(xm, ym, zm) myecube.draw(ectex, 0.0, 0.0, 0.0) mx=mymouse.x my=mymouse.y #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: rot += (mx-omx)*0.2 tilt -= (my-omy)*0.2 omx=mx omy=my #Press ESCAPE to terminate k = mykeys.read() if k >-1: if k==112: #key P display.screenshot("envcube.jpg")
mtrx.identity() #tilt can be used as a means to prevent the view from going under the landscape! if tilt<-1: sf=1.0/-tilt else: sf=1.0 mtrx.translate(0,-10*sf-5.0,-40*sf) #zoom camera out so we can see our robot mtrx.rotate(tilt, 0, 0) #Robot still affected by scene tilt #draw robot mylight.on() robot.drawAll(metalimg) mylight.off() mtrx.rotate(0, rot, 0) #rotate rest of scene around robot mtrx.translate(xm,ym,zm) #translate rest of scene relative to robot position myecube.draw(ectex,xm,ym,zm)#Draw environment cube myfog.on() mymap.draw(mountimg1) #Draw the landscape station.drawAll(metalimg) myfog.off() mx=mymouse.x my=mymouse.y #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: rot += (mx-omx)*0.2 tilt -= (my-omy)*0.2 omx=mx omy=my #Press ESCAPE to terminate
if tilt < -1: sf = 15 - 12.5/abs(tilt) else: sf = 2.5 xoff = sf*math.sin(math.radians(rot)) yoff = abs(1.25*sf*math.sin(math.radians(tilt))) + 3.25 zoff = -sf*math.cos(math.radians(rot)) CAMERA.rotate(tilt, rot, 0) CAMERA.position((xm + xoff, ym + yoff, zm + zoff)) #zoom CAMERA out so we can see our robot #draw robot robot.position(xm, ym, zm) robot.rotateToY(-rot) robot.draw() station.draw() mymap.draw() #Draw the landscape myecube.draw() #Draw environment cube myecube.position(xm, ym, zm) mx, my = mymouse.position() #if mx>DISPLAY.left and mx<DISPLAY.right and my>DISPLAY.top and my<DISPLAY.bottom: rot -= (mx-omx) * 0.2 tilt += (my-omy) * 0.1 omx = mx omy = my #Press ESCAPE to terminate k = mykeys.read() if k >-1: if k==119: #key W xm-=math.sin(math.radians(rot))
else: sf = 2.5 xoff = sf * math.sin(math.radians(rot)) yoff = abs(1.25 * sf * math.sin(math.radians(tilt))) + 3.25 zoff = -sf * math.cos(math.radians(rot)) CAMERA.rotate(tilt, rot, 0) CAMERA.position((xm + xoff, ym + yoff, zm + zoff)) #zoom CAMERA out so we can see our robot #draw robot robot.position(xm, ym, zm) robot.rotateToY(-rot) robot.draw() station.draw() mymap.draw() #Draw the landscape myecube.draw() #Draw environment cube myecube.position(xm, ym, zm) mx, my = mymouse.position() #if mx>DISPLAY.left and mx<DISPLAY.right and my>DISPLAY.top and my<DISPLAY.bottom: rot -= (mx - omx) * 0.2 tilt += (my - omy) * 0.1 omx = mx omy = my #Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 119: #key W xm -= math.sin(math.radians(rot))