home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / MacWT 0.04 / wt / linux-console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  3.4 KB  |  126 lines  |  [TEXT/MMCC]

  1. /*
  2. **  wt -- a 3d game engine
  3. **
  4. **  Copyright (C) 1994 by Chris Laurel
  5. **  email:  claurel@mr.net
  6. **  snail mail:  Chris Laurel, 5700 W Lake St #208,  St. Louis Park, MN  55416
  7. **
  8. **  This program is free software; you can redistribute it and/or modify
  9. **  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or
  11. **  (at your option) any later version.
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. **  GNU General Public License for more details.
  17. **
  18. **  You should have received a copy of the GNU General Public License
  19. **  along with this program; if not, write to the Free Software
  20. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. #include <vgakeyboard.h>
  24. #include "wt.h"
  25. #include "error.h"
  26. #include "input.h"
  27.  
  28.  
  29. static void add_special(Intent *intent, int special);
  30.  
  31. static Boolean rotating_cw = False;
  32. static Boolean rotating_ccw = False;
  33. static Boolean moving_forward = False;
  34. static Boolean moving_backward = False;
  35. static Boolean running = False;
  36. static Boolean strafing = False;
  37.  
  38.  
  39. void init_input_devices(void)
  40. {
  41.      if (keyboard_init())
  42.       fatal_error("Unable to open console");
  43. }
  44.  
  45.  
  46. void end_input_devices(void)
  47. {
  48.      keyboard_close();
  49. }
  50.  
  51.  
  52. Intent *read_input_devices(void)
  53. {
  54.      static Intent intent;
  55.  
  56.  
  57.      intent.force_x = intent.force_y = intent.force_z = 0.0;
  58.      intent.force_rotate = 0.0;
  59.      intent.n_special = 0;
  60.  
  61.      keyboard_update();
  62.      if (keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
  63.       rotating_ccw = True;
  64.      if (keyboard_keypressed(SCANCODE_CURSORBLOCKRIGHT))
  65.       rotating_cw = True;
  66.      if (keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
  67.       moving_forward = True;
  68.      if (keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
  69.       moving_backward= True;
  70.      if (keyboard_keypressed(42) || keyboard_keypressed(54))
  71.       running= True;
  72.      if (keyboard_keypressed(57))
  73.       add_special(&intent, INTENT_JUMP);
  74.      if (keyboard_keypressed(56) || keyboard_keypressed(100))
  75.       strafing= True;
  76.  
  77.      if (!keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
  78.       rotating_ccw = False;
  79.      if (!keyboard_keypressed( SCANCODE_CURSORBLOCKRIGHT))
  80.       rotating_cw = False;
  81.      if (!keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
  82.       moving_forward = False;
  83.      if (!keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
  84.       moving_backward= False;
  85.      if (!keyboard_keypressed(42) && !keyboard_keypressed(54))
  86.       running= False;
  87.      if (!keyboard_keypressed(56) && !keyboard_keypressed(100))
  88.       strafing= False;
  89.      if (keyboard_keypressed(SCANCODE_Q))
  90.       add_special(&intent, INTENT_END_GAME);
  91.  
  92.      if (rotating_cw) {
  93.       if (strafing)
  94.            intent.force_y -= 0.5;
  95.       else
  96.            intent.force_rotate -= 0.5;
  97.      }
  98.      if (rotating_ccw) {
  99.       if (strafing) {
  100.            intent.force_y += 0.5;
  101.       } else
  102.            intent.force_rotate += 0.5;
  103.      }
  104.      if (moving_forward)
  105.       intent.force_x += 0.5;
  106.      if (moving_backward)
  107.       intent.force_x -= 0.5;
  108.      if (running) {
  109.       intent.force_x *= 2.0;
  110.       intent.force_y *= 2.0;
  111.       intent.force_z *= 2.0;
  112.       intent.force_rotate *= 2.0;
  113.      }
  114.  
  115.      return &intent;
  116. }
  117.  
  118.  
  119. void add_special(Intent *intent, int special)
  120. {
  121.      if (intent->n_special < MAX_SPECIAL_INTENTIONS) {
  122.       intent->special[intent->n_special] = special;
  123.       intent->n_special++;
  124.      }
  125. }
  126.