class Missile(object): def __init__(self, w=1.0, h=1.0): self.isActive = False self.x = 0.0 self.y = 0.0 self.z = 0.0 self.dx = 0.0 self.dy = 0.0 self.dz = 0.0 self.w = w self.h = h self.countDown = 0 self.picture = Plane(w, h) #initialise the launch of the missile def fire(self, x, y, z, dx, dy, dz, cnt=10): self.isActive = True self.x = x self.y = y self.z = z self.dx = dx self.dy = dy self.dz = dz self.countDown = cnt self.picture.position(x, y, z) self.picture.rotateToY(atan(dx / dz)) #move and draw def move(self, tex): if self.countDown > 0: self.picture.translate(self.dx, self.dy, self.dz) self.picture.rotateIncY(32) self.picture.draw(tex) self.countDown -= 1
class Missile(object): def __init__(self, w=1.0, h=1.0): self.isActive = False self.x = 0.0 self.y = 0.0 self.z = 0.0 self.dx = 0.0 self.dy = 0.0 self.dz = 0.0 self.w = w self.h = h self.countDown = 0 self.picture = Plane(w, h) #initialise the launch of the missile def fire(self, x, y, z, dx, dy, dz, cnt=10): self.isActive = True self.x = x self.y = y self.z = z self.dx = dx self.dy = dy self.dz = dz self.countDown = cnt self.picture.position(x, y, z) self.picture.rotateToY(atan(dx/dz)) #move and draw def move(self, tex): if self.countDown > 0: self.picture.translate(self.dx, self.dy, self.dz) self.picture.rotateIncY(32) self.picture.draw(tex) self.countDown -= 1
do = -0.001 # uv increment # Fetch key presses. mykeys = Keyboard() fr = 0 # Display scene and rotate shape while DISPLAY.loop_running(): myshape.draw() myshape.rotateIncY(0.247) myshape.rotateIncZ(0.1613) myshape.translateX(dx) if myshape.x() > 5: dx = -0.05 elif myshape.x() < -5: dx = 0.05 mywater.draw() offset = (offset + do) % 1.0 # move texture offset in v direction mywater.set_offset((0.0, offset)) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: i_n = (i_n + 1) % num_n mywater.buf[0].textures[0] = waterbump[i_n] next_time = time.time() + spf av_fps = av_fps*0.9 + tick/spf*0.1 # exp smooth moving average print(av_fps,"FPS") tick = 0 tick += 1
ball.position(sx, sy, sz) ball.rotateIncX(dsz / radius * 50) defocus.start_blur() ball.draw() mymap.draw() myecube.draw() defocus.end_blur() defocus.blur(ball, 4, 15, 2) defocus.blur(mymap, 4, 15, 2) defocus.blur(myecube, 4, 15, 2) monster.draw() # write up the score score0.draw() score1.draw() camera.was_moved = False #Press ESCAPE to terminate k = mykeys.read() if k == 27: #Escape key DISPLAY.destroy() mykeys.close() mymouse.stop() break
do = -0.001 # uv increment # Fetch key presses. mykeys = Keyboard() fr = 0 # Display scene and rotate shape while DISPLAY.loop_running(): myshape.draw() myshape.rotateIncY(0.247) myshape.rotateIncZ(0.1613) myshape.translateX(dx) if myshape.x() > 5: dx = -0.05 elif myshape.x() < -5: dx = 0.05 mywater.draw() offset = (offset + do) % 1.0 # move texture offset in v direction mywater.set_offset((0.0, offset)) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: i_n = (i_n + 1) % num_n mywater.buf[0].textures[0] = waterbump[i_n] next_time = time.time() + spf av_fps = av_fps * 0.9 + tick / spf * 0.1 # exp smooth moving average print(av_fps, "FPS") tick = 0 tick += 1
if sz < -maphalf: #monster end if (sx-rx)**2 + (sy-ry)**2 < 10: dsz = abs(dsz) else: score[0] += 1 radius = 0.1 + (radius - 0.1)*0.75 # ball gets smaller each time you score ball = Sphere(radius,12,12,0.0,"sphere",0,0,0) maxdsz += 0.01 # max speed in z direction increases too sx, sy, sz = 0, mapheight/3, 0 dsx, dsy, dsz = 0.3*random.random()-0.15, 0, -0.1 ball.position(sx, sy, sz) ball.rotateIncX(dsz/radius*50) monster.draw(monstimg) ball.draw(ballimg) # write up the score Draw.string(arialFont, str(score[0]), -10, 20, -5, 0.0, 0.05, 0.05) Draw.string(arialFont, str(score[1]), 10, 20, -5, 0.0, 0.05, 0.05) display.swapBuffers() #Press ESCAPE to terminate k = mykeys.read() if k==27: #Escape key display.destroy() mykeys.close() mymouse.stop()
mycylinder.rotateIncY(2) mycylinder.rotateIncZ(1) mytcone.draw(coffimg) mytcone.rotateIncY(2) mytcone.rotateIncZ(-1) mytorus.draw(patimg) mytorus.rotateIncY(3) mytorus.rotateIncZ(1) mylathe.draw(patimg) mylathe.rotateIncY(2) mylathe.rotateIncZ(1) myPlane.draw(coffimg) myPlane.rotateIncY(9) Draw.string(arialFont, "Raspberry Pi ROCKS!", -0.8, -0.7, -2.2, 10.0, 0.003, 0.003) #pi3d.drawString(destineFont,"Some nice OpenGL bitmap fonts to play with",-1.3,-0.3,-2.2, 10.0, 0.002,0.002) k = mykeys.read() if k >-1: if k==112: display.screenshot("shapesPic.jpg") elif k==27: mykeys.close() texs.deleteAll() display.destroy() break else:
ball.position(sx, sy, sz) ball.rotateIncX(dsz/radius*50) defocus.start_blur() ball.draw() mymap.draw() myecube.draw() defocus.end_blur() defocus.blur(ball, 4, 15, 2) defocus.blur(mymap, 4, 15, 2) defocus.blur(myecube, 4, 15, 2) monster.draw() # write up the score score0.draw() score1.draw() camera.was_moved = False #Press ESCAPE to terminate k = mykeys.read() if k==27: #Escape key DISPLAY.destroy() mykeys.close() mymouse.stop() break
rot=0.0 rot1=90.0 rot2=0.0 m1Rad = 4 # radius of moon orbit m2Rad = 0.55 # radius moon's moon orbit #create a light mylight = Light(0,5,5,5,"sun",10,0,6, .1,.1,.2, 0) mylight.on() # Display scene while 1: display.clear() myplane.draw(starsimg) myplane.rotateIncZ(0.01) mysphere.draw(earthimg) mysphere.rotateIncY(0.1) mysphere2.draw(cloudimg) mysphere2.rotateIncY(.15) mymoon.draw(moonimg) mymoon.position(mysphere.x+m1Rad*sin(rot1),mysphere.y+0,mysphere.z-m1Rad*cos(rot1)) mymoon.rotateIncY(0.2) mymoon2.draw(watimg) mymoon2.position(mymoon.x+m2Rad*sin(rot2),mymoon.y+0,mymoon.z-m2Rad*cos(rot2)) mymoon2.rotateIncY(3)