Subversion Repositories Kolibri OS

Rev

Rev 5243 | Rev 5260 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5243 Rev 5251
Line 146... Line 146...
146
    snd->length_samples = length_samples;
146
    snd->length_samples = length_samples;
147
    snd->data = malloc(length_samples*2);
147
    snd->data = malloc(length_samples*2);
148
    rskos_snd_create_buffer(&snd->hbuf, snd->data, length_samples);
148
    rskos_snd_create_buffer(&snd->hbuf, snd->data, length_samples);
149
};
149
};
Line -... Line 150...
-
 
150
 
-
 
151
void soundbuf_update(rs_soundbuf_t *snd) {
-
 
152
    rskos_snd_update_buffer(&snd->hbuf, snd->data, snd->length_samples);
-
 
153
};
150
 
154
 
151
void soundbuf_free(rs_soundbuf_t *snd) {
155
void soundbuf_free(rs_soundbuf_t *snd) {
152
    snd->status = 0;
156
    snd->status = 0;
153
    free(snd->data);
157
    free(snd->data);
Line 215... Line 219...
215
 
219
 
Line 216... Line 220...
216
void game_reg_init() {
220
void game_reg_init() {
Line -... Line 221...
-
 
221
    
-
 
222
    game.loader_counter = 0;
217
    
223
    
Line -... Line 224...
-
 
224
    game.menu_replay_timeout = 0;
-
 
225
    
218
    game.loader_counter = 0;
226
    game.process_timer = 0;
Line 219... Line 227...
219
    
227
    
220
    game.process_timer = 0;
228
    game.sound_index = 0;
Line -... Line 229...
-
 
229
    
-
 
230
    game.need_redraw = 1;
221
    
231
    
222
    game.need_redraw = 1;
232
    game.score = 0;
Line 223... Line 233...
223
    
233
    game.time = 0;
Line 224... Line 234...
224
    game.score = 0;
234
    
225
    game.time = 0;
235
//    game.game_mode = GAME_MODE_RAMPAGE;
226
 
236
 
Line 227... Line 237...
227
    game.selected = 0;
237
    game.selected = 0;
228
    game.selected_x = game.selected_y = 0;
238
    game.selected_x = game.selected_y = 0;
229
    
239
    
230
    game.explosions_count = 0;
240
    game.explosions_count = 0;
Line 250... Line 260...
250
//        window_scale_str[3] = '3'; 
260
//        window_scale_str[3] = '3'; 
251
//    #endif
261
//    #endif
Line 252... Line 262...
252
    
262
    
Line 253... Line 263...
253
    game.keyboard_state = 0;
263
    game.keyboard_state = 0;
254
    
264
    
255
    game.menu_index = 0;
265
//    game.menu_index = 0;
Line 256... Line 266...
256
    game.menu_item_index = 0;
266
//    game.menu_item_index = 0;
257
};
267
};
Line 349... Line 359...
349
                game.explosions_count++;
359
                game.explosions_count++;
350
            };
360
            };
351
        };
361
        };
352
    };
362
    };
Line 353... Line 363...
353
    
363
    
354
    if (game.score > 99) {
364
//    if (game.score > 99) {
355
        game.status = STATUS_MENU;
365
//        game.status = STATUS_MENU;
356
        game.need_redraw = 1;
366
//        game.need_redraw = 1;
Line 357... Line 367...
357
    };
367
//    };
358
    
368
    
-
 
369
    if (found) {
-
 
370
        game.need_redraw = 1;
359
    if (found) {
371
        soundbuf_play(&game.sound_explosion[ game.sound_index ]);
Line 360... Line 372...
360
        game.need_redraw = 1;
372
        game.sound_index = (game.sound_index+1) % SOUND_EXPLOSION_COUNT;
361
    };
373
    };
Line -... Line 374...
-
 
374
    
-
 
375
    return found;
-
 
376
};
-
 
377
 
-
 
378
 
-
 
379
//void game_check_and_explode_rampage() {
-
 
380
//    
-
 
381
//    
362
    
382
//    
363
    return found;
383
//};
364
};
384
 
365
 
385
 
366
void game_fall() {
386
void game_fall() {
Line 392... Line 412...
392
        if (game.loader_counter == 2) {
412
        if (game.loader_counter == 2) {
Line 393... Line 413...
393
                
413
                
Line -... Line 414...
-
 
414
            game_textures_init_stage2();
-
 
415
            
-
 
416
            
-
 
417
            // Sounds...
-
 
418
            
-
 
419
            int soundlen = 40555;
-
 
420
            
-
 
421
            int freqs[SOUND_EXPLOSION_COUNT] = { 440, 523, 587, 698, 783, 880, 1046, 1174 };
-
 
422
            
-
 
423
            int i;
-
 
424
            for (i = 0; i < SOUND_EXPLOSION_COUNT; i++) {
-
 
425
 
-
 
426
                soundbuf_init(&game.sound_explosion[i], soundlen);
-
 
427
 
-
 
428
 
-
 
429
                rs_sgen_init(3, soundlen);
-
 
430
 
-
 
431
                rs_sgen_func_noise(2, 1000);
-
 
432
                rs_sgen_func_phaser(0, 2, 0.9, 15.2 + 1.0*i/SOUND_EXPLOSION_COUNT, 6.0, 3.0, 2000.0, 1.73); 
-
 
433
                rs_sgen_func_normalize(0, 1.0);
-
 
434
 
-
 
435
 
-
 
436
                rs_sgen_func_sin(1, freqs[i], 110.3);
-
 
437
                rs_sgen_func_sin(2, 1.5*freqs[i], 110.2);
-
 
438
 
-
 
439
                rs_sgen_func_add(0, 0, 1, 1.0, 0.2);
-
 
440
                rs_sgen_func_add(0, 0, 2, 1.0, 0.2);
-
 
441
 
-
 
442
                rs_sgen_func_lowpass(2, 0, 1.0, 0.0, 20.0);
-
 
443
                rs_sgen_func_normalize(2, 1.0);
-
 
444
 
-
 
445
                rs_sgen_wave_out(2);
-
 
446
 
-
 
447
                memcpy(game.sound_explosion[i].data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2);
-
 
448
                soundbuf_update(&game.sound_explosion[i]);
-
 
449
 
-
 
450
                rs_sgen_term();
-
 
451
            
-
 
452
            };
-
 
453
            
-
 
454
 
-
 
455
            soundlen = 1024;
-
 
456
            
-
 
457
            soundbuf_init(&game.sound_tick, soundlen);
-
 
458
        //    soundbuf_init(&game.sound_tack, soundlen);
-
 
459
            
-
 
460
            rs_sgen_init(2, soundlen);
-
 
461
            rs_sgen_func_noise(1, 1000);
-
 
462
            
-
 
463
            rs_sgen_func_highpass(0, 1, 0.05, 0.0, 16.0);
-
 
464
            rs_sgen_func_normalize(0, 1.0);
-
 
465
            rs_sgen_wave_out(0);
-
 
466
            memcpy(game.sound_tick.data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2);
-
 
467
            soundbuf_update(&game.sound_tick);
-
 
468
 
-
 
469
        //    rs_sgen_func_lowpass(0, 1, 0.5, 0.0, 22.0);
-
 
470
        //    rs_sgen_func_normalize(0, 1.0);
-
 
471
        //    rs_sgen_wave_out(0);
-
 
472
        //    memcpy(game.sound_tack.data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2);
-
 
473
        //    soundbuf_update(&game.sound_tack);
-
 
474
 
-
 
475
            rs_sgen_term();
-
 
476
            
-
 
477
            soundlen = 123000; 
-
 
478
            
-
 
479
            soundbuf_init(&game.sound_bang, soundlen);
-
 
480
            rs_sgen_init(2, soundlen);
-
 
481
            rs_sgen_func_pm(1, 220.0, 1.2, 1.0, 880.0*4, 1.0 );
-
 
482
            rs_sgen_func_lowpass(0, 1, 1.0, 0.0, 15.0);
-
 
483
            rs_sgen_func_normalize(0, 1.0);
-
 
484
            rs_sgen_wave_out(0);
-
 
485
            memcpy(game.sound_bang.data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2);
-
 
486
            soundbuf_update(&game.sound_bang);
-
 
487
            
-
 
488
            
-
 
489
            soundbuf_init(&game.sound_click, 1024);
-
 
490
            soundbuf_sin(&game.sound_click, 0.25);
Line 394... Line 491...
394
            game_textures_init_stage2();
491
            
395
               
492
              
Line 396... Line 493...
396
            
493
            soundbuf_play(&game.sound_bang); // <-- Loaded. Bang!
Line 419... Line 516...
419
                game.explosions_count--;
516
                game.explosions_count--;
420
                i--;
517
                i--;
421
            };
518
            };
422
        };
519
        };
Line 423... Line 520...
423
        
520
        
424
        if ((game.time+1)/25 != game.time/25) {
521
        if ((game.time-1)/25 != game.time/25) {
-
 
522
            game.need_redraw = 1;
-
 
523
            
-
 
524
            if (game.time < 10*25) {
425
            game.need_redraw = 1;
525
                soundbuf_play(&game.sound_tick);
Line 426... Line 526...
426
        };
526
            };
Line -... Line 527...
-
 
527
            
Line -... Line 528...
-
 
528
        };
-
 
529
        
-
 
530
        game.time--;
-
 
531
        
-
 
532
        if (game.time < 1) {
Line -... Line 533...
-
 
533
            // Game Over
-
 
534
            game.status = STATUS_MENU;
Line -... Line 535...
-
 
535
            game.need_redraw = 1;
-
 
536
            soundbuf_play(&game.sound_bang);
-
 
537
            
-
 
538
            game.menu_replay_timeout = 40;
-
 
539
        };
-
 
540
        
-
 
541
        
-
 
542
 
-
 
543
    }
-
 
544
    else if (game.status == STATUS_MENU) {
-
 
545
        
-
 
546
        if (game.menu_replay_timeout > 0) {
427
        
547
            game.menu_replay_timeout--;
Line 428... Line 548...
428
        game.time++;
548
            if (game.menu_replay_timeout == 1) {
Line 429... Line 549...
429
        
549
                game.menu_replay_timeout = 0;
Line 461... Line 581...
461
 
581
 
462
    #ifndef RS_KOS
582
    #ifndef RS_KOS
463
        rs_audio_init(RS_AUDIO_FMT_MONO16, RS_AUDIO_FREQ_16000, 0); 
583
        rs_audio_init(RS_AUDIO_FMT_MONO16, RS_AUDIO_FREQ_16000, 0); 
Line 464... Line -...
464
    #endif
-
 
465
 
-
 
466
    soundbuf_init(&game.sound_test1, 2048);
-
 
467
//    soundbuf_fill(&game.sound_test1, 2, 50);
584
    #endif
468
    soundbuf_sin_fade(&game.sound_test1, 0.7);
-
 
469
 
-
 
470
    soundbuf_init(&game.sound_test2, 1024);
-
 
471
    //soundbuf_fill(&game.sound_test2, 8, 40);
585
 
472
    soundbuf_sin(&game.sound_test2, 0.48);
-
 
473
 
-
 
474
    soundbuf_init(&game.sound_test3, 1024);
-
 
Line 475... Line 586...
475
    //soundbuf_fill(&game.sound_test3, 12, 60);
586
 
Line 493... Line 604...
493
    game_font_term();
604
    game_font_term();
Line 494... Line 605...
494
    
605
    
Line -... Line 606...
-
 
606
    game_textures_free();
Line -... Line 607...
-
 
607
    
-
 
608
    
-
 
609
    int i;
Line 495... Line -...
495
    game_textures_free();
-
 
496
    
610
 
497
    
611
    for (i = 0; i < SOUND_EXPLOSION_COUNT; i++) {
-
 
612
        soundbuf_free(&game.sound_explosion[i]);
498
    
613
    };
Line 499... Line 614...
499
 
614
    
Line 500... Line 615...
500
    
615
    soundbuf_free(&game.sound_click);
Line 538... Line 653...
538
//            game.shoot_keypressed = 1;
653
//            game.shoot_keypressed = 1;
539
            break;
654
            break;
540
    };
655
    };
Line 541... Line 656...
541
    
656
    
542
    
657
    
543
    if (game.status == STATUS_MENU) {
658
//    if (game.status == STATUS_MENU) {
544
    
659
//    
545
        switch (key) {
660
//        switch (key) {
546
            case RS_KEY_LEFT:
661
//            case RS_KEY_LEFT:
547
                BIT_SET(game.keyboard_state, RS_ARROW_LEFT_MASK);
662
//                BIT_SET(game.keyboard_state, RS_ARROW_LEFT_MASK);
548
                //PlayBuffer(hBuff, 0);
663
//                //PlayBuffer(hBuff, 0);
549
                break;
664
//                break;
550
            case RS_KEY_RIGHT:
665
//            case RS_KEY_RIGHT:
551
                BIT_SET(game.keyboard_state, RS_ARROW_RIGHT_MASK);
666
//                BIT_SET(game.keyboard_state, RS_ARROW_RIGHT_MASK);
552
                //StopBuffer(hBuff);
667
//                //StopBuffer(hBuff);
553
                break;
668
//                break;
554
            case RS_KEY_UP:
669
//            case RS_KEY_UP:
555
                BIT_SET(game.keyboard_state, RS_ARROW_UP_MASK);
670
//                BIT_SET(game.keyboard_state, RS_ARROW_UP_MASK);
556
                menu_cursor_up();
671
//                menu_cursor_up();
557
                //ResetBuffer(hBuff, 0);
672
//                //ResetBuffer(hBuff, 0);
558
                break;
673
//                break;
559
            case RS_KEY_DOWN:
674
//            case RS_KEY_DOWN:
560
                BIT_SET(game.keyboard_state, RS_ARROW_DOWN_MASK);
675
//                BIT_SET(game.keyboard_state, RS_ARROW_DOWN_MASK);
561
                menu_cursor_down();
676
//                menu_cursor_down();
562
                break;
677
//                break;
563
            case RS_KEY_RETURN:
678
//            case RS_KEY_RETURN:
564
                menu_cursor_click();
679
//                menu_cursor_click();
565
                break;
680
//                break;
566
            case RS_KEY_ESCAPE:
681
//            case RS_KEY_ESCAPE:
567
                menu_open(0);
682
//                menu_open(0);
568
                break;
683
//                break;
569
        };
684
//        };
Line 570... Line 685...
570
 
685
//
Line 571... Line 686...
571
    };
686
//    };
572
    
687
    
573
    if (game.status == STATUS_PLAYING) {
688
    if (game.status == STATUS_PLAYING) {
574
        
689
        
-
 
690
 
575
 
691
        #ifndef RS_KOS
Line 576... Line 692...
576
        #ifndef RS_KOS
692
            if (key == RS_KEY_SPACE) {
577
            if (key == RS_KEY_SPACE) {
693
                game.score = 101;
578
                game.score = 101;
694
            };
579
            };
695
            
580
        #endif
696
        #endif
581
 
697
 
Line -... Line 698...
-
 
698
        if (key == RS_KEY_ESCAPE) {
-
 
699
            game.time = 0;
-
 
700
            game.score = 0;
-
 
701
            game.status = STATUS_MENU;
-
 
702
            game.need_redraw = 1;
-
 
703
        };
-
 
704
        
582
        if (key == RS_KEY_ESCAPE) {
705
        if (key == RS_KEY_A) {
Line 583... Line 706...
583
            game.time = 0;
706
            soundbuf_play(&game.sound_bang);
Line 584... Line 707...
584
            game.score = 0;
707
        };
Line 619... Line 742...
619
    unsigned short d;
742
    unsigned short d;
620
} cc_t;
743
} cc_t;
Line 621... Line 744...
621
 
744
 
Line -... Line 745...
-
 
745
void GameMouseDown(int x, int y) {
-
 
746
    
Line 622... Line 747...
622
void GameMouseDown(int x, int y) {
747
    x = (signed short) x;
Line 623... Line 748...
623
    
748
    y = (signed short) y;
624
    
749
    
Line 625... Line 750...
625
    game.need_redraw = 1;
750
    game.need_redraw = 1;
Line -... Line 751...
-
 
751
    
-
 
752
//    game.tx = x;
626
    
753
//    game.ty = y;
627
    game.tx = x;
754
    
628
    game.ty = y;
755
    if (game.status == STATUS_MENU) {
629
    
756
            
Line -... Line 757...
-
 
757
        if ( (!game.menu_replay_timeout) && (y > 0) ) {
630
    if (game.status == STATUS_MENU) {
758
            
631
            
759
            int i;
632
        int i;
760
            for (i = 0; i < FIELD_LENGTH; i++) {
633
        for (i = 0; i < FIELD_LENGTH; i++) {
761
                game.field[i] = (unsigned char) (0.99 * fabs(rs_noise(i, seed*7 + 10)) * CRYSTALS_COUNT) | CRYSTAL_VISIBLE_BIT;
-
 
762
            };
-
 
763
            
-
 
764
            game.sound_index = 0;
634
            game.field[i] = (unsigned char) (0.99 * fabs(rs_noise(i, seed*7 + 10)) * CRYSTALS_COUNT) | CRYSTAL_VISIBLE_BIT;
765
            game.selected = 0;
635
        };
766
            game.time = 25*60 - 1;
Line 636... Line 767...
636
        
767
            game.score = 0;
Line 653... Line 784...
653
            return;
784
            return;
654
        };
785
        };
Line 655... Line 786...
655
        
786
        
Line -... Line 787...
-
 
787
        //FIELD_ITEM(field_x, field_y) = 0;
-
 
788
        
-
 
789
        
-
 
790
//        if (game.game_mode == GAME_MODE_MATCH3) {
656
        //FIELD_ITEM(field_x, field_y) = 0;
791
        
657
        
792
        
658
        if (!game.selected) {
793
            if (!game.selected) {
659
            game.selected = 1;
794
                game.selected = 1;
660
            game.selected_x = field_x;
-
 
-
 
795
                game.selected_x = field_x;
661
            game.selected_y = field_y;                                                                      
796
                game.selected_y = field_y;                                                                      
662
            
797
                soundbuf_play(&game.sound_click);
Line 663... Line 798...
663
        }
798
            }
664
        else {
799
            else {
Line 680... Line 815...
680
                    game.process_timer = 0;
815
                        game.process_timer = 0;
681
                };
816
                    };
Line 682... Line 817...
682
                
817
                    
683
            }
818
                }
-
 
819
                else {
684
            else {
820
                    soundbuf_play(&game.sound_click);
685
                if ( (game.selected_x != field_x) && (game.selected_y != field_y) ) {
821
                    if ( (game.selected_x != field_x) && (game.selected_y != field_y) ) {
686
                    game.selected_x = field_x;
822
                        game.selected_x = field_x;
687
                    game.selected_y = field_y;
823
                        game.selected_y = field_y;
688
                }
824
                    }
689
                else {
825
                    else {
-
 
826
                        game.selected = 0;
690
                    game.selected = 0;
827
                        
691
                };
828
                    };
Line 692... Line 829...
692
            };
829
                };
Line -... Line 830...
-
 
830
                
-
 
831
            };
693
            
832
            
694
        };
833
//        } else if (game.mode == GAME_MODE_RAMPAGE) {
695
        
834
//            
-
 
835
//            game.selected = 1;
-
 
836
//            game.selected_x = field_x;
-
 
837
//            game.selected_y = field_y;   
696
//        int i;
838
//            
697
//        for (i = field_y; i > 0; i--) {
-
 
Line 698... Line 839...
698
//            FIELD_ITEM(field_x, i) = FIELD_ITEM(field_x, (i-1) );
839
//            game_check_and_explode_rampage();
Line 699... Line 840...
699
//        };
840
//            
Line 710... Line 851...
710
 
851
 
Line 711... Line 852...
711
void game_ding(int i) {
852
void game_ding(int i) {
712
    
853
    
713
    switch (i) {
854
    switch (i) {
714
        case 0:
855
        case 0:
715
            soundbuf_play(&game.sound_test2);
856
//            soundbuf_play(&game.sound_test2);
716
            break;
857
            break;
717
        case 1:
858
        case 1:
718
            soundbuf_play(&game.sound_test3);
859
//            soundbuf_play(&game.sound_test3);
Line 719... Line 860...
719
            break;
860
            break;