#64778 - vexon - Mon Dec 26, 2005 6:45 pm
hello, I've been working on my first GBA game today which I'm planning to complete :p.
I'm currently having some issues with the movement of the cluster which contains the blocks which are moved individual and are also represented by an array. Could someone please help me out by saying what should be changed in my code to get the blocks moving properly?
the link to the GBA file here
here's the code.. I'm using the HAMlib:
Thanks in advance :)[/url]
I'm currently having some issues with the movement of the cluster which contains the blocks which are moved individual and are also represented by an array. Could someone please help me out by saying what should be changed in my code to get the blocks moving properly?
the link to the GBA file here
here's the code.. I'm using the HAMlib:
Code: |
#include <mygba.h>
//GFX INCLUDES - START// #include "GFX\master.pal.c"; //titlescreen #include "GFX\title_screen.raw.c"; #include "GFX\title_screen.map.c"; //logo screen (credits) //game bg #include "GFX\game_bg.raw.c"; #include "GFX\game_bg.map.c"; //block #include "GFX\block.raw.c"; //GFX INCLUDES - END// //GLOBAL VARIABLES - START// bool bAddcluster = true; char* keypressed; int speed = 1; int speedmultiplier = 0; int controlspeed = 0; int score = 0; int time = 0; u8 tickcount=0; u8 block[16]; u8 staticblock[120]; u8 currentstaticblock=0; u8 block_y[16]; u8 block_x[16]; char* clustertype; u8 clusterpos_x; u8 clusterpos_y; int completerow; char field[13][10]; //rows, colls //GLOBAL VARIABLES - END// //FUNCTION PROTOTYPES - START// void tick(); //every frame (60 a second) void update(); //updates movement void proces_input(); //looks for input and what to do then void addcluster(); //adds a another block combination to fall from the sky void clusterfall(); //let's a cluster drop void rotatecluster(); //rotate that cluster 90 degrees void createcluster(char* type); //create a new cluster int movecluster(); //move cluster int checkrow(); //check if there's a full row void makestatic(); //deactivate the cluster if it's grounded void checkcollision(); //check for collision to see it can be made static. //FUNCTION PROTOTYPES - END// //FUNCTION DECLARATIONS - START// int main(void) { for(int fillfield = 0; fillfield <= 10; fillfield++){ field[fillfield][13] = 1; } map_fragment_info_ptr bg_game; map_fragment_info_ptr bg_title_screen; ham_Init(); ham_SetBgMode(1); ham_LoadBGPal((void*)master_Palette,256); ham_LoadObjPal((void*)master_Palette,256); ham_bg[0].ti = ham_InitTileSet((void*)title_screen_Tiles, SIZEOF_16BIT(title_screen_Tiles),1,1); ham_bg[0].mi = ham_InitMapEmptySet(3,0); bg_title_screen = ham_InitMapFragment((void*)title_screen_Map, 30,20,0,0,30,20,0); ham_InsertMapFragment(bg_title_screen,0,0,0); ham_InitBg(0,1,1,0); while(!F_CTRLINPUT_A_PRESSED) { //show logo :) } ham_ResetBg(); //ham_InitText(1); ham_SetBgMode(1); ///ham_SetTextCol(000, 000); // Setup the tileset for our image ham_bg[1].ti = ham_InitTileSet((void*)game_bg_Tiles, SIZEOF_16BIT(game_bg_Tiles),1,1); // Setup the map for our image ham_bg[1].mi = ham_InitMapEmptySet(3,0); bg_game = ham_InitMapFragment((void*)game_bg_Map, 30,20,0,0,30,20,0); ham_InsertMapFragment(bg_game,1,0,0); // Display the background ham_InitBg(1,1,0,0); ham_StartIntHandler(INT_TYPE_VBL,(void*)&tick); while(1) { //keep in eternal looopy } ham_ResetAll(); return 0; } void tick(){ if(speedmultiplier >= 20){ //DEBUG START ham_VBAText("crap"); //DEBUG END addcluster(); clusterfall(); speedmultiplier = 0; } checkcollision(); proces_input(); speedmultiplier += speed; update(); completerow = checkrow(); ham_CopyObjToOAM(); } void update(){ for(int blockN = 0; blockN <= 16; blockN++){ ham_SetObjX(block[blockN],block_x[blockN]); ham_SetObjY(block[blockN],block_y[blockN]); } ham_DrawText(50,180,"00:01"); } void proces_input(){ if(controlspeed > 5){ if(F_CTRLINPUT_UP_PRESSED) { //if (block_y[blockN] > 0) block_y[blockN]-=12; rotatecluster(); } if(F_CTRLINPUT_DOWN_PRESSED) { for(int blockN = 0; blockN <= 16; blockN++){ if (block_y[blockN] < 140){ block_y[blockN]+=12; } } } if(F_CTRLINPUT_LEFT_PRESSED) { for(int blockN = 0; blockN <= 16; blockN++){ if (block_x[blockN] > 60){ block_x[blockN]-=12; } } } if(F_CTRLINPUT_RIGHT_PRESSED) { for(int blockN = 0; blockN <= 16; blockN++){ if (block_x[blockN] < 168){ block_x[blockN]+=12; } } } controlspeed = 0; } controlspeed++; } void addcluster(){ if(bAddcluster == true){ createcluster("L"); bAddcluster = false; } } void rotatecluster(){ //NU DOEN!! for(int blockN = 0; blockN <= 16; blockN++){ block_y[blockN]-=12; block_y[blockN]+=12; block_x[blockN]-=12; block_x[blockN]+=12; } } void clusterfall(){ for(int blockN = 0; blockN <= 16; blockN++){ block_y[blockN]+=12; } for(int row = 0; row <= 12; row++){ //check each row for(int column = 0; column <= 10; column++){ //check each column if(field[row][column] == 2){ field[row][column-1] = 2; field[row][column] = 0; break; } } } } void createcluster(char* type){ clustertype = type; if(type == "L"){ char Lclustershape[4][4] = {{0,2,0,0},{0,2,0,0},{0,2,2,0},{0,0,0,0}}; int Crow = 0; int Ccol = 0; for(int row = 13; row >= 8; row--){ //check each row for(int column = 2; column < 7; column++){ //check each column field[row][column] = Lclustershape[Crow][Ccol]; Ccol++; } Crow++; } clusterpos_x = 120; clusterpos_y = 0; block_x[1] = clusterpos_x; block_y[1] = clusterpos_y; block_x[2] = clusterpos_x; block_y[2] = clusterpos_y+12; block_x[3] = clusterpos_x; block_y[3] = clusterpos_y+24; block_x[4] = clusterpos_x+12; block_y[4] = clusterpos_y+24; block[1] = ham_CreateObj((void*)block_Bitmap, 0, 1,OBJ_MODE_NORMAL,1,0,0,0,0,0,0, block_x[1],block_y[1]); block[2] = ham_CreateObj((void*)block_Bitmap, 0, 1,OBJ_MODE_NORMAL,1,0,0,0,0,0,0, block_x[2],block_y[2]); block[3] = ham_CreateObj((void*)block_Bitmap, 0, 1,OBJ_MODE_NORMAL,1,0,0,0,0,0,0, block_x[3],block_y[3]); block[4] = ham_CreateObj((void*)block_Bitmap, 0, 1,OBJ_MODE_NORMAL,1,0,0,0,0,0,0, block_x[4],block_y[4]); } } int checkrow(){ int fullrow; for(int row = 0; row <= 12; row++){ //check each row if(fullrow == -1){ for(int column = 0; column <= 10; column++){ //check each column if(field[row][column] == 0){ fullrow = -1; break; }else{ fullrow = row; } } }else{ break; } } return fullrow; } void makestatic(){ for(int blockN = 0; blockN <= 16; blockN++){ staticblock[currentstaticblock] = block[blockN]; block[blockN] = 0; currentstaticblock++; } for(int row = 0; row <= 12; row++){ //check each row for(int column = 0; column <= 10; column++){ //check each column if(field[row][column] == 2){ field[row][column] = 1; } } } bAddcluster=true; } void checkcollision(){ for(int row = 0; row < 13; row++){ //check each row for(int column = 0; column <= 10; column++){ //check each column if(field[row][column] == 2){ if(field[row][column+1] == 1){ makestatic(); break; } }else{ } } } } //FUNCTION DECLARATIONS - END// |
Thanks in advance :)[/url]