offset NPC350
#define
shootvar = [EBP-84]
localvar2 = [EBP-88]
localvar3 = [EBP-8C]
npc.groundtimer = [ecx+18]
npc.groundvel = [ecx+1C]
L_framerect_distance = 0
U_framerect_distance = 0
sprite_left = 20
sprite_right = 20
sprite_up = 10
sprite_down = 10
time_between_shots = 30
jump_vel = 800
jump_gravity = 50
jump_distance = 200
max_fall_speed = 500
bullet_speed = 300
walk_speed = 500
dbl_walk_speed = A00
walk_timer = 100
#enddefine
push ebp ;This starts the code
mov ebp, esp
sub esp, 70
mov dword [EBP-70],0
mov dword [EBP-7C],0
mov dword [EBP-78],0
mov dword [EBP-74],0
mov dword [EBP-70],0
mov dword [EBP-6C],0
mov dword [EBP-68],0
mov dword [EBP-64],0
mov dword [EBP-60],0
mov dword [EBP-5C],0
mov dword [EBP-58],0
mov dword [EBP-54],0
mov dword [EBP-50],0
mov dword [EBP-4C],0
mov dword [EBP-48],0
mov dword [EBP-44],0
mov dword [EBP-40],0
mov dword [EBP-3C],0
mov dword [EBP-38],0
mov dword [EBP-34],0
mov dword [EBP-30],0
mov dword [EBP-2C],0
mov dword [EBP-28],0
mov dword [EBP-24],0
mov dword [EBP-20],0
mov dword [EBP-1C],0
mov dword [EBP-18],0
mov dword [EBP-14],0
mov dword [EBP-10],0
mov dword [EBP-C],0
mov dword [EBP-8],0
mov dword [EBP-4],0
mov eax, npc.scriptstate
jmp [eax*4+:StateTable]
:stateldle
add npc.Y, 5FF
mov npc.framenum, 0
cmp npc.directive, 1
je :render
mov npc.directive, 1
add npc.X -1000
jmp :StateFight
:StateFight
add npc.Y 5FF ;gravity
push 5FF ;check to jump
push 0
call Random
add esp, 8
setpointer
cmp eax, 20
je :StateFightJump
push 0
push 2
call random
add esp, 8
setpointer
cmp eax 1
;jl :StateFightShoot
je :StateFightWalk
;jg :StateFightRun
;----------------------------------------
:StateFightJump ;jumping vels here and scriptstate to fight air.
mov npc.moveY -jump_vel
mov npc.scriptstate, 9
mov eax, PlayerXpos ;check direction to jump
cmp npc.x, eax
jl :player_is_left_jump
mov npc.direction, 0
mov npc.moveX -jump_distance
jmp :dir_jump_check_end
:player_is_left_jump
mov npc.direction, 2
mov npc.moveX jump_distance
:dir_jump_check_end
jmp :add_vels
;----------------------------------------
;moveX is never altered here in the chunk of code below, except when you hit a wall.
;moveX is handled in the jump prep (above)
:StateFightAir
mov npc.scriptstate, 9
mov edx, npc.collision ;see if we are still in the air
and edx, 8
jne :hit_floor
mov edx, npc.collision ;did we hit a wall?
and edx, 1
jne :hit_wall_air
mov edx, npc.collision ;did we hit a wall?
and edx, 4
jne :hit_wall_air
jmp :in_air_fight
:hit_wall_air
mov npc.moveX, 0
jmp :end_fight_air
:in_air_fight
:down_check_end
mov eax, PlayerXpos
cmp npc.x, eax
jl :player_is_left
mov npc.direction, 0
jmp :dir_air_end
:player_is_left
mov npc.direction, 2
:dir_air_end
mov eax, npc.direction
mov shootvar, eax
inc npc.directive
cmp npc.directive, time_between_shots
jl :end_fight_air
mov npc.directive, 0
mov eax npc.direction
mov shootvar, eax
jmp :create_bullet
:end_fight_air
add npc.moveY jump_gravity
cmp npc.moveY, max_fall_speed
jl :fall_speed_ok
mov npc.moveY, max_fall_speed
:fall_speed_ok
mov eax, npc.moveY
add npc.Y, eax
mov eax, npc.moveX
add npc.X, eax
jmp :render
:hit_floor ;reset everything and set scriptstate to state fight
xor eax, eax
mov npc.directive, eax
mov npc.framenum, 1
mov npc.moveY, eax
mov npc.moveX, eax
mov npc.scriptstate, 3
jmp :render
;----------------------------------------
:StateFightShoot
;----------------------------------------
:StateFightWalk
inc npc.frametimer
cmp npc.frametimer, walk_timer
jl :Walk_end
mov npc.frametimer,1
cmp npc.framenum,2
je :1_to_0
jg :2_to_0
cmp npc.scriptstate, 5
je :0_to_1
jne :0_t0_2
:1_to_0
mov npc.framenum, 1
mov npc.scripttimer,3
jmp :Walk_end
:2_to_0
mov npc.framenum, 1
mov npc.scripttimer,2
jmp :Walk_end
:0_to_1
mov npc.framenum, 2
jmp :Walk_end
:0_t0_2
mov npc.framenum, 3
jmp :Walk_end
:Walk_end
mov edx, npc.collision ;check collision stuff
and edx, 1
jne :hit_wall_walk_L
mov edx, npc.collision
and edx, 4
jne :hit_wall_walk_R
jmp :end_hit_wall_walk
:hit_wall_walk_R
mov npc.direction, 0
mov npc.moveX, 0
jmp :end_hit_wall_walk
:hit_wall_walk_L
mov npc.direction, 2
mov npc.moveX, 0
:end_hit_wall_walk
add npc.X walk_speed
cmp npc.direction, 2
je :add_vels
add npc.X -dbl_walk_speed
jmp :add_vels
;----------------------------------------
:StateFightRun ;???
jmp :render
;----------------------------------------
:create_bullet
push 0
push 0
mov eax, shootvar ;direction shot
push eax
;-------
cmp eax, 0
je :left_fire
cmp eax, 1
je :up_fire
cmp eax, 2
je :right_fire
cmp eax, 3
je :down_fire
:left_fire
add eax, -bullet_speed
jmp :end_L_R
:up_fire
add edx, -bullet_speed
jmp :end_L_R
:right_fire
add eax, bullet_speed
jmp :end_L_R
:down_fire
add edx, bullet_speed
:end_L_R
;-------
push edx ;Y vel
push eax ;X vel
mov eax, npc.Y
mov edx, npc.X
push eax
push edx
push 7B ;bullet
call 46efd0
add esp,20
cmp npc.scriptstate, 8
je :end_fight_air
jmp :render
;----------------------------------------
:StateDie
mov npc.framenum, 1
inc npc.objecttimer
cmp npc.objecttimer, 40
jne :exp_done
mov eax, npc.X
mov edx, npc.Y
push 1
push edx
push eax
call 0040EA70
add esp,0C
push 1
push 2C
call playsound
add esp, 8
setpointer
:exp_done
jmp :add_vels
;----------------------------------------
:add_vels
mov eax, npc.moveX
mov edx, npc.moveY
add npc.X eax
add npc.Y edx
:render
xor eax, eax
mov eax,npc.framenum
imul al, al, sprite_left
mov npc.DisplayL,eax
add eax, sprite_right
mov npc.displayR,eax
mov eax, U_framerect_distance
cmp npc.direction, 2
jne :render_left
add eax sprite_up
:render_left
mov npc.displayU,eax
add eax,sprite_down
mov npc.displayD,eax
:end_of_code
mov esp, ebp
pop ebp
retn
:StateTable
print :StateIdle ;<ANP0000
print :StateFight ;<ANP0001
print :StateShoot ;<ANP0002