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 #Press ESCAPE to terminate
smode = False #adjust CAMERA position in and out so we can see our tank CAMERA.rotate(tilt, mouserot, 0) CAMERA.position((xm + xoff, ym + yoff + 5, zm + zoff)) oxm, ozm = xm, zm #draw player tank with smoothing on pitch and roll to lessen jerkiness tmnow = time.time() if tmnow > (ltm + 0.5): tankpitch_to, tankroll_to = mymap.pitch_roll(xm, zm) tankpitch += (tankpitch_to - tankpitch)/3.0 tankroll += (tankroll_to - tankroll)/3.0 drawTiger(xm, ym, zm, tankrot, tankroll, tankpitch, 180 - turret, (tilt*-2.0 if tilt > 0.0 else 0.0)) mymap.draw() # Draw the landscape #Draw enemy tank etdx = -math.sin(math.radians(etr)) etdz = -math.cos(math.radians(etr)) etx += etdx etz += etdz ety = mymap.calcHeight(etx, etz) + avhgt etr += 0.5 if tmnow > (ltm + 0.5): pitch, roll = mymap.pitch_roll(etx, etz) ltm = tmnow # updating this here but not for users tank relies on everything # being done in the right order drawTiger(etx, ety, etz, etr, roll, pitch, etr, 0) #Draw buildings
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) mtrx.translate(xm,ym,zm) myecube.draw(ectex,xm,ym,zm) mymap.draw(landimg) #myclip.enable() #mymap2.draw(surface1) #myclip.disable() 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
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 if mSx < -mapwidth / 2: mSx = -mapwidth / 2
CAMERA = Camera.instance() # Display scene and rotate cuboid while DISPLAY.loop_running(): CAMERA.reset() CAMERA.rotate(tilt, rot, 0) CAMERA.position((xm, ym, zm)) # for opaque objects it is more efficient to draw from near to far as the # shader will not calculate pixels already concealed by something nearer monolith.draw() mytrees1.draw() mytrees2.draw() mytrees3.draw() mymap.draw() myecube.draw() 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.2 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))
mymouse = Mouse() mymouse.start() omx=mymouse.x omy=mymouse.y camera = Matrix() while True: display.clear() camera.identity() camera.translate(xm,-2+ym-mapheight,-maphalf-2.5) myecube.draw(ectex,xm,ym,zm) mymap.draw(groundimg) #monster movement drx = sx - rx if abs(drx) > max_speed: drx = drx/abs(drx) * max_speed dry = sy - ry if abs(dry) > max_speed: dry = dry/abs(dry) * max_speed rx += drx ry += dry monster.position(rx, ry, -maphalf) dsy -= gravity sx += dsx sy += dsy sz += dsz
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 k = mykeys.read() if k >-1:
walk = False # Display scene and rotate cuboid angle = 0 #################################################### LOOP ############################################### while 1: display.clear() camera.identity() camera.rotate(tilt,0,0) camera.rotate(0,rot,0) camera.translate(xm,ym,zm) myecube.draw(ectex,xm,ym,zm) myfog.on() mymap.draw(rockimg1) mymap2.draw(rockimg2) mytrees1.drawAll(tree2img) raspberry.drawAll(raspimg) monst.draw(monstimg) # monster movement mDy -= gravity mDelx,mDelz = mSx+xm, mSz+zm #distance from monster mDist = math.sqrt(mDelx**2 + mDelz**2) mDx -= 0.01*mDelx/mDist mDz -= 0.01*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 if mSx < -mapwidth/2: mSx = -mapwidth/2