view gSprite.c @ 95:b0249b856488

change_ps2util
author Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
date Thu, 26 May 2011 18:13:40 +0900
parents cb6c6de125dc
children 0b65ca27f113
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include "libps2.h"
#include "ps2util.h"
#include "gSprite.h"
#include <stdbool.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;

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,
	(unsigned short)x, (unsigned short)y,
	(unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2,
	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
	(unsigned short)sptable[number].tw, (unsigned short)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,
	(unsigned short)x, (unsigned short)y,
	(unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h,
	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
	(unsigned short)sptable[number].tw, (unsigned short)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 = false;
}


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()
{
}