annotate gSprite.c @ 0:0fae5658fb0b

Initial revision
author gongo
date Thu, 02 Nov 2006 08:55:19 +0000
parents
children 3780d1b2943e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 /*
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
2 * 2006/07/24 16:46:19 sugiyama
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
3 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
4 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
5 #include <stdlib.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
6 #include "libps2.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 #include "ps2util.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include "col.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
9 #include "field.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
10 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
11 #include "game.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12 #include "gSprite.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14 #define DEFOBJ 100
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15 #define SPRITE_COL 0x4f
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 #define SCREEN_HALF_W 320
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17 #define SCREEN_HALF_H 240
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
18
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19 static SpriteTable sptable[DEFOBJ];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20 static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21 static unsigned int sp_counter;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
22 static Bool flag_spriteInited = FALSE; // スプライトロードフラグ
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
23
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
24 static TEXTURE *sprite_tex;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
25
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
26 extern CarPtr car;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
27
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
28 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
29 gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
30 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
31 sptable[number].tx = tx;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
32 sptable[number].ty = ty;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
33 sptable[number].tw = tw;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
34 sptable[number].th = th;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
35 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
36
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
37 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
38 gSprite_PutSprite(int number, int x, int y)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
39 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
40 ps2utilSprite *p = &sp[sp_counter];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
41
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
42 ps2util_sprite_Set_basicAttribute(
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
43 p,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
44 (ushort)x, (ushort)y,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
45 (ushort)sptable[number].tw*2, (ushort)sptable[number].th*2,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
46 (ushort)sptable[number].tx, (ushort)sptable[number].ty,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
47 (ushort)sptable[number].tw, (ushort)sptable[number].th,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
48 SPRITE_PRIO_FOREGROUND);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
49
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
50 ps2util_sprite_Request(p);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
51 sp_counter++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
52 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
53
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
54 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
55 gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
56 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
57 ps2utilSprite *p = &sp[sp_counter];
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
58
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
59 ps2util_sprite_Set_basicAttribute(
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
60 p,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
61 (ushort)x, (ushort)y,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
62 (ushort)sptable[number].tw*w, (ushort)sptable[number].th*h,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63 (ushort)sptable[number].tx, (ushort)sptable[number].ty,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
64 (ushort)sptable[number].tw, (ushort)sptable[number].th,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
65 SPRITE_PRIO_FOREGROUND);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
66
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67 ps2util_sprite_Request(p);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
68 sp_counter++;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
69 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
70
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
71 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
72 gSprite_Init_Png(char *texname)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
73 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
74 if (!(sprite_tex = read_png_file(texname))) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
75 fprintf(stderr,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
76 "cannot creat texture - init_png().\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
77 fflush(stderr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
78 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
79 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
80
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
81 if (ps2util_tex_Set(sprite_tex) == -1) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
82 fprintf(stderr,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
83 "cannot set texture - init_png().\n");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
84 fflush(stderr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
85 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
86 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
87
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
88 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
89
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
90 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
91 gSprite_Create()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
93 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
94
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
95 for (i=0; i<DEFOBJ; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
96 if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
97 fprintf(stderr,
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
98 "cannot create sprite No.%d - create_sprite()\n", i);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
99 fflush(stderr);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
100 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
101 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
102 ps2util_sprite_Unuse_alpha(&sp[i]);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
103 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
104
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
105 flag_spriteInited = TRUE;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
106 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
107
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
108 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
109 gSprite_Init()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
110 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
111 ps2util_graphic_Init();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
112 gSprite_Init_Png("img/main2.png");
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
113 gSprite_Create(); // スプライト生成
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
114
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
115 /* スプライトの登録 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
116 gSprite_DefSprite(10, 1, 1, 512, 666); /* タイトル */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
117 gSprite_DefSprite(17, 1, 35, 33, 33); /* 選択マーク */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
118 gSprite_DefSprite(23, 1, 1, 106, 34); /* スピードメーター */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
119 gSprite_DefSprite(24, 51, 40, 18, 20); /* 右矢印 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
120 gSprite_DefSprite(25, 33, 40, 17, 20); /* 左矢印 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
121 gSprite_DefSprite(26, 56, 89, 55, 26); /* km/h */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
122 gSprite_DefSprite(27, 62, 62, 39, 26); /* Rap */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
123 gSprite_DefSprite(28, 430, 62, 53, 46); /* 1P */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
124 gSprite_DefSprite(29, 460, 6, 53, 46); /* 2P */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
125 gSprite_DefSprite(51, 333, 116, 165, 140); /* 選択画面の車 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
126 gSprite_DefSprite(52, 181, 116, 165, 140);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
127 gSprite_DefSprite(53, 12, 116, 165, 140);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
128 gSprite_DefSprite(81, 115, 1, 148, 114); /* 選択画面のコース */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
129 // 本当は (82, 272,...)です。二つ目のコース絵がないので
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
130 gSprite_DefSprite(82, 272, 1, 148, 114);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
132
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 gSprite_Clear()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
135 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
136 int i;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
137
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138 for (i=0; i<DEFOBJ; i++) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
139 sprite_disappear(&sp[i].attribute);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141 sp_counter = 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
143
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
144 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
145 gSprite_Draw_Reset()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
146 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
147 if (flag_spriteInited == TRUE) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
148 gSprite_Clear();
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
150 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
151
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
152 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
153 gSprite_PutSprite_Pause()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
155 }