Page 1 of 2

Tiles and sprites question

Posted: Mon Dec 28, 2015 9:44 am
by Ced2911
Hi, i have some questions about tiles and sprites collision.

What is the best way to handle tile drawing ?
Use the PLAN_A and draw all the tiles on it ?
Or draw all tiles like a sprite ?

How do you detect player and tiles collision ?
Are you looking for all tiles in the screen ?
Are you looking for the 9 titles around the player ? (3 rows x 3 columns)

Thank you :D

Re: Tiles and sprites question

Posted: Wed Dec 30, 2015 12:08 pm
by Ced2911
:) so i found how to deal with tile and sprite collision :)

Based on sprite sample

Code: Select all



typedef struct  {
	u16 col_x;
	u16 col_y;
	u16 tile;
} collision_info_t;

static u16 checkTileXCollision(u16 x, u16 y0, u16 y1, collision_info_t * coll) {
	u16 tile = 0;
	u16 y;

	for(y = y0; y <= y1; y++) {
		tile = MAP_getTile(&MyLevel, x, y, 0);
		if (tile) {
			coll->col_x = x;
			coll->col_y = y;
			coll->tile = tile;
			return tile;
		}
	}
	return tile;
}


static u16 checkTileYCollision(u16 y, u16 x0, u16 x1, collision_info_t * coll) {
	u16 tile = 0;
	u16 x;

	for(x = x0; x <= x1; x++) {
		tile = MAP_getTile(&MyLevel, x, y, 0);
		if (tile) {
			coll->col_x = x;
			coll->col_y = y;
			coll->tile = tile;
			return tile;
		}
	}
	return tile;
}

static void updateTileCollision() {

	// @todo use boundingbox
	#define BOX_X	16
	#define BOX_W	16
	#define BOX_H	40

	    s16 __xr = ((fix32ToInt(posx) + BOX_W + BOX_X)  >>3);
	    s16 __xl = ((fix32ToInt(posx) + BOX_X) >>3);
		s16 __y = (fix32ToInt(posy)>>3);
		s16 __yb = ((fix32ToInt(posy)+ BOX_H) >>3);

		collision_info_t col= {};
		u16 left = 0;
		u16 right = 0;
		u16 bottom = 0;
		u16 top = 0;

		// XAXIS
		// Left
		if (checkTileXCollision(__xl, __y, __yb-1, &col)) {
			posx = FIX32((col.col_x<<3) - 8);
			movx = 0;
		}
		// Right
		else if (checkTileXCollision(__xr, __y, __yb-1, &col)) {
			u16 m = (col.col_x<<3) - BOX_X - BOX_W;
			posx = FIX32(m);
			movx = 0;
		}

		// YAXIS
		if (movy>0 && checkTileYCollision(__yb, __xl, __xr, &col)) {
			posy = FIX32((col.col_y<<3) - BOX_H);
			movy = 0;
		}

		if (left || right/* || bottom*/) {
			VDP_drawText("COLL", 5, 0);
		} else {
			VDP_drawText("NO_C", 5, 0);
		}
}


Now i have some other questions :)
How to deal with map and plan scrolling ?
Do i need to refresh the plan in a vblank ?

Re: Tiles and sprites question

Posted: Wed Dec 30, 2015 2:06 pm
by Stef
Your questions are such generic and basics that we can't really reply them in a fast way, dealing with collision is up to the developer and many solutions exists for instance ! I think you search in the forum, i guess many of your questions has already been replied or at least discussed :)
SGDK provide methods to deal with MAP and scrolling :

https://github.com/Stephane-D/SGDK/blob ... c/vdp_bg.h This unit contains methods to set scrolling on bg plan (A and B)
https://github.com/Stephane-D/SGDK/blob ... vdp_tile.h This unit contains methods to set MAP infos (with VDP_setMap(..) or VDP_setMapEx(..) for instance).

Re: Tiles and sprites question

Posted: Sat Jan 09, 2016 9:32 pm
by alko
How to remove fonts from VDP-RAM ?
Not enough space for a boss-sprite.
Image

Re: Tiles and sprites question

Posted: Sat Jan 09, 2016 10:56 pm
by tryphon
Simply overwrite ?

Re: Tiles and sprites question

Posted: Sat Jan 09, 2016 10:58 pm
by Stef
It depends about which methods you are using in your code to load your gfx data to VRAM but normally you are free to overwrite the font space if you really want to, but then you won"t be able to display number or string for debug stuff :-/

Re: Tiles and sprites question

Posted: Sun Jan 10, 2016 9:44 am
by tryphon
It's better to use KDebug methods anyway :)

Re: Tiles and sprites question

Posted: Sun Jan 10, 2016 1:42 pm
by alko
Incidentally, in this case, it would be useful mirror of plane.
Twice would save memory of VDP-RAM, due with a symmetric background.

Re: Tiles and sprites question

Posted: Sun Jan 10, 2016 9:03 pm
by Stef
Mirror of plane exists and are supported by hardware, rescomp does it automatically if your background image is correctly done :)

Re: Tiles and sprites question

Posted: Sun Jan 10, 2016 9:19 pm
by alko
But are stored in VRAM two symmetrical parts of the image.

Image

Re: Tiles and sprites question

Posted: Mon Jan 11, 2016 9:50 am
by Stef
What did you used to generate the image resource ? and the symmetry should be aligned on tile (8 pixels blocks) else it cannot be optimized.

Re: Tiles and sprites question

Posted: Mon Jan 11, 2016 10:27 am
by alko
I painted in the paint-dot-net, then through the photoshop - was save in 16с palette.
image size 240*64 - It must be divisible by 8.

Image

Re: Tiles and sprites question

Posted: Mon Jan 11, 2016 4:17 pm
by Stef
and you imported it in binary form with rescomp ?

Re: Tiles and sprites question

Posted: Mon Jan 11, 2016 5:02 pm
by alko
Yes of course.
ResComp 1.3 (november 2014)
Stephane Dallongeville
Image

Re: Tiles and sprites question

Posted: Mon Jan 11, 2016 6:59 pm
by Stef
Can you show me the content of your .res file and the code you used to display the background ?