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