オープンフレームワークスをつかった簡単なゲーム作成をしているのですが、以下のソースコードで実行される画面に時間制限機能をつけたいと思っております。
また、時間をテキストとして右上に表示できるようにするにはどのような関数を使えば良いのでしょうか?自分でも調べましたがなかなか出てこず、苦戦しております。ご教授していただけると幸いです。
c++
1#include "ofApp.h" 2 3static const int NUM = 210; 4 5float loc_x[NUM]; 6float loc_y[NUM]; 7float speed_x[NUM]; 8float speed_y[NUM]; 9float radius[NUM]; 10int red[NUM]; 11int blue[NUM]; 12int green[NUM]; 13 14//-------------------------------------------------------------- 15void ofApp::setup(){ 16 ofBackground(0, 0, 0); 17 ofSetFrameRate(60); 18 ofSetCircleResolution(64); 19 ofEnableAlphaBlending(); 20 21 ofTrueTypeFont::setGlobalDpi(72); 22 23 verdana.load("verdana.ttf", 30); // フォントのデータを指定する 24 verdana.setLetterSpacing(1.0); // 文字間を指定する 25 26 for(int i = 0; i < NUM; i++){ 27 loc_x[i] = ofRandom(0, ofGetWidth()); 28 loc_y[i] = ofRandom(0, ofGetHeight()); 29 speed_x[i] = ofRandom(4); 30 speed_y[i] = ofRandom(4); 31 radius[i] = ofRandom(30, 40); 32 red[i] = ofRandom(255); 33 blue[i] = ofRandom(255); 34 green[i] = ofRandom(255); 35 } 36} 37//-------------------------------------------------------------- 38void ofApp::update(){ 39 for(int i = 0; i < NUM; i++){ 40 loc_x[i] = loc_x[i] + speed_x[i]; 41 loc_y[i] = loc_y[i] + speed_y[i]; 42 43 if(loc_x[i] < 0){ 44 speed_x[i] = speed_x[i] * -1; 45 } 46 if(loc_x[i] > ofGetWidth()){ 47 speed_x[i] = speed_x[i] * -1; 48 } 49 if(loc_y[i] < 0){ 50 speed_y[i] = speed_y[i] * -1; 51 } 52 if(loc_y[i] > ofGetHeight()){ 53 speed_y[i] = speed_y[i] * -1; 54 } 55 } 56} 57 58//-------------------------------------------------------------- 59void ofApp::draw(){ 60 for(int i = 0; i < NUM/3; i++){ 61 ofSetColor(60, 255, 0, 200); 62 ofDrawCircle(loc_x[i], loc_y[i], radius[i]); 63 } 64 for(int i = 0; i < NUM/3; i++){ 65 ofSetColor(140, 255, 20, 200); 66 ofDrawCircle(loc_x[i+1], loc_y[i], radius[i]); 67 } 68 for(int i = 0; i < NUM/3; i++){ 69 ofSetColor(200, 255, 40, 200); 70 ofDrawCircle(loc_x[i], loc_y[i+1], radius[i]); 71 } 72 ofSetColor(250, 255, 0, 200); 73 ofDrawCircle(loc_x[1], loc_y[3], radius[3]); 74 75 ofSetColor(30, 200, 200); // 文字色を指定 76 ofDrawBitmapString("Find for Yellow!!", ofGetWidth()-950, ofGetHeight()-700); // 文字とポジションを指定して描画 77} 78 79//-------------------------------------------------------------- 80void ofApp::keyPressed(int key){ 81 82} 83 84//-------------------------------------------------------------- 85void ofApp::keyReleased(int key){ 86 87} 88 89//-------------------------------------------------------------- 90void ofApp::mouseMoved(int x, int y ){ 91 92} 93 94//-------------------------------------------------------------- 95void ofApp::mouseDragged(int x, int y, int button){ 96 97} 98 99//-------------------------------------------------------------- 100void ofApp::mousePressed(int x, int y, int button){ 101 102} 103 104//-------------------------------------------------------------- 105void ofApp::mouseReleased(int x, int y, int button){ 106 107} 108 109//-------------------------------------------------------------- 110void ofApp::mouseEntered(int x, int y){ 111 112} 113 114//-------------------------------------------------------------- 115void ofApp::mouseExited(int x, int y){ 116 117} 118 119//-------------------------------------------------------------- 120void ofApp::windowResized(int w, int h){ 121 122} 123 124//-------------------------------------------------------------- 125void ofApp::gotMessage(ofMessage msg){ 126 127} 128 129//-------------------------------------------------------------- 130void ofApp::dragEvent(ofDragInfo dragInfo){ 131 132} 133
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/23 01:47