view gSprite.c @ 21:447281fe6845

*** empty log message ***
author gongo
date Sat, 04 Nov 2006 12:32:49 +0000
parents 3780d1b2943e
children a1908b83f8fa
line wrap: on
line source

/*
 * $Id$
 */
#include <stdio.h>
#include <stdlib.h>
#include "libps2.h"
#include "ps2util.h"
#include "col.h"
#include "field.h"
#include "car.h"
#include "game.h"
#include "gSprite.h"

#define DEFOBJ 100
#define SPRITE_COL 0x4f
#define SCREEN_HALF_W 320
#define SCREEN_HALF_H 240

static SpriteTable   sptable[DEFOBJ];
static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
static unsigned int  sp_counter;
static Bool          flag_spriteInited = FALSE; // スプライトロードフラグ

static TEXTURE *sprite_tex;

extern CarPtr car;

void
gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
{
    sptable[number].tx = tx;
    sptable[number].ty = ty;
    sptable[number].tw = tw;
    sptable[number].th = th;
}

void
gSprite_PutSprite(int number, int x, int y)
{
    ps2utilSprite *p = &sp[sp_counter];

    ps2util_sprite_Set_basicAttribute(
	p,
	(ushort)x, (ushort)y,
	(ushort)sptable[number].tw*2, (ushort)sptable[number].th*2,
	(ushort)sptable[number].tx, (ushort)sptable[number].ty,
	(ushort)sptable[number].tw, (ushort)sptable[number].th,
	SPRITE_PRIO_FOREGROUND);

    ps2util_sprite_Request(p);
    sp_counter++;
}

void
gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
{
    ps2utilSprite *p = &sp[sp_counter];

    ps2util_sprite_Set_basicAttribute(
	p,
	(ushort)x, (ushort)y,
	(ushort)sptable[number].tw*w, (ushort)sptable[number].th*h,
	(ushort)sptable[number].tx, (ushort)sptable[number].ty,
	(ushort)sptable[number].tw, (ushort)sptable[number].th,
	SPRITE_PRIO_FOREGROUND);

    ps2util_sprite_Request(p);
    sp_counter++;
}

static void
gSprite_Init_Png(char *texname)
{
    if (!(sprite_tex = read_png_file(texname))) {
	fprintf(stderr,
		"cannot creat texture - init_png().\n");
	fflush(stderr);
	exit(EXIT_FAILURE);
    }

    if (ps2util_tex_Set(sprite_tex) == -1) {
	fprintf(stderr,
		"cannot set texture - init_png().\n");
	fflush(stderr);
	exit(EXIT_FAILURE);
    }

}

static void
gSprite_Create()
{
    int i;

    for (i=0; i<DEFOBJ; i++) {
	if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
	    fprintf(stderr,
		    "cannot create sprite No.%d - create_sprite()\n", i);
	    fflush(stderr);
	    exit(EXIT_FAILURE);
	}
	ps2util_sprite_Unuse_alpha(&sp[i]);
    }

    flag_spriteInited = TRUE;
}

void
gSprite_Init()
{
    ps2util_graphic_Init();
    gSprite_Init_Png("img/main2.png");
    gSprite_Create(); // スプライト生成

    /* スプライトの登録 */
    gSprite_DefSprite(10,   1,   1, 512, 666); /* タイトル   */
    gSprite_DefSprite(17,   1,  35,  33,  33); /* 選択マーク */
    gSprite_DefSprite(23,   1,   1, 106,  34); /* スピードメーター */
    gSprite_DefSprite(24,  51,  40,  18,  20); /* 右矢印 */
    gSprite_DefSprite(25,  33,  40,  17,  20); /* 左矢印 */
    gSprite_DefSprite(26,  56,  89,  55,  26); /* km/h   */
    gSprite_DefSprite(27,  62,  62,  39,  26); /* Rap   */
    gSprite_DefSprite(28, 430,  62,  53,  46); /* 1P */
    gSprite_DefSprite(29, 460,   6,  53,  46); /* 2P */
    gSprite_DefSprite(51, 333, 116, 165,  140); /* 選択画面の車 */
    gSprite_DefSprite(52, 181, 116, 165,  140);
    gSprite_DefSprite(53,  12, 116, 165,  140);
    gSprite_DefSprite(81, 115,   1, 148, 114); /* 選択画面のコース */
    // 本当は (82, 272,...)です。二つ目のコース絵がないので 
    gSprite_DefSprite(82, 272,   1, 148, 114);
}

static void
gSprite_Clear()
{
    int i;

    for (i=0; i<DEFOBJ; i++) {
	sprite_disappear(&sp[i].attribute);
    }
    sp_counter = 0;
}

void
gSprite_Draw_Reset()
{
    if (flag_spriteInited == TRUE) {
	gSprite_Clear();
    }
}

void
gSprite_PutSprite_Pause()
{
}