/[hegemonie]/hegemonie/GameEngine/HgMobile.m
ViewVC logotype

Diff of /hegemonie/GameEngine/HgMobile.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by nicov, Wed Aug 20 13:26:26 2003 UTC revision 1.9 by dam, Fri Aug 22 07:57:32 2003 UTC
# Line 26  Line 26 
26  #include <Foundation/NSCoder.h>  #include <Foundation/NSCoder.h>
27  #include <Foundation/NSNotification.h>  #include <Foundation/NSNotification.h>
28    
29    #include "Ode.h"
30  #include "GameEngine/HgMobile.h"  #include "GameEngine/HgMobile.h"
31    
32  /**  /**
# Line 45  Line 46 
46  - (id) initWithGame: (HgGame *)game  - (id) initWithGame: (HgGame *)game
47               player: (HgPlayer *)player               player: (HgPlayer *)player
48             position: (coord_t)position             position: (coord_t)position
49             velocity: (coord_t)velocity       linearvelocity: (coord_t)linearVelocity
50      angularVelocity: (coord_t)angularVelocity      angularVelocity: (coord_t)angularVelocity
        acceleration: (float)acceleration  
           direction: (float)direction  
51  {  {
52    NSParameterAssert (game);    NSParameterAssert (game);
53      NSParameterAssert (player);
   /* FIXME - check velocity, ... */  
54    
55    [super initWithGame: game    [super initWithGame: game
56             withPlayer: player             withPlayer: player
57              position : position];              position : position];
58    if (self != nil)    if (self != nil)
59      {      {
60          _velocity = velocity;        [self setLinearVelocity: linearVelocity];
61          _angularVelocity = angularVelocity;        [self setAngularVelocity: angularVelocity];
         _acceleration = acceleration;  
         _direction = direction;  
62      }      }
63        
64    return self;    return self;
65  }  }
66    
67  /**  /**
68   * Return the mobile object velocity.   * Return the mobile object linear velocity (speed).
69   */   */
70  - (coord_t) velocity  - (coord_t) linearVelocity
71  {  {
72    return _velocity;    return CoordFromOde (dBodyGetLinearVel ([self dBody]));
73  }  }
74    
75  /**  /**
76   * Change the mobile object velocity.   * Change the mobile object linear velocity (speed).
77   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
78   * the current object.   * the current object.
79   */   */
80  - (void) setVelocity: (coord_t)velocity  - (void) setLinearVelocity: (coord_t)linearVelocity
81  {  {
82    _velocity = velocity;    dBodySetLinearVel ([self dBody],
83                         linearVelocity.x, linearVelocity.y, linearVelocity.z);
84    
85    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
86                                                        object: [self game]                                                        object: [self game]
# Line 92  Line 89 
89  }  }
90    
91  /**  /**
92   * Return the mobile object's direction.   * Return the mobile object angular velocity.
93   */   */
94  - (float) direction  - (coord_t) angularVelocity
 {  
   return _direction;  
 }  
   
 /**  
  * Change the mobile object direction.  
  * Post an notification named "updateObject" containing the current game and  
  * the current object.  
  */  
 - (void) setDirection: (float)direction  
95  {  {
96    _direction = direction;    return CoordFromOde (dBodyGetAngularVel ([self dBody]));
   
   [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"  
                                                       object: [self game]  
                 userInfo: [NSDictionary dictionaryWithObject: self  
                                                       forKey: @"HgObject"]];  
97  }  }
98    
99  /**  /**
100   * Change the mobile object acceleration.   * Change the mobile object angular velocity.
101   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
102   * the current object.   * the current object.
103   */   */
104  - (void) setAcceleration: (float)acceleration  - (void) setAngularVelocity: (coord_t)angularVelocity
105  {  {
106    _acceleration = acceleration;    dBodySetAngularVel ([self dBody],
107                          angularVelocity.x, angularVelocity.y, angularVelocity.z);
108    
109    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
110                                                        object: [self game]                                                        object: [self game]
# Line 130  Line 113 
113  }  }
114    
115  /**  /**
  * Return the mobile object angularVelocity.  
  */  
 - (coord_t) angularVelocity  
 {  
   return _angularVelocity;  
 }  
   
   
 - (void) updatePositon  
 {  
  /* FIXME - not implemented */  
 }  
   
 /**  
116   * Change the mobile object maxSpeed.   * Change the mobile object maxSpeed.
117   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
118   * the current object.   * the current object.
119   */   */
120  - (void) setMaxSpeed: (unsigned)maxSpeed  - (void) setMaxSpeed: (unsigned)maxSpeed
121  {  {
122      _maxSpeed = maxSpeed;    _maxSpeed = maxSpeed;
123    
124    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
125                                                        object: [self game]                                                        object: [self game]
# Line 182  Line 151 
151   */   */
152  - (void)encodeWithCoder: (NSCoder *)encoder  - (void)encodeWithCoder: (NSCoder *)encoder
153  {  {
154    [super encodeWithCoder: encoder];    NSParameterAssert (encoder);
155    [encoder encodeValueOfObjCType:@encode(coord_t) at:&_velocity];  
156    [encoder encodeValueOfObjCType:@encode(coord_t) at:&_angularVelocity];    [super encodeWithCoder: encoder];
157    [encoder encodeValueOfObjCType: "f" at: &_acceleration];    coord_t linearVelocity = [self linearVelocity];
158      [encoder encodeValueOfObjCType: @encode(coord_t) at: &linearVelocity];
159      coord_t  angularVelocity = [self angularVelocity];
160      [encoder encodeValueOfObjCType: @encode(coord_t) at: &angularVelocity];
161    [encoder encodeValueOfObjCType: "I" at: &_maxSpeed];    [encoder encodeValueOfObjCType: "I" at: &_maxSpeed];
   [encoder encodeValueOfObjCType: "I" at: &_maxAcceleration];  
   [encoder encodeValueOfObjCType: "f" at: &_acceleration];  
162  }  }
163    
164  - (id)initWithCoder: (NSCoder *)decoder  - (id)initWithCoder: (NSCoder *)decoder
165  {  {
166      NSParameterAssert (decoder);
167    
168    if ( (self = [super initWithCoder: decoder]) )    if ( (self = [super initWithCoder: decoder]) )
169      {      {
170        [decoder decodeValueOfObjCType:@encode(coord_t) at:&_velocity];        coord_t linearVelocity, angularVelocity;
171        [decoder decodeValueOfObjCType:@encode(coord_t) at:&_angularVelocity];        [decoder decodeValueOfObjCType: @encode(coord_t) at: &linearVelocity];
172        [decoder decodeValueOfObjCType: "f" at: &_acceleration];        [self setLinearVelocity: linearVelocity];
173          [decoder decodeValueOfObjCType: @encode(coord_t) at: &angularVelocity];
174          [self setAngularVelocity: angularVelocity];
175        [decoder decodeValueOfObjCType: "I" at: &_maxSpeed];        [decoder decodeValueOfObjCType: "I" at: &_maxSpeed];
       [decoder decodeValueOfObjCType: "I" at: &_maxAcceleration];  
       [decoder decodeValueOfObjCType: "f" at: &_acceleration];  
176      }      }
177        
178    return self;    return self;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26