ジャンプ

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
ckey

ジャンプ

#1

投稿記事 by ckey » 9年前

void sel(){

typedef struct {
float x, y, z;
float rhw;
D3DCOLOR cor;
float tex_u, tex_v;
}VERTEX_2D;

VERTEX_2D vertex[4];

const unsigned char animex1[] =
{
0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 2,
0xff
};

const unsigned char animex2[] =
{
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7,
0xff
};

const unsigned char animex3[] =
{
8, 8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11, 11,
0xff
};

const unsigned char animex4[] =
{
12, 12, 12, 12, 12, 12, 12, 12,
13, 13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15, 15,
0xff
};

const unsigned char *animex_data[] =
{
animex1, animex2, animex3, animex4
};


static unsigned char animex_style = 2;
static unsigned char cntx = 0;
const unsigned char *ptx = animex_data[animex_style];


int ux = *(ptx + cntx);
cntx++;
if (*(ptx + cntx) == 0xff)
{
cntx = 0;
}

vertex[0].x = input_lr;
vertex[0].y = input_ud;
vertex[0].z = 0.0f;

vertex[1].x = input_lr + x;
vertex[1].y = input_ud;
vertex[1].z = 0.0f;

vertex[2].x = input_lr + x;
vertex[2].y = input_ud + y;
vertex[2].z = 0.0f;

vertex[3].x = input_lr;
vertex[3].y = input_ud + y;
vertex[3].z = 0.0f;

vertex[0].rhw = 1.0f;
vertex[1].rhw = 1.0f;
vertex[2].rhw = 1.0f;
vertex[3].rhw = 1.0f;

vertex[0].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[1].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[2].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[3].cor = D3DCOLOR_XRGB(255, 255, 255);

if (GetKeyboardPress(DIK_LEFT)){
input_lr -= 4.0f;
animex_style = 1;
}
if (GetKeyboardPress(DIK_UP)){
input_ud -= 4.0f;
animex_style = 3;
}
if (GetKeyboardPress(DIK_DOWN)){
input_ud += 4.0f;
animex_style = 0;
}
if (GetKeyboardPress(DIK_RIGHT)){
input_lr += 4.0f;
animex_style = 2;
}
if (GetKeyboardPress(DIK_BACK)){

}

vertex[3].tex_u = ux % 4 * 0.25f;
vertex[3].tex_v = ux / 4 * 0.25f + 0.25f;
vertex[0].tex_u = ux % 4 * 0.25f;
vertex[0].tex_v = ux / 4 * 0.25f;
vertex[1].tex_u = ux % 4 * 0.25f + 0.25;
vertex[1].tex_v = ux / 4 * 0.25f;
vertex[2].tex_u = ux % 4 * 0.25f + 0.25f;
vertex[2].tex_v = ux / 4 * 0.25f + 0.25f;
/////////////////////////////////////////////////////

int x, y;
int grd = 360;
double px = 288, py = grd;
double vx = 0, vy = 0;
double ay = 0;
int frmcnt = 0;


while (1) {

//① 地面上にいる場合
if (vy == 0) {
x = 64 * ((frmcnt / 30) % 2);
y = 0;
}

//② ジャンプの頂上付近
else if (vy < 2.5 && vy >-2.0) {
x = 192;
y = 0;
}

//③ 上昇中(勢いがある!!)
else if (vy < 0) {
x = 128;
y = 0;
}

//④ 落下中(着地に備えている)
else {
x = 0;
y = 64;
}

//⑤ 地面上でスペースキーが押下された時
if (vy == 0 && GetKeyboardPress(DIK_K) == 1) {
vy = -4.5; //初速
ay = 0.1f; //重力
}

//⑥ 座標値の更新
vy += ay;
py += vy;

//⑦ 地面に潜り込んでしまった場合の修正
if (py > grd) {
py = grd;
vy = 0;
ay = 0;
}
frmcnt++;

}


g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertex, sizeof(VERTEX_2D));

}
ジャンプさせたいのですが分からないのでジャンプさせるプログラムを教えてください

ckey

Re: ジャンプ

#2

投稿記事 by ckey » 9年前

コード:

void	sel(){

typedef struct {
float x, y, z;
float rhw;
D3DCOLOR cor;
float tex_u, tex_v;
}VERTEX_2D;

VERTEX_2D vertex[4];

const unsigned char animex1[] =
{
0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 2,
0xff
};

const unsigned char animex2[] =
{
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7,
0xff
};

const unsigned char animex3[] =
{
8, 8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11, 11,
0xff
};

const unsigned char animex4[] =
{
12, 12, 12, 12, 12, 12, 12, 12,
13, 13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15, 15,
0xff
};

const unsigned char *animex_data[] =
{
animex1, animex2, animex3, animex4
};


static unsigned char animex_style = 2;
static unsigned char cntx = 0;
const unsigned char *ptx = animex_data[animex_style];


int ux = *(ptx + cntx);
cntx++;
if (*(ptx + cntx) == 0xff)
{
cntx = 0;
}

vertex[0].x = input_lr;
vertex[0].y = input_ud;
vertex[0].z = 0.0f;

vertex[1].x = input_lr + x;
vertex[1].y = input_ud;
vertex[1].z = 0.0f;

vertex[2].x = input_lr + x;
vertex[2].y = input_ud + y;
vertex[2].z = 0.0f;

vertex[3].x = input_lr;
vertex[3].y = input_ud + y;
vertex[3].z = 0.0f;

vertex[0].rhw = 1.0f;
vertex[1].rhw = 1.0f;
vertex[2].rhw = 1.0f;
vertex[3].rhw = 1.0f;

vertex[0].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[1].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[2].cor = D3DCOLOR_XRGB(255, 255, 255);
vertex[3].cor = D3DCOLOR_XRGB(255, 255, 255);

if (GetKeyboardPress(DIK_LEFT)){
input_lr -= 4.0f;
animex_style = 1;
}
if (GetKeyboardPress(DIK_UP)){
input_ud -= 4.0f;
animex_style = 3;
}
if (GetKeyboardPress(DIK_DOWN)){
input_ud += 4.0f;
animex_style = 0;
}
if (GetKeyboardPress(DIK_RIGHT)){
input_lr += 4.0f;
animex_style = 2;
}
if (GetKeyboardPress(DIK_BACK)){

}

vertex[3].tex_u = ux % 4 * 0.25f;
vertex[3].tex_v = ux / 4 * 0.25f + 0.25f;
vertex[0].tex_u = ux % 4 * 0.25f;
vertex[0].tex_v = ux / 4 * 0.25f;
vertex[1].tex_u = ux % 4 * 0.25f + 0.25;
vertex[1].tex_v = ux / 4 * 0.25f;
vertex[2].tex_u = ux % 4 * 0.25f + 0.25f;
vertex[2].tex_v = ux / 4 * 0.25f + 0.25f;
/////////////////////////////////////////////////////

int x, y;
int	grd = 360;
double px = 288, py = grd;
double vx = 0, vy = 0;
double ay = 0;
int frmcnt = 0;


while (1) {

//① 地面上にいる場合
if (vy == 0) {
x = 64 * ((frmcnt / 30) % 2);
y = 0;
}

//② ジャンプの頂上付近
else if (vy < 2.5 && vy >-2.0) {
x = 192;
y = 0;
}

//③ 上昇中(勢いがある!!)
else if (vy < 0) {
x = 128;
y = 0;
}

//④ 落下中(着地に備えている)
else {
x = 0;
y = 64;
}

//⑤ 地面上でスペースキーが押下された時
if (vy == 0 && GetKeyboardPress(DIK_K) == 1) {
vy = -4.5; //初速
ay = 0.1f; //重力
}

//⑥ 座標値の更新
vy += ay;
py += vy;

//⑦ 地面に潜り込んでしまった場合の修正
if (py > grd) {
py = grd;
vy = 0;
ay = 0;
}
frmcnt++;

}


g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertex, sizeof(VERTEX_2D));

}


閉鎖

“C言語何でも質問掲示板” へ戻る