[
板情報
|
カテゴリランキング
]
したらばTOP
■掲示板に戻る■
全部
1-100
最新50
|
メール
|
1-
101-
201-
301-
401-
501-
601-
701-
801-
901-
1001-
1101-
1201-
1301-
1401-
1501-
1601-
1701-
1801-
1901-
2001-
2101-
2201-
2301-
2401-
2501-
2601-
2701-
2801-
2901-
3001-
3101-
3201-
3301-
3401-
3501-
3601-
3701-
3801-
3901-
4001-
4101-
4201-
4301-
4401-
4501-
4601-
4701-
4801-
4901-
5001-
5101-
5201-
5301-
5401-
この機能を使うにはJavaScriptを有効にしてください
|
管理人の独り言(プログラミング関連)
2493
:
774さん
:2010/07/23(金) 15:40:42
#include <iostream>
#include <list>
#include <memory>
#include <algorithm>
#include <random>
#include <ctime>
#include <cmath>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#define nullptr NULL
class IShot{
public:
virtual bool Move() = 0;
virtual void Show(SDL_Surface *screen, SDL_Surface *image) = 0;
virtual bool HitTest() = 0;
};
class CShotLine : public IShot{
public:
virtual bool Move(){
m_x += m_v * std::sin(m_rad);
m_y += m_v * std::cos(m_rad);
if(m_x < 0 || m_x > 600 || m_y < 0 || m_y > 300){
return false;
}
return true;
}
virtual void Show(SDL_Surface *screen, SDL_Surface *image){
SDL_Rect rc;
rc.x = m_x;
rc.y = m_y;
SDL_BlitSurface(image, nullptr, screen, &rc);
}
virtual bool HitTest(){
return false;
}
CShotLine(int x, int y, int v, double rad)
: m_x(x), m_y(y), m_v(v), m_rad(rad)
{}
private:
double m_x, m_y;
int m_v;
double m_rad;
};
//関数
int main(int argc, char **argv){
if(SDL_Init(SDL_INIT_VIDEO) < 0) return -1;
SDL_WM_SetCaption("TEST", NULL);
SDL_Surface *screenSurface;
screenSurface = SDL_SetVideoMode(600, 300, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_Surface *image = IMG_Load("shot.png");
std::list<std::unique_ptr<IShot>> shots;
std::mt19937 engine(static_cast<unsigned int>(std::time(nullptr)));
unsigned int i = 0;
for(;;){
{
SDL_Rect dest;
dest.x = 0;
dest.y = 0;
dest.w = 600;
dest.h = 480;
SDL_FillRect(screenSurface, &dest, 0x00000000);
}
shots.emplace_back(new CShotLine(engine() % 600, engine() % 100, engine() % 2 + 1, (double)i++ / 200));
shots.erase(std::remove_if(shots.begin(), shots.end(), [](std::unique_ptr<IShot> &b){return !b->Move();}), shots.end());
std::for_each(shots.begin(), shots.end(), [&](std::unique_ptr<IShot> &b){b->Show(screenSurface, image);});
SDL_Flip(screenSurface);
SDL_Event ev;
while(SDL_PollEvent(&ev)){
switch(ev.type){
case SDL_QUIT:{
return 0;
}
case SDL_KEYDOWN:{
SDLKey *key = &ev.key.keysym.sym;
if(*key == 27){
return false;
}
break;
}
}
}
}
SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
新着レスの表示
名前:
E-mail
(省略可)
:
※書き込む際の注意事項は
こちら
※画像アップローダーは
こちら
(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)
スマートフォン版
掲示板管理者へ連絡
無料レンタル掲示板