Guest User

Untitled

a guest
May 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  Gameplay.m
  3. //  OrcInvasion
  4. //
  5. //  Created by Jan on 11/8/11.
  6. //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "Gameplay.h"
  10.  
  11. #import "OIheaders.h"
  12.  
  13. @implementation Gameplay
  14.  
  15. - (id) initWithGame:(Game *)theGame {
  16.     self = [super initWithGame:theGame];
  17.    
  18.     if (self != nil) {  
  19.         level = [[Level alloc] initWithGame:self.game gameplay:self];
  20.         physics = [[Physics alloc] initWithGame:self.game level:level];
  21.         player = [[Player alloc] initWithGame:self.game arrow:level.arrow];
  22.         hud = [[GameHud alloc] initWithGame:self.game];
  23.         hudRenderer = [[GUIRenderer alloc] initWithGame:self.game scene:hud.scene];
  24.         renderer = [[Renderer alloc] initWithGame:self.game gameplay:self];
  25.    
  26.         //demoplayer = [[DemoPlayer alloc] initWithGame:self.game level:level];
  27.    
  28.         hudRenderer.drawOrder = 1;    
  29.         player.updateOrder = 0;
  30.         //demoplayer.updateOrder = 0;
  31.         physics.updateOrder = 1;
  32.         level.updateOrder = 2;
  33.         hud.updateOrder = 3;
  34.         self.updateOrder = 4;
  35.     }
  36.     return self;
  37. }
  38.  
  39. - (void) activate {
  40.     [self.game.components addComponent:level];
  41.     [self.game.components addComponent:renderer];
  42.     [self.game.components addComponent:hud];
  43.     [self.game.components addComponent:hudRenderer];
  44.     [self.game.components addComponent:physics];
  45.     [self.game.components addComponent:player];
  46.     //[self.game.components addComponent:demoplayer];  
  47. }
  48.  
  49. - (void) deactivate {
  50.     [self.game.components removeComponent:level];
  51.     [self.game.components removeComponent:renderer];
  52.     [self.game.components removeComponent:hud];
  53.     [self.game.components removeComponent:hudRenderer];
  54.     [self.game.components removeComponent:physics];
  55.     [self.game.components removeComponent:player];
  56.     //[self.game.components removeComponent:demoplayer];
  57. }
  58.  
  59. @synthesize lives, level, score, hud;
  60.  
  61. - (void) initialize {    
  62.     [self reset];
  63.     [super initialize];
  64. }
  65.  
  66. - (void) updateWithGameTime:(GameTime *)gameTime {
  67.    
  68.     if (lives < 0) {
  69.         //TODO lose screen
  70.        [orcInvasion popState];
  71.     }
  72.  
  73.     if (score == 3) {
  74.         //TODO win screen
  75.         [orcInvasion popState];
  76.     }
  77.      
  78.     if (level.arrow.hit) {
  79.         [level.arrow resetWithGame:self.game];
  80.     }  
  81.    
  82.     if (level.arrow.position.x > self.game.window.clientBounds.width || level.arrow.position.x < 0 || level.arrow.position.y < 0) {
  83.         [level.arrow resetWithGame:self.game];
  84.     }
  85. }
  86.  
  87. - (void) reset {
  88.     lives = 3;
  89.     score = 0;
  90.     [level reset];
  91.     [hud reset];
  92. }
  93.  
  94. - (void) dealloc {    
  95.     [level release];
  96.     [hudRenderer release];
  97.     [hud release];
  98.     [renderer release];
  99.     [physics release];
  100.     [player release];  
  101.     //[demoplayer release];
  102.    
  103.     [super dealloc];
  104. }
  105.  
  106. @end
Add Comment
Please, Sign In to add comment