Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.45 KB | None | 0 0
  1. //********************************************************************//
  2. //* F. PERMADI MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE      *//
  3. //* SUITABILITY OF                                                   *//
  4. //* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT       *//
  5. //* LIMITED                                                          *//
  6. //* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A      *//
  7. //* PARTICULAR PURPOSE                                               *//
  8. //********************************************************************//
  9. import java.awt.*;
  10. import java.applet.*;
  11.  
  12. //*******************************************************************//
  13. //* main class
  14. //*******************************************************************//
  15. public class Rayc extends Applet implements Runnable
  16. {
  17.   // this is Java's stuff
  18.   Thread fThread;
  19.  
  20.   // size of tile (wall height)
  21.   static final int TILE_SIZE = 64;
  22.   static final int WALL_HEIGHT = 64;
  23.   static final int PROJECTIONPLANEWIDTH = 320;
  24.   static final int PROJECTIONPLANEHEIGHT = 200;
  25.   static final int ANGLE60 = PROJECTIONPLANEWIDTH;
  26.   static final int ANGLE30 = (ANGLE60/2);
  27.   static final int ANGLE15 = (ANGLE30/2);
  28.   static final int ANGLE90 = (ANGLE30*3);
  29.   static final int ANGLE180 = (ANGLE90*2);
  30.   static final int ANGLE270 = (ANGLE90*3);
  31.   static final int ANGLE360 = (ANGLE60*6);
  32.   static final int ANGLE0 = 0;
  33.   static final int ANGLE5 = (ANGLE30/6);
  34.   static final int ANGLE10 = (ANGLE5*2);
  35.  
  36.   // trigonometric tables
  37.   float fSinTable[];
  38.   float fISinTable[];
  39.   float fCosTable[];
  40.   float fICosTable[];
  41.   float fTanTable[];
  42.   float fITanTable[];
  43.   float fFishTable[];
  44.   float fXStepTable[];
  45.   float fYStepTable[];
  46.  
  47.   // offscreen buffer
  48.   Image fOffscreenImage;
  49.   Graphics fOffscreenGraphics;
  50.  
  51.   // player's attributes
  52.   int fPlayerX = 100;
  53.   int fPlayerY = 160;
  54.   int fPlayerArc = ANGLE0;
  55.   int fPlayerDistanceToTheProjectionPlane = 277;
  56.   int fPlayerHeight =32;
  57.   int fPlayerSpeed = 16;
  58.   int fProjectionPlaneYCenter = PROJECTIONPLANEHEIGHT/2;
  59.   // the following variables are used to keep the player coordinate in the overhead map
  60.   int fPlayerMapX, fPlayerMapY, fMinimapWidth;
  61.  
  62.   // movement flag
  63.   boolean fKeyUp=false;
  64.   boolean fKeyDown=false;
  65.   boolean fKeyLeft=false;
  66.   boolean fKeyRight=false;
  67.  
  68.   // 2 dimensional map
  69.   byte fMap[];
  70.   static final byte W=1;                                // wall
  71.   static final byte O=0;                                // opening
  72.   static final int MAP_WIDTH=12;
  73.   static final int MAP_HEIGHT=12;
  74.  
  75.   //*******************************************************************//
  76.   //* Convert arc to radian
  77.   //*******************************************************************//
  78.   float arcToRad(float arcAngle)
  79.   {
  80.      return ((float)(arcAngle*Math.PI)/(float)ANGLE180);    
  81.   }
  82.  
  83.   //*******************************************************************//
  84.   //* Create tigonometric values to make the program runs faster.
  85.   //*******************************************************************//
  86.   public void createTables()
  87.   {
  88.     int i;
  89.     float radian;
  90.     fSinTable = new float[ANGLE360+1];
  91.     fISinTable = new float[ANGLE360+1];
  92.     fCosTable = new float[ANGLE360+1];
  93.     fICosTable = new float[ANGLE360+1];
  94.     fTanTable = new float[ANGLE360+1];
  95.     fITanTable = new float[ANGLE360+1];
  96.     fFishTable = new float[ANGLE60+1];
  97.     fXStepTable = new float[ANGLE360+1];
  98.     fYStepTable = new float[ANGLE360+1];
  99.  
  100.     for (i=0; i<=ANGLE360;i++)
  101.     {
  102.       // get the radian value (the last addition is to avoid division by 0, try removing
  103.           // that and you'll see a hole in the wall when a ray is at 0, 90, 180, or 270 degree)
  104.       radian = arcToRad(i) + (float)(0.0001);
  105.       fSinTable[i]=(float)Math.sin(radian);
  106.       fISinTable[i]=(1.0F/(fSinTable[i]));
  107.       fCosTable[i]=(float)Math.cos(radian);
  108.       fICosTable[i]=(1.0F/(fCosTable[i]));
  109.       fTanTable[i]=(float)Math.tan(radian);
  110.       fITanTable[i]=(1.0F/fTanTable[i]);
  111.  
  112.         //  you can see that the distance between xi is the same
  113.         //  if we know the angle
  114.         //  _____|_/next xi______________
  115.         //       |
  116.         //  ____/|next xi_________   slope = tan = height / dist between xi's
  117.         //     / |
  118.         //  __/__|_________  dist between xi = height/tan where height=tile size
  119.         // old xi|
  120.         //                  distance between xi = x_step[view_angle];
  121.         //
  122.         //
  123.         // facine left
  124.       // facing left
  125.       if (i>=ANGLE90 && i<ANGLE270)
  126.       {
  127.         fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]);
  128.         if (fXStepTable[i]>0)
  129.           fXStepTable[i]=-fXStepTable[i];
  130.       }
  131.       // facing right
  132.       else
  133.       {
  134.         fXStepTable[i] = (float)(TILE_SIZE/fTanTable[i]);
  135.         if (fXStepTable[i]<0)
  136.           fXStepTable[i]=-fXStepTable[i];
  137.       }
  138.  
  139.       // FACING DOWN
  140.       if (i>=ANGLE0 && i<ANGLE180)
  141.       {
  142.         fYStepTable[i] = (float)(TILE_SIZE*fTanTable[i]);
  143.         if (fYStepTable[i]<0)
  144.           fYStepTable[i]=-fYStepTable[i];
  145.       }
  146.       // FACING UP
  147.       else
  148.       {
  149.         fYStepTable[i] = (float)(TILE_SIZE*fTanTable[i]);
  150.         if (fYStepTable[i]>0)
  151.           fYStepTable[i]=-fYStepTable[i];
  152.       }
  153.     }
  154.  
  155.     for (i=-ANGLE30; i<=ANGLE30; i++)
  156.     {
  157.         radian = arcToRad(i);
  158.         // we don't have negative angle, so make it start at 0
  159.         // this will give range 0 to 320
  160.         fFishTable[i+ANGLE30] = (float)(1.0F/Math.cos(radian));
  161.     }
  162.  
  163.         // CERATE A SIMPLE MAP
  164.         byte[] map=
  165.         {
  166.                 W,W,W,W,W,W,W,W,W,W,W,W,
  167.                 W,O,O,O,O,O,O,O,O,O,O,W,
  168.                 W,O,O,O,O,O,O,O,O,O,O,W,
  169.                 W,O,O,O,O,O,O,O,W,O,O,W,
  170.                 W,O,O,W,O,W,O,O,W,O,O,W,
  171.                 W,O,O,W,O,W,W,O,W,O,O,W,
  172.                 W,O,O,W,O,O,W,O,W,O,O,W,
  173.                 W,O,O,O,W,O,W,O,W,O,O,W,
  174.                 W,O,O,O,W,O,W,O,W,O,O,W,
  175.                 W,O,O,O,W,W,W,O,W,O,O,W,
  176.                 W,O,O,O,O,O,O,O,O,O,O,W,
  177.                 W,W,W,W,W,W,W,W,W,W,W,W
  178.         };
  179.         fMap=map;
  180.   }
  181.  
  182.   //*******************************************************************//
  183.   //* Called when program starts
  184.   //*******************************************************************//
  185.   public void start()
  186.   {
  187.     createTables();
  188.     fThread=new Thread(this);
  189.     fThread.start();
  190.   }
  191.  
  192.   //*******************************************************************//
  193.   //* Running thread
  194.   //*******************************************************************//
  195.   public void run()
  196.   {
  197.         requestFocus();
  198.         // create offscreen buffer
  199.     fOffscreenImage=createImage(size().width, size().height);
  200.     fOffscreenGraphics=fOffscreenImage.getGraphics();
  201.  
  202.     while(true)
  203.     {
  204.           // rotate left
  205.       if (fKeyLeft)
  206.       {
  207.         if ((fPlayerArc-=ANGLE10)<ANGLE0)
  208.           fPlayerArc+=ANGLE360;
  209.       }
  210.           // rotate right
  211.       else if (fKeyRight)
  212.       {
  213.         if ((fPlayerArc+=ANGLE10)>=ANGLE360)
  214.           fPlayerArc-=ANGLE360;
  215.       }
  216.  
  217.           //  _____     _
  218.           // |\ arc     |
  219.           // |  \       y
  220.           // |    \     |
  221.       //            -
  222.           // |--x--|  
  223.           //
  224.           //  sin(arc)=y/diagonal
  225.           //  cos(arc)=x/diagonal   where diagonal=speed
  226.       float playerXDir=fCosTable[fPlayerArc];
  227.       float playerYDir=fSinTable[fPlayerArc];
  228.  
  229.           // move forward
  230.       if (fKeyUp)
  231.       {
  232.         fPlayerX+=(int)(playerXDir*fPlayerSpeed);
  233.         fPlayerY+=(int)(playerYDir*fPlayerSpeed);
  234.       }
  235.           // move backward
  236.       else if (fKeyDown)
  237.       {
  238.         fPlayerX-=(int)(playerXDir*fPlayerSpeed);
  239.         fPlayerY-=(int)(playerYDir*fPlayerSpeed);
  240.       }
  241.  
  242.       render();
  243.       try
  244.       {
  245.         Thread.sleep(50);
  246.       }
  247.       catch (Exception sleepProblem)
  248.       {
  249.         showStatus("Sleep problem");
  250.       }
  251.     }
  252.   }
  253.  
  254.   //*******************************************************************//
  255.   //* Draw background image
  256.   //*******************************************************************//
  257.   public void drawBackground()
  258.   {
  259.     // sky
  260.         int c=25;
  261.         int r;
  262.         for (r=0; r<PROJECTIONPLANEHEIGHT/2; r+=10)
  263.         {
  264.                 fOffscreenGraphics.setColor(new Color(c, 125, 225));
  265.                 fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 10);
  266.                 c+=20;
  267.         }
  268.         // ground
  269.         c=22;
  270.         for (; r<PROJECTIONPLANEHEIGHT; r+=15)
  271.         {
  272.                 fOffscreenGraphics.setColor(new Color(c, 20, 20));
  273.                 fOffscreenGraphics.fillRect(0, r, PROJECTIONPLANEWIDTH, 15);
  274.                 c+=15;
  275.         }
  276.   }
  277.  
  278.   //*******************************************************************//
  279.   //* Draw map on the right side
  280.   //*******************************************************************//
  281.   public void drawOverheadMap()
  282.   {
  283.         fMinimapWidth=5;
  284.     for (int u=0; u<MAP_WIDTH; u++)
  285.     {
  286.       for (int v=0; v<MAP_HEIGHT; v++)
  287.       {
  288.         if (fMap[v*MAP_WIDTH+u]==W)
  289.         {
  290.                   fOffscreenGraphics.setColor(Color.cyan);
  291.         }
  292.                 else
  293.         {
  294.                   fOffscreenGraphics.setColor(Color.black);
  295.         }
  296.             fOffscreenGraphics.fillRect(PROJECTIONPLANEWIDTH+(u*fMinimapWidth),
  297.                         (v*fMinimapWidth), fMinimapWidth, fMinimapWidth);
  298.       }
  299.     }
  300.         fPlayerMapX=PROJECTIONPLANEWIDTH+(int)(((float)fPlayerX/(float)TILE_SIZE) * fMinimapWidth);
  301.         fPlayerMapY=(int)(((float)fPlayerY/(float)TILE_SIZE) * fMinimapWidth);
  302.   }
  303.  
  304.   //*******************************************************************//
  305.   //* Draw ray on the overhead map (for illustartion purpose)
  306.   //* This is not part of the ray-casting process
  307.   //*******************************************************************//
  308.   public void drawRayOnOverheadMap(float x, float y)
  309.   {
  310.         fOffscreenGraphics.setColor(Color.yellow);
  311.         // draw line from the player position to the position where the ray
  312.         // intersect with wall
  313.         fOffscreenGraphics.drawLine(fPlayerMapX, fPlayerMapY,
  314.                 (int)(PROJECTIONPLANEWIDTH+((float)(x*fMinimapWidth)/(float)TILE_SIZE)),
  315.                 (int)(((float)(y*fMinimapWidth)/(float)TILE_SIZE)));
  316.         // draw a red line indication the player's direction
  317.         fOffscreenGraphics.setColor(Color.red);
  318.     fOffscreenGraphics.drawLine(fPlayerMapX, fPlayerMapY,
  319.       (int)(fPlayerMapX+fCosTable[fPlayerArc]*10),
  320.           (int)(fPlayerMapY+fSinTable[fPlayerArc]*10));
  321.   }
  322.  
  323.   //*******************************************************************//
  324.   //* Renderer
  325.   //*******************************************************************//
  326.   public void render()
  327.   {
  328.         drawBackground();
  329.         drawOverheadMap();
  330.  
  331.     int verticalGrid;        // horizotal or vertical coordinate of intersection
  332.     int horizontalGrid;      // theoritically, this will be multiple of TILE_SIZE
  333.                              // , but some trick did here might cause
  334.                              // the values off by 1
  335.     int distToNextVerticalGrid; // how far to the next bound (this is multiple of
  336.     int distToNextHorizontalGrid; // tile size)
  337.     float xIntersection;  // x and y intersections
  338.     float yIntersection;
  339.     float distToNextXIntersection;
  340.     float distToNextYIntersection;
  341.  
  342.     int xGridIndex;        // the current cell that the ray is in
  343.     int yGridIndex;
  344.  
  345.     float distToVerticalGridBeingHit;      // the distance of the x and y ray intersections from
  346.     float distToHorizontalGridBeingHit;      // the viewpoint
  347.  
  348.     int castArc, castColumn;
  349.  
  350.     castArc = fPlayerArc;
  351.         // field of view is 60 degree with the point of view (player's direction in the middle)
  352.         // 30  30
  353.         //    ^
  354.         //  \ | /
  355.         //   \|/
  356.         //    v
  357.         // we will trace the rays starting from the leftmost ray
  358.         castArc-=ANGLE30;
  359.         // wrap around if necessary
  360.     if (castArc < 0)
  361.     {
  362.       castArc=ANGLE360 + castArc;
  363.     }
  364.  
  365.     for (castColumn=0; castColumn<PROJECTIONPLANEWIDTH; castColumn+=5)
  366.     {
  367.           // ray is between 0 to 180 degree (1st and 2nd quadrant)
  368.           // ray is facing down
  369.       if (castArc > ANGLE0 && castArc < ANGLE180)
  370.       {
  371.                 // truncuate then add to get the coordinate of the FIRST grid (horizontal
  372.                 // wall) that is in front of the player (this is in pixel unit)
  373.                 // ROUND DOWN
  374.         horizontalGrid = (fPlayerY/TILE_SIZE)*TILE_SIZE  + TILE_SIZE;
  375.  
  376.         // compute distance to the next horizontal wall
  377.         distToNextHorizontalGrid = TILE_SIZE;
  378.  
  379.         float xtemp = fITanTable[castArc]*(horizontalGrid-fPlayerY);
  380.                 // we can get the vertical distance to that wall by
  381.                 // (horizontalGrid-GLplayerY)
  382.                 // we can get the horizontal distance to that wall by
  383.                 // 1/tan(arc)*verticalDistance
  384.                 // find the x interception to that wall
  385.         xIntersection = xtemp + fPlayerX;
  386.       }
  387.       // else, the ray is facing up
  388.       else
  389.       {
  390.         horizontalGrid = (fPlayerY/TILE_SIZE)*TILE_SIZE;
  391.         distToNextHorizontalGrid = -TILE_SIZE;
  392.  
  393.         float xtemp = fITanTable[castArc]*(horizontalGrid - fPlayerY);
  394.         xIntersection = xtemp + fPlayerX;
  395.  
  396.         horizontalGrid--;
  397.       }
  398.           // LOOK FOR HORIZONTAL WALL
  399.       if (castArc==ANGLE0 || castArc==ANGLE180)
  400.       {
  401.         distToHorizontalGridBeingHit=9999999F;//Float.MAX_VALUE;
  402.       }
  403.       // else, move the ray until it hits a horizontal wall
  404.       else
  405.       {
  406.         distToNextXIntersection = fXStepTable[castArc];
  407.         while (true)
  408.         {
  409.           xGridIndex = (int)(xIntersection/TILE_SIZE);
  410.           // in the picture, yGridIndex will be 1
  411.           yGridIndex = (horizontalGrid/TILE_SIZE);
  412.  
  413.           if ((xGridIndex>=MAP_WIDTH) ||
  414.             (yGridIndex>=MAP_HEIGHT) ||
  415.             xGridIndex<0 || yGridIndex<0)
  416.           {
  417.             distToHorizontalGridBeingHit = Float.MAX_VALUE;
  418.             break;
  419.           }
  420.           else if ((fMap[yGridIndex*MAP_WIDTH+xGridIndex])!=O)
  421.           {
  422.             distToHorizontalGridBeingHit  = (xIntersection-fPlayerX)*fICosTable[castArc];
  423.             break;
  424.           }
  425.           // else, the ray is not blocked, extend to the next block
  426.           else
  427.           {
  428.             xIntersection += distToNextXIntersection;
  429.             horizontalGrid += distToNextHorizontalGrid;
  430.           }
  431.         }
  432.       }
  433.  
  434.  
  435.       // FOLLOW X RAY
  436.       if (castArc < ANGLE90 || castArc > ANGLE270)
  437.       {
  438.         verticalGrid = TILE_SIZE + (fPlayerX/TILE_SIZE)*TILE_SIZE;
  439.         distToNextVerticalGrid = TILE_SIZE;
  440.  
  441.         float ytemp = fTanTable[castArc]*(verticalGrid - fPlayerX);
  442.         yIntersection = ytemp + fPlayerY;
  443.       }
  444.       // RAY FACING LEFT
  445.       else
  446.       {
  447.         verticalGrid = (fPlayerX/TILE_SIZE)*TILE_SIZE;
  448.         distToNextVerticalGrid = -TILE_SIZE;
  449.  
  450.         float ytemp = fTanTable[castArc]*(verticalGrid - fPlayerX);
  451.         yIntersection = ytemp + fPlayerY;
  452.  
  453.         verticalGrid--;
  454.       }
  455.           // LOOK FOR VERTICAL WALL
  456.       if (castArc==ANGLE90||castArc==ANGLE270)
  457.       {
  458.         distToVerticalGridBeingHit = 9999999;//Float.MAX_VALUE;
  459.       }
  460.       else
  461.       {
  462.         distToNextYIntersection = fYStepTable[castArc];
  463.         while (true)
  464.         {
  465.           // compute current map position to inspect
  466.           xGridIndex = (verticalGrid/TILE_SIZE);
  467.           yGridIndex = (int)(yIntersection/TILE_SIZE);
  468.  
  469.           if ((xGridIndex>=MAP_WIDTH) ||
  470.             (yGridIndex>=MAP_HEIGHT) ||
  471.             xGridIndex<0 || yGridIndex<0)
  472.           {
  473.             distToVerticalGridBeingHit = Float.MAX_VALUE;
  474.             break;
  475.           }
  476.           else if ((fMap[yGridIndex*MAP_WIDTH+xGridIndex])!=O)
  477.           {
  478.             distToVerticalGridBeingHit =(yIntersection-fPlayerY)*fISinTable[castArc];
  479.             break;
  480.           }
  481.           else
  482.           {
  483.             yIntersection += distToNextYIntersection;
  484.             verticalGrid += distToNextVerticalGrid;
  485.           }
  486.         }
  487.       }
  488.  
  489.           // DRAW THE WALL SLICE
  490.           float scaleFactor;
  491.           float dist;
  492.       int topOfWall;   // used to compute the top and bottom of the sliver that
  493.       int bottomOfWall;   // will be the staring point of floor and ceiling
  494.       // determine which ray strikes a closer wall.
  495.       // if yray distance to the wall is closer, the yDistance will be shorter than
  496.           // the xDistance
  497.       if (distToHorizontalGridBeingHit < distToVerticalGridBeingHit)
  498.           {
  499.                 // the next function call (drawRayOnMap()) is not a part of raycating rendering part,
  500.                 // it just draws the ray on the overhead map to illustrate the raycasting process
  501.             drawRayOnOverheadMap(xIntersection, horizontalGrid);
  502.         dist=distToHorizontalGridBeingHit;
  503.         fOffscreenGraphics.setColor(Color.gray);
  504.       }
  505.       // else, we use xray instead (meaning the vertical wall is closer than
  506.       //   the horizontal wall)
  507.           else
  508.           {
  509.                 // the next function call (drawRayOnMap()) is not a part of raycating rendering part,
  510.                 // it just draws the ray on the overhead map to illustrate the raycasting process
  511.             drawRayOnOverheadMap(verticalGrid, yIntersection);
  512.         dist=distToVerticalGridBeingHit;
  513.         fOffscreenGraphics.setColor(Color.darkGray);
  514.           }
  515.  
  516.           // correct distance (compensate for the fishbown effect)
  517.       dist /= fFishTable[castColumn];
  518.           // projected_wall_height/wall_height = fPlayerDistToProjectionPlane/dist;
  519.           int projectedWallHeight=(int)(WALL_HEIGHT*(float)fPlayerDistanceToTheProjectionPlane/dist);
  520.       bottomOfWall = fProjectionPlaneYCenter+(int)(projectedWallHeight*0.5F);
  521.       topOfWall = PROJECTIONPLANEHEIGHT-bottomOfWall;
  522.           if (bottomOfWall>=PROJECTIONPLANEHEIGHT)
  523.                 bottomOfWall=PROJECTIONPLANEHEIGHT-1;
  524.           //fOffscreenGraphics.drawLine(castColumn, topOfWall, castColumn, bottomOfWall);
  525.           fOffscreenGraphics.fillRect(castColumn, topOfWall, 5, projectedWallHeight);
  526.  
  527.           // TRACE THE NEXT RAY
  528.           castArc+=5;
  529.           if (castArc>=ANGLE360)
  530.                 castArc-=ANGLE360;
  531.     }
  532.  
  533.         // blit to screen
  534.     paint(getGraphics());
  535.   }
  536.  
  537.   //*******************************************************************//
  538.   //* Called when leaving the page.
  539.   //*******************************************************************//
  540.   public void stop()
  541.   {
  542.         if((fThread != null) && fThread.isAlive())
  543.         {
  544.       fThread.stop();
  545.       fThread = null;
  546.         }
  547.   }
  548.  
  549.   //*******************************************************************//
  550.   //* Called everytime applet need painting or whenever repaint is
  551.   //*   called.
  552.   //*******************************************************************//
  553.   public void paint(Graphics g)
  554.   {
  555.     if (fOffscreenImage!=null)
  556.       g.drawImage(fOffscreenImage, 0, 0, this);
  557.   }
  558.  
  559.   //*******************************************************************//
  560.   //* Detect keypress
  561.   //*******************************************************************//
  562.   public boolean keyDown(Event evt, int key)
  563.   {
  564.     switch (key)
  565.     {
  566.       case Event.UP:
  567.       case 'i':
  568.       case 'I':
  569.         fKeyUp=true;
  570.         break;
  571.       case Event.DOWN:
  572.       case 'k':
  573.       case 'K':
  574.         fKeyDown=true;
  575.         break;
  576.       case Event.LEFT:
  577.       case 'j':
  578.       case 'J':
  579.         fKeyLeft=true;
  580.         break;
  581.       case Event.RIGHT:
  582.       case 'l':
  583.       case 'L':
  584.         fKeyRight=true;
  585.         break;
  586.       default:
  587.     }
  588.     return true;
  589.   }
  590.  
  591.   //*******************************************************************//
  592.   //* Detect key release
  593.   //*******************************************************************//
  594.   public boolean keyUp(Event evt, int key)
  595.   {
  596.     switch (key)
  597.     {
  598.       case Event.UP:
  599.       case 'i':
  600.       case 'I':
  601.         fKeyUp=false;
  602.         break;
  603.       case Event.DOWN:
  604.       case 'k':
  605.       case 'K':
  606.         fKeyDown=false;
  607.         break;
  608.       case Event.LEFT:
  609.       case 'j':
  610.       case 'J':
  611.         fKeyLeft=false;
  612.         break;
  613.       case Event.RIGHT:
  614.       case 'l':
  615.       case 'L':
  616.         fKeyRight=false;
  617.         break;
  618.       default:
  619.     }
  620.     return true;
  621.   }
  622. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement