コード例 #1
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		//最初のフレームにファイル読み込み
		if ( gFirst ){
			gFirst = false;
			char* buffer = 0;
			int size = 0;
			readFile( &buffer, &size, "bar.dds" );
			gImageHeight = getUnsigned( &( buffer[ 12 ] ) );
			gImageWidth = getUnsigned( &( buffer[ 16 ] ) );
			gImageData = new unsigned[ gImageWidth * gImageHeight ];
			for ( int i = 0; i < gImageWidth * gImageHeight; ++i ){
				gImageData[ i ] = getUnsigned( &( buffer[ 128 + i * 4 ] ) );
			}
		}
		unsigned* vram = videoMemory();
		int windowWidth = width();
		int windowHeight = height();
		int partX = 0;
		int partY = 1;
		//適当に32x32の領域で敷き詰めます。
		for ( int tileY = 0; tileY + 32 < windowHeight; tileY += 32 ){
			for ( int tileX = 0; tileX + 32 < windowWidth; tileX += 32 ){
				for ( int y = 0; y < 32; ++y ){
					for ( int x = 0; x < 32; ++x ){
						unsigned* dst = &vram[ ( tileY + y ) * windowWidth + ( tileX + x ) ];
						*dst = gImageData[ ( partY * 32 + y ) * gImageWidth + ( partX * 32 + x ) ];
					}
				}
				//適当にタイルを選択。数字に根拠はない。
				partX = ( partX + 9973 ) % 4; 
				partY = ( partY + 9967 ) % 4;
			}
		}
	}
コード例 #2
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		unsigned* vram = videoMemory();
		static unsigned i;
		vram[ i ] += i * 100;
		i += 9973; //1万以下最大の素数
		i %= ( width() * height() );
	}
コード例 #3
0
ファイル: main.cpp プロジェクト: hakugenn/test
	void Framework::update(){
		unsigned* vram = videoMemory();
		static unsigned i;
		vram[ 200*width() + 100] = 0xff0000;
		//vram[ i ] += i * 100;
		//i += 9973; //1万以下最大の素数
		//i %= ( width() * height() );
	}
コード例 #4
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		if ( gFirstFrame ){
			gImage = new Image( "background.dds" );
			gFirstFrame = false;
		}
		unsigned* vram = videoMemory();
		int ww = width(); //window width
		int wh = height(); //window height
		//一旦全部真っ黒に
		for ( int i = 0; i < ww * wh; ++i ){
			vram[ i ] = 0;
		}
		int iw = gImage->width(); //image width
		int ih = gImage->height(); //image height
		Vector2 offset;
		offset.x = static_cast< double >( iw ) / 2.0;
		offset.y = static_cast< double >( ih ) / 2.0;
		
		double rotation = static_cast< double >( gCount );
		double sine = sin( rotation );
		double cosine = cos( rotation );
		Matrix22 matrix( cosine, -sine, sine, cosine ); //行列を作って
		//3点作る
		Vector2 a, b, c;
		rotate( &a, Vector2( 0, 0 ), offset, matrix ); //左上
		rotate( &b, Vector2( iw, 0 ), offset, matrix ); //右上
		rotate( &c, Vector2( 0, ih ), offset, matrix ); //左下
		//b-a,c-aを計算
		Vector2 ab, ac;
		ab.setSub( b, a );
		ac.setSub( c, a );
		//補間開始
		double rcpWidth = 1.0 / static_cast< double >( iw );
		double rcpHeight = 1.0 / static_cast< double >( ih );
		for ( int y = 0; y < ih; ++y ){
			double yf = static_cast< double >( y ) + 0.5;
			double v = yf * rcpHeight;
			for ( int x = 0; x < iw; ++x ){
				double xf = static_cast< double >( x ) + 0.5;
				double u = xf * rcpWidth;
				Vector2 p;
				p.setInterporation( a, ab, ac, u, v );
				p -= Vector2( 0.5, 0.5 ); //添え字へ
				int rx, ry;
				rx = round( p.x );
				ry = round( p.y );
				//範囲内なら貼り付け
				if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){
					vram[ ry * ww + rx ] = gImage->pixel( x, y );
				}
			}
		}
		++gCount;

		ostringstream oss;
		oss << frameRate();
		drawDebugString( 0, 0, oss.str().c_str() );
	}
コード例 #5
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		unsigned* vram = videoMemory();
		static int color = 1;
		int pixelNumber = width() * height();
		for ( int i = 0; i < pixelNumber; ++i ){
			vram[ i ] = color;
		}
		color *= 3;
	}
コード例 #6
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		if ( gFirstFrame ){
			gImage = new Image( "background.dds" );
			gFirstFrame = false;
		}
		unsigned* vram = videoMemory();
		int ww = width(); //window width
		int wh = height(); //window height
		//一旦全部真っ黒に
		for ( int i = 0; i < ww * wh; ++i ){
			vram[ i ] = 0;
		}
		int iw = gImage->width(); //image width
		int ih = gImage->height(); //image height
		Vector2 offset;
		offset.x = static_cast< double >( iw ) / 2.0;
		offset.y = static_cast< double >( ih ) / 2.0;
		double rotation = static_cast< double >( gCount );
		double sine = sin( rotation );
		double cosine = cos( rotation );
		Matrix22 matrix( cosine, -sine, sine, cosine );
		for ( int y = 0; y < ih; ++y ){
			for ( int x = 0; x < iw; ++x ){
				//回転先を計算
				int rx, ry;
				rotate( &rx, &ry, x, y, offset, matrix );
				//範囲内なら貼り付け
				if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){
					vram[ ry * ww + rx ] = gImage->pixel( x, y );
				}
			}
		}
		++gCount;

		ostringstream oss;
		oss << frameRate();
		drawDebugString( 0, 0, oss.str().c_str() );
	}
コード例 #7
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		if ( gFirstFrame ){
			setFrameRate( 60 );
			gFirstFrame = false;
			for ( int i = 0; i < 5; ++i ){
				for ( int j = 0; j < 4; ++j ){
					gWall[ i ][ j ].set( 
						48 + i * 64,
						16 + j * 64,
						16 );
				}
				gWall[ i ][ 4 ].set( 48 + i * 64, 16 + 2 * 64 + 32, 16 );
			}
			gPlayer.set( 16, 16, 16 );
		}
		int dx = 0;
		int dy = 0;
		if ( isKeyOn( 'a' ) ){
			dx -= 1;
		}else if ( isKeyOn( 's' ) ){
			dx += 1;
		}
		if ( isKeyOn( 'w' ) ){
			dy -= 1;
		}else if ( isKeyOn( 'z' ) ){
			dy += 1;
		}
		//衝突処理
		unsigned color = 0xffff0000;
		gPlayer.mX += dx;
		gPlayer.mY += dy;
		bool hit = false;
		for ( int i = 0; i < 5; ++i ){
			for ( int j = 0; j < 5; ++j ){
				if ( gPlayer.isIntersect( gWall[ i ][ j ] ) ){
					hit = true;
					color = 0xffffffff;
				}
			}
		}
		if ( hit ) {
			gPlayer.mX -= dx;
			gPlayer.mY -= dy;
		}
		//描画
		unsigned* vram = videoMemory();
		//一旦クリア
		for ( int i = 0; i < width() * height(); ++i ){
			vram[ i ] = 0;
		}
		//動かないほう描画
		for ( int i = 0; i < 5; ++i ){
			for ( int j = 0; j < 5; ++j ){
				for ( int y = 0; y < 32; ++y ){
					for ( int x = 0; x < 32; ++x ){
						int tx = x + gWall[ i ][ j ].mX - 16;
						int ty = y + gWall[ i ][ j ].mY - 16;
						vram[ ty * width() + tx ] = 0xff00ff00;
					}
				}
			}
		}
		//動くほう描画
		for ( int y = 0; y < 32; ++y ){
			for ( int x = 0; x < 32; ++x ){
				int tx = x + gPlayer.mX - 16;
				int ty = y + gPlayer.mY - 16;
				vram[ ty * width() + tx ] = color; 
			}
		}
	}
コード例 #8
0
ファイル: main.cpp プロジェクト: rainbow23/GameLib2008
	void Framework::update(){
		if ( gFirstFrame ){
			gImage = new Image( "background.dds" );
			gFirstFrame = false;
		}
		unsigned* vram = videoMemory();
		int ww = width(); //window width
		int wh = height(); //window height
		//一旦全部真っ黒に
		for ( int i = 0; i < ww * wh; ++i ){
			vram[ i ] = 0;
		}
		int iw = gImage->width(); //image width
		int ih = gImage->height(); //image height

		//行列を作ろう
		double rotation = static_cast< double >( gCount );
		//画像中心を原点に、拡大、回転、中心を戻す、の順。
		Matrix23 translationMatrix1;
		Matrix23 scalingMatrix;
		Matrix23 rotationMatrix;
		Matrix23 translationMatrix2;
		//移動1(画像中心を原点に)
		translationMatrix1.setTranslation( Vector2( -iw/2, -ih/2 ) );
		//拡大
		Vector2 scale( sin( rotation )*2.0 + 1.0, cos( rotation )*2.0 + 1.0 );
		scalingMatrix.setScaling( Vector2( scale.x, scale.y ) );
		//回転
		rotationMatrix.setRotation( rotation );
		//戻す
		translationMatrix2.setTranslation( Vector2( iw/2, ih/2 ) );
		//行列の統合(逆順)
		Matrix23 transform;
		transform = translationMatrix2;
		transform *= rotationMatrix;
		transform *= scalingMatrix;
		transform *= translationMatrix1;

		//3点作る
		Vector2 a, b, c;
		transform.multiply( &a, Vector2( 0, 0 ) );
		transform.multiply( &b, Vector2( iw, 0 ) );
		transform.multiply( &c, Vector2( 0, ih ) );
		//b-a,c-aを計算
		Vector2 ab, ac;
		ab.setSub( b, a );
		ac.setSub( c, a );
		//補間開始
		double rcpWidth = 1.0 / static_cast< double >( iw );
		double rcpHeight = 1.0 / static_cast< double >( ih );
		for ( int y = 0; y < ih; ++y ){
			double yf = static_cast< double >( y ) + 0.5;
			double v = yf * rcpHeight;
			for ( int x = 0; x < iw; ++x ){
				double xf = static_cast< double >( x ) + 0.5;
				double u = xf * rcpWidth;
				Vector2 p;
				p.setInterporation( a, ab, ac, u, v );
				p -= Vector2( 0.5, 0.5 ); //添え字へ
				int rx, ry;
				rx = round( p.x );
				ry = round( p.y );
				//範囲内なら貼り付け
				if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){
					vram[ ry * ww + rx ] = gImage->pixel( x, y );
				}
			}
		}
		++gCount;

		ostringstream oss;
		oss << frameRate();
		drawDebugString( 0, 0, oss.str().c_str() );
	}