### Author Topic: Unicorn's C Questions and Stuff  (Read 3909 times)

0 Members and 1 Guest are viewing this topic.

#### Unicorn

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Unicorn's C Questions and Stuff
« on: August 05, 2016, 05:33:34 am »
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:
Code: [Select]
`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?
Code: [Select]
`/* 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)
« Last Edit: August 05, 2016, 05:48:01 am by Unicorn »

• 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 ??? ??? ??? ??? ???

#### Juju

• aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
• CodeWalrus Staff
• Super User
• Server Maintenance
• Moderator
• Forum Maintenance
• Original 5
• CodeWalrus Supporter
• Join Date: Nov 2014
• Location: Inside a walrus
• Posts: 3203
• Post Rating Ratio: +36/-2
• Couch potato
• Gender:
• WalriiPoints: 99999
##### Re: Unicorn's C Questions and Stuff
« Reply #1 on: August 05, 2016, 06:31:12 am »
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
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader --Snektron

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

#### Unicorn

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #2 on: August 05, 2016, 08:05:02 pm »
So fill the variable gfx_tilemap_t like I would in matrix?

Code: [Select]
` 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 ??? ??? ??? ??? ???

• Full User
• CodeWalrus Supporter
• Join Date: Jan 2015
• Location: France & Canada
• Posts: 433
• Post Rating Ratio: +7/-1
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #3 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
• 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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #4 on: August 06, 2016, 12:23:39 am »
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:

Code: [Select]
`#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.

« Last Edit: August 06, 2016, 12:56:49 am by Unicorn »
• 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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #5 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.

Also, how would I decompress my sprites? I was looking at an example and it doesn't seem to make much sense.
« Last Edit: August 07, 2016, 04:53:08 am by Unicorn »
• 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

• -< \'V/,,,
• Super User
• Join Date: Aug 2016
• Location: don't panic
• Posts: 1160
• Post Rating Ratio: +8/-11
• woah
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #6 on: August 16, 2016, 04:23:41 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

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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #7 on: August 16, 2016, 06:53:22 am »
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

• -< \'V/,,,
• Super User
• Join Date: Aug 2016
• Location: don't panic
• Posts: 1160
• Post Rating Ratio: +8/-11
• woah
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #8 on: August 16, 2016, 06:56:34 am »
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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #9 on: August 16, 2016, 07:03:38 am »
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

• -< \'V/,,,
• Super User
• Join Date: Aug 2016
• Location: don't panic
• Posts: 1160
• Post Rating Ratio: +8/-11
• woah
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #10 on: August 16, 2016, 07:08:38 am »
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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #11 on: August 16, 2016, 07:16:31 am »
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

• -< \'V/,,,
• Super User
• Join Date: Aug 2016
• Location: don't panic
• Posts: 1160
• Post Rating Ratio: +8/-11
• woah
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #12 on: August 16, 2016, 07:23:33 am »
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

• -< \'V/,,,
• Super User
• Join Date: Aug 2016
• Location: don't panic
• Posts: 1160
• Post Rating Ratio: +8/-11
• woah
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #13 on: August 16, 2016, 10:19:11 am »
Also, things get a little more complex than Mateo's tilemap example.

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
« Last Edit: August 16, 2016, 12:27:17 pm by kotu »
• 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

• ??? ??? ??? ??? ???
• Super User
• CW Contest II - 2nd place
• Join Date: Jan 2015
• Location: ??? ??? ??? ??? ???
• Posts: 2830
• Post Rating Ratio: +5/-2
• make :PICKACHUP: a thing!
• Gender:
##### Re: Unicorn's C Questions and Stuff
« Reply #14 on: August 17, 2016, 05:20:26 pm »
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 ??? ??? ??? ??? ???

You can also use the following HTML or bulletin board code to share it on your page or forum signature!

Also do not forget to check our affiliates below.