startpage.c 2.5 KB
/*
 * This is the handler for the start page. It takes controller input
 * and provides Sprites as output and also a return value which says
 * what the next page should be.
 */
#include <ultra64.h>
#include "uimain.h"
#include "font.h"

/*
 * XXX A simple sprite for testing
 */
#include "sp_ball.h"

/*
 * XXX Some test stuff
 */
static int xpos = 100;
static int ypos = 100;

#define NUM_BMS        (24*40)
static Bitmap textBoxBmp[NUM_BMS];
static Gfx textBoxDl[NUM_DL(NUM_BMS)];

extern Font tvfont;

static Sprite textBox = {
        0,0,                    /* Position: x,y */
        0,0,                    /* Sprite size in texels (x,y) */
        1.0,1.0,                /* Sprite Scale: x,y */
        0,0,                    /* Explosion (x,y) */
        SP_TRANSPARENT,                   /* Sprite Attributes */
        0x1234,                 /* Sprite Depth: Z */
        255,255,255,255,        /* Sprite Coloration: RGBA */
        0,0,NULL,               /* Color LookUp Table: start_index, length, address */
        0,1,                    /* Sprite Bitmap index: start index, step increment */
        NUM_BMS,                /* Number of bitmaps */
        NUM_DL(NUM_BMS),        /* Number of display list locations allocated */
        15, 128,                /* Sprite Bitmap Height: Used_height, physical height */
        G_IM_FMT_I,             /* Sprite Bitmap Format */
        G_IM_SIZ_4b,            /* Sprite Bitmap Texel Size */
        textBoxBmp,             /* Pointer to bitmaps */
        textBoxDl,              /* Display list memory */
        NULL,                   /* HACK: dynamic_dl pointer */
};

static int fontColor = 255;

int startInit()
{
    if (drawString("Press Start", &tvfont, 11, 1, &textBox) == 0) {
        return 0;
    }

    return -1;
}

int startPage(u16 cntrl, Sprite **sp)
{
    if (cntrl != 0) {
        if (cntrl & CONT_A) {
            xpos += 10;
            ypos += 10;
        }
        if (cntrl & CONT_B) {
            xpos -= 10;
            ypos -= 10;
        }
    }
    
    /*
     * Just write some letters
     */
    fontColor = (fontColor+10) & 0xff;
    spMove(&textBox, xpos, ypos);
    if (fontColor > 128) {
        spScale(&textBox, 1.2, 1.2);
    } else {
        spScale(&textBox, 1.0, 1.0);
    } 
    spColor (&textBox, 255, fontColor, 255, 255);
    sp[0] = &textBox;

    sp[1] = &ball_sprite;
    sp[2] = 0;

    if (cntrl & CONT_START) {
        return 1;
    } else {
        /*
         * Come back to current page
         */
        return 0;
    }

}