Jump to content
Bochum_Boy

Creating a Level Loader

Recommended Posts

Hi,

 

for my project I try to create a level loader. The routine should load an array with information how to prepopulate a level. 

 

So, I create a set of level arrays that are loaded and then applied to my screen. This is done in lines 276 - 298. During initalization, in the draw level routine, the array is interpreted in the DrawBoard routine. 

 

Now,  I got two problems:

 

1) The balls never occur on my screen, thus the level is not prepopulated.

2) Is there a chance to create instances of objects instead of copying the structures. Example: I want to have 5 instances of red balls without creating manually those five objects. 

 

I attached my code as is:

 

 

#include <lynx.h>
#include <conio.h>
#include <tgi.h>
#include <joystick.h>
#include <6502.h>
#include <stdlib.h>
#include <_mikey.h>
#include <_suzy.h>
#include <time.h>



#define MIKEY (*(struct __mikey *)0xFD00)


//Bear Sprite
unsigned char bb_w1[] = {
	0xd,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xbb, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0xb, 0xb0, 0x0, 0xbb, 0x55, 0xbb, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0xb, 0xb5, 0x5b, 0xbb, 0xbb, 0xbb, 0x55, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x5, 0x55, 0x5b, 0xb8, 0x88, 0x88, 0x88, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0xb, 0xb8, 0x88, 0x88, 0x88, 0xbb, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0xb, 0xb8, 0x8b, 0xb8, 0x88, 0x55, 0xaa, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0xb, 0xb8, 0x88, 0x85, 0x55, 0x55, 0x55, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0xb, 0xbb, 0xb8, 0x85, 0x55, 0x55, 0x55, 0x0, 0x0, 0x0, 
	0xd,   0x0, 0x0, 0x88, 0x88, 0xbb, 0xb5, 0x55, 0x55, 0x0, 0x0, 0x0, 0x0, 
	0xd,   0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 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00
	};


	unsigned char ball_w[] = {
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x1, 0x10, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x11, 0x11, 0x0, 0x0, 
	0x7,   0x0, 0x1, 0x1f, 0x11, 0x10, 0x0, 
	0x7,   0x0, 0x1, 0x11, 0x11, 0x10, 0x0, 
	0x7,   0x0, 0x0, 0x11, 0x11, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x1, 0x10, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00
	};


unsigned char ball_g[] = {
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x9, 0x90, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x99, 0x99, 0x0, 0x0, 
	0x7,   0x0, 0x9, 0x99, 0x99, 0x90, 0x0, 
	0x7,   0x0, 0x9, 0x99, 0x99, 0x90, 0x0, 
	0x7,   0x0, 0x0, 0x99, 0x99, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x9, 0x90, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00
	};


unsigned char ball_y[] = {
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x9, 0x90, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x99, 0x99, 0x0, 0x0, 
	0x7,   0x0, 0x9, 0x99, 0x99, 0x90, 0x0, 
	0x7,   0x0, 0x9, 0x99, 0x99, 0x90, 0x0, 
	0x7,   0x0, 0x0, 0x99, 0x99, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x9, 0x90, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00
	};

unsigned char empty[] = {
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
	0x7,   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00
};

char* Screen[7][7];

char level_1[7][7] =
{
	{9, 9, 1, 1, 1, 9, 9},
	{9, 9, 1, 1, 1, 9, 9},
	{1, 1, 1, 1, 1, 1, 1},
	{1, 1, 1, 0, 1, 1, 1},
	{1, 1, 1, 1, 1, 1, 1},
	{9, 9, 1, 1, 1, 9, 9},
	{9, 9, 1, 1, 1, 9, 9},
};

char level_2[7][7] =
{
	{9, 9, 1, 1, 1, 9, 9},
	{9, 9, 1, 1, 1, 9, 9},
	{1, 1, 2, 1, 2, 1, 1},
	{1, 1, 2, 2, 1, 1, 1},
	{1, 1, 1, 2, 1, 1, 1},
	{9, 9, 1, 1, 1, 9, 9},
	{9, 9, 1, 1, 1, 9, 9},
};

//Arrays of sprites
    
char* bb_spritedata[] =
{
	bb_w0, bb_w1,
    bb_t0, bb_t1
};



//Struct of Bear
typedef struct {
  char depository;
  SCB_REHVST_PAL sprite;
  unsigned char run_index;
  signed int lives;
  signed int crystals;
  unsigned char jump_index;
} sprite_t;

//Struct of Soil
typedef struct {
  char depository;
  SCB_REHVST_PAL sprite;
  signed char index;
} soil_t;


//Struct of Crystal
typedef struct {
  char depository;
  SCB_REHVST_PAL sprite;
  signed char hvel;
  signed char vvel;
} ballsprite_t;



//Spritepacks
sprite_t BBear = {
    0x0,
    {
    BPP_4 | TYPE_NORMAL,REHVST | LITERAL,
    0x02,
	0,
    bb_w0,
    80, 75,
    0x100, 0x100,
    0x000, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
},0,5,5,0
};

soil_t SSoil_Bottom = {0x0,
    {
    BPP_4 | TYPE_BACKGROUND ,REHVST | LITERAL,
    0x05,
	0,
    soil_0,
    1, 99,
    0x400, 0x100,
    0x100, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
    },0
};




ballsprite_t CCrystal = {
    0x0,
    {
    BPP_4 | TYPE_NORMAL,REHVST | LITERAL,
    0x3,
    0,
    ball_r,
    5, 75,
    0x100, 0x100,
    0x000, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
},5,2,
};

ballsprite_t Ball_red = {
    0x0,
    {
    BPP_4 | TYPE_NORMAL,REHVST | LITERAL,
    0x3,
    0,
    ball_r,
    0, 0,
    0x100, 0x100,
    0x000, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
},0,0,
};


ballsprite_t Ball_green = {
    0x0,
    {
    BPP_4 | TYPE_NORMAL,REHVST | LITERAL,
    0x3,
    0,
    ball_g,
    0, 0,
    0x100, 0x100,
    0x000, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
},0,0,
};

ballsprite_t Ball_empty = {
    0x0,
    {
    BPP_4 | TYPE_NORMAL,REHVST | LITERAL,
    0x3,
    0,
    empty,
    0, 0,
    0x100, 0x100,
    0x000, 0x000,
    {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}
},0,0,
};




//Variables
signed char Run_Index = 0;

signed int  Score = 0;
unsigned int hasInit_level = 0;


unsigned char joy,ticks;

char text[20];

signed int  cannon_pos = 0;
signed int  x_dir = 0;
signed int y_dir = 10;

// cell size
int squareWidth  = 10;
int squareHeight = 10;

// Level size
int width = 7;
int height = 7;



static void WaitTicks(int t) {
	int i;
	for (i=0; i < t; i++) { ; }
}


int check_pos(int pos) {
	if (abs(pos) > 90) {
		if(pos< -90) {pos = -90;}
		if(pos> 90) {pos = 90;}
	}

	return pos;
}

int get_x_dir(int pos) {

	signed int dir;
	
	if (pos < 0) {

		if(pos < -75) {
			dir = -5;
		}

		if (pos < -60 && pos >= -75) {
			dir = -4;
		}
		
		if (pos < -40 && pos >= -60) {
			dir = -3;
		}

		if (pos < -20 && pos >= -40) {
			dir = -2;
		}

		if (pos < 0 && pos >= -20) {
			dir = -1;
		}

	}
	else {
		
		if(pos > 75) {
			dir = 5;
		}

		if (pos > 60 && pos <= 75) {
			dir = 4;
		}
		
		if (pos > 40 && pos <= 60) {
			dir = 3;
		}

		if (pos > 20 && pos <= 40) {
			dir = 2;
		}

		if (pos > 0 && pos <= 20) {
			dir = 1;
		}
	}

	if (pos == 0) {
		dir = 0;
	}

	return dir;
}

// Routine to load level
void LoadLevel(int level) {
	int i, j;
	if (level == 1) {
		for (i=0; i < 7; i++) {
			for (j=0; j < 7; j++) {
				Screen[i][j] = level_1[i][j];
				WaitTicks(5);
			}
		}
	}

	
}

void DrawBoard() {
	int i, j;
	for (i=0; i < width; i++) {
		for (j=0; j < height; j++) {


			// game board
			if (level_1[i][j] == 1 ) {
				Ball_green.sprite.hpos = i*squareWidth;
				Ball_green.sprite.vpos = j*squareHeight;
				tgi_sprite(&Ball_green);

			}

			
			else if (level_1[i][j] == 9){
				Ball_red.sprite.hpos = i*squareWidth;
				Ball_red.sprite.vpos = j*squareHeight;
				tgi_sprite(&Ball_red);
			}
			else {
				Ball_red.sprite.hpos = i*squareWidth;
				Ball_red.sprite.vpos = j*squareHeight;
				tgi_sprite(&Ball_empty);

			}
		}
	}

	hasInit_level = 1;
}

//Routine to create level
void draw_level(){
   
   //Soil_Sprite
   tgi_sprite(&SSoil_Bottom.sprite);
   // Create Level

   if( hasInit_level == 0 ) {
   		LoadLevel(1);
		DrawBoard();
   }
}





//Win

void victory(int Score){
    tgi_clear();
	itoa(Score, &text[0],10);
    tgi_outtextxy(50,10,text);
    tgi_outtextxy(50,50,"Won!");
 
}




void game(void)
{       
        char buffer[16];
        clock_t now = clock();
        
        

        while (1) {
        
        
        
        if (!tgi_busy()) {
            
            tgi_clear();
            
            tgi_setcolor(COLOR_GREEN);
            tgi_outtextxy(0, 0, "WIP");
            
            
               
            //Draw level
            draw_level();
            
            //Get input
            joy = joy_read(JOY_1);
            
            
            //Reset sprite collindex
            BBear.sprite.sprcoll = 0x02;
            
    
    
        //Movements
        if (JOY_BTN_RIGHT(joy)) {
			cannon_pos += 5;
			cannon_pos = check_pos(cannon_pos);

        }
        
        if (JOY_BTN_LEFT(joy)) {
			cannon_pos -= 5;
			cannon_pos = check_pos(cannon_pos);
            }
        
        if (JOY_BTN_DOWN(joy)) {
			Run_Index--;
        }
        
        //Jumping
        if (JOY_BTN_UP(joy)) {
			Run_Index--;
        }

		//Fire the Crystal
        if (JOY_BTN_FIRE(joy)) {
            CCrystal.sprite.hpos = BBear.sprite.hpos;
            CCrystal.sprite.vpos = BBear.sprite.vpos;
			x_dir = get_x_dir(cannon_pos);

			CCrystal.vvel = -1;
			CCrystal.hvel = x_dir;

        }

		//Vertical movement regardless direction of
        CCrystal.sprite.vpos += CCrystal.vvel;
		CCrystal.sprite.hpos += CCrystal.hvel;
		WaitTicks(50);


        
        
        
    //Draw collidable sprites
    tgi_sprite(&CCrystal.sprite);    
    tgi_sprite(&BBear.sprite);
    
    
    //Debugging text
    itoa(Score, &buffer[0],10);
    tgi_outtextxy(30, 0, buffer);
    
    //itoa(BBear.lives, &buffer[0],10);
	itoa(cannon_pos, &buffer[0],10);
    tgi_outtextxy(70, 0, buffer);
    
    itoa(y_dir, &buffer[0],10);
    tgi_outtextxy(120, 0, buffer);
                
    tgi_updatedisplay();
        }
    }
}


 

 

 

Share this post


Link to post
Share on other sites

I'm reading you code on my mobile so can't analyse it deeply, but can say two things.

 

If you care performances avoid structures with cc65 when you can.

 

Since sprites are structures, defining arrays of structures that contain sprites is not a good idea IMHO.

 

Second, if you draw sprites that reuse the palette, check if the first Sprite of the new frame has a palette, or nothing is going to be drawn.

Share this post


Link to post
Share on other sites

It depends on how much you care about performance... when I wrote Remnant for the Lynx in C, oh, 19 years ago, I did use structs to define sprites. In fact, I would just declare a static array of X number of sprites, then manually link the SCBs together at runtime in the game based on what was onscreen. Never had any performance issues, but I also did not heavily utilize interrupts either in that game.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...