-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
816 lines (634 loc) · 18.4 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
/* png example for KOS 1.1.x
* hacked up to shit by futurepr0n
*/
#include <kos.h>
#include <iostream>
#include <png/png.h>
//extern "C"{
#include <zlib/zlib.h>
//}
#include <mp3/sndserver.h>
#include <modplug/stdafx.h>
#include <modplug/sndfile.h>
long bitrateold, bitratenew;
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS);
/* font data */
extern char wfont[];
extern "C" {
int zlib_getlength(char*);
}
/* textures */
pvr_ptr_t font_tex;
pvr_ptr_t back_tex;
pvr_ptr_t bsg_back_tex;
pvr_ptr_t background_tex;
pvr_ptr_t starfield_tex;
char *data;
/** MikMod Stuff **/
uint16 sound_buffer[65536] = {0};
CSoundFile *soundfile;
void *mod_callback(snd_stream_hnd_t hnd, int len, int * actual) {
int res;
res = soundfile->Read(sound_buffer, len) * 4/*samplesize*/;
//printf("res: %i, len: %i\n",res,len);
if(res < len) {
soundfile->SetCurrentPos(0);
soundfile->Read(&sound_buffer[res], len - res);
}
*actual = len;
return sound_buffer;
}
/** MikMod Stuff **/
/* Stuff from my battlestar*/
//int done = 0;
//int bullets = 0;
//char highScore[5];
//char playerScore[5];
//int points = 0;
//int hScore = 1000;
typedef struct{
int x;
int y;
int imgX;
int imgY;
//int dir;
void *img_data;
pvr_ptr_t texture_pointer;
int isalive;
int pctr;
}obj;
//obj prs_circle;
//obj spl_background;
//obj background;
//obj starfield;
obj player;
//obj enemy[MAX_NUM_ENEMIES];
//obj chain[MAX_NUM_BULLETS];
void initSplash();
void initStorySplash();
void initStarfield();
void initBackground();
void initShip();
/* init background */
void back_init(void) {
back_tex = pvr_mem_malloc(512 * 512 * 2);
png_to_texture("/rd/background.png", back_tex, PNG_NO_ALPHA);
}
/* init background */
void bsg_back_init(void) {
bsg_back_tex = pvr_mem_malloc(512 * 512 * 2);
png_to_texture("/rd/bsg-open-title.png", bsg_back_tex, PNG_NO_ALPHA);
}
/* init font */
void font_init(void) {
int i, x, y, c;
unsigned short * temp_tex;
font_tex = pvr_mem_malloc(256 * 256 * 2);
temp_tex = (unsigned short *)malloc(256 * 128 * 2);
c = 0;
for(y = 0; y < 128 ; y += 16)
for(x = 0; x < 256 ; x += 8) {
for(i = 0; i < 16; i++) {
temp_tex[x + (y + i) * 256 + 0] = 0xffff * ((wfont[c + i] & 0x80) >> 7);
temp_tex[x + (y + i) * 256 + 1] = 0xffff * ((wfont[c + i] & 0x40) >> 6);
temp_tex[x + (y + i) * 256 + 2] = 0xffff * ((wfont[c + i] & 0x20) >> 5);
temp_tex[x + (y + i) * 256 + 3] = 0xffff * ((wfont[c + i] & 0x10) >> 4);
temp_tex[x + (y + i) * 256 + 4] = 0xffff * ((wfont[c + i] & 0x08) >> 3);
temp_tex[x + (y + i) * 256 + 5] = 0xffff * ((wfont[c + i] & 0x04) >> 2);
temp_tex[x + (y + i) * 256 + 6] = 0xffff * ((wfont[c + i] & 0x02) >> 1);
temp_tex[x + (y + i) * 256 + 7] = 0xffff * (wfont[c + i] & 0x01);
}
c += 16;
}
pvr_txr_load_ex(temp_tex, font_tex, 256, 256, PVR_TXRLOAD_16BPP);
}
void text_init(void) {
const char* filename = "/rd/text.gz";
int length = zlib_getlength(const_cast<char*>(filename));
//int length = zlib_getlength("/rd/text.gz");
gzFile f;
data = (char *)malloc(length + 1); // I am not currently freeing it
f = gzopen("/rd/text.gz", "r");
gzread(f, data, length);
data[length] = 0;
gzclose(f);
printf("length [%d]\n", length);
}
/* draw background */
void draw_back(void) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_RGB565, 512, 512, back_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = 0.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 1.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 1.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 1.0f;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
/* draw the title screen background */
void draw_splash_back(void) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_RGB565, 512, 512, bsg_back_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = 0.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 1.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 1.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 1.0f;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
void draw_background(void) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_RGB565, 512, 512, background_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = 0.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 0.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 1.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 1.0f;
pvr_prim(&vert, sizeof(vert));
vert.x = 640.0f;
vert.y = 480.0f;
vert.z = 1.0f;
vert.u = 1.0f;
vert.v = 1.0f;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
void draw_ship(obj Obj) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
// Update texture size to 64x32 (next power of 2 for 46x24)
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, 64, 64, Obj.texture_pointer, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
float half_width = 64.0f / 2;
float half_height = 64.0f / 2;
// Calculate UV coordinates
float u_max = 64.0f / 64.0f; // 46 / next power of 2
float v_max = 64.0f / 64.0f; // 24 / next power of 2
// Top-left vertex
vert.x = Obj.x - half_width;
vert.y = Obj.y - half_height;
vert.z = 1.0f;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Top-right vertex
vert.x = Obj.x + half_width;
vert.y = Obj.y - half_height;
vert.u = u_max;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Bottom-left vertex
vert.x = Obj.x - half_width;
vert.y = Obj.y + half_height;
vert.u = 0.0f;
vert.v = v_max;
pvr_prim(&vert, sizeof(vert));
// Bottom-right vertex
vert.flags = PVR_CMD_VERTEX_EOL;
vert.x = Obj.x + half_width;
vert.y = Obj.y + half_height;
vert.u = u_max;
vert.v = v_max;
pvr_prim(&vert, sizeof(vert));
}
/* draw the starfield */
void draw_starfield(float x1, float y1, float z1, float a, float r, float g, float b, int c, float xs, float ys) {
pvr_vertex_t vert;
int ix, iy;
float u1, v1, u2, v2;
ix = (c % 32) * 8;
iy = (c / 32) * 16;
u1 = (ix + 0.5f) * 1.0f / 256.0f;
v1 = (iy + 0.5f) * 1.0f / 256.0f;
u2 = (ix + 7.5f) * 1.0f / 256.0f;
v2 = (iy + 15.5f) * 1.0f / 256.0f;
vert.flags = PVR_CMD_VERTEX;
vert.x = x1;
vert.y = y1 + 16.0f * ys;
vert.z = z1;
vert.u = u1;
vert.v = v2;
vert.argb = PVR_PACK_COLOR(a, r, g, b);
vert.oargb = 0;
pvr_prim(&vert, sizeof(vert));
vert.x = x1;
vert.y = y1;
vert.u = u1;
vert.v = v1;
pvr_prim(&vert, sizeof(vert));
vert.x = x1 + 8.0f * xs;
vert.y = y1 + 16.0f * ys;
vert.u = u2;
vert.v = v2;
pvr_prim(&vert, sizeof(vert));
vert.flags = PVR_CMD_VERTEX_EOL;
vert.x = x1 + 8.0f * xs;
vert.y = y1;
vert.u = u2;
vert.v = v1;
pvr_prim(&vert, sizeof(vert));
}
/* draw one character */
void draw_char(float x1, float y1, float z1, float a, float r, float g, float b, int c, float xs, float ys) {
pvr_vertex_t vert;
int ix, iy;
float u1, v1, u2, v2;
ix = (c % 32) * 8;
iy = (c / 32) * 16;
u1 = (ix + 0.5f) * 1.0f / 256.0f;
v1 = (iy + 0.5f) * 1.0f / 256.0f;
u2 = (ix + 7.5f) * 1.0f / 256.0f;
v2 = (iy + 15.5f) * 1.0f / 256.0f;
vert.flags = PVR_CMD_VERTEX;
vert.x = x1;
vert.y = y1 + 16.0f * ys;
vert.z = z1;
vert.u = u1;
vert.v = v2;
vert.argb = PVR_PACK_COLOR(a, r, g, b);
vert.oargb = 0;
pvr_prim(&vert, sizeof(vert));
vert.x = x1;
vert.y = y1;
vert.u = u1;
vert.v = v1;
pvr_prim(&vert, sizeof(vert));
vert.x = x1 + 8.0f * xs;
vert.y = y1 + 16.0f * ys;
vert.u = u2;
vert.v = v2;
pvr_prim(&vert, sizeof(vert));
vert.flags = PVR_CMD_VERTEX_EOL;
vert.x = x1 + 8.0f * xs;
vert.y = y1;
vert.u = u2;
vert.v = v1;
pvr_prim(&vert, sizeof(vert));
}
/* draw a string */
void draw_string(float x, float y, float z, float a, float r, float g, float b, char *str, float xs, float ys) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
float orig_x = x;
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, 256, 256, font_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
while(*str) {
if(*str == '\n') {
x = orig_x;
y += 40;
str++;
continue;
}
draw_char(x, y, z, a, r, g, b, *str++, xs, ys);
x += 8 * xs;
}
}
/* base y coordinate */
int y = 0;
/* draw one frame */
void draw_frame(void) {
pvr_wait_ready();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_OP_POLY);
draw_back();
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
/* 1720 and 480 are magic numbers directly related to the text scrolling
* 1720 is enough room for the whole text to scroll from the bottom of
* the screen to off the top. 31 lines * 40 pixels + 480 pixel high screen
* 480 is the height of the screen (starts the text at the bottom)
*/
draw_string(0, y % 1720 + 440, 3, 1, 1, 1, 1, data, 2, 2);
pvr_list_finish();
pvr_scene_finish();
y--;
}
/* draw spash frame */
void draw_splash_frame(void) {
pvr_wait_ready();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_OP_POLY);
draw_splash_back();
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
pvr_list_finish();
pvr_scene_finish();
}
void draw_scrolling_background(float x_offset) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, 512, 512, starfield_tex, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
// Draw first copy of the background
vert.argb = PVR_PACK_COLOR(1, 1, 1, 1);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
// Top-left vertex
vert.x = x_offset;
vert.y = 0;
vert.z = 3;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Top-right vertex
vert.x = x_offset + 640.0f;
vert.y = 0;
vert.u = 1.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Bottom-left vertex
vert.x = x_offset;
vert.y = 480.0f;
vert.u = 0.0f;
vert.v = 1.0f;
pvr_prim(&vert, sizeof(vert));
// Bottom-right vertex
vert.x = x_offset + 640.0f;
vert.y = 480.0f;
vert.u = 1.0f;
vert.v = 1.0f;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
// Draw second copy of the background
vert.flags = PVR_CMD_VERTEX;
// Top-left vertex
vert.x = x_offset + 640.0f;
vert.y = 0;
vert.z = 3;
vert.u = 0.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Top-right vertex
vert.x = x_offset + 1280.0f;
vert.y = 0;
vert.u = 1.0f;
vert.v = 0.0f;
pvr_prim(&vert, sizeof(vert));
// Bottom-left vertex
vert.x = x_offset + 640.0f;
vert.y = 480.0f;
vert.u = 0.0f;
vert.v = 1.0f;
pvr_prim(&vert, sizeof(vert));
// Bottom-right vertex
vert.x = x_offset + 1280.0f;
vert.y = 480.0f;
vert.u = 1.0f;
vert.v = 1.0f;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
/* Draw the scene for the gameplay*/
void draw_scene(void) {
static float x_offset = 0;
pvr_wait_ready();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_OP_POLY);
draw_background();
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
draw_scrolling_background(x_offset);
draw_ship(player); // Uncommented and moved inside the translucent polygon list
pvr_list_finish();
pvr_scene_finish();
x_offset -= 1.0f;
if (x_offset <= -640.0f) {
x_offset += 640.0f;
}
}
int main(int argc, char **argv) {
int done = 0;
/* from mp3test.c */
maple_device_t *cont;
cont_state_t *state;
/* -------------- */
/* MikMod Stuff */
uint8 *mod_buffer;
uint32 hnd;
char filename[] = "/rd/mrdeath.xm";
/********************/
/* init kos */
pvr_init_defaults();
/* init splash screen */
initSplash();
initStorySplash();
initBackground();
initStarfield();
initShip();
printf("modplug_test beginning\n");
snd_stream_init();
hnd = fs_open(filename, O_RDONLY);
if(!hnd) {
printf("Error reading %s\n", filename);
return 0;
}
printf("Filesize: %i\n", fs_total(hnd));
mod_buffer = (uint8 *)malloc(fs_total(hnd));
if(!mod_buffer) {
printf("Not enough memory\n");
return 0;
}
printf("Memory allocated\n");
if((size_t)fs_read(hnd, mod_buffer, fs_total(hnd)) != fs_total(hnd)) {
printf("Read error\n");
free(mod_buffer);
return 0;
}
printf("File read\n");
soundfile = new CSoundFile;
if(!soundfile) {
printf("Not enough memory\n");
free(mod_buffer);
return 0;
}
printf("CSoundFile created\n");
if(!soundfile->Create(mod_buffer, fs_total(hnd))) {
printf("Mod not loaded\n");
free(mod_buffer);
delete soundfile;
return 0;
}
printf("Mod loaded\n");
soundfile->SetWaveConfig(44100, 16, 2);
printf("Type: %li\n", soundfile->GetType());
printf("Title: %s\n", soundfile->GetTitle());
/*fs_close(hnd);
free(mod_buffer);*/
snd_stream_hnd_t shnd = snd_stream_alloc(mod_callback, SND_STREAM_BUFFER_MAX);
snd_stream_start(shnd, 44100, 1);
while(1) {
draw_scene();
/* Check key status */
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
if(cont) {
state = (cont_state_t *)maple_dev_status(cont);
if(state && state->buttons & CONT_START)
break;
if(state && state->buttons & CONT_DPAD_LEFT)
player.x--;
if(state && state->buttons & CONT_DPAD_RIGHT)
player.x++;
if(state && state->buttons & CONT_DPAD_UP)
player.y--;
if(state && state->buttons & CONT_DPAD_DOWN)
player.y++;
// Use joystick for movement
if (state) {
// Check the X axis of the main joystick
if (state->joyx < -10) { // Threshold to avoid sensitivity issues
player.x--; // Move left
} else if (state->joyx > 10) {
player.x++; // Move right
}
// Check the Y axis of the main joystick
if (state->joyy < -10) {
player.y--; // Move up
} else if (state->joyy > 10) {
player.y++; // Move down
}
}
}
snd_stream_poll(shnd);
timer_spin_sleep(10);
}
delete soundfile;
snd_stream_destroy(shnd);
snd_stream_shutdown();
return 0;
}
void initSplash(){
int done = 0;
/* init background */
bsg_back_init();
while(!done) {
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
if(st->buttons & CONT_START)
done = 1;
MAPLE_FOREACH_END()
draw_splash_frame();
}
return;
}
void initStorySplash(){
int done = 0;
/* init background */
/* init font */
font_init();
/* init background */
back_init();
/* init text */
text_init();
/* init soundstream and mp3 stuff (from mp3test) */
snd_stream_init();
mp3_init();
mp3_start("/rd/theme.mp3", 0);
/* keep drawing frames until start is pressed */
while(!done) {
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
if(st->buttons & CONT_START)
done = 1;
MAPLE_FOREACH_END()
draw_frame();
}
/* Clean up the sound stuff on exit */
mp3_stop();
//mp3_shutdown();
//snd_stream_shutdown();
return;
}
void initBackground(){
background_tex = pvr_mem_malloc(512 * 512 * 2);
png_to_texture("/rd/space_bg1.png", background_tex, PNG_NO_ALPHA);
}
void initStarfield(){
starfield_tex = pvr_mem_malloc(512 * 512 * 2);
png_to_texture("/rd/starfield_one1.png", starfield_tex, PNG_MASK_ALPHA);
}
void initShip(){
// Allocate memory for 64x32 texture (next power of 2 for 46x24)
player.texture_pointer = pvr_mem_malloc(64 * 64 * 2);
png_to_texture("/rd/vipersm2.png", player.texture_pointer, PNG_FULL_ALPHA);
// Set initial position to the center of the screen
player.x = 320; // Half of 640 (screen width)
player.y = 240; // Half of 480 (screen height)
player.isalive = 1; // Set the ship as alive
}