Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LoadDragon0000000000/b4189a5a0c0a390b8999dca3cf6b17e0 to your computer and use it in GitHub Desktop.
Save LoadDragon0000000000/b4189a5a0c0a390b8999dca3cf6b17e0 to your computer and use it in GitHub Desktop.
// 右壁の作成 x:壁のX座標 y1:壁の上方 y2:壁の下方
void GameControl::SetRightWall(float x, float y1, float y2) {
if (x <= Player->GetX() && Player->GetX() <= x + 3.0f && Player->GetY() <= y1 && Player->GetY() >= y2) {
if (Player->GetX() <= x + 0.20f) {
Player->SetX(x + 0.20f);
}
}
}
// 左壁の作成
void GameControl::SetLeftWall(float x, float y1, float y2) {
if (x - 3.0f <= Player->GetX() && Player->GetX() <= x && Player->GetY() <= y1 && Player->GetY() >= y2) {
if (x - 0.10f <= Player->GetX()/* && Player->GetX() <= x + 0.20f*/) {
Player->SetX(x - 0.10f); // 0.20f
}
}
}
// 天井の作成
void GameControl::SetCeiling(const float x1, const float x2, const float y) {
if (x1 <= Player->GetX() && Player->GetX() <= x2 && Player->GetY() <= y) {
if (y - 0.30f <= Player->GetY()) {
Player->SetY(y - 0.310f);
}
}
}
// 床の作成
void GameControl::SetFloor(char* moveDirection, float moveX1, float moveX2, float moveScala, float Slope, float h) {
if (h - 0.50f <= Player->GetY() && Player->GetY() <= h + 0.50f) {
if (moveX1 <= Player->GetX() && Player->GetX() <= moveX2) {
Player->DrawMoveAnime(moveX1, moveX2);
}
}
// ==================================================================================================
// ここから別の.cpp このソースは最終的な状態を含めているので、今回の質問と関係ないソースばかりです。
// ようは、Playerを移動させる処理です
// ジオメトリ:3Dモデルのこと
// ==================================================================================================
#include "ClassGeometry.h"
#include <stdio.h>
#pragma warning(disable:4996)
// ジオメトリをキー入力で移動させる
void Geometry::DrawMoveAnime(char* moveDirection, float moveX1, float moveX2, float moveScala, float Slope, float h) {
if (this != NULL) {
static int ButtonA;
static int ButtonD;
static bool WalkSwitch = false; // 歩き状態かどうか
static float AddSpeed = 1.0f; // ダッシュで加速するときに使用する
// 平行移動
D3DXMatrixIdentity(&matTranslation);
// キャラが進むべきX座標とY座標
float TempMoveVectorX = 0.0f, TempMoveVectorY = 0.0f;
if (moveX1 <= matWorld._41 && matWorld._41 <= moveX2 && MoveSwitch == true) {
if (moveX1 != -5.0f && moveX2 != 100.0f) { // 基本地面の設定時以外のとき、坂登り中のスイッチがオンになる
ShapeSwitch = true;
}
if ((moveDirection[3] == 1 && moveDirection[1] == 0) || (moveDirection[10] == 1 && moveDirection[8] == 0)) { // 右へ
pAnimController->SetTrackEnable(1, FALSE); // 歩行モーション
pAnimController->SetTrackEnable(0, TRUE);
// ダッシュキーが押されたときの処理
//if (moveDirection[4] == 1) { // 通常速度
// if (AddSpeed <= 2.50f) AddSpeed += 0.010f;
//}
//else {
// if (AddSpeed > 1.0f) AddSpeed -= 0.010f;
//}
if (moveDirection[4] == 1) {
AddSpeed = 2.0f;
}
if (moveDirection[4] == 0) {
AddSpeed = 1.0f;
}
TempMoveVectorX += (cosf(Slope * DEGTORAD) * moveScala) * AddSpeed;
TempMoveVectorY += (sinf(Slope * DEGTORAD) * moveScala) * AddSpeed;
D3DXMatrixTranslation(&matTranslation, TempMoveVectorX, TempMoveVectorY, 0);
++ButtonD;
matWorld = matWorld * matTranslation;
}
else
if (moveDirection[3] == 0 && moveDirection[10] == 0) { // 右移動キーからボタンが離されたとき
ButtonD = 0;
}
if ((moveDirection[1] == 1 && moveDirection[3] == 0) || (moveDirection[8] == 1 && moveDirection[10] == 0)) { // 左へ
pAnimController->SetTrackEnable(1, FALSE); // 歩行モーション
pAnimController->SetTrackEnable(0, TRUE);
// ダッシュキーが押されたときの処理
//if (moveDirection[4] == 1) { // 通常速度
// if (AddSpeed <= 2.50f) AddSpeed += 0.010f;
//}
//else {
// if (AddSpeed > 1.0f) AddSpeed -= 0.010f;
//}
if (moveDirection[4] == 1) {
AddSpeed = 2.0f;
}
if (moveDirection[4] == 0) {
AddSpeed = 1.0f;
}
TempMoveVectorX -= (cosf(Slope * DEGTORAD) * moveScala * AddSpeed);
TempMoveVectorY -= (sinf(Slope * DEGTORAD) * moveScala * AddSpeed);
D3DXMatrixTranslation(&matTranslation, TempMoveVectorX, TempMoveVectorY, 0);
++ButtonA;
matWorld = matWorld * matTranslation;
}
else
if (moveDirection[1] == 0 && moveDirection[8] == 0) {
ButtonA = 0;
}
if (moveDirection[3] == 0 && moveDirection[10] == 0 && moveDirection[1] == 0 && moveDirection[8] == 0) {
AddSpeed = 1.0f;
}
}
// 回転
if (ButtonD >= 1 && MoveSwitch == true) { //
// 元の座標の保持
float TempPlayerX = GetX(), TempPlayerY = GetY(), TempPlayerZ = GetZ();
// 原点へ移動
D3DXMatrixIdentity(&matTranslation);
D3DXMatrixTranslation(&matTranslation, 0, 0, 0);
matWorld = matWorld * matTranslation;
// 原点にて回転
D3DXMatrixIdentity(&matRotation);
D3DXMatrixIdentity(&matWorld);
D3DXMatrixRotationY(&matRotation, (270) * DEGTORAD);
matWorld = matWorld * matRotation;
// 元の座標へ移動
D3DXMatrixIdentity(&matTranslation);
D3DXMatrixTranslation(&matTranslation, TempPlayerX, TempPlayerY, TempPlayerZ);
matWorld = matWorld * matTranslation;
}
if (ButtonA >= 1 && MoveSwitch == true) { //
// 元の座標の保持
float TempPlayerX = GetX(), TempPlayerY = GetY(), TempPlayerZ = GetZ();
// 原点へ移動
D3DXMatrixIdentity(&matTranslation);
D3DXMatrixTranslation(&matTranslation, 0, 0, 0);
matWorld = matWorld * matTranslation;
// 原点にて回転
D3DXMatrixIdentity(&matRotation);
D3DXMatrixIdentity(&matWorld);
D3DXMatrixRotationY(&matRotation, (90) * DEGTORAD);
matWorld = matWorld * matRotation;
// 元の座標へ移動
D3DXMatrixIdentity(&matTranslation);
D3DXMatrixTranslation(&matTranslation, TempPlayerX, TempPlayerY, TempPlayerZ);
matWorld = matWorld * matTranslation;
}
// 立ちモーションの再生
if ((moveDirection[0] == 0 && moveDirection[1] == 0 && moveDirection[2] == 0 && moveDirection[3] == 0) &&
(moveDirection[7] == 0 && moveDirection[8] == 0 && moveDirection[9] == 0 && moveDirection[10] == 0)) {
if (AnimeStandInvalid == false) {
pAnimController->SetTrackEnable(1, TRUE);
pAnimController->SetTrackEnable(0, FALSE);
}
}
// 重力設定
SetGravityLine(moveX1, moveX2, Slope, h);
}
}
// 坂道とか自動的に登る
// ついでにNowPositionY(重力線)も設定
void Geometry::DrawAutoShapeMoveAnime(float x1, float x2, float r, float h) {
if (this != NULL) {
if (x1 <= GetX() && GetX() <= x2) {
ShapeSwitch = true;
NowPositionY = (tanf(r * DEGTORAD) * (GetX() - x1) + h);
matWorld._42 += sinf(r * DEGTORAD) * 0.030f;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment