Join us on Discord!
You can help CodeWalrus stay online by donating here.

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

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)
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

Yuki

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.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

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
  • Calculators owned: TI-Nspire CX CAS, TI-Nspire CX, TI-Nspire CAS (x3), TI-Nspire (x2), TI-Nspire CM-C CAS, TI-Nspire CAS+, TI-80, TI-82 Stats.fr, TI-82 Plus, TI-83 Plus, TI-83 Plus.fr USB, TI-84+, TI-84+ Pocket SE, TI-84+ C Silver Edition, TI-84 Plus CE, TI-89 Titanium, TI-86, TI-Voyage 200, TI-Collège Plus, TI-Collège Plus Solaire, 3 HP, some Casios
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Unicorn

#4
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!
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

Unicorn

#5
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

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
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

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.
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

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
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

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.
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

kotu

#13
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
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



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

Powered by EzPortal