Guest User

Untitled

a guest
May 17th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @synthesize spawnRate = _spawnRate;
  2. @synthesize levelNum = _levelNum;
  3. @synthesize enemyHP = _enemyHP;
  4. @synthesize bgImageName = _bgImageName;
  5.  
  6. - (id)initWithLevelNum:(int)levelNum
  7.             spawnRate:(float)spawnRate
  8.             enemyHP:(int)enemyHP
  9.             bgImageName:(NSString *)bgImageName {
  10.  
  11.     if ((self = [super init])) {
  12.         self.levelNum = levelNum;
  13.         self.spawnRate = spawnRate;
  14.         self.enemyHP = enemyHP;
  15.         self.bgImageName = bgImageName;
  16.     }
  17.    
  18.     return self;
  19.    
  20. }
  21. ============
  22.  
  23.  
  24. #import "SpaceManagerCocos2d.h"
  25. #import "ParticleFactory.h"
  26.  
  27. @class GameLayer;
  28.  
  29. @interface Truck : cpCCSprite {
  30.    
  31.     GameLayer* _game;
  32.     CCTexture2D* textureWheel;
  33.     CCTexture2D* textureChassis;
  34.     CCParticleSystemQuad* tFront;
  35.     CCParticleSystemQuad* tMid;
  36.     CCParticleSystemQuad* tRear;
  37.     cpCCSprite* thrustSprite;
  38.     cpConstraint* motor1;
  39.     cpConstraint* motor2;
  40.     float motorRateMultiplier;
  41.     int thrustFactorX;
  42.     int thrustFactorY;
  43.     cpVect velocity;
  44.    
  45. }
  46.  
  47. @property(assign) cpCCNode* chassis;
  48. @property(assign) cpShape* bodyShape;
  49.  
  50. -(id) initWithGame:(GameLayer*)game;
  51. -(void) moveTruck:(float)joyPadXVel;
  52. -(void) attemptBoost:(float)joyPadXVel : (float)joyPadYVel;
  53. -(void) showThrustGraphic;
  54. -(void) hideThrustGraphic;
  55.  
  56.  
  57.  
  58. @end
  59.  
  60. //.m
  61.  
  62.  
  63. #import "Truck.h"
  64. #import "GameLayer.h"
  65.  
  66. @interface Truck (Private)
  67.  
  68. -(void) buildTruckWithGame:(GameLayer*)game;
  69.  
  70. @end
  71.  
  72. @implementation Truck
  73. @synthesize chassis;
  74. @synthesize bodyShape;
  75.  
  76. -(id) initWithGame:(GameLayer*)game
  77. {
  78.     self = [super init];
  79.    
  80.     if (self != nil)
  81.     {
  82.    
  83.         _game = game;
  84.        
  85.         textureWheel = [[[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"nWheel.png"]]autorelease];
  86.         textureChassis = [[[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"chassis.png"]]autorelease];
  87.        
  88.         [self buildTruckWithGame:game];
  89.        
  90.         thrustFactorX=3000;
  91.         thrustFactorY=4000;
  92.        
  93.     }
  94.    
  95.     return self;
  96. }
  97.  
  98. -(void) buildTruckWithGame:(GameLayer*)game
  99. {
  100.    
  101.     motorRateMultiplier = -10;
  102.    
  103.     float springStiffness = 2000.0;
  104.     float springDamping = 25.0;
  105.     float springRestLength = 35.0;
  106.    
  107.     float wheelFriction = 1.2;
  108.     float wheelMass = 10;
  109.     float wheelRad = 25;
  110.  
  111. #pragma mark CHASSIS
  112.    
  113.     bodyShape = [game.spaceManager addRectAt:cpv(100, 200) mass:50 width:100.0 height:50.0 rotation:0.0];
  114.    
  115.     chassis = [cpCCSprite spriteWithTexture:textureChassis];
  116.     chassis.shape = bodyShape;
  117.     chassis.spaceManager = game.spaceManager;
  118.     chassis.autoFreeShapeAndBody = YES;
  119.     [self addChild:chassis];
Add Comment
Please, Sign In to add comment