local Actor = require(make_path("actor2")) local NPC = Actor:new() function NPC:new(x,y) local n = Actor:new(x,y) n.spriteIndex = 69 n.range = 64 + 16 n.found = false n.enemy_x_debug = 0 n.enemy_x_debug = 0 --n.dir_vec_debug_x = 0 --n.dir_vec_debug_y = 0 n.hit_x = 0 n.hit_y = 0 n.raycast_frames = 0 n.raycast_frames_to_wait = 120 return setmetatable(n, {__index=self}) end function NPC:update() local enemy_x = cirnoInstance.x + 8 local enemy_y = cirnoInstance.y + 8 self.enemy_x_debug = enemy_x self.enemy_y_debug = enemy_y --local dir_vec = get_direction_vector(self.x, self.y, enemy_x, enemy_y) --self.dir_vec_debug_x = dir_vec.dir_x --self.dir_vec_debug_y = dir_vec.dir_y self.raycast_frames += 1 if (self.raycast_frames % self.raycast_frames_to_wait == 0) then local hit_x, hit_y, hit_status = raycast(self.x, self.y, enemy_x, enemy_y, self.range, 2) --if (raycast_hit) then self.hit_x = hit_x self.hit_y = hit_y --end self.found = hit_status == true end end function NPC:draw() --circfill(self.x,self.y,self.range,18) local col = 30 spr(self.spriteIndex,self.x,self.y) print(string.format("Found: %s", tostring(self.found)),self.x,self.y-16,col) --print(string.format("dir_x: %.2f dir_y: %.2f",self.dir_vec_debug_x, self.dir_vec_debug_y),self.x,self.y-8,28) --print(string.format("hit_x: %.2f dir_y: %.2f", self.hit_x, self.hit_y),self.x, self.y,28) --line(self.x,self.y, self.enemy_x_debug, self.enemy_y_debug, 14) line(self.x,self.y, self.hit_x, self.hit_y, col) end return NPC