ページ 1 / 1
[雑談]んん、書き込みが消えてるぞ。
Posted: 2020年7月27日(月) 20:19
by あたっしゅ
viewtopic.php?f=3&t=20942
c++ マウスを使ったゲーム - ミクプラ(ja)
に影響を受けた書き込みが消えてるぞ。
まぁ、ここは、質問に答える場であって、質問の名を借りた「俺の考えたゲームの制作代行」をする場ではないから。
今日はとりあえず、Embarcadero® C++Builder 10.3 コミュニティ版で for_each 使ってみたぽ。
Re: [雑談]んん、書き込みが消えてるぞ。
Posted: 2020年7月30日(木) 07:11
by あたっしゅ
コード:
#include <vector>
#include <algorithm>
#include <functional>
class TObj {
public:
TObj() {}
virtual TObj() {}
virtual void draw() {}
};
class TPlayer: public TObj {
public:
TPlayer() {}
virtual TPlayer() {}
virtual void draw() {}
};
int
main()
{
std::vector<TObj*> objs;
objs.push_back( new TObj() );
objs.push_back( new TObj() );
objs.push_back( nrew TPlayer() );
#if 0
for( auto&& x:objs ) {
x->draw();
}
#else
for_each( objs.begin(), objs.end(), std::mem_fun(TObj::draw) );
#endif
}
デコンストラクタを、スマートに書きたい。
Re: [雑談]んん、書き込みが消えてるぞ。
Posted: 2020年7月30日(木) 20:49
by あたっしゅ
今度は、
https://www.onlinegdb.com/ で実行できるのを確認済み。
コード:
#include <vector>
#include <algorithm>
#include <functional>
class TObj {
public:
TObj() {}
virtual ~TObj() {}
virtual void draw() {}
};
class TPlayer: public TObj {
public:
TPlayer() {}
virtual ~TPlayer() {}
virtual void draw() {}
};
int
main()
{
using namespace std;
TObj objs[ 3 ];
TPlayer player;
vector<TObj*> all;
all.push_back( objs );
all.push_back( &player );
for( auto&& x:all ) { x->draw(); }
return 0;
}
// end.
Re: [雑談]んん、書き込みが消えてるぞ。
Posted: 2020年8月05日(水) 19:22
by あたっしゅ
俺のプログラミング・ブログ・スレッドへ、ようこそ。
viewtopic.php?f=3&t=20935
c++ 玉の反射について - プログラマ専用SNS ミクプラ(ja)
> 最も手っ取り早い(しかし,しょぼい,ごまかし的な)方法の1つとして,2つの弾の速度を入れ替えるというものがある.
とりあえず、「2つの弾の速度を入れ替える」実装をしてみた。
コード:
for( int i=0; i<MAX-1; i++ ) {
for( int j=i+1; j<MAX; j++ ) {
if(
abs(objs[ i ].m_x - objs[ j ].m_x )*2
+ abs( objs[ i ].m_y - objs[ j ].m_y )*2 < 100
) {
float tmpv = objs[ i ].m_vx;
objs[ i ].m_vx = objs[ j ].m_vx;
objs[ j ].m_vx = tmpv;
tmpv = objs[ i ].m_vy;
objs[ i ].m_vy = objs[ j ].m_vy;
objs[ j ].m_vy = tmpv;
}
}
}
物理るのではなく、エフェクトるのが目的なので、これでいいか。