Keyboard 同时移动对象和跳跃(键盘输入)

Keyboard 同时移动对象和跳跃(键盘输入),keyboard,Keyboard,我使用的字符类读取一个键代码并进行移动 基于此。它跳跃和移动,但问题是它没有 同时正确地跳跃和移动。有什么办法可以解决吗 这个 import java.awt.*; 导入javax.swing.*; 导入java.awt.event.*; 公共阶级性质 { int c_posX,c_posY;//x和y位置 int c_velx;//x的速度 公共整数重力=1,c_速度=20,c_直径=25; public int c_speedY=26;//初始跳跃速度。 公共字符(int c_posX,in

我使用的字符类读取一个键代码并进行移动 基于此。它跳跃和移动,但问题是它没有 同时正确地跳跃和移动。有什么办法可以解决吗 这个

import java.awt.*;
导入javax.swing.*;
导入java.awt.event.*;
公共阶级性质
{
int c_posX,c_posY;//x和y位置
int c_velx;//x的速度
公共整数重力=1,c_速度=20,c_直径=25;
public int c_speedY=26;//初始跳跃速度。
公共字符(int c_posX,int c_posY)
{
this.c_posX=c_posX;
this.c_posY=c_posY;
c_velx=0;
}
public int getCposX()
{
返回c_posX;
}
//创建一个方法来检查玩家的Y坐标
public int getCposY()
{
返回c_posY;
}
//创建一个方法来检查播放器的宽度
public int getCdiam()
{
返回c_直径;
}
public void updateCY()//如果角色正在跳跃,则继续添加重力
{
if(ifJumping()==true){
c_speedY=c_speedY-重力;
c_posY=c_posY-c_speedY;
}
}
按下公共无效键(int keycode)
{
if(keycode==37)//如果用户按下左箭头
{
c_velx=-c_speedX;
}
如果(键代码==39)
{
c_velx=c_speedX;//如果用户按下右箭头
}
如果(键代码==38)
{
initialize(keycode);//如果用户按下向上箭头,请检查它是否可以跳转
}
}
public void updateCX()//更新字符的x位置
{
c_posX+=c_velx;
c_velx=0;
}
public int returnKey(int-keycode)
{
返回键码;
}
public void stopJumping()//角色达到一定速度后停止跳跃
{
if(DoneJumping()==true)
{
c_posY=0;
}
}
public boolean ifJumping()//检查字符是否正在跳跃
{
如果(c)
import java.awt.*;

import javax.swing.*;
import java.awt.event.*;

public class Character 
{
    int c_posX, c_posY; // x and y positions
    int c_velx; // velocity for x
    public int gravity = 1, c_speedX = 20, c_diam = 25; 
    public int c_speedY = 26; // the initial jumping speed.
    public Character(int c_posX, int c_posY)

    {
        this.c_posX = c_posX;
        this.c_posY = c_posY;
        c_velx = 0;
    }

    public int getCposX() 
    {
        return c_posX;
    }

    // Create a method to check the Y coordinate of the player
    public int getCposY() 
    {
        return c_posY;
    }

    // Create a method to check the width of the player
    public int getCdiam() 
    {
        return c_diam;
    }

    public void updateCY() // if the character is jumping, then continue to add gravity
        {
      if (ifJumping() == true) {
            c_speedY = c_speedY - gravity;
            c_posY = c_posY - c_speedY;
        }

    }
public void keyPressed(int keycode) 
{
    if (keycode == 37) // if the user presses the left arrow
    {
        c_velx = -c_speedX;
    }
    if (keycode == 39) 
    {
        c_velx = c_speedX; // if the user presses the right arrow
    }
    if (keycode == 38) 
    {
        initialize(keycode); // if the user presses the up arrow,check if it can jump
    }

}

public void updateCX() // update the x position of the character
{
    c_posX += c_velx;
    c_velx = 0;
}

public int returnKey(int keycode)
{
    return keycode;
}

public void stopJumping()  // stop jumping once the character reaches a certain velocity
{
    if (DoneJumping() == true) 
    {
        c_posY = 0;
    }
}

public boolean ifJumping() // check if the character is jumping
{
    if (c_speedY <= 25 & DoneJumping() == false) {
        return true;
    }
    return false;
}

public boolean DoneJumping() // return true if the character's y velocity is less than -30.
{
    if (c_speedY < (-30)) 
    {
        return true;
    }
    return false;
}

public void initialize(int keycode) 
{
    if (ifJumping() == false) // start jumping if it is not jumping 
    {
        c_speedY = 25;
        c_posY = c_posY - c_speedY;

    }
}