精灵的对角运动

精灵的对角运动,第1张

精灵对角运动

这是基于您的最后评论的代码

// Set of currently pressed keysprivate final Set<Integer> pressed = new TreeSet<Integer>();@Overridepublic void keyPressed(KeyEvent arg0) {    int c = arg0.getKeyCode();    pressed.add(c);    if (pressed.size() > 1) {        Integer[] array = pressed.toArray(new Integer[] {});        if (array[0] == KeyEvent.VK_LEFT && array[1] == KeyEvent.VK_UP) { velx = -4; vely = -4;        } else if (array[0] == KeyEvent.VK_UP && array[1] == KeyEvent.VK_RIGHT) { velx = 4; vely = 4;        } else if (array[0] == KeyEvent.VK_RIGHT && array[1] == KeyEvent.VK_DOWN) { velx = 4; vely = -4;        } else if (array[0] == KeyEvent.VK_LEFT && array[1] == KeyEvent.VK_DOWN) { velx = -4; vely = 4;        }    } else {        if (c == KeyEvent.VK_LEFT) { velx = -4; vely = 0;        } else if (c == KeyEvent.VK_RIGHT) { velx = 4; vely = 0;        } else if (c == KeyEvent.VK_UP) { velx = 0; vely = -4;        } else if (c == KeyEvent.VK_DOWN) { velx = 0; vely = 4;        }    }}@Overridepublic void keyReleased(KeyEvent arg0) {    velx = 0;    vely = 0;    pressed.remove(Integer.valueOf(arg0.getKeyCode()));}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5506801.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存