[A89] Re: Sprites


[Prev][Next][Index][Thread]

[A89] Re: Sprites




On Thu, 29 Nov 2001 09:06:22 EST TerrisUS@aol.com writes:
> 
> Anyone know of any good very basic Sprite tutorial files or 
> programs?
> That is, basic stuff like getting a sprite into a program, 
> manipulating the 
> sprite, working with the sprite in TIGCC, etc.

I could say "go look at some tutorials, they're all over the internet",
but I know that you posted this for a reason (too lazy, too stupid, too
busy, too something).  So I'll give you a  couple of programs I wrote for
the sole purpose of learning how to work with sprites in TIGCC.  It's not
much, not pretty, and not very good (I'm fairly inexperienced), but it
will give you something to start with.  I'll give you a tip too: I never
looked at a sprite tutorial before I did these, all of this is in the
TIGCC documentation.  That documentation is great, use it.

/* sprite1.c  begin */
// C Source File
// Created 9/26/2001; 5:07:51 PM

/*
Sprite Test
Jonathan Kotta
the_juggernaut@juno.com

This is just a test program to learn how to use sprites
and control them with the keyboard
*/

#define OPTIMIZE_ROM_CALLS    // Use ROM Call Optimization

#define SAVE_SCREEN           // Save/Restore LCD Contents

#include <tigcclib.h>         // Include All Header Files
#include <kbd.h>

short _ti89;                  // Produce .89Z File

// Main Function
void _main(void)
{
//pixel coordinates
int x_screen = 79, y_screen = 49;
//these variables are for keyboard reading
void *kbq = kbd_queue();
unsigned int key = 0;
unsigned int arrow_key = 0;
//the cross hair sprite
static unsigned char cross_hairs[] =
{0x10,0x38,0x54,0xFE,0x54,0x38,0x10};
int sprite_on = TRUE;

  //clear the screen
 ClrScr();
 //draw the cross hairs
 Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM, SPRT_XOR);
  //loop forever (if escape is pressed, code within the 
  //while loop will exit the program)
  while(0 == 0) 
  {  
    //clear the key variables
    key = 0;
    arrow_key = 0;
    //this makes sure the loop doesn't repeat too fast
    //it's a 1/20 second delay
    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER, 1); 
    while(!OSTimerExpired(USER_TIMER));
    //check if a key was pressed
   if(!kbhit()) 
     //if no keys pressed, go to idle mode
      idle();
    //if keys were pressed
    else 
    {
      //OSGetStatKeys is used for reading arrow keys and is
      //zero if no key is pressed
      //sprite_on is TRUE if sprite is VISIBLE
     if(((arrow_key = OSGetStatKeys()) != 0)&&sprite_on)
     {
      switch(arrow_key) 
      {
       //if up arrow was pressed, then:
       //erase the cross hairs
       //increment the y_screen coodinate
         //and redraw the cross hairs
       case ARROW_UP:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         y_screen--;
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         break;
       //just like above
       case ARROW_DOWN:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         y_screen++;
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         break;
       case ARROW_RIGHT:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         x_screen++;
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         break;
       case ARROW_LEFT:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         x_screen--;
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         break;
       //if some other key was pressed, ignore and start over
       default:
         break;       
       } //end switch
     } //end if
     else 
     {
       OSdequeue(&key, kbq);
      switch(key) 
      {
        //exit if escape is pressed
       case KEY_ESC:
         return;
       //hide the cross hairs if clear is pressed
       //and change sprite_on
       case KEY_CLEAR:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         if(sprite_on)
           sprite_on = FALSE;
         else
           sprite_on = TRUE;
         break;
       default:
         break;
      } 
     } //end else
    } //end else
  } //end while
} //end main
/* sprite1.c end */

/* sprite2.c begin */
/ C Source File
// Created 9/26/2001; 5:07:51 PM

/**********************************************************
Sprite Test 2
Jonathan Kotta
the_juggernaut@juno.com

This is just a test program to learn how to use sprites
and control them with the keyboard
**********************************************************/

#define OPTIMIZE_ROM_CALLS    // Use ROM Call Optimization

#define SAVE_SCREEN           // Save/Restore LCD Contents

#include <tigcclib.h>         // Include All Header Files
#include <kbd.h>

short _ti89;                  // Produce .89Z File

/************** GLOBAL VARIABLES ***************/
//none

/************** FUNCTION PROTOTYPES ***************/
void arrows(unsigned int arrow_key, int *x_coordinate, int
*y_coordinate);
//changes the values of the variables pointed to by 
//x_coordinate and y_coordinate
//arrow_key to be determined by OSGetStatKeys()

/************** MAIN FUNCTION ***************/
void _main(void)
{
//pixel coordinates
int x_screen = 79, y_screen = 49;
//these variables are for keyboard reading
void *kbq = kbd_queue();
unsigned int key = 0;
unsigned int arrow_key = 0;
//the cross hair sprite
static unsigned char cross_hairs[] =
{0x10,0x38,0x54,0xFE,0x54,0x38,0x10};
//status of cross hairs sprite
int sprite_on = TRUE;
  //clear the screen
 ClrScr();
 //draw the cross hairs
 Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM, SPRT_XOR);
  //loop forever (if escape is pressed, code within the 
  //while loop will exit the program)
  while(0 == 0) 
  {  
    //clear the key variables
    key = 0;
    arrow_key = 0;
    //this makes sure the loop doesn't repeat too fast
    //it's a 1/20 second delay
    OSFreeTimer(USER_TIMER);
    OSRegisterTimer(USER_TIMER, 1); 
    while(!OSTimerExpired(USER_TIMER));
    //check if a key was pressed
   if(!kbhit()) 
     //if no keys pressed, go to idle mode
      idle();
    //if keys were pressed
    else 
    {
      //OSGetStatKeys is used for reading arrow keys and is
      //zero if no key is pressed
      //sprite_on is TRUE if sprite is VISIBLE
     if(((arrow_key = OSGetStatKeys()) != 0)&&(sprite_on))
     {
        Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
        arrows(arrow_key, &x_screen, &y_screen);
       Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
     } //end if
     else 
     {
       OSdequeue(&key, kbq);
      switch(key) 
      {
        //exit if escape is pressed
       case KEY_ESC:
         return;
       //hide the cross hairs if clear is pressed
       //and change sprite_on
       case KEY_CLEAR:
         Sprite8(x_screen-3, y_screen+3, 7, cross_hairs, LCD_MEM,
SPRT_XOR);
         if(sprite_on)
           sprite_on = FALSE;
         else
           sprite_on = TRUE;
         break;
       default:
         break;
      } 
     } //end else
    } //end else
  } //end while
} //end main

/************** FUNCTION DEFINITIONS ***************/

void arrows(unsigned int arrow_key, int *x_coord, int *y_coord)
{
  switch(arrow_key) 
  {
    //if up arrow was pressed, then:
    //decrement variable pointed to by y_coord
    //decrement because y decreases as you go up on the screen
    case ARROW_UP:
      (*y_coord)--;
      break;
    //just like above
    case ARROW_DOWN:
      (*y_coord)++;
      break;
    case ARROW_RIGHT:
      (*x_coord)++;
      break;
    case ARROW_LEFT:
      (*x_coord)--;
      break;
    //if some other key was pressed, ignore and start over
    default:
      break;       
  } //end switch
}
/* sprite2.c end */
________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.