Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.59 KB | None | 0 0
  1. '''rcw_cadgen early module for kick it level generation
  2. Created on 19.02.2011
  3.  
  4. @author: RoadCrewWorker
  5. '''
  6. import os, stat
  7.  
  8. class BodyLibrary:
  9.     '''Enum class to facilitate finding and selecting geometry'''
  10.     Player_Start_Location = 3
  11.     Particle_Generator = 2
  12.     #Planes
  13.     Plane_Boundary = 398
  14.     Plane_Rain=707
  15.     Plane_Sun=709
  16.     Plane_Water=510
  17.     #Cubes
  18.     Cube_1m_A = 645
  19.     Cube_1m_B = 646
  20.     Cube_1m_C = 647
  21.     Cube_1m_D = 648
  22.     Cube_1m_E = 649
  23.     Cube_1m_F = 650
  24.     Cube_1m_G = 651
  25.     Cube_1m_H = 652
  26.     Cube_1m_I = 653
  27.     Cube_Unbeveled = 657
  28.     Cube_Wall = 728
  29.     Cube_Mostly_Transparent = 708
  30.     #Rings
  31.     Ring_Blocky=699
  32.     Ring_Jagged=701
  33.     Rings_Hollow_Yellow=460
  34.     Rings_Hollow_Wriggle=461
  35.     Rings_Hollow_Chopped=462
  36.     #Throbbers
  37.     Throbber_Hex = 702
  38.     Throbber_Ribbon = 721
  39.     Throbber_Ribbon2 = 722
  40.     Throbber_Ribbon3 = 724
  41.     Throbber_Cube = 723
  42.     #ScorePlates
  43.     ScorePlate_10 = 335
  44.     ScorePlate_20 = 336
  45.     ScorePlate_30 = 337
  46.     ScorePlate_50 = 338
  47.     ScorePlate_100 = 339
  48.     #Enemies
  49.     Enemy_Ding = 684
  50.     Enemy_Hyposphere = 685
  51.     Enemy_Bow_Roller = 686
  52.     Enemy_Phalanx = 692
  53.     Enemy_FanBlade = 694
  54.     Enemy_Flange = 695
  55.     Enemy_Smoothsquid = 696
  56.     Enemy_PlusSign = 697
  57.     Enemy_Bumblebee = 700
  58.     Enemy_PlusSign2 = 718
  59.     Enemy_Cylinder_Triad = 719
  60.     Enemy_Radial_Centipede2 = 720
  61.     Enemy_HexFlowy = 754
  62.     Enemy_bumblebee2 = 755
  63.     #Lights
  64.     Data_Ring=371
  65.     Data_Wall_1000m=384
  66.     Data_Red_Bars_128m=440
  67.     #Various
  68.     Multitentacle = 730
  69.     Sphere_1m = 659
  70.     Sphere_tendrils = 732
  71.     Tube = 756
  72.     Tube_Passable = 757
  73.     Dragon = 759
  74.     Prism_1m_Hexagonal = 705
  75.     S_Shape = 637
  76.     Dna_Element = 607
  77.     Tunnel2=452
  78.     Icosahedron=478
  79.     Monolith_Small=599
  80.     Flat_Bar_Yellow=643
  81.     Flat_Bar_Orange=644
  82.     Tentacle_A=751
  83.     X_Struts=735
  84.  
  85. class Entity(object):
  86.     '''An abstract entity defining its own coordinate space, movement or color overlay'''    
  87.     def __init__(self):
  88.         '''Constructor'''
  89.         #Appearance
  90.         self.Color = [255, 255, 255]
  91.         self.Transparency = 0.0
  92.         self.SpawnDistance = 0
  93.         #Defines own subspace
  94.         self.Position = [0.0, 0.0, 0.0]
  95.         self.Scale = [1.0, 1.0, 1.0]
  96.         self.Rotation = [0.0, 0.0, 0.0]
  97.         #Animation
  98.         self.Velocity = [0.0, 0.0, 0.0]
  99.         self.RotationVelocity = [0.0, 0.0, 0.0]
  100.         self.Origin = [0.0, 0.0, 0.0]
  101.        
  102.     def setSeconds(self, seconds):
  103.         self.Position[2] = (129.0 - seconds) * 1595.2
  104.            
  105. class Body(Entity):
  106.     '''An actual kick it geometry object that can be written into a level file. Used by other meta objects.'''
  107.     def __init__(self, type, time):
  108.         Entity.__init__(self)
  109.         self.setSeconds(time)
  110.         self.PieceType = type
  111.         self.Unkissable = 0
  112.         self.Shootable = 0
  113.         self.ThrobberType = 0
  114.         self.Behaviors = 0
  115.         self.AnimationSpeed = 0 #common, 6 for enemies
  116.         self.LightingData = 1028.051 #common, 1000002 for enemies
  117.         self.Alpha = 50 #common
  118.         self.Bright = 0 #common
  119.         self.KissType = 0 #common
  120.         self.WeaponType = 0 #common
  121.         self.SeekTargetType = 0 #common
  122.         self.WeaponPeriod = 0.0 #common
  123.         self.SeekTargetAcceleration = 0.0 #common
  124.                
  125.     def SerializeData(self):
  126.         data = [ 'OBJ', \
  127.                 self.Rotation[0], self.Rotation[1], self.Rotation[2], \
  128.                 self.Position[0], self.Position[1], self.Position[2], \
  129.                 0, self.PieceType, 0, 0, 0, 0, 0, 0, 0, self.Unkissable, \
  130.                 self.Scale[0], self.Scale[1], self.Scale[2], \
  131.                 self.Color[0], self.Color[1], self.Color[2], \
  132.                 self.RotationVelocity[0], self.RotationVelocity[1], self.RotationVelocity[2], \
  133.                 self.Velocity[0], self.Velocity[1], self.Velocity[2], \
  134.                 self.Origin[0], self.Origin[1], self.Origin[2], \
  135.                 self.Shootable, self.Transparency, self.Alpha, self.Bright, self.SpawnDistance, self.LightingData, \
  136.                 self.KissType, self.WeaponPeriod, self.SeekTargetAcceleration, self.Behaviors, self.ThrobberType, \
  137.                 self.WeaponType, self.SeekTargetType, self.AnimationSpeed]
  138.         data.extend([0]*43)
  139.         data.append('END')
  140.         return data        
  141.        
  142. class Level(object):
  143.     def __init__(self):
  144.         self.Entities = []
  145.         self.Skycube = 26
  146.         self.Ambient = 0
  147.         self.TimeLimit = 6;    
  148.         self.TimeLeft = 999999;
  149.         self.Gravity = 2;
  150.         self.FogStart = 5000;    
  151.         self.FogEnd = 9000;    
  152.         self.FogColor = [102, 183, 255];
  153.         #Legacy
  154.         self.ClipFar = 30000
  155.      
  156.     def SerializeString(self):
  157.         data = [self.TimeLimit, self.TimeLeft, 0, self.Gravity, \
  158.                 self.FogStart, self.FogEnd, self.FogColor[0], self.FogColor[1], self.FogColor[2], \
  159.                 0, 0, self.ClipFar, 0, 0, self.Skycube, self.Ambient, 0, 1001]
  160.         data.extend([0]*44)
  161.         self.Entities.sort(key=lambda entity: entity.Position[2], reverse=True)
  162.         for entity in self.Entities: data.extend(entity.SerializeData())
  163.         return ' \n'.join([str(d) for d in data])
  164.        
  165.     def storeLevel(self, filename):
  166.         os.chmod(filename, stat.S_IWRITE) #Remove this eventually
  167.         l = open(filename, 'w+')
  168.         l.write(self.SerializeString())
  169.         l.close()
  170.         os.chmod(filename, stat.S_IREAD) #ditto
  171.      
  172.     def Add(self, entity):
  173.         self.Entities.append(entity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement