33 |
#include <Foundation/NSBundle.h> |
#include <Foundation/NSBundle.h> |
34 |
#include <AppKit/NSEvent.h> |
#include <AppKit/NSEvent.h> |
35 |
|
|
36 |
|
#include "Common/Coord.h" |
37 |
#include "Common/Camera.h" |
#include "Common/Camera.h" |
38 |
|
|
39 |
#include "Model/MdlGameEngineDisplay.h" |
#include "Model/MdlGameEngineDisplay.h" |
42 |
#include "Map/Sea/SeaDisplay.h" |
#include "Map/Sea/SeaDisplay.h" |
43 |
|
|
44 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
45 |
|
#include "GameEngine/HgPlayer.h" |
46 |
#include "GameEngine/HgPlayerState.h" |
#include "GameEngine/HgPlayerState.h" |
47 |
#include "GameEngine/HgShip.h" |
#include "GameEngine/HgShip.h" |
48 |
|
|
128 |
|
|
129 |
- (BOOL) keyDown: (NSEvent *)event |
- (BOOL) keyDown: (NSEvent *)event |
130 |
{ |
{ |
131 |
|
HgPlayerState *playerState = [_view playerState]; |
132 |
Camera *camera = [_view camera]; |
Camera *camera = [_view camera]; |
133 |
|
|
134 |
NSParameterAssert (event); |
NSParameterAssert (event); |
136 |
switch ([event keyCode]) |
switch ([event keyCode]) |
137 |
{ |
{ |
138 |
case SDLK_UP: |
case SDLK_UP: |
139 |
[camera forward: 3.0f]; |
[playerState setAcceleration: [playerState acceleration] + 3.0f]; |
140 |
return YES; |
break; |
141 |
case SDLK_DOWN: |
case SDLK_DOWN: |
142 |
[camera backward: 3.0f]; |
[playerState setAcceleration: [playerState acceleration] - 3.0f]; |
143 |
return YES; |
break; |
144 |
case SDLK_RIGHT: |
case SDLK_RIGHT: |
145 |
[camera strafRight: 3.0f]; |
[playerState setDirection: [playerState direction] + 3.0f]; |
146 |
return YES; |
break; |
147 |
case SDLK_LEFT: |
case SDLK_LEFT: |
148 |
[camera strafLeft: 3.0f]; |
[playerState setDirection: [playerState direction] - 3.0f]; |
149 |
return YES; |
break; |
150 |
case SDLK_PAGEUP: |
case SDLK_PAGEUP: |
151 |
[camera moveUp: 3.0f]; |
[camera moveUp: 3.0f]; |
152 |
return YES; |
break; |
153 |
case SDLK_PAGEDOWN: |
case SDLK_PAGEDOWN: |
154 |
[camera moveDown: 3.0f]; |
[camera moveDown: 3.0f]; |
155 |
return YES; |
break; |
156 |
|
default: |
157 |
|
return NO; |
158 |
} |
} |
159 |
|
|
160 |
return NO; |
[[_view client] updatePlayerState: playerState]; |
161 |
|
return YES; |
162 |
} |
} |
163 |
|
|
164 |
@end |
@end |
208 |
aspect: 1024.0f / 768.0f |
aspect: 1024.0f / 768.0f |
209 |
zNear: 0.01 |
zNear: 0.01 |
210 |
zFar: 750.0 |
zFar: 750.0 |
211 |
eye: MakeCoord (0.0, 197.0, 0.0) |
eye: MakeCoord (0.0f, 0.0f, 0.0f) |
212 |
center: MakeCoord (0.0, 197.0, 30.0) |
center: MakeCoord (0.0f, 0.0f, 100.0f) |
213 |
up: MakeCoord (0.0, 1.0, 0.0)]; |
up: MakeCoord (0.0f, 1.0f, 0.0f)]; |
214 |
|
|
215 |
/* search game */ |
/* search game */ |
216 |
NetGameList *gameList = [[NetGameList alloc] init]; |
NetGameList *gameList = [[NetGameList alloc] init]; |
226 |
_client = [NetGameList connectToGame: game |
_client = [NetGameList connectToGame: game |
227 |
withName: @"player1" |
withName: @"player1" |
228 |
shipClass: @"MyShip"]; |
shipClass: @"MyShip"]; |
|
|
|
229 |
NSAssert (_client, |
NSAssert (_client, |
230 |
@"Client not connect to the game"); |
@"Client not connect to the game"); |
231 |
|
|
232 |
|
/* Map */ |
233 |
MapDisplay *map = [[_client game] map]; |
MapDisplay *map = [[_client game] map]; |
234 |
NSAssert (map, @"Internal inconsitency"); |
NSAssert (map, @"Internal inconsitency"); |
235 |
[map precalculateNormals]; |
[map precalculateNormals]; |
236 |
|
|
237 |
|
/* Player State */ |
238 |
|
HgPlayer *player = [_client player]; |
239 |
|
NSAssert (player, @"Internal inconsitency"); |
240 |
|
_playerState = [[HgPlayerState alloc] initWithPlayer: player]; |
241 |
|
|
242 |
/* sky */ |
/* sky */ |
243 |
_sky = [[SkyDisplay alloc] init]; |
_sky = [[SkyDisplay alloc] init]; |
244 |
|
|
259 |
|
|
260 |
HgGame *game = [_client game]; |
HgGame *game = [_client game]; |
261 |
MapDisplay *map = [game map]; |
MapDisplay *map = [game map]; |
262 |
|
HgShip *ship = [[_client player] ship]; |
263 |
|
|
264 |
|
NSAssert (game && map && ship, @"Internal inconsitency"); |
265 |
|
|
266 |
NSAssert (game && map, @"Internal inconsitency"); |
[_camera move: SubCoord([ship position], [_camera center])]; |
267 |
|
|
268 |
glMatrixMode (GL_PROJECTION); |
glMatrixMode (GL_PROJECTION); |
269 |
glPushMatrix (); |
glPushMatrix (); |
303 |
|
|
304 |
- (void) endGame |
- (void) endGame |
305 |
{ |
{ |
306 |
|
[_client disconnect]; |
307 |
|
|
308 |
RELEASE (_sky); |
RELEASE (_sky); |
309 |
RELEASE (_sea); |
RELEASE (_sea); |
310 |
RELEASE (_camera); |
RELEASE (_camera); |
311 |
|
RELEASE (_playerState); |
312 |
RELEASE (_client); |
RELEASE (_client); |
313 |
} |
} |
314 |
|
|
315 |
|
- (NetClient *) client |
316 |
|
{ |
317 |
|
return _client; |
318 |
|
} |
319 |
|
|
320 |
|
- (HgPlayerState *) playerState |
321 |
|
{ |
322 |
|
return _playerState; |
323 |
|
} |
324 |
|
|
325 |
- (Camera *) camera |
- (Camera *) camera |
326 |
{ |
{ |
327 |
return _camera; |
return _camera; |