DeinZeug
kaptludoWorldWithBallWithoutCollisionTest.py — text/python-source, 7 KB (7745 bytes)
Dateiinhalt
# -*- coding: utf-8 -*- from visual import * from random import* scene.x = 0 # Fensterpos v. links scene.y = 0 # Fensterpos v. oben scene.height =1000 # Fensterhöhe scene.width = 1920 # Fensterbreite scene.range = (6,6,6) # Abstand scene.center = (100,1,100) # Festlegung Blickziel scene.userspin = False # Blickwechsel abgeschaltet scene.userzoom = False # Benutzerzoom abgeschaltet scene.fov = 2 # Kamerawinkel colors=[color.yellow,color.magenta,color.green,color.orange,color.white,color.blue,color.cyan,color.red] ground = box(pos=(50*2,-1,50*2), length=100*2, height=1, width=100*2, material=materials.rough) landscape = box(pos=(50,-0.5,50), length=101, height=30, width=101, material=materials.earth, opacity=0) class house(): #class house def __init__(self, px, pz, pLength, pWidth, pcolor=color.cyan, popacity=1): #__init__ a = box(pos=(px*2, 4.5, pz*2), length=pLength*2, height=10, width=pWidth*2, color=pcolor, opacity=popacity) b = curve(pos=[(px+0.5*pLength,0,pz+0.5*pWidth),(px-0.5*pLength,0,pz+0.5*pWidth),(px-0.5*pLength,0,pz-0.5*pWidth),(px+0.5*pLength,0,pz-0.5*pWidth),(px+0.5*pLength,0,pz+0.5*pWidth)]) #outer walls wall1=house(50,0.5,100,1,colors[randint(0,7)]) wall2=house(50,99.5,100,1,colors[randint(0,7)]) wall3=house(0.5,50,1,100,colors[randint(0,7)]) wall4=house(99.5,50,1,100,colors[randint(0,7)]) #inner cross house1=house(25,50,40,1,colors[randint(0,7)]) house2=house(75,50,40,1,colors[randint(0,7)]) house3=house(50,25,1,40,colors[randint(0,7)]) house4=house(50,75,1,40,colors[randint(0,7)]) #central walls house5=house(43.25,40,7.5,1,colors[randint(0,7)]) house6=house(56.75,40,7.5,1,colors[randint(0,7)]) house7=house(43.25,60,7.5,1,colors[randint(0,7)]) house8=house(56.75,60,7.5,1,colors[randint(0,7)]) house9=house(40,43.25,1,7.5,colors[randint(0,7)]) house10=house(60,43.25,1,7.5,colors[randint(0,7)]) house11=house(40,56.75,1,7.5,colors[randint(0,7)]) house12=house(60,56.75,1,7.5,colors[randint(0,7)]) #sector I bubble1 = sphere(pos=(65*2,1*2,15*2), radius=5*2, color = colors[randint(0,7)]) bubble2 = sphere(pos=(75*2,-2*2,23*2), radius=7*2, color = colors[randint(0,7)]) bubble3 = sphere(pos=(80*2,4.5*2,35*2), radius=5*2, color = colors[randint(0,7)]) bubble4 = sphere(pos=(90*2,1*2,5*2), radius=6*2, color = colors[randint(0,7)]) bubble5 = sphere(pos=(70*2,5.5*2,44*2), radius=6*2, color = colors[randint(0,7)]) bubble6 = sphere(pos=(60*2,5*2,29*2), radius=5*2, color = colors[randint(0,7)]) bubble7 = sphere(pos=(90*2,3*2,23*2), radius=5*2, color = colors[randint(0,7)]) bubble8 = sphere(pos=(95*2,5*2,37*2), radius=7*2, color = colors[randint(0,7)]) #sector II dice1=house(34.5,47,6,6,colors[randint(0,7)]) dice2=house(29.5,42,6,6,colors[randint(0,7)]) dice3=house(40,34,6,6,colors[randint(0,7)]) dice4=house(47,25,6,6,colors[randint(0,7)]) dice5=house(42,15,6,6,colors[randint(0,7)]) dice6=house(37,10,6,6,colors[randint(0,7)]) dice7=house(34,25,6,6,colors[randint(0,7)]) dice8=house(29,30,6,6,colors[randint(0,7)]) dice9=house(25,15,6,6,colors[randint(0,7)]) dice10=house(20,12,6,6,colors[randint(0,7)]) dice11=house(15,17,6,6,colors[randint(0,7)]) dice12=house(11,9,6,6,colors[randint(0,7)]) dice13=house(11,29,6,6,colors[randint(0,7)]) dice14=house(16,34,6,6,colors[randint(0,7)]) dice15=house(11,39,6,6,colors[randint(0,7)]) #sector III walllab1=house(10,54,1,8,colors[randint(0,7)]) walllab2=house(8,62,16,1,colors[randint(0,7)]) walllab3=house(16,58.5,1,8,colors[randint(0,7)]) walllab4=house(5,80,10,1,colors[randint(0,7)]) walllab5=house(10,80,1,20,colors[randint(0,7)]) walllab6=house(8,90,5,1,colors[randint(0,7)]) walllab7=house(10,70,10,1,colors[randint(0,7)]) walllab8=house(30,60,1,20,colors[randint(0,7)]) walllab9=house(28,70,5,1,colors[randint(0,7)]) walllab10=house(26,68,1,4,colors[randint(0,7)]) walllab11=house(26,92,1,16,colors[randint(0,7)]) walllab12=house(34,84,17,1,colors[randint(0,7)]) walllab13=house(42,89,1,10,colors[randint(0,7)]) walllab14=house(40.5,94,4,1,colors[randint(0,7)]) walllab15=house(45,70,10,1,colors[randint(0,7)]) walllab16=house(40,70,1,12,colors[randint(0,7)]) #sector IV walllab1=house(60,90,1,20,colors[randint(0,7)],0.2) walllab2=house(90,60,20,1,colors[randint(0,7)],0.2) walllab3=house(60,80,10,1,colors[randint(0,7)],0.2) walllab4=house(80,60,1,10,colors[randint(0,7)],0.2) walllab5=house(80,90,20,1,colors[randint(0,7)],0.2) walllab6=house(90,80,1,20,colors[randint(0,7)],0.2) walllab7=house(70,75,1,11,colors[randint(0,7)],0.2) walllab8=house(75,70,11,1,colors[randint(0,7)],0.2) #main base circle base =cylinder(pos=(50*2,-0.5,50*2), axis=(0,0.11,0), radius=0.5, material=materials.emissive, color=color.red, opacity=0.3) baseLamp = local_light(pos=(50*2,2,50*2), color=color.red) #sector lights sectorILamp=local_light(pos=(75*2,2,25*2), color=color.cyan) sectorIILamp=local_light(pos=(25*2,2,25*2), color=color.orange) sectorIIILamp=local_light(pos=(25*2,2,75*2), color=color.magenta) sectorIVLamp=local_light(pos=(75*2,2,75*2), color=color.green) # Ball ball1 = sphere(pos=(0,0,0), color=color.red, radius=0.5) ball2 = sphere(pos=(105,0,100), color=color.red, radius=0.5) roam=False while True: rate(200) ball1.pos=scene.center-(0,1,0) roam = True # If in roaming mode, change center and forward according to mouse position if roam: ray = scene.mouse.ray newray = norm(vector(ray.x, 0, ray.z)) angle = arcsin(dot(cross(scene.forward,newray),scene.up)) newforward = rotate(scene.forward, axis=scene.up, angle=angle/150) scene.forward = newforward # Falls Tastatur gedrückt... ball1.pos=scene.center-(0,1,0) if scene.kb.keys: s = scene.kb.getkey() if ball1.color==color.red: if s == 'up' or s=='w': # vor gehen scene.center += scene.forward*mag(scene.center-scene.mouse.camera)/12 elif s == 'down' or s=='s': # hinter gehen scene.center -= scene.forward*mag(scene.center-scene.mouse.camera)/12 elif s == 'left' or s=='a': # links gehen scene.center -= cross(scene.forward,scene.up)/6 elif s == 'right' or s=='d': # rechts gehen scene.center += cross(scene.forward,scene.up)/6 elif s=='c': ball1.color=color.cyan elif ball1.color==color.cyan:#catching ball if s == 'up' or s=='w': scene.center += scene.forward*mag(scene.center-scene.mouse.camera)/9 elif s == 'down' or s=='s': scene.center -= scene.forward*mag(scene.center-scene.mouse.camera)/9 elif s == 'left' or s=='a': scene.center -= cross(scene.forward,scene.up)/4.5 elif s == 'right' or s=='d': scene.center += cross(scene.forward,scene.up)/4.5 elif s=='r': ball1.color=color.red if mag(ball1.pos-ball2.pos)<1 and ball1.color==color.cyan: ball1.color=color.red ball2.color=color.cyan ball2.pos=(100,0,100) ball1.pos=(randint(1,200),0,randint(1,200)) print str(ball1.pos) if mag(ball1.pos-ball2.pos)<1 and ball2.color==color.cyan: ball2.color=color.red ball1.color=color.cyan ball1.pos=(100,0,100) ball2.pos=((randint(1,200),0,randint(1,200))) print str(ball2.pos) ball1.pos=scene.center-(0,1,0)