⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.c

📁 经典的老游戏digger的源代码.提起digger相信很多人会回忆起曾经为了它挑灯夜战的时光
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Digger Remastered
   Copyright (c) Andrew Jenner 1998-2004 */

#include "def.h"
#include "main.h"
#include "sound.h"
#include "hardware.h"
#include "record.h"
#include "digger.h"
#ifdef _WINDOWS
#include "win_dig.h"
#endif

bool escape=FALSE,firepflag=FALSE,aleftpressed=FALSE,arightpressed=FALSE,
     auppressed=FALSE,adownpressed=FALSE,start=FALSE,af1pressed=FALSE;
bool fire2pflag=FALSE,aleft2pressed=FALSE,aright2pressed=FALSE,
     aup2pressed=FALSE,adown2pressed=FALSE,af12pressed=FALSE;

Sint4 akeypressed;

Sint4 dynamicdir=-1,dynamicdir2=-1,staticdir=-1,staticdir2=-1,joyx=0,joyy=0;

bool joybut1=FALSE,joybut2=FALSE;

Sint4 keydir=0,keydir2=0,jleftthresh=0,jupthresh=0,jrightthresh=0,
      jdownthresh=0,joyanax=0,joyanay=0;

bool joyflag=FALSE,pausef=FALSE;

bool krdf[17]={FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
               FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};


#ifdef ARM

#include "C:kernel.h"
#define rightpressed (_kernel_osbyte(129,keycodes[0][0],255)&0xff==0xff)
#define uppressed (_kernel_osbyte(129,keycodes[1][0],255)&0xff==0xff)
#define leftpressed (_kernel_osbyte(129,keycodes[2][0],255)&0xff==0xff)
#define downpressed (_kernel_osbyte(129,keycodes[3][0],255)&0xff==0xff)
#define f1pressed (_kernel_osbyte(129,keycodes[4][0],255)&0xff==0xff)
#define right2pressed (_kernel_osbyte(129,keycodes[5][0],255)&0xff==0xff)
#define up2pressed (_kernel_osbyte(129,keycodes[6][0],255)&0xff==0xff)
#define left2pressed (_kernel_osbyte(129,keycodes[7][0],255)&0xff==0xff)
#define down2pressed (_kernel_osbyte(129,keycodes[8][0],255)&0xff==0xff)
#define f12pressed (_kernel_osbyte(129,keycodes[9][0],255)&0xff==0xff)

/* Default key codes for ARM */

int keycodes[17][5]={{134,0,-2,-2,-2},   /* 1 Right */
                     {198,0,-2,-2,-2},   /* 1 Up */
                     {230,0,-2,-2,-2},   /* 1 Left */
                     {214,0,-2,-2,-2},   /* 1 Down */
                     {142,0,-2,-2,-2},   /* 1 Fire */
                     {134,0,-2,-2,-2},   /* 2 Right */
                     {198,0,-2,-2,-2},   /* 2 Up */
                     {230,0,-2,-2,-2},   /* 2 Left */
                     {214,0,-2,-2,-2},   /* 2 Down */
                     {142,0,-2,-2,-2},   /* 2 Fire */
                     {20,-2,-2,-2,-2},   /* Cheat */
                     {43,-2,-2,-2,-2},   /* Accelerate */
                     {45,-2,-2,-2,-2},   /* Brake */
                     {137,-2,-2,-2,-2},  /* Music */
                     {139,-2,-2,-2,-2},  /* Sound */
                     {140,-2,-2,-2,-2},  /* Exit */
                     {32,-2,-2,-2,-2}};  /* Pause */

#define ASCIIF8 138

/* This function exclusively used in keyboard redefinition */
void findkey(int kn)
{
  int k=0,i,j;
  bool f=FALSE;
  do {
    for (i=130;i<256 && !f;i++)
      if (_kernel_osbyte(129,i,255)&0xff==0xff)
        f=TRUE;
    gretrace();
    if (kbhit())
      k=getkey();
  } while (k==0 && !f);
  j=i-1;
  if (k==0) k=-2;
  if (k>='a' && k<='z')
    k-='a'-'A';
  for (i=0;i<5;i++)
    keycodes[kn][i]=-2;
  if (kn>9)
    i=0;
  else {
    i=2;
    keycodes[kn][0]=j;
    keycodes[kn][1]=0;
  }
  keycodes[kn][i++]=k;
  if (k>='A' && k<='Z') {
    keycodes[kn][i++]=k-('A'-'a'); /* lower case */
    keycodes[kn][i++]=k-'@'; /* ctrl code */
  }
  krdf[kn]=TRUE;
}

#else

#ifdef _WINDOWS
#define rightpressed  (key_pressed(0,TRUE))
#define uppressed     (key_pressed(1,TRUE))
#define leftpressed   (key_pressed(2,TRUE))
#define downpressed   (key_pressed(3,TRUE))
#define f1pressed     (key_pressed(4,FALSE))
#define right2pressed (key_pressed(5,TRUE))
#define up2pressed    (key_pressed(6,TRUE))
#define left2pressed  (key_pressed(7,TRUE))
#define down2pressed  (key_pressed(8,TRUE))
#define f12pressed    (key_pressed(9,FALSE))

int keycodes[19][5]={{VK_RIGHT,VK_NUMPAD6,0,0,0}, /* 1 Right */
                     {VK_UP,VK_NUMPAD8,0,0,0},             /* 1 Up */
                     {VK_LEFT,VK_NUMPAD4,0,0,0},   /* 1 Left */
                     {VK_DOWN,VK_NUMPAD2,0,0,},   /* 1 Down */
                     {VK_F1,VK_RETURN,0,0,0},       /* 1 Fire */
                     {'D',0,0,0,0},             /* 2 Right */
                     {'W',0,0,0,0},             /* 2 Up */
                     {'A',0,0,0,0},               /* 2 Left */
                     {'S',0,0,0,0},             /* 2 Down */
                     {VK_TAB,0,0,0,0},                     /* 2 Fire */
                     {'T',0,0,0,0},                    /* Cheat */
                     {VK_ADD,0,0,0,0},                 /* Accelerate */
                     {VK_SUBTRACT,0,0,0,0},            /* Brake */
                     {VK_F7,0,0,0,0},                  /* Music */
                     {VK_F9,0,0,0,0},                  /* Sound */
                     {VK_F10,0,0,0,0},                 /* Exit */
                     {VK_SPACE,0,0,0,0},              /* Pause */
                     {VK_F8,0,0,0,0},
                     {VK_ESCAPE,'N',0,0,0}};

#define ASCIIF8 VK_F8

#else

bool leftpressed=FALSE,rightpressed=FALSE,uppressed=FALSE,downpressed=FALSE,
     f1pressed=FALSE,left2pressed=FALSE,right2pressed=FALSE,up2pressed=FALSE,
     down2pressed=FALSE,f12pressed=FALSE;

/* Default key codes */

int keycodes[17][5]={{0x4d,0xcd,0x14d,-2,-2}, /* 1 Right */
                     {0x48,0xc8,0x148,-2,-2}, /* 1 Up */
                     {0x4b,0xcb,0x14b,-2,-2}, /* 1 Left */
                     {0x50,0xd0,0x150,-2,-2}, /* 1 Down */
                     {0x3b,0xbb,0x13b,-2,-2}, /* 1 Fire */
                     {31,159,83,115,19},      /* 2 Right */
                     {17,145,87,119,23},      /* 2 Up */
                     {30,158,65,97,1},        /* 2 Left */
                     {44,172,90,122,26},      /* 2 Down */
                     {15,143,9,-2,-2},        /* 2 Fire */
                     {20,-2,-2,-2,-2},        /* Cheat */
                     {43,-2,-2,-2,-2},        /* Accelerate */
                     {45,-2,-2,-2,-2},        /* Brake */
                     {321,-2,-2,-2,-2},       /* Music */
                     {323,-2,-2,-2,-2},       /* Sound */
                     {324,-2,-2,-2,-2},       /* Exit */
                     {32,-2,-2,-2,-2}};       /* Pause */

#define ASCIIF8 322

#endif

Uint4 scancode;

int pki;

#ifndef _WINDOWS
bool *flagp[10]={
  &rightpressed,&uppressed,&leftpressed,&downpressed,&f1pressed,
  &right2pressed,&up2pressed,&left2pressed,&down2pressed,&f12pressed};

/* We need to know when keys are released so we know when to stop.
   This routine is only called on platforms where keyboard makes and breaks
   cause interrupts (this being the handler). On platforms where makes and
   breaks set and release flags, these "variables" are actually macros linking
   to these flags (they are each only read once).
*/
void processkey(Uint4 key)
{
  for (pki=0;pki<10;pki++) {
    if (key==keycodes[pki][0]) /* Make */
      *flagp[pki]=TRUE;
    if (key==keycodes[pki][1]) /* Break */
      *flagp[pki]=FALSE;
  }
  scancode=key;
}
#endif

/* This function exclusively used in keyboard redefinition */
void findkey(int kn)
{
  int k=0,i;
  scancode=0;
  do {
    if (kbhit())
      k=getkey();
#ifdef _WINDOWS
    do_windows_events();
#endif
  } while (k==0 && (scancode==0 || scancode&0x80));
  if (kbhit())
    k=getkey();
  if (k==0)
    k=-2;
#ifndef _WINDOWS
  if (k>='a' && k<='z')
    k-='a'-'A';
  for (i=0;i<5;i++)
    keycodes[kn][i]=-2;
  if (kn>9)
    i=0;
  else {
    i=2;
    keycodes[kn][0]=scancode&0x7f;
    keycodes[kn][1]=scancode|0x80;
  }
  keycodes[kn][i++]=k;
  if (k>='A' && k<='Z') {
    keycodes[kn][i++]=k-('A'-'a'); /* lower case */
    keycodes[kn][i]=k-'@'; /* ctrl code */
  }
#else
  for (i=0;i<5;i++)
    keycodes[kn][i]=k;
#endif
  krdf[kn]=TRUE;
}

#endif


void readjoy(void);

/* The standard ASCII keyboard is also checked so that very short keypresses
   are not overlooked. The functions kbhit() (returns bool denoting whether or
   not there is a key in the buffer) and getkey() (wait until a key is in the
   buffer, then return it) are used. These functions are emulated on platforms
   which only provide an inkey() function (return the key in the buffer, unless
   there is none, in which case return -1. It is done this way around for
   historical reasons, there is no fundamental reason why it shouldn't be the
   other way around. */
void checkkeyb(void)
{
  int i,j,k=0;
  bool *aflagp[10]={&arightpressed,&auppressed,&aleftpressed,&adownpressed,
                    &af1pressed,&aright2pressed,&aup2pressed,&aleft2pressed,
                    &adown2pressed,&af12pressed};
  if (leftpressed)
    aleftpressed=TRUE;
  if (rightpressed)
    arightpressed=TRUE;
  if (uppressed)
    auppressed=TRUE;
  if (downpressed)
    adownpressed=TRUE;
  if (f1pressed)
    af1pressed=TRUE;
  if (left2pressed)
    aleft2pressed=TRUE;
  if (right2pressed)
    aright2pressed=TRUE;
  if (up2pressed)
    aup2pressed=TRUE;
  if (down2pressed)
    adown2pressed=TRUE;
  if (f12pressed)
    af12pressed=TRUE;
#ifndef _WINDOWS
  while (kbhit()) {
    akeypressed=getkey();
    for (i=0;i<10;i++)
      for (j=2;j<5;j++)
        if (akeypressed==keycodes[i][j])
          *aflagp[i]=TRUE;
    for (i=10;i<17;i++)
      for (j=0;j<5;j++)
        if (akeypressed==keycodes[i][j])
          k=i;
#else
  akeypressed=0;
  if (kbhit())
  {
    akeypressed=getkey();
    command_buffer=translate_key_code_to_function(akeypressed);
    if (command_buffer!=19)
      start=TRUE;
  }

  if (command_buffer)
  {
    k=command_buffer-1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -