Full-Screen Exclusive Mode (FSEM)


Controlling the Sprite

The sprite's movements are controlled by key presses, caught by a KeyBehavior object. KeyBehavior is a version of the TouristControls class of Chapter 18 but without the key processing parts. What remains is the testing of the key press to decide which method of the Animator class to call. standardMove( ) shows how a key press (actually its key code) is converted into different calls to the Animator object (called animBeh):

     private void standardMove(int keycode)     { if(keycode == forwardKey )         animBeh.moveForward( );       else if ...  // more if-tests of keycode         ...       else if(keycode == activeKey)         animBeh.toggleActive( );       else if(keycode == punchKey)         animBeh.punch( );       else if(keycode == inKey)         animBeh.shiftInViewer( );       else if(keycode == outKey)         animBeh.shiftOutViewer( );     }

The activeKey key code, the letter a, is used for toggling the sprite's activity. When the sprite is active, it's visible in the scene and can be affected by key presses. When it's inactive, the sprite is invisible and nothing affects it (apart from the a key).

The punchKey key code (the letter p) sets the sprite into punching pose, as illustrated by the righthand image in Figure 19-1.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net