ベクターコンテナクラスで掛け算とわり算をした値を入れいのですが値が変更されていないため原因が知りたいです。また警告文も出ていないため困っています。新しいプロジェクトを作りfloatとintで値の動きを確認しましたがintのときは値が代わりfloatの時は値が変わりません
これは何が原因のどういう現象なのでしょうか?自分はflaotを使いたいのですが
コメント部//////のstd::vector<float> b(2,0);のb[0],b[1]部で代入部
#include "DxLib.h" #include <vector> #include <math.h> #include <fstream> #include "string.h" #include <iostream> static std::ofstream ofs("Log.txt"); #define CELL 64 class game { private: class Position { public: Position() { pos_x = 0; pos_y = 0; } float pos_x; float pos_y; }; Position* pos; Position* move; public: int map[100][100] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, }; int player_graph[10]; int map_graph[40]; bool isGround; game() { pos = new Position(); move = new Position(); pos->pos_x = 100.0f; isGround = false; LoadDivGraph("mario_resource/Mario_64px.png", 7, 7, 1, 64, 64, player_graph); LoadDivGraph("mario_resource/Block_64px.png",40,10,4,64,64,map_graph); } /*キー入力*/ void key_Update() { if (keybord(KEY_INPUT_LEFT) > 0)//← { } else if (keybord(KEY_INPUT_RIGHT) > 0)//→ { } else if (keybord(KEY_INPUT_UP) > 0)//上 { pos->pos_y -= 5; } else if (keybord(KEY_INPUT_DOWN) > 0)//下 { pos->pos_y += 5; } else if (keybord(KEY_INPUT_SPACE) > 0)//ジャンプ { } else//何も押していない時 { } } /*当たり判定*/ bool Collision() { Position p; p.pos_x = pos->pos_x + CELL + move->pos_x; p.pos_y = pos->pos_y + CELL + move->pos_y; p.pos_x = (p.pos_x / CELL); p.pos_y = (p.pos_y / CELL); if (map[(int)p.pos_y][(int)p.pos_x] == 1) { ofs << "Collision x: " << p.pos_x << std::endl; ofs << "Collision y: " << p.pos_y << std::endl; return true; } return false; } void Update() { key_Update(); if (Collision() == true) { Position p; p.pos_x = pos->pos_x + CELL + move->pos_x; p.pos_y = pos->pos_y + CELL + move->pos_y; ofs << "p.pos_x: " << p.pos_x << std::endl; ofs << "p.pos_y: " << p.pos_y << std::endl; DrawFormatString(100, 100, GetColor(255, 255, 255), "衝突!"); ////////////////////////////////////////////////////////////////////// /*ブロック座標*/ float x = p.pos_x; float y = p.pos_y; std::vector<float> b(2, 0); //b[0] = (x / CELL) * CELL; //b[1] = (y / CELL) * CELL; float tx = (p.pos_x / CELL) * CELL; float ty = (p.pos_y / CELL) * CELL; //ofs << "b[0]" << b[0] << std::endl; //ofs << "b[1]" << b[1] << std::endl; ofs << "tx: " << (p.pos_x / CELL) * CELL << std::endl; ofs << "ty: " << (float)(p.pos_y / CELL) * CELL << std::endl; std::vector<float> pl(2, 0); ////////////////////////////////////////////////////////////////////// /*プレイヤーめり込み座標*/ pl[0] = pos->pos_x + CELL + move->pos_x; pl[1] = pos->pos_y + CELL + move->pos_y; ofs << "pl[0]" << pl[0] << std::endl; ofs << "pl[1]" << pl[1] << std::endl; std::vector<float> ov(2, 0);//めり込みベクトル ov[0] = b[0] - pl[0]; ov[1] = b[1] - pl[1]; ofs << "ov[0]" << ov[0] << std::endl; ofs << "ov[1]" << ov[1] << std::endl; float o_range = sqrt( (ov[0] * ov[0]) + (ov[1] * ov[1]) );//めりこみ量 ofs << " o_range: " << o_range << std::endl; std::vector<float> i(2, 0);//移動ベクトル i[0] = move->pos_x; i[1] = move->pos_y; float im = sqrt((i[0] * i[0]) + (i[1] * i[1]));//移動量 ofs << " im: " << im << std::endl; float r = (1 - (o_range / im) ); ofs << " : " << (float)(o_range / im) << std::endl; ofs << " r: " << r << std::endl; std::vector<float> tt(2, 0); tt[0] = (i[0] * r); tt[1] = (i[1] * r); //tt[1] = sqrt((i[1] * r)); //tt[1] += CELL; //pos->pos_y -= CELL; //ofs << "tt[0]: " << tt[0] << std::endl; ofs << "tt[1]: " << tt[1] <<" pos->pos_y: "<<pos->pos_y<< std::endl; if (isGround == false) { ofs << "tt[1]: " << tt[1] << " pos->pos_y: " << pos->pos_y << std::endl; pos->pos_y += tt[1]; ofs <<" pos->pos_y: " << pos->pos_y << std::endl; } isGround = true; } else { } if (isGround == false) { move->pos_y = 29.0; pos->pos_y += move->pos_y; } DrawFormatString(100, 200, GetColor(255, 255, 255), "%d",isGround); } void Draw_Update() { for (int y = 0; y < 100; y++) { for (int x = 0; x < 100; x++) { if (map[y][x] == 1) { DrawGraph(x * 64,y * 64,map_graph[0],true); } } } DrawGraph((int)pos->pos_x,(int)pos->pos_y,player_graph[0],true); } };
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。