Game object becoming corrupted

tbizzle

Well-known member
One of my game objects "key card" is getting corrupted somehow when i use my flamethrower weapon object, making the key card unable to be collided with. Any help with this one would be greatly appreciated.

 

dale_coop

Moderator
Staff member
You might have made a modifications in one of the script that causes that.
Modifications in the handle object collision script maybe?
 

tbizzle

Well-known member
@dale_coop here is my script. I remember you telling my to not use " LDX selfObject" for the one part, but when I don't use that for some reason my game breaks. If worse comes to worse I'll just have to use a tile for my key card pickup.

Part 1:
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:
;;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
            ;DestroyObject
        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 #%00001000
                
                
                BNE isMonsterWeaponCol
                    JMP +notAmonsterWeaponCollision
                isMonsterWeaponCol:
                    
                    
                    JSR getOtherColBox
                    JSR doCompareBoundingBoxes
                        ;DestroyObject    ;Destroys all objects lol
                        ;;; 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
                            
                            
                            JSR doHandleHurtMonster
                            ChangeActionStep otherObject, #$07
                              
                            
                             LDA selfObject
                             CMP #$0A
                             BEQ skipper
                             LDX selfObject
                               DestroyObject
                                 skipper:                             
                            
                            JMP +done               
                    +skipCollision
                +notAmonsterWeaponCollision
                INX
                CPX #TOTAL_MAX_OBJECTS
                BEQ +lastCollisionForThisObject
                    JMP loop_objectCollision
            +lastCollisionForThisObject
            JMP +done
            
            
        +notPlayerWeapon
            
            LDA Object_flags,x
            AND #%00000010
            BNE +isPlayerForCol
                ;; not player for collions
                    JMP +notPlayerForCollisions
            +isPlayerForCol
 

tbizzle

Well-known member
Part 2:

Code:
LDX #$00
                    loop_objectPlayerCollisions:
                        CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                        LDA Object_status,x
                        AND #%10000000
                        BNE +isActive
                            JMP +skipCollision
                        +isActive
                        LDA Object_flags,x
                        AND #%00001000
                        BNE +isPlayerMonsterCol
                        JMP +notPlayerMonsterCollision
                        +isPlayerMonsterCol
                            
                            JSR getOtherColBox
                            JSR doCompareBoundingBoxes
                                ;;; if they have collided, it is a 1
                                ;;; if not, it is a zero.
                                BNE +dontSkipCol
                                    JMP +skipCollision
                                +dontSkipCol
                                    TXA
                                    STA otherObject
                                    ;; There was a collision between a monster and a weapon.
                                    ;; player is self.
                                    ;; monster is other.
                                    ;JMP RESET
                                    
                                        JSR doHandleHurtPlayer
                                    
                                    JMP +done
                                    
                        +notPlayerMonsterCollision:
                        
                        ;;;;;;; THIS IS WHERE I WANT TO ADD A CHECK FOR MONSTER WEAPON ;;;;;;;

                            LDA Object_flags,x
                            AND #%00010000
                            BNE +isPlayerMonsterWeaponCol
                                JMP +isNotPlayerMonsterWeaponCol
                            +isPlayerMonsterWeaponCol
                                JSR getOtherColBox
                                JSR doCompareBoundingBoxes
                                BNE +doCollision
                                    JMP +skipCollision
                                +doCollision
                                    TXA
                                    STA otherObject
                                    ;; There was a collision between a player and a monster weapon.
                                    ;; player is self.
                                    ;; monster weapon is other.
                              
                                    DestroyObject                    ;; normally we destroy it because its a weapon ;;
                                    LDX selfObject                    ;; 9Panzer edit ;;   
                                    JSR doHandleHurtPlayer
                                    JMP +done
      
                        +isNotPlayerMonsterWeaponCol:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                        
                            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
                                    LDA updateScreenData
                                    ORA #%0000100
                                    STA updateScreenData
                                    .include SCR_PICKUP_SCRIPTS
                                    JMP +done
                                    
                        +isNotPlayerPowerupCol 
                            LDA Object_flags,x
                            AND #%10000000
                            BNE +isPlayerNPCCol
                                JMP +isNotPlayerNPCCol
                            +isPlayerNPCCol
                                JSR getOtherColBox
                                JSR doCompareBoundingBoxes
                                BEQ +skipCollision
                                    TXA
                                    STA otherObject
                                    ;; There was a collision between a player and a powerup.
                                    ;; player is self.
                                    ;; powerup is other.
                                    TXA
                                    PHA
                                        LDX selfObject
                                        LDA xPrev
                                        STA Object_x_hi,x
                                        STA xHold_hi
                                        
                                        LDA yPrev
                                        STA Object_y_hi,x
                                        STA yHold_hi
                                        
                                        LDA #$00
                                        STA Object_h_speed_lo,x
                                        STA Object_h_speed_hi,x
                                        STA Object_v_speed_lo,x
                                        STA Object_v_speed_hi,x
                                        STA Object_x_lo,x
                                        STA Object_y_lo,x
                                    PLA
                                    TAX
                                    JMP +done
                                    
                            +isNotPlayerNPCCol
                            
                            +skipCollision
                    
                            INX
                            CPX #TOTAL_MAX_OBJECTS
                            BEQ +lastCollisionForThisObject
                            ;JSR doWaitFrame
                                JMP loop_objectPlayerCollisions
                            +lastCollisionForThisObject
                            ; PLA
                            ; TAX
                            JMP +done
                        
                            
                            ;; Add other object to object collision types here.
                        JMP +done
                            
            
        +notPlayerForCollisions
    
+done
 ;DestroyObject 
    PLA
    TAY
    PLA
    TAX
+skipObjectCollisionCheck
    ReturnBank
 

dale_coop

Moderator
Staff member
@tbizzle Can you share the file directly?

The code you shared seems totally correct to me.

The only error I see is that lines:
Code:
LDA selfObject
CMP #$0A
BEQ skipper
    LDX selfObject
    DestroyObject
skipper:

Code:
LDX selfObject
LDA Object_type,x
CMP #$0A
BEQ skipper  
    DestroyObject
skipper:

But I don't think it's the cause of your issue.
 
Last edited:

dale_coop

Moderator
Staff member
Confirmed, that script looks correct (except the 0A lines I mentionned).
The error might be elsewhere.

Your flamethrower weapon object is a "player weapon"?
 

dale_coop

Moderator
Staff member
Do you do something special when you create the weapon (like manipulate the other objects on screens or...)? or in one of the action steps of the weapon?
The key card is flagged as a "pickup" object? Placed on the screen or created by code?
 

tbizzle

Well-known member
The key is flagged as "power up/pickup" just like all the other pickups. The other pickups don't go blank like the key. The pickup scripts for all my pick ups are coded the same exact way. They should all behave the ame way also within the Handle Object Collisions script. I am at a total loss as what the issue could be. I am just going to go with a "pickup" tile, I've already tested it and it works fine. Just a shame I feel anything I now create with that empty slot is going to get corrupted somehow. Well, you win some and you lose some. Thank you, @dale_coop
 

dale_coop

Moderator
Staff member
If you use the flamethrower weapon and leave the room and comeback, the key works?

if it DOES work, it might be the flamethrower object that corrupts your key object.
can you share the input script that creates that flamethrower object and also any AI script that is used by that flamethrower object.

Or mayube you have extra code somwhere that does things while checking the flamethrower object? (in the handle game timer or the sprite drawing, ... or the physics scripts )
 

tbizzle

Well-known member
@dale_coop Here is the input script for the flamethrower, I am using no AI scripts along with the flamethrower other than "null'.

Code:
;;; Check if the B-button is pressed
LDA gamepad
AND #%00000001 ;A-button
BNE +
RTS ;;; If the B-button is not pressed we exit the script.
+
    
    LDA myFlame_10
    CMP #$01
    BCS work2
    LDA myFlame
    CMP #0
    BNE work2     
    JMP canNotShoot111
        work2:     
        CountObjects #%00000100
        CMP #1
        BNE shooter
        JMP canNotShoot111
        shooter:
     SubtractValue #$01, myFlame, #$01, #$00     
           UpdateHudElement #$06   
     TXA
     PHA
     TYA
     PHA
        LDX player1_object
        LDA Object_x_hi,x
            CLC
        ADC #$04
        STA tempA
        LDA Object_y_hi,x
            CLC
        ADC #$04
        STA tempB
        LDA Object_direction,x
        AND #%00000111
        STA tempC
        PlaySound #sfx_magicCast
              
        CreateObject tempA, tempB, #$04, #$00
                    
            
            LDA tempC
            STA Object_direction,x
            TAY
            LDA DirectionTableOrdered,y
            STA temp1
            TXA
            STA temp
            StartMoving temp, temp1
    PLA
    TAY
    PLA   
    TAX   
    canNotShoot111:
 

tbizzle

Well-known member
@dale_coop I found what the problem was! I inserted this line of code quite some time ago inside of the Physics script (thank god I commented it):

Code:
StopMoving temp, #$FF, #$00

To stop my player from endlessly recoiling. It must have been doing something to my pickups. I put in a check to only apply it to my player and the issue has not occured since!

Code:
    CPX player1_object
    BNE +continueP
    StopMoving temp, #$FF, #$00
        +continueP:

Do you know how I could also have it check for a monster??? It would be cool if the monsters recoil wasn't all crazy also.
 
Last edited:
Top Bottom