Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
20 May, 2013, 04:48:41 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2 3   Go Down
  Print  
Author Topic: Sprites and Maps in C 68k -  (Read 2724 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« on: 02 February, 2011, 15:11:32 »
0

Hello,

I would like to program in C on my TI-89 Titanium and make one (tile) map. I looked at the code a bit of Zelda, but it was terrible...
Does someone could tell me specifically how to make a map and sprites in C?
I already downloaded TIGCC.

Thank you!
Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Ranman
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Last Login: 23 April, 2013, 23:37:04
Date Registered: 16 October, 2008, 23:25:59
Posts: 1390


Total Post Ratings: +78

View Profile
« Reply #1 on: 02 February, 2011, 17:39:52 »
0

What is your experience level with the C language?
Logged

Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator.  Download available here.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #2 on: 03 February, 2011, 10:31:28 »
0

I know how to make a sprite now, but not maps.

unsigned char homme[] = {
          0b01111110,
         0b11111111,
         0b10100101,
         0b10000001,
         0b01111110,
         0b10100101,
         0b10111101,
         0b01111110
         };
« Last Edit: 03 February, 2011, 10:31:59 by Kiligolo » Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Ranman
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Last Login: 23 April, 2013, 23:37:04
Date Registered: 16 October, 2008, 23:25:59
Posts: 1390


Total Post Ratings: +78

View Profile
« Reply #3 on: 03 February, 2011, 11:46:40 »
+2

I know how to make a sprite now, but not maps.

unsigned char homme[] = {
          0b01111110,
         0b11111111,
         0b10100101,
         0b10000001,
         0b01111110,
         0b10100101,
         0b10111101,
         0b01111110
         };


First off... Here are some great resources for programming in C with TIGCC:

* TIGCC Documentation
* Technoplaza Tutorials
* The C Book


A tilemap is essentially an array of sprites. So, if this is one sprite:

unsigned char homme[8] =
{
    0b01111110,
    0b11111111,
    0b10100101,
    0b10000001,
    0b01111110,
    0b10100101,
    0b10111101,
    0b01111110
};


Then an array of sprites (tilemap) would look like this:

unsigned char homme[4][8] =
{
    {
        0b01111110,
        0b11111111,
        0b10100101,
        0b10000001,
        0b01111110,
        0b10100101,
        0b10111101,
        0b01111110
    },
    {
        0b01111110,
        0b11111111,
        0b10100101,
        0b10000001,
        0b01111110,
        0b10100101,
        0b10111101,
        0b01111110
    },
    {
        0b01111110,
        0b11111111,
        0b10100101,
        0b10000001,
        0b01111110,
        0b10100101,
        0b10111101,
        0b01111110
    },
    {
        0b01111110,
        0b11111111,
        0b10100101,
        0b10000001,
        0b01111110,
        0b10100101,
        0b10111101,
        0b01111110
    },
};


Keep in mind... in your example as well as my example, the sprite is just a simple black & white sprite without a corresponding mask. If you intend on using grayscale along with masks, then to completely define each sprite you will need a sprite for each video plane as well as a sprite mask (total of 3 sprites).

Do you understand the purpose of a sprite mask? How about the idea of multiple planes for grayscale? If not... the  TIGCC Documentation is fairly helpful.

I'll be around if you have any more questions.
Logged

Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator.  Download available here.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #4 on: 03 February, 2011, 11:52:53 »
0

What is the routine to call a tile map?
Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Ranman
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Last Login: 23 April, 2013, 23:37:04
Date Registered: 16 October, 2008, 23:25:59
Posts: 1390


Total Post Ratings: +78

View Profile
« Reply #5 on: 04 February, 2011, 09:23:50 »
+1

What is the routine to call a tile map?
I may have been a little misleading with my previous post...

A traditional tilemap is essentially a 2 dimensional array of sprites that represents a visual 2D map for use in some types of games.

Example of an 8x8 tilemap:

unsigned char game_tilemap[8][8] =
{
  {0,0,1,1,1,1,0,0},
  {0,1,1,1,0,0,0,0},
  {1,1,1,0,0,0,0,3},
  {1,0,0,3,0,4,0,3},
  {0,0,0,0,0,0,0,0},
  {3,0,3,0,0,2,2,2},
  {3,0,0,0,2,2,2,2},
};


legend: 0 = grass, 1 = mountain, 2 = water, 3 = tree, 4 = house

Notice that each item in the game_tilemap uniquely represents the index of the sprite that will be drawn.


Next we will need to define a sprite for each item used in the tilemap. From the above example, there will be 5 sprites and each will visually represent the items defined in legend (0 = grass, 1 = mountain, 2 = water, 3 = tree, 4 = house).

Now it is time to actually define the array of sprites utilized by the tilemap (note: 5 sprites, each sprite 8 pixels tall):

unsigned char game_sprites[5][8] =   
{
  { // 0 = grass
    0b10001000,
    0b00000000,
    0b00100010,
    0b00000000,
    0b10001000,
    0b00000000,
    0b00100010,
    0b00000000,
  },
  { // 1 = mountain
    0b00000000,
    0b00010000,
    0b00111000,
    0b01111100,
    0b11011110,
    0b10101111,
    0b01110111,
    0b11111011,
  },
  { // 2 = water
    0b11110000,
    0b00001111,
    0b11110000,
    0b00001111,
    0b11110000,
    0b00001111,
    0b11110000,
    0b00001111,
  },
  { // 3 = tree
    0b00000000,
    0b00111110,
    0b01111111,
    0b01111111,
    0b01111111,
    0b00111110,
    0b00001000,
    0b00001000,
  },
  { // 4 = building
    0b00000000,
    0b00011000,
    0b00111100,
    0b01111110,
    0b11111111,
    0b01100110,
    0b01100110,
    0b01100110,
  },
};


A pointer (or address) to the beginning of an 8bit wide sprite can be defined like this:

unsigned char* pSprite;


Example: if we need to get the address of the tree sprite, then we can do this:   

    pSprite = &game_sprites[3][0];
      or
    pSprite = game_sprites[3];


Next we need to draw the tilemap to the screen


int tilemap_x;
int tilemap_y;
int lcd_x;
int lcd_y;
unsigned char* pSprite;
unsigned char sprite_index;

// initialize the lcd Y value since we starting the first row
lcd_y = 0;

for (tilemap_y = 0; tilemap_y < 8; tilemap_y++)
{
  // initialize the lcd X value since we are starting a new collumn
  lcd_x = 0;

  for (tilemap_x = 0; tilemap_x < 8; tilemap_x++)
  {
    // first, get the sprite index from the tilemap
    sprite_index = game_tilemap[tilemap_y][tilemap_x];

    // second, get the pointer (address) to the sprite
    pSprite = &game_sprites[sprite_index][0];

    // draw the sprite to the screen
    Sprite8 (lcd_x, lcd_y, 8, pSprite, LCD_MEM, SPRT_RPLC); // refer to TIGCC docs for Sprite8 details

    // increment the lcd X position in preparation for next sprite
    lcd_x = lcd_x + 8;
  }

  // increment the lcd Y position in preparation for next row of sprites
  lcd_y = lcd_y + 8;
}


Obviously, this is not the most optimized method for drawing a tilemap to the screen; but I think it illustrates each of the main ideas well.


Does this help any?
« Last Edit: 04 February, 2011, 10:08:17 by Ranman » Logged

Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator.  Download available here.
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 22:10:34
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1853

Total Post Ratings: +208

View Profile WWW
« Reply #6 on: 05 February, 2011, 12:59:42 »
0

I think that this does help, because you're explaining the principles behind the Genlib and ExtGraph tilemap engines that I mentioned to Kiligolo on TI-Bank Smiley
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #7 on: 05 February, 2011, 15:06:05 »
0

Thanks.
Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #8 on: 25 March, 2011, 14:01:47 »
0

up! Grin
I would like to know, with Sprite16() routine, how do the equivalent of Pt-Off() in Axe. I want all the pixels in the area where the sprite will be turn off until another sprite is displayed.
Is it possible?
« Last Edit: 25 March, 2011, 14:02:08 by Kiligolo » Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 22:10:34
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1853

Total Post Ratings: +208

View Profile WWW
« Reply #9 on: 25 March, 2011, 14:08:24 »
0

I replied to you on TI-Bank Wink
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #10 on: 13 April, 2011, 10:07:48 »
0

I know it is off topic but how can I do a pause with a determinate time? (Bad english... ^^')
Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 22:10:34
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1853

Total Post Ratings: +208

View Profile WWW
« Reply #11 on: 13 April, 2011, 10:12:32 »
0

You can:
* use the AMS timers (OSRegisterTimer & friends), based on AUTO_INT_5 whose rate is normally ~19.32 Hz (on HW2 calculators);
* use the programmable rate generator (AUTO_INT_5) directly, and set its rate mostly as you wish through the PRG_* functions;
* use WaitForMillis-type functions, busy wait loops calibrated for waiting approximately the number of seconds passed to the function. Between others, TI-Chess uses such a function for debouncing keypresses.
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #12 on: 13 April, 2011, 10:17:38 »
0

Thanks.
Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Kiligolo
LV5 Advanced (Next: 300)
*****
Offline Offline

Gender: Male
Last Login: 13 January, 2013, 11:35:54
Date Registered: 11 October, 2010, 18:01:20
Location: France
Posts: 218


Topic starter
Total Post Ratings: +5

View Profile
« Reply #13 on: 29 January, 2012, 21:13:37 »
0

Hi there!

I have a problem with grayscales and ams planes. I made a tilemap but when i start the programm there is nothing displayed but the TI isn't frozen i can press ESC key to see a big bug...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
int tilemap_x;
int tilemap_y;
int lcd_x;
int lcd_y;
unsigned char* pSprite;
unsigned char sprite_index;
int key = 0, pUserx = 1, pUsery = 1;

unsigned char map1[MAP_Y][MAP_X] =
{
{01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01},
{01,02,02,02,02,02,02,02,00,00,00,00,00,00,00,00,00,00,00,01},
{01,02,02,02,02,02,02,00,00,00,00,05,06,07,00,00,00,00,00,01},
{01,02,02,02,00,00,00,00,00,00,00,10,11,12,00,00,00,00,00,01},
{01,02,00,00,00,00,15,16,00,00,00,13,14,13,00,00,00,00,00,01},
{01,00,00,00,00,00,17,20,00,00,00,21,21,21,03,04,04,03,00,01},
{00,00,00,00,00,00,00,00,00,00,00,00,21,00,03,04,04,03,00,01},
{21,21,21,05,06,07,00,00,00,00,21,21,21,00,03,03,03,03,02,01},
{00,00,21,10,11,12,00,00,21,21,21,00,00,00,00,00,02,02,02,01},
{01,00,21,13,14,13,00,21,21,00,00,00,00,00,02,02,02,02,02,01},
{01,00,21,21,21,21,21,21,00,00,00,00,02,02,02,02,02,02,02,01},
{01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01,01},
};

ClrScr();
GrayOn();

while (key != KEY_ESC)
{
while (map1[pUsery][pUserx] != 14)
{
//Affichage

    //Gris clair
    GraySetAMSPlane(LIGHT_PLANE);
lcd_y = 0;
for (tilemap_y = 0; tilemap_y < MAP_Y; tilemap_y++)
{
  lcd_x = 0;
  for (tilemap_x = 0; tilemap_x < MAP_X; tilemap_x++)
  {
    sprite_index = map1[tilemap_y][tilemap_x];
    pSprite = &game_sprites_light[sprite_index][0];
Sprite8 (lcd_x, lcd_y, 8, vide, LCD_MEM, SPRT_AND);
    Sprite8 (lcd_x, lcd_y, 8, pSprite, LCD_MEM, SPRT_OR);
    lcd_x += 8;
  }
  lcd_y += 8;
}

    //Gris foncé
    GraySetAMSPlane(DARK_PLANE);
lcd_y = 0;
for (tilemap_y = 0; tilemap_y < MAP_Y; tilemap_y++)
{
  lcd_x = 0;
  for (tilemap_x = 0; tilemap_x < MAP_X; tilemap_x++)
  {
    sprite_index = map1[tilemap_y][tilemap_x];
    pSprite = &game_sprites_dark[sprite_index][0];
    Sprite8 (lcd_x, lcd_y, 8, pSprite, LCD_MEM, SPRT_OR);
    lcd_x += 8;
  }
  lcd_y += 8;
}
Sprite8 (pUserx * 8, pUsery * 8, 8, vide, LCD_MEM, SPRT_AND);
Sprite8 (pUserx * 8, pUsery * 8, 8, mec, LCD_MEM, SPRT_OR);
    GraySetAMSPlane(LIGHT_PLANE);
Sprite8 (pUserx * 8, pUsery * 8, 8, mec, LCD_MEM, SPRT_OR);

//Demande de touche
key = ngetchx();
if (key)
{
//Actualisation de la position de l'utilisateur
pUserx += (key == KEY_RIGHT) - (key == KEY_LEFT);
pUsery += (key == KEY_DOWN) - (key == KEY_UP);

//Verification de sa position
if (map1[pUsery][pUserx] == 1 || map1[pUsery][pUserx] == 3 || (map1[pUsery][pUserx] > 4 && map1[pUsery][pUserx] != 14 && map1[pUsery][pUserx] < 21) || pUserx == 21 || pUserx == -1 || pUsery == -1 || pUsery == 13)
{
pUserx -= (key == KEY_RIGHT) - (key == KEY_LEFT);
pUsery -= (key == KEY_DOWN) - (key == KEY_UP);
}
if (key == KEY_ESC)
return 0;
}
}
}
GrayOff();
return 0;
}

Thanks.
« Last Edit: 29 January, 2012, 21:14:46 by Kiligolo » Logged

Spoiler for Calcul Mental:
Version 1.3 :100%!!
Here is a program that reduces your dependence on the calculator! Click here!
Spoiler for Some screen shots:
       
The screenshots are in french but there is an english version
Xeda112358
Xombie. I am it.
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Last Login: Today at 03:57:36
Date Registered: 31 October, 2010, 08:46:36
Location: Land of Little Cubes and Tea, NY
Posts: 3741


Total Post Ratings: +598

View Profile
« Reply #14 on: 29 January, 2012, 21:20:43 »
0

Sorry, I do not know an answer to this, but I am also learning C for the 68K calcs, so I am here just to say thank you Azn The code is very helpful for me to study Smiley
Logged



Grammer Download (2.29.04.12)
Latest update (possibly incomplete)
My pastebin
Spoiler for FileSyst:
FileSyst is an application that provides a folder and filesystem for the TI-83+/84+ calculators. It is designed to be easy to access and use in BASIC, and it can be used to access game files and save data, or to create a command prompt, among other things:

Spoiler for Graphiti:
This is a graph explorer for graph theory. It will require lots of work to finish. Currently you can:
Add/delete vertices
Add edges (direction not shown, but they are directed)
Arrange vertices in a circle (in the future, you will be able to define levels of rings and the number of nodes in each)
Create complete graphs quickly

Plans:
Add adjacency matrix viewer
Deleting edges
Multiple graphs support
Arrows for directed graphs
Planarity testing
Matrix operations
Weighted edges
Chromatic polynomials
Chromatic numbers

Spoiler for Stats:

Samocal             [o---------]
Virtual Processor   [o---------]
EnG                 [oo--------]
Grammer             [ooo-------]
AsmComp             [ooo-------]
Partex              [oooo------]
BatLib              [oooooooo--]
Grammer82           [----------]
Grammer68000        [----------]


Pseudonyms:  Zeda, Xeda, Thunderbolt
Languages:   English, français
Programming: z80 Assmebly
             Grammer
             TI-BASIC (83/84/+/SE, 89/89t/92)
Known For:   -Creator of the Grammer programming language
              (Winning program of zContest2011)
             -BatLib- One of the most feature packed libraries for BASIC programmers available
              with over 100 functions and a simple programming language
             -Learning to program z80 in hexadecimal before using an assembler (no computer was
              available!)
╔═╦╗░╠═╬╣▒║ ║║▓╚═╩╝█


Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.42 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.