Condensed Object Collision Help? [4.5.9]

crazygrouptrio

Active member
Trying to speed up my game a bit by cutting out the fat of the collision script I don't need. This script DOES work like I want but it causes the game to crash on occasion. Anyone better at coding want to check it for me?
Short version is I want ONLY player weapons to hurt monsters, and ONLY monster weapons hurt the player, so I tried to handle both weapons together as one flag and skip collisions for those specific objects (so the player's weapon doesn't hurt the player, same for monster). Maybe this is too much checking and causes the crash? Or I gutted something that is necessary.

Here's the entire doHandleObjectCollisions script. For the adventure module:
Code:
    ;;; object collions have to check from current index
    ;;; through the rest of the objects on the field of play.
    ;;; Objects prior to its index have already checked against this particular object
    SwitchBank #$1C
;;STEP 1: Check for inactivity.
    LDA Object_status,x
    AND #%10000000
    BNE +doCheckSelfForObjectCollision
        ;; object is inactive.
        JMP +skipObjectCollisionCheck
    +doCheckSelfForObjectCollision:
    
    LDA Object_vulnerability,x ;; loads vulnerability byte for monster object
    AND #%00000001 
    BEQ +continueCollisionCheck
    
        JMP +skipObjectCollisionCheck
    +continueCollisionCheck:
;;STEP 2: Check for hurt state.
    ;;; In this module, monsters will use action step 7 for their hurt state.
    TXA
    STA selfObject
    STA temp
    GetActionStep temp
    CMP #$07
    BNE +notHurt
        JMP +skipObjectCollisionCheck
    +notHurt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;STEP 3: Set up bounds for self collision.
    TXA
    PHA
    LDY Object_type,x
    LDA ObjectFlags,y
    STA tempA ;; temp A now holds the current object flags.
            ;; collision box is still held over from the physics routine.
    LDA xHold_hi;Object_x_hi,x
    CLC
    ADC self_left
    STA bounds_left
    LDA xHold_hi;Object_x_hi,x
    CLC
    ADC self_right
    STA bounds_right
    
    LDA yHold_hi;Object_y_hi,x
    CLC
    ADC self_top
    STA bounds_top
    LDA yHold_hi;Object_y_hi,x
    CLC
    ADC self_bottom
    STA bounds_bottom
    TYA
    PHA
    ;;; we probably want this to live inside bank 1C
    ;;; so that we can access flag data easily with no RAM.
    ;;;; Right now, in this module, it is there by default.
    ;;;; If it is not, we will have to bankswap to 1c here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Check the type of object.
;;; If it is a weapon, it will check against monsters only.
        LDA Object_flags,x
        AND #%00000100 ; using just 1 weapon instead of monster/player weapon
        BNE +isWeapon
            JMP +notPlayerWeapon
        +isWeapon

                LDX #$00
                loop_objectCollision:
                    CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                LDA Object_status,x
                AND #%10000000
                BNE +isActive
                    JMP +skipCollision
                +isActive:
                LDA Object_flags,x
                AND #%00001010 ; checking player and monster together
                BNE isMonsterWeaponCol

                    JMP +notAmonsterWeaponCollision
                isMonsterWeaponCol:
                    JSR getOtherColBox
                    JSR doCompareBoundingBoxes
                        ;;; if they have collided, it is a 1
                        ;;; if not, it is a zero.
                        BEQ +skipCollision
                            TXA
                            STA otherObject
                            ;; There was a collision between a monster and a weapon.
                            ;; weapon is self.
                            ;; monster is other.
                            ;DestroyObject
                            ;ChangeActionStep otherObject, #$07
                LDA Object_flags,x
                AND #%00000010
                BNE isPlayerCol
                LDX selfObject
                LDA Object_type,x
                CMP #$02 ; skip if object 2 (monster weapon)
                BEQ +skipCollision
                                JSR doHandleHurtMonster
                                JMP +done
                isPlayerCol:
                LDX selfObject
                LDA Object_type,x
                CMP #$01 ; skip if object 1 (player weapon)
                BEQ +skipCollision
                JSR doHandleHurtPlayer
                JMP +done
                                
                            ;LDX selfObject
                            ;;DestroyObject
                            ;LDX otherObject
                            JMP +done               
                    +skipCollision
                +notAmonsterWeaponCollision
                INX
                CPX #TOTAL_MAX_OBJECTS
                BEQ +lastCollisionForThisObject
                    JMP loop_objectCollision
            +lastCollisionForThisObject
            JMP +done
            
            
        +notPlayerWeapon
            
            
                    loop_objectPlayerCollisions:
                        CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                        LDA Object_status,x
                        AND #%10000000
                        BNE +isActive
                            JMP +skipCollision
                        +isActive
                        
                        +notPlayerMonsterCollision:
                        
                            LDA Object_flags,x
                            AND #%00100000
                            BNE +isPlayerPowerupCol
                                JMP +isNotPlayerPowerupCol
                            +isPlayerPowerupCol
                                JSR getOtherColBox
                                JSR doCompareBoundingBoxes
                                BNE +doCollision
                                    JMP +skipCollision
                                +doCollision
                                    TXA
                                    STA otherObject
                                    ;; There was a collision between a player and a powerup.
                                    ;; player is self.
                                    ;; powerup is other.
                                    DestroyObject
                                    .include SCR_PICKUP_SCRIPTS
                                    JMP +done
                                    
                        +isNotPlayerPowerupCol   
                            
                                    JMP +done
                                    
                            +isNotPlayerNPCCol
                            
                            +skipCollision
                    
                            INX
                            CPX #TOTAL_MAX_OBJECTS
                            BEQ +lastCollisionForThisObject
                                JMP loop_objectPlayerCollisions
                            +lastCollisionForThisObject
                            ; PLA
                            ; TAX
                            JMP +done
                        
                            
                            ;; Add other object to object collision types here.
                        JMP +done
                            
            
        +notPlayerForCollisions
    
+done   
    PLA
    TAY
    PLA
    TAX
+skipObjectCollisionCheck
    ReturnBank
 

puppydrum64

Active member
I think the problem might be AND #%00001010. This implies that the object is both a player and a monster. Not one or the other.
 
Top Bottom