;JSL $A0C6AB
;JSL $A0C786
;JSL $86F106		;random item drop routine

;Enemy related RAM addresses:
{
; $0F78 - enemy pointer
	; $0F7A - enemy X pos (from room pop)
	; $0F7C - enemy sub-pixel X pos. Often unused.
	; $0F7E - enemy Y pos (from room pop_)
	; $0F80 - enemy sub-pixel Y pos. Often unused.
	; $0F82 - enemy collision width (1/2 pixel value from center)
	; $0F84 - enemy collision height (1/2 pixel value from center)
	; $0F86 - Property bits (from room pop: prop bits) (FEDC BA98 7654 3210)
			; F makes their hitbox solid to Samus, E respawns the enemies if they die,
			; D tells the game to process the enemy's graphic AI, C makes the enemy block Plasma shots
			; B makes the enemy process even when offscreen, A makes the enemy ignore Samus/Projectiles, 
			; 9 instantly deletes the enemy, 8 makes the enemy invisible?
			; 1 and 0 used by geemers as orientation
	; $0F88 - extra property bits (FEDC BA98 7654 3210)
			; F signifies that the enemy processed a new enemy instruction with $0F92, update graphics.
			; 2 enables multiple hitbox/reactions (indepth $0F8E)
			; 0 disables processing of the enemy's movement AI, I think. Isn't disabled if 0F86 A is set (ignore Samus/Projectiles)
	; $0F8A - AI handler. Lowest bit set determines which AI pointer in enemy data to use
			; (None = 18, 1 = 1A, 2 = 1C, 4 = 1E, 8 = 20)
	; $0F8C - Enemy HP
	; $0F8E - Main graphics/hitbox pointer
			; Byte 0 is a counter of some sort. Byte 1 is unused, I think.
			; Bytes 2-3 are X pixel offset. Bytes 4-5 are Y pixel offset.
			; Bytes 6-7 are a pointer to a tilemap, I think. Bytes 8-9 are a pointer to collision detection:
				; Byte 0 is a counter of some sort. Byte 1 is unused, I think.
				; Bytes 2-3 are X pixel offset to left border. Bytes 4-5 are Y pixel offset to bottom border.
				; Bytes 6-7 are X pixel offset to right border. Bytes 8-9 are Y pixel offset to top border.
				; Bytes A-B are for collisions with Samus. Bytes C-D bytes are pointer to code for collision with projectiles.
				; Bytes 2-D repeat 'byte 0' times. Total length is 2 + (n*C), n = byte 0.
			; Bytes 2-9 repeat 'byte 0' times. Total length is 2 + (n*8), n = byte 0
	; $0F90 - ??? (Used by Mochtroid) (LN Chozo uses it as a loop counter)
	; $0F92 - pointer to AI structure. Acts like PLMs instruction pointer ($1D27,X). Positive Enemy instructions set delay timer and 0F8E, and highest bit of 0F88
	; $0F94 - action delay (apparantly) (Used with above?)
	; $0F96 - Which SNES palette the enemy uses (when drawing the sprite, from enemy set number). ORAed with other data to stick directly into OAM.
	; $0F98 - Index to graphics in VRAM
	; $0F9A - Layer control
	; $0F9C - Set to (0F78),#$0D + #$08 when shot? This - 8 = timer for using Hurt AI.
	; $0F9E - Enemy frozen timer
	; $0FA0 - Counter, forces a different kind of processing. Used when hit by Plasma Beam (powerbombs?)
	; $0FA2 - A value that works concurrently with $0FA4 to modify vertical position of sprite
	; $0FA4 - Value that determines if sprite vertical position is lowered or raised (with $0FA2).
		; For many enemies it's used as come sort of counter though
	; $0FA6 - Bank of enemy data
	; $0FA7 - it was 04 during the spore spawn battle. Will look into
	; $0FA8 - Used by AI routines.
	; $0FAA - Used by AI routines.
	; $0FAC - Used by AI routines. Example: air time? vertical jump distance, etc.?
	; $0FAE - Used by AI routines. Example: all-purpose counter, direction and speed, etc.
	; $0FB0 - Used by AI routines. Example: current action of enemy? 
	; $0FB2 - Used by AI routines. Orientation in SMILE?
	; $0FB4 - Used by AI routines. Speed in SMILE
	; $0FB6 - Used by AI routines. Speed2 in SMILE
}	


;------------------------------- BOX Security Drone, recreated in Super Metroid by Black Falcon -------------------------------
;														READ THIS FIRST!!!
;A few things to note on how to use it:
;you have to put EA00 into your boss room's FX2 pointer, this takes care of storing the right palette to the individual parts.
;The boss consists of four different parts, enemy 00 being the main one that controls the other ones.
;set the properties of enemies 01 to 03 to "non-responsive", also change their 'speed' value in SMILE to the following:

; 0000 is Brain									Enemy 03
; 0002 is Blue Armor Part						Enemy 00
; 0004 is Yellow casing							Enemy 01
; 0006 is Green and red legs with top cannon	Enemy 02

;speed 2 of each enemy needs to hold the index of the enemy itself.
;no other enemies should be in the enemy allowed list
;if you have trouble understanding, look up room 7ACB3 of this rom:
;https://dl.dropboxusercontent.com/u/18141148/not_public/BOXnew.smc

;graphics meed to be ripped from this rom as well if you wanna use them elsewhere.

;check 'special gfx' for every part to prevent errors

lorom

;Variables, not all of them are used, it's just for me to keep track.
;Note that I'm not using indexed addresses, because that makes it easier for the main enemy to directly change the RAM of the other
;enemies without having to load the index first
{
	!mainHP = $0F8C					;main enemy part E00
	!mainXpos = $0F7A
	!mainYpos = $0F7E
	!mainproperty = $0F86
	!mainGFXinst = $0F92
	
	!E1Xpos = $0FBA					;enemy 1, Yellow casing
	!E1Ypos = $0FBE
	!E1HP = $0FCC
	!E1HBX = $0FC2
	!E1HBY = $0FC4
	!E1inst = $0FF0
	!E1GFXinst = $0FD2
	!E1GFXtimer = $0FD4
	!E1property = $0FC6
	
	!E2Xpos = $0FFA					;enemy 2, Green legs with red feet
	!E2Ypos = $0FFE
	!E2HP = $100C
	!E2HBX = $1002
	!E2HBY = $1004
	!E2inst = $1030
	!E2GFXinst = $1012
	!E2property = $1006
	
	!E3Xpos = $103A					;enemy 3, just the Brain, lol
	!E3Ypos = $103E
	!E3HP = $104C
	!E3HBX = $1042
	!E3HBY = $1044
	!E3inst = $1070
	!E3GFXinst = $1052
	!E3property = $1046

	!Xpos = $0F7A,x
	!Ypos = $0F7E,x
	!property = $0F86,x
	!Palette = $0F96,x
	!SMILEorientation = $0FB2,x
	!SMILEspeed = $0FB4,x
	!SMILEspeed2 = $0FB6,x

	!inst = $0FB0
	!timer = $0FAE
	!insttimer = $0FAC

	!DMGgradient01 = #$0C00				;values for HP to drop under to trigger gfx change
	!DMGgradient02 = #$0800
	!DMGgradient03 = #$0400
	
	!BOXmaxfallspeed = #$0004
	!BOXjumpheight = #$FFFA
	!BOXbounceoffheight = #$FFFB
	
	!BOXbouncespL = #$0003
	!BOXbouncespR = #$FFFD
	
	!BOXmaxrunspeedright = #$0004
	!BOXmaxrunspeedleft = #$FFFC
	
	!horjumpspeedR = #$0004				;horizontal momentum when jumping at Samus
	!horjumpspeedL = #$FFFC
	
	!runcheckdistance = #$0068				;distance in blocks Samus has to be away from the enemy to trigger running AI
	!howlongtorun	= #$0080				;timer for how long to run in one direction until stopping
	
	!BOXJumpAnimationTimer = #$0005		;time between frames for the jump and landing animations
	!RUNINITANIM = #$0006				;time between frames for initial running animation, also affects timer before it starts to run
										;(the xkas label system is just plain awesome!!!)
	!BOXBombAnimationTimer1 = #$0004										;speed for how fast to rise legs when about to bomb
	!BOXBombAnimationTimer2 = #$0006										;speed for how fast to transform and open the bomb slot
}

{		;update unused enemy slot palettes: alright, this needs some explaination..
		;basically BOX needs 3 palettes, but I don't want to copy the same enemy dna and change the palette pointer for each part
		;so since there are no other enemies in the enemies allowed list, I instead made use of the unused ID slots 0002 and 0003 there.
		;problem was that the game makes these palette black if they are unused, and a code in the enemies init wouldn't do the job, so I had to write code into FX2 instead.
		
org $8FEA00																			;use this as FX2 pointer (room running code)
	LDX $079F : LDA $7ED828,x : AND #$0002 : BNE +								;check for boss bit
	LDA $1776 : CMP #$1234 : BEQ +
	PHB : LDA #$005F : LDX #PartOnePalette : LDY #$C120 : MVN $A57E : PLB					;stores Palettes
	LDA #$1234 : STA $1776
	LDA #$0000 : JSL $808FC1
	LDA #$0006 : JSL $808FC1
+
	RTS
}
	;====================== ENEMY DNA ================================
{
	;labels of the variables are self explanatory
	!HP = $1000
	!Damage = $0032
	!Width = $0028
	!Height = $0008
	!Sound = $00
	!GrappleAI = $801E
	!GFXPointer = $AD8000
	!BOXTouchAI = $8023
	!BOXShotAI = $802D																;normal routine for when the enemy is shot. Redundant because of custom hitboxes
	
org $A0F7D3																			;enemy DNA

	DW $1400,PartOnePalette,!HP,!Damage,!Width,!Height
	DB $A5,$00,!Sound,$00,$00,$00
	DW #BOXInitAI, $0001, $0000, #MainRunAI, !GrappleAI, $804C, $8041, $0000, $0004
	DW $0000,$0000,$0000,$0000,$0000,$0000, !BOXTouchAI, $802D, $0000
	DL !GFXPointer
	DB $02																			;layer
	DW $0000,$F094,$0000															;middle one is vulnerability pointer
}	
	
;======================================================================	
;======================------------------------========================
;======================-- MAIN BLOCK OF CODE --========================
;======================------------------------========================
;======================================================================
	
;org $A5EA2A
org $A5E6C7


		;after applying for the first time to your ROM, comment this palette block, else if you changed them your palettes get reset if you reapply the code
{
PartOnePalette:
DW $7E3F, $7FFF, $04A5, $673F, $2DFD, $0097, $200B, $4B9C, $2232, $098C, $0508, $7FB8, $6EF0, $6620, $5C0D, $1F81		;Blue Armor parts
PartTwoPalette: 
DW $4482, $7FFF, $04A5, $673F, $2DFD, $0097, $200B, $4B9C, $475A, $3AD6, $2232, $11CE, $098C, $0508, $03FF, $5497		;yellow Middle part
PartThreePalette: 
DW $42C0, $7FFF, $18C6, $673F, $2DFD, $0097, $200B, $6BB5, $5711, $424D, $3609, $29A6, $1D26, $3D11, $7B52, $6E86		;greenish metalic parts
}
;================================ SEGMENT TABLES INDEXED BY SPEED IN SMILE


; this part is a bit tricky, so it might take a while to figure out.
; try to closely follow the pointers to get an idea how special enemy format works.

;---------------------------- TILEMAP/STRUCTURE POINTERS
{
	
;
;				how many frames to display current structure map part
;				|
;				|			pointer to structure map
;				v			v
TM_BRAIN:
		DW #$0004, STR_BRAIN_GLOW_A
		DW #$0004, STR_BRAIN_GLOW_B
		DW #$000C, STR_BRAIN_GLOW_C
		DW #$0008, STR_BRAIN_GLOW_B
		DW $80ED, TM_BRAIN
;				^		^
;				|		points to the beginning, aka loops, though you can have it point to another set of tilemaps
;				|
;				always used, basically tells the game the next pointer points to another tilemap
	TM_YELLOW_Standing:
		DW #$0000, STR_YELLOW_CASING
		DW $80ED, TM_YELLOW_Standing

	TM_YELLOW_UPDOWN:
		DW !RUNINITANIM*2, STR_YELLOW_CASING
		DW !RUNINITANIM*2, STR_YELLOW_UPDOWN_A
		DW !RUNINITANIM*2, STR_YELLOW_UPDOWN_B
		DW !RUNINITANIM*2, STR_YELLOW_UPDOWN_A		
	TM_YELLOW_UPDOWN_CONT:
		DW BOXGETSPEED, STR_YELLOW_CASING
		DW BOXGETSPEED, STR_YELLOW_UPDOWN_A
		DW BOXGETSPEED, STR_YELLOW_UPDOWN_B
		DW BOXGETSPEED, STR_YELLOW_UPDOWN_C
		DW BOXGETSPEED, STR_YELLOW_UPDOWN_D
		DW $80ED, TM_YELLOW_UPDOWN_CONT
		
	TM_YELLOW_JUMP:
		DW !BOXJumpAnimationTimer, STR_YELLOW_CASING
		DW !BOXJumpAnimationTimer, STR_YELLOW_JUMP_A
		DW !BOXJumpAnimationTimer, STR_YELLOW_JUMP_B
		DW #$0000, STR_YELLOW_JUMP_C													;timer set to 0 >> animation frame stays forever
		DW $80ED, TM_YELLOW_JUMP	
		
	TM_YELLOW_LAND:
		DW !BOXJumpAnimationTimer, STR_YELLOW_JUMP_C									;basically jump animation played backwards
		DW !BOXJumpAnimationTimer, STR_YELLOW_JUMP_B
		DW !BOXJumpAnimationTimer, STR_YELLOW_JUMP_A
		DW #$0000, STR_YELLOW_CASING
		DW $80ED, TM_YELLOW_LAND				
		
	TM_YELLOW_BOMB:
		DW !BOXBombAnimationTimer1, STR_YELLOW_CASING
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_B
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A
		
		DW !BOXBombAnimationTimer1, STR_YELLOW_CASING
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_B
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A

		DW !BOXBombAnimationTimer1, STR_YELLOW_CASING
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_B
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_A		
		
		DW #$000C, STR_YELLOW_CASING
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_C
		DW #$0000, STR_YELLOW_UPDOWN_D
	TM_YELLOW_GETUP:
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_D
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_C
		DW #$0000, STR_YELLOW_CASING
		
	TM_YELLOW_GETWILD:
		DW #BOXGETDEATHSPEED, STR_YELLOW_CASING
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_C
		DW #BOXGETDEATHSPEED, STR_YELLOW_CASING
		DW #BOXGETDEATHSPEED, STR_YELLOW_UPDOWN_A
		DW !BOXBombAnimationTimer1, STR_YELLOW_UPDOWN_B
		DW #BOXGETDEATHSPEED, STR_YELLOW_UPDOWN_A
		DW #BOXGETDEATHSPEED, STR_YELLOW_CASING				;1
		DW $80ED, TM_YELLOW_GETWILD+4	
		
		
		
;===================================== GREEN LEG PARTS ==========================================
	TM_GREEN_Standing: 
		DW #$0000, STR_GREEN_STAND
		DW $80ED, TM_GREEN_Standing		

	TM_GREEN_JUMP:
		DW !BOXJumpAnimationTimer, STR_GREEN_STAND
		DW !BOXJumpAnimationTimer, STR_GREEN_JUMP_A
		DW !BOXJumpAnimationTimer, STR_GREEN_JUMP_B
		DW #$0000, STR_GREEN_JUMP_C
		DW $80ED, TM_GREEN_JUMP
	TM_GREEN_LAND:
		DW !BOXJumpAnimationTimer, STR_GREEN_JUMP_C
		DW !BOXJumpAnimationTimer, STR_GREEN_JUMP_B
		DW !BOXJumpAnimationTimer, STR_GREEN_JUMP_A
		DW #$0000, STR_GREEN_STAND
		DW $80ED, TM_GREEN_LAND
		
	TM_GREEN_RUNLEFT:																;initial animation when about to run towards Samus
		DW !RUNINITANIM, STR_GREEN_STAND
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_A									;Left legs
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_B
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_A
		DW !RUNINITANIM, STR_GREEN_STAND
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_A									;right legs
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_B
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_A									;FUC*ING HUGE PATTERNS FTW!!!!		
	TM_GREEN_CONTINUE_LEFT:															;the initial animation directly steps into the normal running animation :D
		DW BOXGETSPEED, STR_GREEN_STAND												;BOXGetspeed uses a trick (huge thanks, Scyzer! :) to adjust animation speed
		DW BOXGETSPEED, STR_GREEN_WALKL_A											;depending on how fast the enemy runs, but after the code is run, it acts
		DW BOXGETSPEED, STR_GREEN_WALKL_B											;as if the game just loaded a normal animation speed value
		DW BOXGETSPEED, STR_GREEN_WALKL_C
		DW BOXGETSPEED, STR_GREEN_WALKL_D
		DW $80ED, TM_GREEN_CONTINUE_LEFT
		
	TM_GREEN_RUNRIGHT:
		DW !RUNINITANIM, STR_GREEN_STAND
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_A									;right legs
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_B
		DW !RUNINITANIM, STR_GREEN_RUNRIGHTINIT_A	
		DW !RUNINITANIM, STR_GREEN_STAND
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_A									;Left legs
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_B
		; DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_C
		; DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_B
		DW !RUNINITANIM, STR_GREEN_RUNLEFTINIT_A
	TM_GREEN_CONTINUE_RIGHT:
		DW BOXGETSPEED, STR_GREEN_STAND
		DW BOXGETSPEED, STR_GREEN_WALKL_D
		DW BOXGETSPEED, STR_GREEN_WALKL_C
		DW BOXGETSPEED, STR_GREEN_WALKL_B
		DW BOXGETSPEED, STR_GREEN_WALKL_A
		DW $80ED, TM_GREEN_CONTINUE_RIGHT
		
	TM_GREEN_BOMB:
		DW !BOXBombAnimationTimer1, STR_GREEN_STAND 			;1	
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_B
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A
		
		DW !BOXBombAnimationTimer1, STR_GREEN_STAND 
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A			;2
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_B
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A
		
		DW !BOXBombAnimationTimer1, STR_GREEN_STAND 
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A			;3
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_B
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A
		
		DW #$000C, STR_GREEN_STAND 
		
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_C
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_D
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_E
		DW #$0000, STR_GREEN_BOMB_F
		
TM_GREEN_GETUP:		
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_F
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_E
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_D
		DW !BOXBombAnimationTimer2, STR_GREEN_BOMB_C
		DW #$0000, STR_GREEN_STAND 
		
TM_GREEN_GETWILD:
		DW #BOXGETDEATHSPEED, STR_GREEN_STAND
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_A
		DW #BOXGETDEATHSPEED, STR_GREEN_STAND
		DW #BOXGETDEATHSPEED, STR_GREEN_BOMB_A
		DW !BOXBombAnimationTimer1, STR_GREEN_BOMB_B
		DW #BOXGETDEATHSPEED, STR_GREEN_BOMB_A
		DW #BOXGETDEATHSPEED, STR_GREEN_STAND				;1
		DW $80ED, TM_GREEN_GETWILD+4		
		
		
;===================================== BLUE OUTER ARMOR PARTS ==========================================	
	TM_BLUE_Standing: 
		DW #$0000, STR_BLUE_STAND
		DW $80ED, TM_BLUE_Standing
	TM_BLUE_JUMP:
		DW !BOXJumpAnimationTimer, STR_BLUE_STAND
		DW !BOXJumpAnimationTimer, STR_BLUE_JUMP_A
		DW !BOXJumpAnimationTimer, STR_BLUE_JUMP_B
		DW #$0000, STR_BLUE_JUMP_C
		DW $80ED, TM_BLUE_JUMP		
	TM_BLUE_LAND:
		DW !BOXJumpAnimationTimer, STR_BLUE_JUMP_C
		DW !BOXJumpAnimationTimer, STR_BLUE_JUMP_B
		DW !BOXJumpAnimationTimer, STR_BLUE_JUMP_A
		DW #$0000, STR_BLUE_STAND
		DW $80ED, TM_BLUE_LAND	
		
TM_BLUE_BOMB:
		DW !BOXBombAnimationTimer1, STR_BLUE_STAND				;1
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_B
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		
		DW !BOXBombAnimationTimer1, STR_BLUE_STAND				;2
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_B
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		
		DW !BOXBombAnimationTimer1, STR_BLUE_STAND				;3
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_B
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_A
		
		DW #$000C, STR_BLUE_STAND_DUD		
		
		DW !BOXBombAnimationTimer2, STR_BLUE_BOMB_C				;crouching
		DW !BOXBombAnimationTimer2, STR_BLUE_BOMB_D
		DW #$0000, STR_BLUE_BOMB_E								;end
		
TM_BLUE_GETUP:													;get up from crouching
		DW !BOXBombAnimationTimer2, STR_BLUE_BOMB_E
		DW !BOXBombAnimationTimer2, STR_BLUE_BOMB_D
		DW !BOXBombAnimationTimer2, STR_BLUE_BOMB_C
		DW #$0000, STR_BLUE_STAND
		
;------------------------------------------------

		
;-------------------------------------------------------------		
;Blue running:
{
	TM_BLUE_RUNLEFT:																;initial animation when about to run towards Samus
		DW !RUNINITANIM, STR_BLUE_STAND
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_A									;Left legs
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_B
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_A
		DW !RUNINITANIM, STR_BLUE_STAND
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_A									;right legs
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_B
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_A								
	TM_BLUE_CONTINUE_LEFT:	
		DW PLAYSOUND, STR_BLUE_STAND
		DW BOXGETSPEED, STR_BLUE_WALKL_A
		DW BOXGETSPEED, STR_BLUE_WALKL_B
		DW BOXGETSPEED, STR_BLUE_WALKL_C
		DW BOXGETSPEED, STR_BLUE_WALKL_D
		DW $80ED, TM_BLUE_CONTINUE_LEFT


	TM_BLUE_RUNRIGHT:
		DW !RUNINITANIM, STR_BLUE_STAND
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_A									;right legs
		; DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_B
		; DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_C
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_B
		DW !RUNINITANIM, STR_BLUE_RUNRIGHTINIT_A		
		DW !RUNINITANIM, STR_BLUE_STAND
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_A										;Left legs
		; DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_B
		; DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_C
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_B
		DW !RUNINITANIM, STR_BLUE_RUNLEFTINIT_A
	
TM_BLUE_CONTINUE_RIGHT:	
		DW PLAYSOUND, STR_BLUE_STAND										;playsound pointer points to special code, handle with care!
		DW BOXGETSPEED, STR_BLUE_WALKL_D
		DW BOXGETSPEED, STR_BLUE_WALKL_C
		DW BOXGETSPEED, STR_BLUE_WALKL_B
		DW BOXGETSPEED, STR_BLUE_WALKL_A
		DW $80ED, TM_BLUE_CONTINUE_RIGHT

}
;-------------------------------------------------------------		
}		
;------------------------- Death animation -------------------
{
TM_BLUE_GETWILD:

		DW #BOXGETDEATHSPEED, STR_BLUE_STAND
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_C
		DW #BOXGETDEATHSPEED, STR_BLUE_STAND
		DW #BOXGETDEATHSPEED, STR_BLUE_BOMB_A
		DW !BOXBombAnimationTimer1, STR_BLUE_BOMB_B
		DW #BOXGETDEATHSPEED, STR_BLUE_BOMB_A
		DW #BOXGETDEATHSPEED, STR_BLUE_STAND				;1
		DW $80ED, TM_BLUE_GETWILD+4

TM_BLUE_DEATH:
		DW #$0001, STR_BLUE_STAND
		DW #$000A,STR_BLUE_DEATH_A
		DW #$000A,STR_BLUE_DEATH_B
		DW #$000A,STR_BLUE_DEATH_C
		DW #$0000,STR_BLUE_DEATH_D

}
;================================= STRUCTURES =================================
{
;=================================== BRAIN =================================
 {
		STR_BRAIN_GLOW_A: DW $0001
							DW $0000,$FFE8, SP_BRAINGLOW_A, $0000
								;X coordinate relative to enemy XY
										;y coordinate relative to enemy XY
												;üpointer to sprite map
															;pointer to hitbox, $0000 means no hitbox
		STR_BRAIN_GLOW_B: DW $0001
							DW $0000,$FFE8, SP_BRAINGLOW_B, $0000
		STR_BRAIN_GLOW_C: DW $0001
							DW $0000,$FFE8, SP_BRAINGLOW_C, $0000
 }
;================================= BLUE =================================
{					
	;------------------------------- BLUE STANDING --------------------------------------
	{
		STR_BLUE_STAND:	 DW $0003
							DW $0000,$0000, $0000, HB_BOX_SHELL		;example hitbox pointer
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
	STR_BLUE_STAND_DUD:	 DW $0003
							DW $0000,$FFE4, $0000, HB_BOX_DUD	
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
	}
	;------------------------------- BLUE JUMPING --------------------------------------							
	{							
		STR_BLUE_JUMP_A: DW $0003
							DW $FFF0,$FFE4, SP_BLUE_L, $0000 
							DW $0018,$FFE4, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL
		STR_BLUE_JUMP_B: DW $0003
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL
		STR_BLUE_JUMP_C: DW $0003
							DW $FFF0,$FFF0, SP_BLUE_L, $0000 
							DW $0018,$FFF0, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL
	}						
	;------------------------------- BLUE WALKING --------------------------------------
	{
		STR_BLUE_WALKL_A: DW $0003
							DW $FFF2,$FFE7, SP_BLUE_L, $0000 
							DW $0014,$FFE4, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL		
		STR_BLUE_WALKL_B: DW $0003
							DW $FFEE,$FFE4, SP_BLUE_L, $0000 
							DW $0010,$FFEE, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL
		STR_BLUE_WALKL_C: DW $0003
							DW $FFE8,$FFEA, SP_BLUE_L, $0000 
							DW $0014,$FFEC, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL	
		STR_BLUE_WALKL_D: DW $0003
							DW $FFEE,$FFEC, SP_BLUE_L, $0000 
							DW $0016,$FFEA, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL		
	}							
	;-------------------------------- BLUE WALKINIT			
	{			
STR_BLUE_RUNLEFTINIT_A:	 DW $0003
							DW $FFF0,$FFE4, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL 

STR_BLUE_RUNLEFTINIT_B:	 DW $0003
							DW $FFF0,$FFE0, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL 

; STR_BLUE_RUNLEFTINIT_C:	 DW $0003
							; DW $FFF0,$FFE2, SP_BLUE_L, $0000 
							; DW $0018,$FFE8, SP_BLUE_R, $0000
							; DW $0000,$FFE4, $0000, HB_BOX_SHELL 

		;-------------- RIGHT
							
STR_BLUE_RUNRIGHTINIT_A:	 DW $0003
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE4, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL 		

STR_BLUE_RUNRIGHTINIT_B:	 DW $0003
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE0, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_SHELL 

; STR_BLUE_RUNRIGHTINIT_C:	 DW $0003
							; DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							; DW $0018,$FFE2, SP_BLUE_R, $0000
							; DW $0000,$FFE4, $0000, HB_BOX_SHELL 							
	} 
	;-------------------------------- BOMBING AND CROUCHING ----------------------------
	{

		STR_BLUE_BOMB_A: DW $0003
							DW $FFEE,$FFE4, SP_BLUE_L, $0000 
							DW $001A,$FFE4, SP_BLUE_R, $0000
							DW $0000,$FFE2, $0000, HB_BOX_SHELL					;leg animation
		STR_BLUE_BOMB_B: DW $0003
							DW $FFEC,$FFDE, SP_BLUE_L, $0000 
							DW $001C,$FFDE, SP_BLUE_R, $0000
							DW $0000,$FFE0, $0000, HB_BOX_SHELL
							
		STR_BLUE_BOMB_C: DW $0003												;crouching with bomb slot opening
							DW $FFF0,$FFE8, SP_BLUE_L, $0000 
							DW $0018,$FFE8, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_DUD
		STR_BLUE_BOMB_D: DW $0003
							DW $FFF2,$FFEC, SP_BLUE_L, $0000 
							DW $0016,$FFEC, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_DUD	
		STR_BLUE_BOMB_E: DW $0003
							DW $FFF4,$FFF0, SP_BLUE_L, $0000 
							DW $0014,$FFF0, SP_BLUE_R, $0000
							DW $0000,$FFE4, $0000, HB_BOX_DUD							
	}		
	;--------------------------------- DEATH ANIMATION  -------------------------------
	{
		STR_BLUE_DEATH_A:	 DW $0002
							DW $FFE8,$0018, SP_BLUE_L, $0000
							DW $0020,$0018, SP_BLUE_R, $0000
	
		STR_BLUE_DEATH_B:	 DW $0002
							DW $FFE0,$0016, SP_BLUE_L, $0000
							DW $0038,$0018, SP_BLUE_R, $0000
	
		STR_BLUE_DEATH_C:	 DW $0002
							DW $FFD8,$0014, SP_BLUE_L, $0000
							DW $0044,$0018, SP_BLUE_R, $0000
	
		STR_BLUE_DEATH_D:	 DW $0002
							DW $FFD0,$0010, SP_BLUE_L, $0000
							DW $0050,$0018, SP_BLUE_R, $0000
	
	
	
	}
}				
;================================= YELLOW =================================
{
		STR_YELLOW_CASING:	DW $0001
							DW $0000,$FFE8, SP_YELLOW_CASING, $0000

		STR_YELLOW_JUMP_A:	DW $0001
							DW $0000,$FFEA, SP_YELLOW_CASING, $0000
		STR_YELLOW_JUMP_B:	DW $0001
							DW $0000,$FFEC, SP_YELLOW_CASING, $0000
		STR_YELLOW_JUMP_C:	DW $0001
							DW $0000,$FFE4, SP_YELLOW_CASING, $0000							
							
		STR_YELLOW_UPDOWN_A:	DW $0001
							DW $0000,$FFE7, SP_YELLOW_CASING, $0000
		STR_YELLOW_UPDOWN_B:	DW $0001
							DW $0000,$FFE6, SP_YELLOW_CASING, $0000
		STR_YELLOW_UPDOWN_C:	DW $0001
							DW $0000,$FFEA, SP_YELLOW_CASING, $0000
		STR_YELLOW_UPDOWN_D:	DW $0001
							DW $0000,$FFEC, SP_YELLOW_CASING, $0000							
}
;================================= GREEN =================================
{			
	;---------------------------- GREEN STANDING --------------------------------------
	{							
		STR_GREEN_STAND:		DW $0006
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000
								DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
								DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
	}	
	;----------------------------- GREEN RISING LEGS AND BOMB DROP --------------------------------------
	{

		STR_GREEN_BOMB_A:		DW $0006										;rising legs
							DW $FFDE,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0022,$FFE8, SP_GREENLEG_A_R, $0000
								DW $FFE8,$FFE6, SP_GREENLEG_B_L, $0000
								DW $0012,$FFE6, SP_GREENLEG_B_R, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000			
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000

		STR_GREEN_BOMB_B:		DW $0006
							DW $FFDC,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0024,$FFE8, SP_GREENLEG_A_R, $0000
								DW $FFE6,$FFE2, SP_GREENLEG_B_L, $0000
								DW $0014,$FFE2, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000
							
		STR_GREEN_BOMB_C:		DW $0007
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
								DW $FFEA,$FFE8, SP_GREENLEG_B_L, $0000
								DW $000E,$FFE8, SP_GREENLEG_B_R, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000									
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
										DW $0000,$FFE8, SP_BOMBSLOT_A, $0000		

		STR_GREEN_BOMB_D:		DW $0007
							DW $FFE2,$FFEA, SP_GREENLEG_A_L, $0000
							DW $001E,$FFEA, SP_GREENLEG_A_R, $0000
								DW $FFEC,$FFEC, SP_GREENLEG_B_L, $0000
								DW $000C,$FFEC, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000									
										DW $0000,$FFE4, SP_BOMBSLOT_B, $0000		

		STR_GREEN_BOMB_E:		DW $0007
							DW $FFE4,$FFEC, SP_GREENLEG_A_L, $0000
							DW $001A,$FFEC, SP_GREENLEG_A_R, $0000
								DW $FFEE,$FFF0, SP_GREENLEG_B_L, $0000
								DW $000A,$FFF0, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000									
										DW $0000,$FFE2, SP_BOMBSLOT_C, $0000		

		STR_GREEN_BOMB_F:		DW $0007
							DW $FFE4,$FFEC, SP_GREENLEG_A_L, $0000
							DW $001A,$FFEC, SP_GREENLEG_A_R, $0000
								DW $FFEE,$FFF0, SP_GREENLEG_B_L, $0000
								DW $000A,$FFF0, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000									
										DW $0000,$FFE0, SP_BOMBSLOT_D, $0000		
	}
	;------------------------------- GREEN WALKING --------------------------------------
	{
							
		STR_GREEN_WALKL_A:	DW $0006
							DW $FFDA,$FFE4, SP_GREENLEG_A_L, $0000
							DW $0020,$FFE6, SP_GREENLEG_A_R, $0000
								DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
								DW $000C,$FFE4, SP_GREENLEG_B_R, $0000
									DW $FFF4,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0014,$FFE8, SP_GREENLEG_C_R, $0000

		STR_GREEN_WALKL_B:	DW $0006
							DW $FFD7,$FFEA, SP_GREENLEG_A_L, $0000
							DW $001C,$FFE4, SP_GREENLEG_A_R, $0000
								DW $FFE8,$FFE4, SP_GREENLEG_B_L, $0000
								DW $0008,$FFEE, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0010,$FFE8, SP_GREENLEG_C_R, $0000		
							
		STR_GREEN_WALKL_C:	DW $0006
							DW $FFD6,$FFEA, SP_GREENLEG_A_L, $0000
							DW $0018,$FFED, SP_GREENLEG_A_R, $0000
								DW $FFE0,$FFEA, SP_GREENLEG_B_L, $0000
								DW $000C,$FFEC, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE4, SP_GREENLEG_C_L, $0000
									DW $000C,$FFE4, SP_GREENLEG_C_R, $0000	
							
		STR_GREEN_WALKL_D:	DW $0006
							DW $FFE2,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
								DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
								DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
									DW $FFEC,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0008,$FFE8, SP_GREENLEG_C_R, $0000	
							
  }	
	;------------------------------- GREEN JUMPING --------------------------------------
	{
		STR_GREEN_JUMP_A:		DW $0006
							DW $FFDE,$FFE8, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFEA, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
							DW $0022,$FFE8, SP_GREENLEG_A_R, $0000
							DW $0010,$FFEA, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000
							
		STR_GREEN_JUMP_B:		DW $0006
							DW $FFDC,$FFE8, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE6, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
							
							DW $0024,$FFE8, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE6, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000

		STR_GREEN_JUMP_C:		DW $0006
							DW $FFE0,$FFF0, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFEC, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFEA, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFF0, SP_GREENLEG_A_R, $0000
							DW $0010,$FFEC, SP_GREENLEG_B_R, $0000
							DW $0010,$FFEA, SP_GREENLEG_C_R, $0000							
}
	;------------------------------- GREEN WALKINIT ----------------------------------
	{
					
STR_GREEN_RUNLEFTINIT_A:		DW $0006
							DW $FFE0,$FFE4, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE4, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE4, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000	
							
STR_GREEN_RUNLEFTINIT_B:		DW $0006
							DW $FFE0,$FFE0, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE0, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE0, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000	
							
; STR_GREEN_RUNLEFTINIT_C:		DW $0006
							; DW $FFE0,$FFE2, SP_GREENLEG_A_L, $0000
							; DW $FFE8,$FFE2, SP_GREENLEG_B_L, $0000
							; DW $FFF0,$FFE2, SP_GREENLEG_C_L, $0000
							
							; DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
							; DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
							; DW $0010,$FFE8, SP_GREENLEG_C_R, $0000	
							
;---------------------------------------------------							

STR_GREEN_RUNRIGHTINIT_A:		DW $0006
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFE4, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE4, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE4, SP_GREENLEG_C_R, $0000

STR_GREEN_RUNRIGHTINIT_B:		DW $0006
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFE0, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE0, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE0, SP_GREENLEG_C_R, $0000

STR_GREEN_RUNRIGHTINIT_C:		DW $0006
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
							DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
							
							DW $0020,$FFE2, SP_GREENLEG_A_R, $0000
							DW $0010,$FFE2, SP_GREENLEG_B_R, $0000
							DW $0010,$FFE2, SP_GREENLEG_C_R, $0000

							
}		
	;------------------------------- GREEN DEATH ----------------------------------
		STR_GREEN_DEATH:		DW $0006
							DW $FFE0,$FFE8, SP_GREENLEG_A_L, $0000
							DW $0010,$FFE8, SP_GREENLEG_C_R, $0000
								DW $FFE8,$FFE8, SP_GREENLEG_B_L, $0000
								DW $0010,$FFE8, SP_GREENLEG_B_R, $0000
									DW $FFF0,$FFE8, SP_GREENLEG_C_L, $0000
									DW $0020,$FFE8, SP_GREENLEG_A_R, $0000
					
}		
}					
;==============================================================================
;================================== HITBOXES ==================================
;==============================================================================
{
			HB_BOX_SHELL:	DW $0003 ; number of individual hitbox parts
								DW $FFF4,$FFFA,$000C,$0010, !BOXTouchAI, #BrainShotAI
																			;shot AI for this individual hitbox
																;Touch AI rfor this individual hitbox
  														;end Y coordinate of HB relative to structure part Y
														;basically with this you define the upper left and the lower right corners of the rectangular hitbox
												  ;end X coordinate of HB relative to structure part X
											;start Y coordinate of HB relative to structure part Y
									  ;start x coordinate of HB relative to structure part X
								DW $FFD8,$FFF8,$FFF6,$0010, !BOXTouchAI, #BOXShotAI
								DW $000B,$FFF8,$0028,$0010, !BOXTouchAI, #BOXShotAI
			
			HB_BOX_DUD:		DW $0004
								DW $FFF4,$FFFA,$000A,$000C, !BOXTouchAI, #BOXShotAI
								DW $FFF4,$000C,$000C,$0010, !BOXTouchAI, #BrainShotAI
								DW $FFD8,$FFF8,$FFF4,$000E, !BOXTouchAI, #BOXShotAI
								DW $000C,$FFF8,$0028,$000E, !BOXTouchAI, #BOXShotAI
}
;==============================================================================
;=============================== SPRITE TABLES ================================
;==============================================================================
{
		SP_BRAINGLOW_A:	DW $0004		;sprite maps, handled in the same manner as normal enemies
								DB $F0, $81, $F0, $40, $21 : DB $00, $80, $F0, $42, $21
								DB $F0, $81, $00, $60, $21 : DB $00, $80, $00, $62, $21
		SP_BRAINGLOW_B:	DW $0004
								DB $F0, $81, $F0, $44, $21 : DB $00, $80, $F0, $46, $21
								DB $F0, $81, $00, $64, $21 : DB $00, $80, $00, $66, $21
		SP_BRAINGLOW_C:	DW $0004
								DB $F0, $81, $F0, $48, $21 : DB $00, $80, $F0, $4A, $21
								DB $F0, $81, $00, $68, $21 : DB $00, $80, $00, $6A, $21			
;-----------------------								
			SP_BLUE_L:	DW $0007
								DB $F0, $81, $F0, $00, $21 : DB $F8, $81, $F0, $01, $21
								DB $F0, $81, $00, $03, $21 : DB $F8, $81, $00, $04, $21
								DB $F0, $01, $10, $06, $21 : DB $F8, $01, $10, $16, $21
								DB $00, $00, $10, $07, $21
			SP_BLUE_R:	DW $0007
								DB $F8, $81, $F0, $00, $61 : DB $F0, $81, $F0, $01, $61
								DB $F8, $81, $00, $03, $61 : DB $F0, $81, $00, $04, $61
								DB $00, $00, $10, $06, $61 : DB $F8, $01, $10, $16, $61
								DB $F0, $01, $10, $07, $61	

								
;----------------------------------------------------------
		SP_YELLOW_CASING:	DW $0006
								DB $F8, $01, $0C, $4C, $21 : DB $00, $00, $0C, $4D, $21
								DB $F0, $81, $F0, $08, $21 : DB $00, $80, $F0, $0A, $21
								DB $F0, $81, $00, $0C, $21 : DB $00, $80, $00, $0E, $21
								
;--------------
			SP_GREENLEG_A_L:	DW $0003
								DB $F8, $81, $F0, $84, $21 : DB $F8, $81, $00, $86, $21
								DB $F8, $81, $10, $80, $21
			SP_GREENLEG_B_L:	DW $0004
								DB $FC, $81, $F0, $88, $21 : DB $FC, $81, $00, $8A, $21
								DB $00, $00, $10, $82, $21 : DB $00, $00, $18, $92, $21
			SP_GREENLEG_C_L:	DW $0004					
								DB $F8, $81, $F0, $8C, $21 : DB $F8, $81, $00, $8E, $21
								DB $FC, $01, $10, $83, $21 : DB $FC, $01, $18, $93, $21
								
			SP_GREENLEG_A_R:	DW $0003
								DB $F8, $81, $F0, $84, $61 : DB $F8, $81, $00, $86, $61
								DB $F8, $81, $10, $80, $61
			SP_GREENLEG_B_R:	DW $0004
								DB $FC, $81, $F0, $88, $61 : DB $FC, $81, $00, $8A, $61
								DB $00, $00, $10, $82, $61 : DB $00, $00, $18, $92, $61
			SP_GREENLEG_C_R:	DW $0004					
								DB $F8, $81, $F0, $8C, $61 : DB $F8, $81, $00, $8E, $61
								DB $FC, $01, $10, $83, $61 : DB $FC, $01, $18, $93, $61
								
			SP_BOMBSLOT_A:	DW $0002
								DB $F0, $81, $F0, $20, $21 : DB $00, $80, $F0, $20, $61
			SP_BOMBSLOT_B:	DW $0002
								DB $F0, $81, $F0, $22, $21 : DB $00, $80, $F0, $22, $61
			SP_BOMBSLOT_C:	DW $0002
								DB $F0, $81, $F0, $24, $21 : DB $00, $80, $F0, $24, $61		
			SP_BOMBSLOT_D:	DW $0002
								DB $F0, $81, $F0, $26, $21 : DB $00, $80, $F0, $26, $61								
								
}

;thoughts and info
{
;What the enemy should decide:
;	Samus is left or right near the ground and near the enemy:
	; -> either drop a bomb or start jumping
;	Samus is at least 5 blocks away from the enemy on either side:
	; -> start walking, chasing Samus, eventually hitting a wall or scratching on ground if he ran past Samus, and start jumping, then dropping a bomb
	; 0FAA 		palette backup
	; 0FA8 		if 0 = Enemy is on the ground, 1 = enemy is in the air
	; 0FAA		Graphics flag for VRAM update
	; 0FAC 		internal timer for instruction to run until stop
	; 0FAE 		timer to wait until perform instructions
	; 0FB0 		Executes instructions
	; 0FB2 		(Speed from SMILE)
	; 0FB4 		(Speed2 from SMILE)
	
; DIE ANIMATION: Enemy explodes and scatteres its pieces all around
; Scyzer> BF now just give it a cool death animation where the pieces break off in different directions
; <Black_Falcon> yeaaaahhh
; <Black_Falcon> so gonna do that
; <Black_Falcon> thanks
; <Black_Falcon> :D
; <Scyzer> and then like, the nucleus part flies out of the box and flees the room
; <Scyzer> and then you can battle it later as a new enemy
; <Scyzer> bitches would love that
}



PALETTETABLE:
	DW $0200, $0200, $0400, $0600													;palettes for the enemy parts, representing the value in the enemy allowed list*2 and reversed
	
BOXSPEEDTABLE:																		;Speed table in frames used by BOXGETSPEED routine, easily editable
	DW $0008, $0007, $0006, $0004, $0004, $0003, $0002, $0001
	
BOX_INIT_SEGMENTGFX:
	DW TM_BRAIN
	DW TM_BLUE_Standing
	DW TM_YELLOW_Standing
	DW TM_GREEN_Standing	

PLAYSOUND:																			;play a stepping sound during the animation loop
	PHY : LDA #$004B : JSL $8090A3 : BRA $01		
BOXGETSPEED:
	PHY : LDX $0E54
	LDA $7E7804 : BPL + : EOR #$FFFF : INC			
+	ASL : TAY
	LDA BOXSPEEDTABLE,y : STA $0F94,x												;store speed depending on running speed, table is right above
	PLY : DEY : DEY : PLA : PEA $C297 : RTL										;this last line of code was taken from an enemy AI made by Scyzer
																					;to make this code act as if it would have just loaded an
																					;animation speed value. really clever! :D
BOXGETDEATHSPEED:
print pc, " DEATH"
	PHY : LDX $0E54
	LDA !insttimer : CMP #$0080 : BMI +
	LDA #$0006 : STA $0F94,x :  BRA ++
+	CMP #$0040 : BMI +
	LDA #$0004 : STA $0F94,x :  BRA ++

+	LDA #$0003 : STA $0F94,x
++	PLY : DEY : DEY : PLA : PEA $C297 : RTL
;SHOT AIs	
{	
BOXShotAI:
	PHX
	LDA $18A6 : ASL : TAX : JSL $90AE06							;dud shot, calls the routine for hitting surfaces, pretty handy! :D	
	PLX : RTL

BrainShotAI:
	LDA !mainHP : BEQ BOXShotAI
	PHX
	LDA #$0007 : JSL $809021
	LDA $18A6 : ASL : TAX
	LDA $0C18,x : BIT #$0010 : BNE + : BIT #$0300 : BEQ ++
+	
	LDA !mainXpos : STA $12 
	LDA !mainYpos : SEC : SBC #$0020 : STA $14 : STZ $18
	LDA #$000C : STA $16 : JSL $B4BC26 							;small yellow smoke
	JSL $A08032														;makes the enemy explode 
	LDA !mainHP : STA !E1HP : STA !E2HP : STA !E3HP : BNE ++
print pc, " DIE "

	;LDA #BOXdeath : STA !inst ;: 
	JSR EXPLOSION
	LDA #BOXdeathphase1 : STA !inst ;: STA !E1inst : STA !E2inst
	LDA !mainproperty : ORA #$0400 : STA !mainproperty
									STA !E1property
								   STA !E2property
								  STA !E3property
	PLX : RTL
++	LDA $18A6 : ASL : TAX : JSL $90AE06 : PLX
+	LDA !mainHP	: CMP !DMGgradient01 : BMI + : RTL	
+	CMP !DMGgradient02 : BPL GRADIENT1
	CMP !DMGgradient03 : BPL GRADIENT2
GRADIENT3:
	LDA $0FAA : CMP #$0003 : BEQ +
	LDA #$9C00 : STA $12 : JSR CHANGEGFX : JSR EXPLOSION		;imports gfx from AD9C00
	LDA #$0003 : STA $0FAA
+	RTL
GRADIENT2:
	LDA $0FAA : CMP #$0002 : BEQ +
	LDA #$9800 : STA $12 : JSR CHANGEGFX : JSR EXPLOSION		;imports gfx from AD9800
	LDA #$0002 : STA $0FAA
+	RTL
GRADIENT1:
	LDA $0FAA : CMP #$0001 : BEQ +
	LDA #$9400 : STA $12 : JSR CHANGEGFX : JSR EXPLOSION		;imports gfx from AD9400
	LDA #$0001 : STA $0FAA
+	RTL
		
CHANGEGFX:
	PHX : LDX $0330 : LDA #$0400 : STA $D0,x
	INX : INX
	LDA $12 : STA $D0,x
	INX : INX
	SEP #$20 : LDA #$AD : STA $D0,x : REP #$20
	INX
	LDA #$7000 : STA $D0,x
	INX : INX : STX $0330 : PLX : RTS
	
EXPLOSION:													;this spawns some explosion gfx at the enemy's position, used when damage gradient gfx changes
	LDA !mainXpos : STA $12
	LDA !mainYpos : SEC : SBC #$0010 : STA $14 : STZ $18
	LDA #$0003 : STA $16 : JSL $B4BC26 							;explosion effect
	LDA !mainXpos : CLC : ADC #$000C : STA $12 
	LDA !mainYpos : SEC : SBC #$0018 : STA $14 : STZ $18
	LDA #$000C : STA $16 : JSL $B4BC26 						;small yellow smoke
	LDA !mainXpos : SEC : SBC #$000C : STA $12 
	LDA !mainYpos : SEC : SBC #$0018 : STA $14 : STZ $18
	LDA #$000C : STA $16 : JSL $B4BC26 						
	LDA #$0025 : JSL $8090A3	 : RTS							;sound
	
RANDOMEXPLOSION:
	JSL $808111 : AND #$003F : CLC : ADC !mainXpos 
								SEC : SBC #$0020 : STA $12
	JSL $808111 : AND #$002F : EOR #$FFFF : CLC : ADC !mainYpos : STA $14
	LDA #$0004 : STA $16 : STZ $18 : JSL $B4BC26 							;explosion effect
	LDA #$0008 : JSL $8090A3 : RTS							;sound
}	
BOXdeathphase1:
!DEATHexplosionheight = #$0040

	JSR STOREGETWILDGFX
	LDA #$0100 : STA !insttimer
	LDA #BOXdeathphase2 : STA !inst
	RTS
	
BOXdeathphase2:
	LDA !insttimer : DEC !insttimer : BNE +
	LDA #BOXdeathphase3 : STA !inst
	LDA #$0016 : JSL $809143
	RTS
+	CMP #$0040 : BEQ ++
	AND #$0007 : CMP #$0003
	BNE +
	JSR RANDOMEXPLOSION	
+	RTS
++  LDA #$000F : JSL $809143 : RTS														;Sound	

BOXdeathphase3:
	LDA #$0040 : STA $1840 : LDA #$0004 : STA $183E									;Rumble
	LDA !mainXpos : STA $12
	LDA !mainYpos : SEC : SBC #$0008 : STA $14 : STZ $18
	LDA #$001D : STA $16 : JSL $B4BC26 							;explosion effect
	LDA !mainXpos : CLC : ADC #$0020 : STA $12
	LDA !mainYpos : SEC : SBC #$0004 : STA $14 : STZ $18
	LDA #$001D : STA $16 : JSL $B4BC26 							;explosion effect
	LDA !mainXpos : SEC : SBC #$0020 : STA $12
	LDA !mainYpos : SEC : SBC #$0010 : STA $14 : STZ $18
	LDA #$001D : STA $16 : JSL $B4BC26 							;explosion effect
	LDA !mainXpos : CLC : ADC #$0028 : STA $12
	LDA !mainYpos : SEC : SBC #$000A : STA $14 : STZ $18
	LDA #$0003 : STA $16 : JSL $B4BC26 								;explosion effect	
	LDA !mainXpos : SEC : SBC #$0028 : STA $12
	LDA !mainYpos : SEC : SBC #$000A : STA $14 : STZ $18
	LDA #$0003 : STA $16 : JSL $B4BC26 								;explosion effect	
	LDA !mainXpos : STA $0CE2
	LDA !mainYpos : STA $0CE4	
	LDX $0F78 : LDA #$0004 : JSR $A0A3AF
	LDA !mainproperty : ORA #$0100 : STA !mainproperty
	STA !E1property : STA !E2property : STA !E3property	
	PHX : PHY : PHP : PHB
	JSL $888288
	JSL $888AA4
	PLB : PLP : PLY : PLX														;explosions		
	LDA #BOXdeathphasefinal : STA !E1inst	
	LDA #$0080 : STA !insttimer
	RTS
	
BOXdeathphasefinal:	
	LDA !insttimer : BEQ +
	DEC !insttimer : RTS
+
	LDA #$00D0 : STA $7EF434
	LDA #$0180 : STA $7EF436 : JSL $A0B8EE											;lotsa item drops, yay!
	LDA #$0100 : STA $7EF434
	LDA #$0160 : STA $7EF436 : JSL $A0B92B
	LDA #$0120 : STA $7EF434
	LDA #$0180 : STA $7EF436 : JSL $A0B8EE
	LDA #$0100 : STA $7EF434
	LDA #$0190 : STA $7EF436 : JSL $A0B92B
	LDA #$0002 : JSL $8081A6																	 ;set boss bit
	LDA #$0003 : JSL $808FC1 															    	 ;Change to elevator music	
	LDA !mainproperty : ORA #$0200 : STA !mainproperty
	STA !E1property : STA !E2property : STA !E3property	
	RTS

;---------------------------------------------------------------- INIT AI
{		
BOXInitAI:
	PHY
	LDX $079F : LDA $7ED828,x : AND #$0002 : BNE ++								;check for boss bit
	LDX $0E54 : LDA $0F86,x : ORA #$2000 : STA $0F86,x : STZ !inst,x
	LDA #$0001 : STA $0F94,x														;Timer for how fast to animate the sprites
	LDA !SMILEspeed : TAY : LDA BOX_INIT_SEGMENTGFX,y : STA $0F92,x				;store standing	LDA #$0000 : JSL $808FC1
	JSR STOREJUMPGFX
	LDA PALETTETABLE,y : STA !Palette : STA $0FAA,x
	LDA !SMILEspeed2 : BEQ +	: PLY : RTL										;First enemy possesses the other enemy parts
+	
	LDA !mainXpos : STA !E1Xpos : STA !E2Xpos : STA !E3Xpos
	LDA !mainYpos : STA !E1Ypos : STA !E2Ypos : STA !E3Ypos	
	LDA #$0050 : STA !timer : STZ !insttimer
	LDA #INITFALL : STA !inst
	PLY : RTL
++
	LDA !mainproperty : ORA #$0200 : STA !mainproperty
	STA !E1property : STA !E2property : STA !E3property
	STZ !inst	
	PLY : RTL
}	
;---------------------------------------------------------------- MAIN RUN AI
MainRunAI:																			;each enemy part can have its own running AI
	LDX $0E54 : LDA !SMILEspeed2 : ASL : TAX
	JSR (SEGMENTRUNROUTINES,x)
	RTL
SEGMENTRUNROUTINES:

	DW MAINPART
	DW PARTS
	DW PARTS
	DW BRAIN																		;RTS for the brain. YES, IT'S TRUE: BOX IS A NO-BRAINER!!!

	BRAIN: RTS

MAINPART:
	LDX $0E54 : LDA !mainHP : BEQ +
	LDA !mainXpos : STA !E1Xpos : STA !E2Xpos : STA !E3Xpos							;Syncs enemy positions, with one frame delay
	LDA !mainYpos : STA !E1Ypos : STA !E2Ypos : STA !E3Ypos						;kinda simulates the segments' inertia when moving as a side effect
+	
	LDA !timer : BEQ + : DEC !timer : BRA ++										;timer for different actions
+	LDA !inst : BPL ++ : JSR (!inst,x)											;execute instructions
++	RTS

PARTS:
	LDX $0E54
	LDA !inst,x : BPL + : JSR (!inst,x)		
+	RTS

PART_EXPL_INIT:
	RTS


INITFALL:																			;first routine to run when Samus entered the room 
;	LDA #INITFALL+20 : STA !inst
	JSR FALLDOWN : BCS + : RTS
+	JSR HITGROUND
	LDA #$0000 : JSL $808FC1
	LDA #$0005 : JSL $808FC1
	LDA #CHECKNEXTAI : STA !inst
	RTS

TESTAI:																				;used by me to test things of course, duh!

	JSR STOREBOMBGFX
	LDA #$0080 : STA !timer
	LDA #TESTAI2 : STA !inst
	RTS
TESTAI2:
	JSR STOREGETUPGFX
	LDA #$0060 : STA !timer
	LDA #TESTAI : STZ !inst
	RTS	
	

;GFX ROUTINES -----------------------------
{
STOREGETWILDGFX:
	LDA #TM_BLUE_GETWILD : STA !mainGFXinst
	LDA #TM_GREEN_GETWILD : STA !E2GFXinst
	LDA #TM_YELLOW_GETWILD : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS	
STOREGETUPGFX:
	LDA #TM_BLUE_GETUP : STA !mainGFXinst
	LDA #TM_GREEN_GETUP : STA !E2GFXinst
	LDA #TM_YELLOW_GETUP : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS	
STOREBOMBGFX:
	LDA #TM_BLUE_BOMB : STA !mainGFXinst
	LDA #TM_GREEN_BOMB : STA !E2GFXinst
	LDA #TM_YELLOW_BOMB : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS		
STORERUNLEFTGFX:
	LDA #TM_BLUE_RUNLEFT : STA !mainGFXinst
	LDA #TM_GREEN_RUNLEFT : STA !E2GFXinst
	LDA #TM_YELLOW_UPDOWN : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS
STORERUNRIGHTGFX:
	LDA #TM_BLUE_RUNRIGHT : STA !mainGFXinst
	LDA #TM_GREEN_RUNRIGHT : STA !E2GFXinst
	LDA #TM_YELLOW_UPDOWN : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS	
STOREJUMPGFX:
	LDA #TM_BLUE_JUMP : STA !mainGFXinst
	LDA #TM_GREEN_JUMP : STA !E2GFXinst
	LDA #TM_YELLOW_JUMP : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS	
STORELANDGFX:
	LDA #TM_BLUE_LAND : STA !mainGFXinst
	LDA #TM_GREEN_LAND : STA !E2GFXinst
	LDA #TM_YELLOW_LAND : STA !E1GFXinst
	LDA #$0001 : STA $0F94 : STA $1014 : STA $0FD4	
	RTS		
}
CHECKNEXTAI:																		;decide what to do based on Samus's movement
	LDA !mainXpos : CLC : ADC !runcheckdistance : CMP $0AF6 : BMI STORERUNNING		;so if Samus is more than 5 blocks away from the enemy, it starts running
				   SEC : SBC !runcheckdistance*2 : CMP $0AF6 : BPL STORERUNNING		;Decide to jump or to drop a bomb
	JSR $808111 : LSR : CMP #$3000 : BPL STOREJUMP
						CMP #$1000 : BPL STORERUNNING		
	LDA #BOXBombAI : STA !inst : RTS
STOREJUMP:
	LDA #BOXJumpAI : STA !inst
	JSR $808111 : LDA $05E5 : LSR : AND #$0003 : INC : STA !insttimer : RTS		;used here for a counter how many jumps to perform (up to 4)
STORERUNNING:				   
	LDA #BOXRunAI : STA !inst														;Start running into one direction for X framse
	LDA !howlongtorun : STA !insttimer : RTS

CHECKSAMUSDIR:
	LDA !mainXpos : SEC : SBC $0AF6 : BPL +										;clears if left
	SEC : RTS
+	CLC : RTS

;JUMP AI:
BOXJumpAI:																			;This AI runs once, to initiate the jump and speeds, the falling routine handles the decrement of speeds
{
print pc, " JUMPCOUNT" 
	LDA !insttimer : AND #$0001 : BNE +
	JSR $808111 : LDA $05E5 : LSR : CMP #$2000 : BPL ++ : BRA +++
+
	JSR CHECKSAMUSDIR : BCC +++													;initiate jump direction based on Samus current position

++	LDA !horjumpspeedR : STA $14 : STA $7E7804 : BRA ++							;Jump Right
+++	LDA !horjumpspeedL : STA $14 : STA $7E7804										;Jump Left
++	LDA.w !BOXJumpAnimationTimer*3 : STA !timer
	JSR STOREJUMPGFX
	LDA #$0000 : STA $7E7802
	LDA #$0000 : STA $7E7806														;go up
	LDA !BOXjumpheight : STA $7E7808
+	LDA #BOXFallAI : STA $0FB0
	LDA #$003F : JSL $8090A3														;Sound
	RTS
}
BOXFallAI:
{
	JSR FALLDOWN : BCC + : LDA $7E7808,x : BMI + 									;checks for accidently hitting the ceiling (if the jump height is too large or when it hits a platform
	JSR HITGROUND																	;hits the ground
	LDA !insttimer : BEQ ++														;here it checks for how many jumps have been performed
	DEC !insttimer 
	LDA #BOXJumpAI : STA !inst : BRA +											;perform another jump

++	LDA #BOXBombAI : STA !inst : RTS												;check if still in AIR
+	LDA $7E7804 : STA $14 : LDA $7E7802 : STA $12 : JSL $A0C6AB					;horizontal movement
	BCC + : JSR HITWALL															;basically everytime it hits a wall, it drops a bomb (that's what it does, right..? :/ )
+	RTS

FALLDOWN:
	LDA #$0001 : STA $0FA8															;first assume the enemy is in the air
	LDX $0E54
	LDA $7E7808,x : CMP !BOXmaxfallspeed : BPL +
	LDA $7E7806,x : CLC : ADC #$8000 : STA $7E7806,x : BNE + 							;subpixel speed. using it as a timer for
	LDA $7E7808,x : CLC : ADC #$0001 : STA $7E7808,x									;Accelerate due to gravity
+	LDA $7E7806,x : STA $12
	LDA $7E7808,x : STA $14
	JSL $A0C786 : BCC + : STZ $0FA8
	LDA #$0000 : STA $7E7808,x : STA $7E7806,x										;the enemy now definitely hit the ground, clear vertical speeds
+	RTS
}
	
HITGROUND:
	LDA #$0004 : STA $1840 : LDA #$0004 : STA $183E									;Rumble
	LDA !mainXpos : CLC : ADC #$0010 : STA $12 
	LDA !mainYpos : STA $14 : STZ $18
	LDA #$0015 : STA $16 : JSL $B4BC26 												;dust
	LDA !mainXpos : SEC : SBC #$0010 : STA $12 
	LDA !mainYpos : STA $14 : STZ $18
	LDA #$0015 : STA $16 : JSL $B4BC26 												;dust
	LDA #$0018 : STA !timer															;time to get Settled
	JSR STORELANDGFX
	LDA #$0025 : JSL $8090A3														;sound
	LDA #$0000 : STA $7E7808 : STA $7E7806 : STZ $0FA8								;enemy is on the floor, clear vertical speeds
	RTS
	
HITWALL:
	STZ !insttimer																	;clear timer for instructions, that makes it go to bomb AI later once he hit the ground
	LDA #$0004 : STA $1840 : LDA #$0004 : STA $183E									;Rumble
	LDA #$0025 : JSL $8090A3														;sound
print pc	
	LDA $7E7804 : BPL +															;check which direction
	LDA !mainXpos : SEC : SBC #$0020 : STA $12 
	LDA !mainYpos : SEC : SBC #$0010 : STA $14 : STZ $18
	LDA #$0015 : STA $16 : JSL $B4BC26 		
	LDA !BOXbouncespL : STA $7E7804 : STA $14 : BRA ++							;store bounce speed left
+
	LDA !mainXpos : CLC : ADC #$0020 : STA $12 
	LDA !mainYpos : SEC : SBC #$0010 : STA $14 : STZ $18
	LDA #$0015 : STA $16 : JSL $B4BC26 
	LDA !BOXbouncespR : STA $7E7804 : STA $14										;store bounce speed right
++	
	LDA #$8000 : STA $7E7802 : STA $12 : JSL $A0C6AB								;horizontal movement
	LDA $0FA8 : BNE +																;skip bounceoff height write if not on the ground
	LDA !BOXbounceoffheight : STA $7E7808 : STA $14
	LDA #$0000 : STA $7E7806 : STZ $12 : JSL $A0C786								;go up
+	
	LDA #$003F : JSL $8090A3														;sound
	JSR STOREJUMPGFX
	RTS		
	
BOXRunAI:																			;Initiates running acceleration
	JSR FALLDOWN : LDA $0FA8 : BEQ +												;just makes sure the enemy falls when running off ledges
	RTS
+
	JSR CHECKSAMUSDIR : BCC +
	LDA #ACCRIGHT : STA !inst
	LDA #$0001 : STA $7E7804
	JSR STORERUNRIGHTGFX : BRA ++
+
	LDA #ACCLEFT : STA !inst
	LDA #$FFFE : STA $7E7804
	JSR STORERUNLEFTGFX
++	LDA #$0000 : STA $7E7802 
print pc, " RUNINIT "
	LDA.w !RUNINITANIM*8 : STA !timer : RTS
	
ACCRIGHT:
	JSR FALLDOWN : BCS +
	LDA #$0001 : STA !insttimer
	LDA #BOXFallAI : STA !inst
+	
	LDA $7E7804 : CMP !BOXmaxrunspeedright : BPL +
	LDA $7E7802 : CLC : ADC #$2000 : STA $7E7802 : BNE + 							;subpixel speed, slowly increasing
	LDA $7E7804 : CLC : ADC #$0001 : STA $7E7804									;Accelerate	
+	
	JSR CHECKSAMUSDIR : BCS +
print pc, "  whendoesthisrun"
	LDA #DECELLERATE : STA !inst : RTS
+	
	LDA !insttimer : BNE +
	LDA #DECELLERATE : STA !inst : RTS
+	DEC !insttimer	
	LDA $7E7802 : STA $12
	LDA $7E7804 : STA $14
	JSL $A0C6AB : BCC +
	JSR HITWALL : LDA #BOXFallAI : STA !inst	
+	RTS
	
ACCLEFT:	
	JSR FALLDOWN : BCS +
	LDA #$0001 : STA !insttimer
	LDA #BOXFallAI : STA !inst
+	
print pc
	LDA $7E7804 : CMP !BOXmaxrunspeedleft : BMI +
	LDA $7E7802 : CLC : ADC #$2000 : STA $7E7802 : BNE + 							;subpixel speed, slowly increasing
	LDA $7E7804 : SEC : SBC #$0001 : STA $7E7804									;Accelerate
+
	JSR CHECKSAMUSDIR : BCC +
	LDA #DECELLERATE : STA !inst : RTS
+	
	LDA !insttimer : BNE +
	LDA #DECELLERATE : STA !inst : RTS
+	DEC !insttimer	
	LDA $7E7802 : STA $12
	LDA $7E7804 : STA $14
	JSL $A0C6AB : BCC +
	JSR HITWALL : LDA #BOXFallAI : STA !inst
+	RTS

;8FC5
;82FB
DECELLERATE:
	JSR FALLDOWN : BCS +
	LDA #$0001 : STA !insttimer
	LDA #BOXFallAI : STA !inst
+
	LDA $7E7804 : BPL +
	LDA $7E7802 : SEC : SBC #$1000 : STA $7E7802 : BNE ++
	LDA $7E7804 : CLC : ADC #$0001 : STA $7E7804 : BMI ++ : BRA +++
+	
	LDA $7E7802 : SEC : SBC #$1000 : STA $7E7802 : BNE ++
	LDA $7E7804 : SEC : SBC #$0001 : STA $7E7804 : BEQ +++ : BMI ++
+++	JSR STOREJUMP
	LDA #$0010 : STA !timer
	LDA #$0000 : STA $7E7802 : STA $7E7804 : RTS	
++	LDA $7E7802 : STA $12
	LDA $7E7804 : STA $14
	JSL $A0C6AB : BCC + : JSR HITWALL : LDA #BOXFallAI : STA !inst	
+	RTS

	
BOXBombAI:
	JSR STOREBOMBGFX
	LDA #$0070 : STA !timer
	LDA #DROPBOMB : STA !inst
	RTS
	
DROPBOMB:
	LDA #$0004 : JSL $80903F
	LDA !mainXpos : STA $12
	LDA !mainYpos : STA $14
	; LDA #$0001
	; LDY #$CB59 : JSL $868097
	; LDA !mainXpos : STA $12
	; LDA !mainYpos : STA $14
	; LDY #$BE25 : JSL $868097
	; LDA #$0030 : STA !timer
	;LDY #$AD7A
;	JSR CHECKSAMUSDIR : BCC $03
	LDY #$AD5E : LDA #$0000 : JSL $868027
;	LDY #$AD7A : LDA #$0000 : JSL $868027
;	LDY #$CB59 : LDA #$0000 : JSL $868027
	LDA #GETUP : STA !inst
	LDA #$0030 : STA !timer
	RTS
	
GETUP:
	JSR STOREGETUPGFX
	LDA #CHECKNEXTAI : STA !inst
	LDA #$0030 : STA !timer	
	RTS

print pc

!BOMBrun = $c4C8
!BOMBgfxInst = $C706

!BOMBradius = $06

 org $86CB59

DW #BOMBinit, !BOMBrun, !BOMBgfxInst		;second pointer is running 
DB !BOMBradius, !BOMBradius				;X and Y radii
DB $60, $A0
DW $0000 
	
org $86C482
BOMBinit:
	SEP #$20
	LDA $1993
	STA $1A27,y
	REP #$20
	LDA #$0100
	STA $1ADB,y
	LDA #$00E0
	STA $1AB7,y
	LDA $0FBA
	CLC
	ADC #$000C
	STA $1A4B,y
	LDA $0FBA
	CLC
	ADC #$0010
	STA $1A93,y
	
org $86F4AB



; CB59  bomb
; 9650  bomb bounces on ground
; 966C  bomb explodes
; 967A  runs effects for bomb explosion
; CB67  chain explosion beam thingy (starting)
; CB75  chain explosion beam thingy (running)	
	