Alternatively, join us on Discord.

Unicorn's C Questions and Stuff [C] [Help]

Started by Unicorn, August 05, 2016, 05:33:34 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Unicorn

August 05, 2016, 05:33:34 am Last Edit: August 05, 2016, 05:48:01 am by Unicorn
I haven't a C topic here, so I made one! I'll just post all those things that I've experimented on here but aren't made into games, or my ideas, or my questions about things that don't yet have topics.

To start it off, a question!

How might I go about using the Tilemap functions in graphx.h? @MateoConLechuga could you help?

I realize there is this command:

void gfx_Tilemap(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset);

But what about this info? How would I set this data up?

/* Type for tilemap */
typedef struct gfx_tilemap {
uint8_t *map;             /* pointer to indexed map array */
gfx_image_t **tiles;          /* pointer to tiles */
uint8_t tile_height;      /* individual tile height */
uint8_t tile_width;       /* individual tile width */
uint8_t draw_height;      /* number of rows to draw in the tilemap */
uint8_t draw_width;       /* number of cols to draw tilemap */
uint8_t type_width;       /* 2^type_width = tile_width */
uint8_t type_height;      /* 2^type_height = tile_height */
uint8_t height;           /* total number of rows in the tilemap */
uint8_t width;            /* total number of cols in the tilemap */
uint8_t y_loc;            /* y pixel location to begin drawing at */
uint24_t x_loc;           /* x pixel location to begin drawing at */
} gfx_tilemap_t;

typedef enum gfx_tilemap_type {
gfx_tile_2_pixel = 1,      /* Set when using 2 pixel tiles */
gfx_tile_4_pixel,          /* Set when using 4 pixel tiles */
gfx_tile_8_pixel,          /* Set when using 8 pixel tiles */
gfx_tile_16_pixel,         /* Set when using 16 pixel tiles */
gfx_tile_32_pixel,         /* Set when using 32 pixel tiles */
gfx_tile_64_pixel,         /* Set when using 64 pixel tiles */
gfx_tile_128_pixel,        /* Set when using 128 pixel tiles */
} gfx_tilemap_type_t;


And the final question: How do I load a map using it? Do I need different sprites that are how ever large my tiles are and then I call some sort of command that sets them to certain places on the tilemap for it to draw? c4ooo explained that I draw it myself and just tell the tilemap how to behave, with tile size and whatnot, which I still need to know how to do.
And I'm assuming I really should learn how to use buffers to erase things.

(I'm thinking about making some type of platformer)



??? ??? ??? ??? ???

Juju

I can't help you that much, but you'd need to make a variable of type gfx_tilemap_t and basically fill it out, like tilemap->tile_height = 30 and whatnot. Same for gfx_image_t. The easiest is to read a file directly into that variable, I don't remember what's the function for it but there's probably some function for that.
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron



if you wanna throw money at me and/or CodeWalrus monthly it's here

Unicorn

So fill the variable gfx_tilemap_t like I would in matrix?


gfx_tilemap_t tilemap[11]

tilemap[0] = map;             /* pointer to indexed map array */
tilemap[1] = tiles;          /* pointer to tiles */

and so on.



??? ??? ??? ??? ???

Adriweb

You do realize that there are example files dealing with such functions ?
It should help quite a bit: https://github.com/CE-Programming/libraries/blob/master/graphics/graphics_examples/demo_5/src/main.c for instance
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Unicorn

August 06, 2016, 12:23:39 am #4 Last Edit: August 06, 2016, 12:56:49 am by Unicorn
Quote from: Adriweb on August 05, 2016, 09:23:11 pm
You do realize that there are example files dealing with such functions ?
It should help quite a bit: https://github.com/CE-Programming/libraries/blob/master/graphics/graphics_examples/demo_5/src/main.c for instance

Ah, I hadn't realized/forgot! Thanks for reminding me :)

So about the above question: Anywasys, I looked into the example, and the only thing I don't really understand is how the tilemapdata.c is generated. It is located in the main src directory and these are teh contents:


#include <stdint.h>

/* This is the data that is displayed with the tilemap */
uint8_t tilemap_map[] = {
0x20,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x22,0x14,0x15,0x04,0x05,0x20,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x22,
0x30,0x54,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x53,0x32,0x04,0x05,0x14,0x15,0x40,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x53,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x01,0x10,0x10,0x10,0x00,0x00,0x01,0x00,0x01,0x00,0x30,0x32,0x04,0x05,0x14,0x15,0x00,0x50,0x51,0x51,0x52,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x00,0x10,0x10,0x10,0x00,0x01,0x00,0x01,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x60,0x61,0x61,0x62,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x01,0x10,0x10,0x10,0x00,0x00,0x01,0x00,0x01,0x00,0x40,0x42,0x04,0x05,0x14,0x15,0x00,0x60,0x61,0x61,0x62,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x14,0x15,0x04,0x05,0x00,0x70,0x71,0x71,0x72,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x01,0x00,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x00,0x00,0x01,0x10,0x10,0x10,0x10,0x10,0x01,0x00,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x01,0x10,0x10,0x10,0x10,0x10,0x01,0x00,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x20,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x43,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x40,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x53,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x20,0x22,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x30,0x32,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x00,0x00,0x00,0x01,0x00,0x01,0x10,0x10,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x01,0x00,0x10,0x10,0x01,0x00,0x30,0x32,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x01,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x30,0x32,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x00,0x10,0x10,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x30,0x32,0x14,0x15,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x01,0x10,0x10,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x30,0x32,0x04,0x05,0x14,0x15,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x30,0x32,
0x30,0x32,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x30,0x32,0x14,0x15,0x24,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x32,
0x30,0x44,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x43,0x32,0x04,0x05,0x20,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x43,0x32,
0x40,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x42,0x14,0x15,0x40,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x42,
};


I hope I am correct in believing that this tells the commands where to put each tile.

Thanks in advance!



??? ??? ??? ??? ???

Unicorn

August 07, 2016, 04:49:12 am #5 Last Edit: August 07, 2016, 04:53:08 am by Unicorn
So @MateoConLechuga cleared up what that is for me, but I still don't understand how I would generate that, if it is what I would use to put each tile it its place.

Also, how would I decompress my sprites? I was looking at an example and it doesn't seem to make much sense.



??? ??? ??? ??? ???

kotu

Quote from: Unicorn on August 07, 2016, 04:49:12 am
So @MateoConLechuga cleared up what that is for me, but I still don't understand how I would generate that, if it is what I would use to put each tile it its place.

Well, normally you would use a map editor program to 'paint' your tile levels. I might be making one soon.. will let you know

Quote from: Unicorn on August 07, 2016, 04:49:12 am
Also, how would I decompress my sprites? I was looking at an example and it doesn't seem to make much sense.

I think you want to look at the graphx1 and graphx2 examples from Mateo's sdk
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Unicorn

so about the compression, apparently it doesnt make much sense, and mateo will be making it better.



??? ??? ??? ??? ???

kotu

well, the examples show 1 example where the background tiles are compressed

maybe the same technique could be used to compress the sprites?
:)
i've not had call to look into that yet.
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Unicorn

There is an example for sprites and tilemaps, but like I've said, they dont make much sense and will be reworked, according to mateo.

About the tilemapper, it seems like you make a spritesheet and then generate a map using an array somehow. I need to figure out how to do THAT.



??? ??? ??? ??? ???

kotu

Well, to create custom maps, you can either code an array BY HAND, which is pretty .... well, it doesn't make it too easy... OR you can use a tilemap editor program, which is easier and more creative. Something like this...


There are some listed here that should do what you want...
http://gamedev.stackexchange.com/questions/225/tools-for-creating-2d-tile-based-maps
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Unicorn

So the problem with that is knowing whetjer it will output the same type of array needed. I would have to look more closly at it, but that seems like it would be a problem.



??? ??? ??? ??? ???

kotu

Well, if you check the link I posted, there are over 10 editors listed on that page, they probably are quite customisable in their output.

But like I said I might be making one myself soon. If I do it will probably be exactly the format you require.
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

kotu

August 16, 2016, 10:19:11 am #13 Last Edit: August 16, 2016, 12:27:17 pm by kotu
Also, things get a little more complex than Mateo's tilemap example.  :P

http://b52i.imgup.net/tilesetd87b.png

If you look at the above image, you will see some of the tiles have yellow background. These have to be drawn over a 'ground' tile (one without any transparency). This means if you want to have transparent tiles like this in your game, you basically need twice the amount of data in your tilemap, one for base tiles, and one for overlay tiles.

Also, for each tile, you need a way of knowing if your character can pass through that tile or not.

If I make a custom tool to help it will allow for use of transparent tiles, or not, to make things simpler if you dont want them. Also it will save the 'block-passable' data too if that is required. [*EDIT* just realised that doesn't have to be saved out]  I should let the user choose 32x32 or 16x16 tiles.

Any input on what a tool should be like and what features it should have would be recommended!!

Thanks
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Unicorn

I suggest you make a topic about your tool, to avoid hijacking mine ;)

But anyways, the yellowish orange is the transparent color, which you define in the tilemap command, I believe, and I do know what transparent means, having used sprites for a while. ;)

You will definitely want to implement transparency, as well as the X by Y of the tiles, and map.



??? ??? ??? ??? ???

Powered by EzPortal