mirror of
https://gitlab.com/MaddoScientisto/cirnofarm.git
synced 2026-06-14 16:43:47 +00:00
Directional shooting
This commit is contained in:
parent
543e3017b2
commit
9f9624661c
4 changed files with 35 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-22 21:09:25",revision=334]]
|
||||
--[[pod_format="raw",created="2024-04-14 14:05:11",modified="2024-04-23 20:41:32",revision=380]]
|
||||
--include("/cirnofarm/src/actor.lua")
|
||||
|
||||
last_coll=0
|
||||
|
|
@ -15,12 +15,20 @@ LAYERS = {
|
|||
{index=1, name="objects", render=false, render_objects=false, spawn_objects=true}
|
||||
}
|
||||
|
||||
function create_bullet(new_x,new_y)
|
||||
function create_bullet(new_x, new_y, dir_x, dir_y)
|
||||
|
||||
-- Calculate the length of the direction vector
|
||||
local length = sqrt(dir_x^2 + dir_y^2)
|
||||
|
||||
-- Normalize the direction vector
|
||||
local normalized_dir_x = dir_x / length
|
||||
local normalized_dir_y = dir_y / length
|
||||
|
||||
add(bullets, {
|
||||
x=new_x,
|
||||
y=new_y,
|
||||
dx=2,
|
||||
dy=2,
|
||||
dx=normalized_dir_x * 2,
|
||||
dy=normalized_dir_y * 2,
|
||||
spriteIndex=80,
|
||||
destroy_sprite_index=66,
|
||||
life=100,
|
||||
|
|
@ -66,13 +74,18 @@ function cirno_init()
|
|||
cb=true, -- Collide with world bounds
|
||||
draw=function(self)
|
||||
spr(self.spriteIndex,self.x,self.y, self.hflip)
|
||||
print(string.format("x:%.2f y:%.2f mx:%.2f my:%.2f bls:%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)
|
||||
--print(string.format("dir_x:%.4f dir_y:%.4f",self.
|
||||
end,
|
||||
update=function(self)
|
||||
self.move_character(self)
|
||||
|
||||
if (btn(4)) then create_bullet(self.x,self.y) end
|
||||
-- Shoot bullet
|
||||
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)
|
||||
end
|
||||
end,
|
||||
move_character=function(self)
|
||||
|
||||
|
|
@ -122,7 +135,9 @@ function cirno_draw()
|
|||
|
||||
--debug_mouse()
|
||||
|
||||
print(string.format("%.4f %dfps",stat(1),stat(7)),2,2,5)
|
||||
print(string.format("%.4f %dfps",stat(1),stat(7)),2,16,5)
|
||||
|
||||
|
||||
end
|
||||
|
||||
function render_layer(layer)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
--[[pod_format="raw",created="2024-04-23 18:57:57",modified="2024-04-23 18:57:58",revision=1]]
|
||||
--[[pod_format="raw",created="2024-04-23 18:57:57",modified="2024-04-23 19:02:49",revision=2]]
|
||||
-- spr_from_atlas() - draw to the screen a slice of a sprite atlas
|
||||
-- param: s - sprite atlas to use (the number in the Picotron spritesheet)
|
||||
-- param: idx - the 0-based index to render from the atlas
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
--[[pod_format="raw",created="2024-04-22 19:32:54",modified="2024-04-22 20:14:13",revision=5]]
|
||||
--[[pod_format="raw",created="2024-04-22 19:32:54",modified="2024-04-23 20:21:06",revision=6]]
|
||||
M = {}
|
||||
|
||||
function M.func()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue