@@ -10,7 +10,7 @@ struct guard_t guard[MAX_GUARDS];
1010
1111struct shakeGuard_t shake [MAX_GUARDS ];
1212
13- uint8_t guardCount ;
13+ static uint8_t guardCount ;
1414
1515void addGuardToShakeQueue (uint8_t id );
1616
@@ -111,38 +111,43 @@ void clearGuards()
111111 moveId = 0 ;
112112}
113113
114- void initGuard (uint8_t x , uint8_t y )
114+ uint8_t initGuard (uint8_t x , uint8_t y )
115115{
116- uint8_t i = guardCount ;
117- uint16_t xPos = x * TILE_W ;
118- uint16_t yPos = y * TILE_H ;
119-
120- guard [i ].x = x ;
121- guard [i ].y = y ;
122- guard [i ].xOffset = 0 ;
123- guard [i ].yOffset = 0 ;
124- guard [i ].holePosX = 0 ;
125- guard [i ].holePosY = 0 ;
126- guard [i ].action = ACT_UNKNOWN ;
127- guard [i ].direction = ACT_RIGHT ;
128- guard [i ].idx = 0 ;
129-
130- guard [i ].sequence = RUN_SEQUENCE ;
131-
132- // Sprite attribute settings
133- vpoke ((GUARD_1 >> 5 ) & 0xff , 0x1f5000 + 8 * (i + 1 )); // Attr0
134- VERA .data0 = (GUARD_1 >> 13 ) & 0xf ; // Attr1
135- VERA .data0 = xPos & 0xff ; // Attr2
136- VERA .data0 = xPos >> 8 ; // Attr3
137- VERA .data0 = yPos & 0xff ; // Attr4
138- VERA .data0 = yPos >> 8 ; // Attr5
139- VERA .data0 = (3 << 2 ); // Attr6
140- VERA .data0 = 0 ; // Attr7
116+ if (guardCount < MAX_GUARDS ) {
117+ uint8_t i = guardCount ;
118+ uint16_t xPos = x * TILE_W ;
119+ uint16_t yPos = y * TILE_H ;
120+
121+ guard [i ].x = x ;
122+ guard [i ].y = y ;
123+ guard [i ].xOffset = 0 ;
124+ guard [i ].yOffset = 0 ;
125+ guard [i ].holePosX = 0 ;
126+ guard [i ].holePosY = 0 ;
127+ guard [i ].action = ACT_UNKNOWN ;
128+ guard [i ].direction = ACT_RIGHT ;
129+ guard [i ].idx = 0 ;
130+
131+ guard [i ].sequence = RUN_SEQUENCE ;
132+
133+ // Sprite attribute settings
134+ vpoke ((GUARD_1 >> 5 ) & 0xff , 0x1f5000 + 8 * (i + 1 )); // Attr0
135+ VERA .data0 = (GUARD_1 >> 13 ) & 0xf ; // Attr1
136+ VERA .data0 = xPos & 0xff ; // Attr2
137+ VERA .data0 = xPos >> 8 ; // Attr3
138+ VERA .data0 = yPos & 0xff ; // Attr4
139+ VERA .data0 = yPos >> 8 ; // Attr5
140+ VERA .data0 = (3 << 2 ); // Attr6
141+ VERA .data0 = 0 ; // Attr7
141142
142143#ifdef DEBUG
143- // displayGuard(guardCount);
144+ // displayGuard(guardCount);
144145#endif
145- guardCount ++ ;
146+ guardCount ++ ;
147+ return 1 ;
148+ } else {
149+ return 0 ;
150+ }
146151}
147152
148153int8_t guardId (uint8_t x , uint8_t y )
0 commit comments