pythonista cartest2 源码

9次阅读

共计 1339 个字符,预计需要花费 4 分钟才能阅读完成。

from scene import *import soundimport randomimport mathA = Action
class MyScene (Scene):
def setup(self):
self.carlist=[]
self.imglist=[‘img1.png’,’img2.png’,’img3.png’,’img4.png’,’img5.png’,’img6.png’,’img7.png’,’img8.png’,’img9.png’,’img10.png’,’img11.png’]
x=100
y=300
self.a=self.spawn_car(x,y-199)
self.b=self.spawn_car(x+199,y-199)
self.spawn_car(x+398,y-199)
self.spawn_car(x,y)
self.spawn_car(x+199,y)
self.spawn_car(x+398,y)
self.spawn_car(x,y+199)
self.spawn_car(x+199,y+199)
self.spawn_car(x+398,y+199)

def spawn_car(self,x,y):
car=SpriteNode(random.choice(self.imglist))
#self.car.anchor_point=(0,0)
car.position=(x,y)
self.add_child(car)
self.carlist.append(car)
return car

def did_change_size(self):
pass

def update(self):
if self.a.bbox.intersects(self.b.bbox):
print(1)
print(self.a.bbox.intersection(self.b.bbox))
”’for car in self.carlist:
act=A.repeat(A.rotate_by(math.pi/2,1),-1)
car.run_action(act)”’

def touch_began(self, touch):
pass

def touch_moved(self, touch):
pass

def touch_ended(self, touch):
pass

if name == ‘__main__’:
run(MyScene(), show_fps=True)

”’display_width=800display_height=600
black=(0,0,0)white=(255,255,255)red=(255,0,0)green=(0,255,0)purple=(238,130,238)
x=0y=200
car(x,y-199,0)car(x+199,y-199,0)car(x+398,y-199,0)
car(x+597,y-199)
car1=car(x,y,0)car2=car(x+199,y,4)car(x+398,y,0)
car(x+597,y)
car5=car(x,y+199,0)car(x+199,y+199,0)car(x+398,y+199,0)
car(x+597,y+199)
”’

正文完
 0