ポリゴンを少しまとめて宇宙戦闘機っぽいものを作って動かしてみました。
ソースはもう少しなんとかしたいところです。
ソースはもう少しなんとかしたいところです。
import pygame import math import copy import random pygame.init() window_size = (800, 600) clock = pygame.time.Clock() screen = pygame.display.set_mode(window_size) print (pygame.ver) class Point: def __init__(self,x,y,z): self.x=x self.y=y self.z=z class Obje: def __init__(self,poly,point): self.poly = poly self.point = point self.sp = random.randint(20,100) def pointSet(self,x,y,z): self.point = Point(x,y,z) def turnY(self,do): ct=math.cos(do*3.1415/360) st=math.sin(do*3.1415/360) for i in range(len(self.poly)): self.poly[i].shift(-self.point.x,-self.point.y,-self.point.z) self.poly[i].turnY(ct,st) self.poly[i].shift(self.point.x,self.point.y,self.point.z) def draw(self,screen): for i in range(len(self.poly)): self.poly[i].drawXYZ(screen,self.point.x,self.point.y,self.point.z) def baseShift(self,x,y,z): for i in range(len(self.poly)): self.poly[i].baseShift(x,y,z) class PolyDat: def __init__(self,co): self.xyz4 = [(-50,0,0),(50,0,0),(50,0,50),(-0,0,50)] self.wk4=[] self.co=co#(255,255,0) self.xy4=[] self.sn = 0 def __lt__(self, other): return self.sn > other.sn def draw(self,screen): self.toWk() self.conv3d2d() pygame.draw.polygon(screen, self.co, self.xy4) def drawXYZ(self,screen,x,y,z): self.toWk() self.shift(x,y,z) self.conv3d2d() pygame.draw.polygon(screen, self.co, self.xy4) def conv3d2d(self): del self.xy4[:] for i in range(len(self.wk4)): x,y,z=self.wk4[i] self.xy4.append(self.conv(x,y,z)) def conv(self,x,y,z): d=200 rx=x*d/(d+z)+400 ry=y*d/(d+z)+300 return (rx,ry) def turnZ(self,ct,st): for i in range(len(self.wk4)): x,y,z=self.wk4[i] rx=x*ct-y*st ry=x*st+y*ct self.wk4[i]=(rx,ry,z) def turnY(self,ct,st): for i in range(len(self.wk4)): x,y,z=self.wk4[i] rx=x*ct-z*st rz=x*st+z*ct self.wk4[i]=(rx,y,rz) def turnX(self,ct,st): for i in range(len(self.wk4)): x,y,z=self.wk4[i] ry=y*ct-z*st rz=y*st+z*ct self.wk4[i]=(x,ry,rz) def baseShift(self,sx,sy,sz): for i in range(len(self.xyz4)): x,y,z=self.xyz4[i] self.xyz4[i]=(x+sx,y+sy,z+sz) def shift(self,sx,sy,sz): for i in range(len(self.wk4)): x,y,z=self.wk4[i] self.wk4[i]=(x+sx,y+sy,z+sz) def size(self,sx,sy,sz): for i in range(len(self.wk4)): x,y,z=self.wk4[i] self.wk4[i]=(x*sx,y*sy,z*sz) def toWk(self): self.wk4=copy.deepcopy(self.xyz4) def backWk(self): self.xyz4=copy.deepcopy(self.wk4) def objeSet(): p=[] for i in range(6): p.append(PolyDat((255,random.randint(180,230),random.randint(30,130)))) p[0].baseShift(0,0,100) p[1].baseShift(0,0,50) p[2].baseShift(-50,-50,0) p[3].baseShift(-50,50,0) p[4].baseShift(50,-50,0) p[5].baseShift(50,50,0) return Obje(copy.deepcopy(p),Point(0,0,0)) def objeAll(): for i in range(100): o.append(objeSet()) for i in range(100): o[i].pointSet(int(i/10)*500-2500,(i%10)*500-2000,800) o=[] def main(): clock.tick(10000) objeAll() bg_color = (0, 0, 0) end_game = False tn=0 while not end_game: tn+=1 for event in pygame.event.get(): if event.type == pygame.QUIT: end_game = True screen.fill(bg_color) #for i in range(len(o)): for i in range(100): o[i].draw(screen) o[i].baseShift(0,0,o[i].sp) pygame.display.flip() clock.tick(5) pygame.quit() quit() main()