castleraider

changeset 289:2cfa1c17205f

Started to add sound effects to the game.
author David Boddie <david@boddie.org.uk>
date Sun Mar 30 19:32:59 2014 +0200
parents 559bd41dc09b
children 3d47f40dec57
files code.oph loader.oph sound.oph
diffstat 3 files changed, 95 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/code.oph	Mon Mar 24 00:14:25 2014 +0100
     1.2 +++ b/code.oph	Sun Mar 30 19:32:59 2014 +0200
     1.3 @@ -312,6 +312,9 @@
     1.4      jsr player_can_jump
     1.5      bcs player_move_not_jump
     1.6  
     1.7 +    ldx #2                          ; jump sound
     1.8 +    jsr play_sound
     1.9 +
    1.10      jsr plot_player                 ; unplot
    1.11  
    1.12      jsr player_jump_animation
    1.13 @@ -377,7 +380,13 @@
    1.14  
    1.15      check_beneath_solid:    ; A solid tile was found.
    1.16  
    1.17 -    lda #0
    1.18 +    lda player_falling          ; If the character is not falling then exit.
    1.19 +    beq check_beneath_fall_exit
    1.20 +
    1.21 +    lda player_y                ; Play the step sound.
    1.22 +    jsr play_step_sound
    1.23 +
    1.24 +    lda #0                      ; Reset the falling flag.
    1.25  
    1.26      check_beneath_fall_exit:
    1.27      sta player_falling
    1.28 @@ -612,7 +621,10 @@
    1.29      check_tile_collect_object:
    1.30  
    1.31      jsr plot_collected_object       ; show the item of treasure in the header
    1.32 -    jmp make_tile_invisible         ; make all tiles of this type invisible
    1.33 +    jsr make_tile_invisible         ; make all tiles of this type invisible
    1.34 +
    1.35 +    ldx #1                          ; item sound
    1.36 +    jmp play_sound
    1.37  
    1.38  check_tile_visible_exit:
    1.39  
    1.40 @@ -723,8 +735,10 @@
    1.41  
    1.42      jsr plot_player         ; Move the player up by one tile.
    1.43      dec player_y            ; We should really check to make sure that there
    1.44 -    jmp plot_player         ; is space above the player to do this.
    1.45 -                            ; Branch and return.
    1.46 +    jsr plot_player         ; is space above the player to do this.
    1.47 +
    1.48 +    lda player_y            ; Play the step sound.
    1.49 +    jmp play_step_sound     ; Branch and return.
    1.50  
    1.51      check_move_exit_not_ok:
    1.52      sec
    1.53 @@ -1005,6 +1019,9 @@
    1.54      sta player_jumping
    1.55      sta player_falling
    1.56  
    1.57 +    ldx #0                          ; demise sound
    1.58 +    jsr play_sound
    1.59 +
    1.60      player_demise_exit:
    1.61      sec
    1.62      rts
    1.63 @@ -1056,3 +1073,4 @@
    1.64  .include "bank_routines.oph"
    1.65  .include "monsters.oph"
    1.66  .include "joystick.oph"
    1.67 +.include "sound.oph"
     2.1 --- a/loader.oph	Mon Mar 24 00:14:25 2014 +0100
     2.2 +++ b/loader.oph	Sun Mar 30 19:32:59 2014 +0200
     2.3 @@ -1,4 +1,4 @@
     2.4 -; Copyright (C) 2011 David Boddie <david@boddie.org.uk>
     2.5 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk>
     2.6  ;
     2.7  ; This program is free software: you can redistribute it and/or modify
     2.8  ; it under the terms of the GNU General Public License as published by
     2.9 @@ -122,6 +122,24 @@
    2.10          cpx #[title_text_end - title_text]
    2.11          bne title_text_loop
    2.12  
    2.13 +    ; Define ENVELOPEs.
    2.14 +    lda #0
    2.15 +    sta $70
    2.16 +    define_envelopes_loop:
    2.17 +
    2.18 +        ldx $70
    2.19 +        lda envelopes_high,x
    2.20 +        tay
    2.21 +        lda envelopes_low,x
    2.22 +        tax
    2.23 +        lda #8
    2.24 +        jsr $fff1
    2.25 +
    2.26 +        inc $70
    2.27 +        lda $70
    2.28 +        cmp #4
    2.29 +        bne define_envelopes_loop
    2.30 +
    2.31      ; Configure the interrupt routine.
    2.32  
    2.33      lda #1                  ; set polling flag to ensure that the interrupt
    2.34 @@ -399,9 +417,6 @@
    2.35      clc
    2.36      rts
    2.37  
    2.38 -
    2.39 -
    2.40 -
    2.41  tiles_block: .byte <tiles_file_name, >tiles_file_name
    2.42               .byte sprite_area_low, sprite_area_high, 0, 0
    2.43               .byte sprite_area_low, sprite_area_high, 0, 0
    2.44 @@ -445,6 +460,13 @@
    2.45  message_text: .byte 10, 10, " Choose a character"
    2.46  message_text_end:
    2.47  
    2.48 +envelopes_low:  .byte <demise_envelope, <item_envelope, <jump_envelope
    2.49 +envelopes_high: .byte >demise_envelope, >item_envelope, >jump_envelope
    2.50 +
    2.51 +demise_envelope:    .byte 1,2,252,250,0,15,15,0,126,0,0,130,126,126
    2.52 +item_envelope:      .byte 2,2,10,254,2,6,2,2,126,0,0,130,126,126
    2.53 +jump_envelope:      .byte 3,1,20,10,5,2,4,4,126,0,0,130,126,126
    2.54 +
    2.55  init_load_window_vdu_bytes: .byte 28,0,30,19,26,12
    2.56  
    2.57  title_text: .byte " Copyright (C) 2014", 13, 10
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/sound.oph	Sun Mar 30 19:32:59 2014 +0200
     3.3 @@ -0,0 +1,47 @@
     3.4 +; Copyright (C) 2014 David Boddie <david@boddie.org.uk>
     3.5 +;
     3.6 +; This program is free software: you can redistribute it and/or modify
     3.7 +; it under the terms of the GNU General Public License as published by
     3.8 +; the Free Software Foundation, either version 3 of the License, or
     3.9 +; (at your option) any later version.
    3.10 +;
    3.11 +; This program is distributed in the hope that it will be useful,
    3.12 +; but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.13 +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.14 +; GNU General Public License for more details.
    3.15 +;
    3.16 +; You should have received a copy of the GNU General Public License
    3.17 +; along with this program.  If not, see <http://www.gnu.org/licenses/>.
    3.18 +
    3.19 +sounds_low:  .byte <demise_sound, <item_sound, <jump_sound, <step_sound
    3.20 +sounds_high: .byte >demise_sound, >item_sound, >jump_sound, >step_sound
    3.21 +
    3.22 +demise_sound:   .byte 1,0, 1,0, 160,0, 6,0
    3.23 +item_sound:     .byte $13,0, 2,0, 160,0, 4,0
    3.24 +jump_sound:     .byte $13,0, 3,0, 50,0, 2,0
    3.25 +step_sound:     .byte $01,0, 241,0
    3.26 +  step_pitch:   .byte               0,0
    3.27 +  step_duration:.byte                   1,0
    3.28 +
    3.29 +play_step_sound:    ; A=row number
    3.30 +
    3.31 +    asl
    3.32 +    sta $80
    3.33 +    lda #40
    3.34 +    sec
    3.35 +    sbc $80
    3.36 +    sta step_pitch
    3.37 +    clc
    3.38 +
    3.39 +    ldx #3          ; Drop through into the next routine.
    3.40 +
    3.41 +play_sound:     ; X=sound number
    3.42 +
    3.43 +    lda sounds_high,x
    3.44 +    tay
    3.45 +    lda sounds_low,x
    3.46 +    tax
    3.47 +    lda #7
    3.48 +    jsr $fff1
    3.49 +
    3.50 +    rts