Added crosshair

This commit is contained in:
MaddoScientisto 2024-04-23 23:04:26 +02:00
commit 42677301c9

View file

@ -1,4 +1,4 @@
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-23 20:41:32",revision=380]] --[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-23 21:04:14",revision=394]]
--include("/cirnofarm/src/actor.lua") --include("/cirnofarm/src/actor.lua")
last_coll=0 last_coll=0
@ -55,6 +55,19 @@ function create_bullet(new_x, new_y, dir_x, dir_y)
}) })
end end
function draw_crosshair(self)
local radius = 20 -- Adjust the radius of the crosshair as needed
local angle = atan2(self.move_x, self.move_y)
local crosshair_x = self.x + 8 + radius * cos(angle)
local crosshair_y = self.y + 8 + radius * sin(angle)
-- Draw the crosshair
spr(self.crosshair_index, crosshair_x, crosshair_y)
--circfill(crosshair_x, crosshair_y, 2, 7) -- Adjust the size and color as needed
end
function cirno_init() function cirno_init()
bullets={} bullets={}
@ -67,6 +80,7 @@ function cirno_init()
speed=0.05, speed=0.05,
hflip=false, hflip=false,
spriteIndex=65, spriteIndex=65,
crosshair_index=82,
move_x=0, move_x=0,
move_y=0, move_y=0,
noclip=false, noclip=false,
@ -76,6 +90,8 @@ function cirno_init()
spr(self.spriteIndex,self.x,self.y, self.hflip) spr(self.spriteIndex,self.x,self.y, self.hflip)
print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f blts:%s",self.x,self.y, print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f blts:%s",self.x,self.y,
self.move_x,self.move_y,count(bullets)),0,0,1) self.move_x,self.move_y,count(bullets)),0,0,1)
draw_crosshair(self)
--print(string.format("dir_x:%.4f dir_y:%.4f",self. --print(string.format("dir_x:%.4f dir_y:%.4f",self.
end, end,
update=function(self) update=function(self)
@ -84,7 +100,7 @@ function cirno_init()
-- Shoot bullet -- Shoot bullet
if (btn(4)) then if (btn(4)) then
--create_bullet(self.x,self.y,self.move_x,self.move_Y) --create_bullet(self.x,self.y,self.move_x,self.move_Y)
create_bullet(self.x,self.y,self.move_x,self.move_y) create_bullet(self.x+8,self.y+8,self.move_x,self.move_y)
end end
end, end,
move_character=function(self) move_character=function(self)