TEST, why cannot i post long text?
I've been in trouble with gdk, i dont know the GDK's Coordinate,It makes me very uncomfortable。i post my code and res, hope Master can hope me...
I am very sorry my English level, i wish u can know me
CODE:
#include "DarkGDK.h"
int Y_MAX = 0, X_MAX = 0;
float vx = 0, vy = 0, vz = 0;
int MapData[100][100];
bool Load_Map_data(void){
FILE *fp;
bool fok = false;
fp = fopen("map2.dat","r");
if (fp != NULL){
fscanf(fp,"%d",&Y_MAX);
fscanf(fp,"%d",&X_MAX);
int z;
for(z = Y_MAX-1; z > -1; z--) {
int x = 0;
//while(x++ < X_MAX){
for(x = 0; x < X_MAX; x++){
fscanf(fp,\"%d\",& MapData[z][x]);
}
}
fclose(fp);
}else{
return false;
}
//load res
dbLoadImage("res.bmp", 1);//block
dbColorBackdrop (dbRGB(0, 0, 0));
return true;
}
void DrawMap(){
dbMakeMatrix(1, 2*40, 2*40, X_MAX, Y_MAX);
dbPositionMatrix (1, 0, 0, 0);
dbPrepareMatrixTexture (1, 1, 2, 1);//
dbGhostMatrixOn (1);
for(int z = Y_MAX-1; z > -1; z--){
int x = 0;
//while(x++ < X_MAX){
for(x = 0; x < X_MAX; x++){
if(MapData[z][x] == 1){
dbSetMatrixTile(1, x, z, 1);//
}else if(MapData[z][x] == 0){
dbSetMatrixTile(1, x, z, 2);//
}
}
}
}
void UpdateMap(){
dbUpdateMatrix ( 1 );
}
void SetView(float x, float y, float z){
dbPositionCamera(x, y, z);
dbPointCamera (0, 0, 0);//??
}
void DarkGDK ( void ){
dbSyncOn ( );
dbSyncRate ( 60 );
if(!Load_Map_data())
return;
DrawMap();
vx = 0; vy = 0; vz = 0;
SetView(vx, vy, vz);
while ( LoopGDK ( ) ){
if ( dbEscapeKey ( ) )
return;
if(dbUpKey()){
vx = vx;
vy = 10;
vz += 10;
}
if(dbDownKey()){
vx = vx;
vy = 10;
vz -= 10;
}
if(dbLeftKey()){
vx -= 10;
vy = 10;
vz = vz;
}
if(dbRightKey()){
vx += 10;
vy = 10;
vz = vz;
}
SetView(vx, vy, vz);
UpdateMap();
dbSync ( );
}
return;
}
map data and bitmap res in Attachment
newer