Tiles and sprites question

SGDK only sub forum

Moderator: Stef

Ced2911
Newbie
Posts: 5
Joined: Tue Apr 14, 2015 8:15 am
Location: France

Tiles and sprites question

Post by Ced2911 » Mon Dec 28, 2015 9:44 am

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

Ced2911
Newbie
Posts: 5
Joined: Tue Apr 14, 2015 8:15 am
Location: France

Re: Tiles and sprites question

Post by Ced2911 » Wed Dec 30, 2015 12:08 pm

:) 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 ?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Wed Dec 30, 2015 2:06 pm

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).

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Tiles and sprites question

Post by alko » Sat Jan 09, 2016 9:32 pm

How to remove fonts from VDP-RAM ?
Not enough space for a boss-sprite.
Image
Image

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: Tiles and sprites question

Post by tryphon » Sat Jan 09, 2016 10:56 pm

Simply overwrite ?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Sat Jan 09, 2016 10:58 pm

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 :-/

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: Tiles and sprites question

Post by tryphon » Sun Jan 10, 2016 9:44 am

It's better to use KDebug methods anyway :)

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Tiles and sprites question

Post by alko » Sun Jan 10, 2016 1:42 pm

Incidentally, in this case, it would be useful mirror of plane.
Twice would save memory of VDP-RAM, due with a symmetric background.
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Sun Jan 10, 2016 9:03 pm

Mirror of plane exists and are supported by hardware, rescomp does it automatically if your background image is correctly done :)

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Tiles and sprites question

Post by alko » Sun Jan 10, 2016 9:19 pm

But are stored in VRAM two symmetrical parts of the image.

Image
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Mon Jan 11, 2016 9:50 am

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.

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Tiles and sprites question

Post by alko » Mon Jan 11, 2016 10:27 am

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
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Mon Jan 11, 2016 4:17 pm

and you imported it in binary form with rescomp ?

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Tiles and sprites question

Post by alko » Mon Jan 11, 2016 5:02 pm

Yes of course.
ResComp 1.3 (november 2014)
Stephane Dallongeville
Image
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Tiles and sprites question

Post by Stef » Mon Jan 11, 2016 6:59 pm

Can you show me the content of your .res file and the code you used to display the background ?

Post Reply