Log In  
Follow
AIbot
[ :: Read More :: ]

Im not sure what is wrong, but whenever I press Z it never shoots

TAB 0

function _init()
init_objects()

-- set up craft
px=63
py=100
pspr=1
vx=0
thrust=0.1
f=0.97
t_spr=17

-- set up stars
map1y=0
map2y=0
map3y=0
map1_spd=1
map2_spd=0.5
map3_spd=0.25
map_height=128
end

function _update()
--scroll map
map1y+=map1_spd
map2y+=map2_spd
map3y+=map3_spd
if map1y>127 then map1y=0 end
if map2y>127 then map2y=0 end
if map3y>127 then map3y=0 end

-- get input and change sprite
-- and thrust
pspr=1
if btn(0) then
vx-=thrust
pspr=3
end
if btn(1) then
vx+=thrust
pspr=2
end

-- apply thrust and friction
vx*=f
px+=vx

--check edges
if px<0 then
px=0
vx=0
end
if px>120 then
px=120
vx=0
end

-- change thrust sprite
t_spr+=1
if t_spr>19 then t_spr=17 end

--fire bullet
if btn(2) then
add_new_bullet(px,py,0,-3)
end

--draw bullet
for b in all(bullets) do
b:update()
end

end

function _draw()
cls()

-- draw stars
map(0,0,0,map1y,16,16)
map(16,0,0,map2y,16,16)
map(32,0,0,map3y,16,16)
map(0,0,0,map1y-map_height,16,16)
map(16,0,0,map2y-map_height,16,16)
map(32,0,0,map3y-map_height,16,16)

spr(pspr,px,py)
spr(t_spr,px,py+8)

--draw bullet
print(#bullets,1,2)
for b in all(bullets) do

b:draw()
end

end

TAB 1

--objects

function init_objects()
--declare objects
bullets={}

end

function add_new_bullet(_x,_y,_dx,_dy)
add(bullets,{
x=_x,
y=_y,
dx=_dx,
dy=_dy,
life=20,
draw=function(self)
circfill(self.x,self.y,2,11)
end,
update=function(self)
self.x=self.dx
self.y=self.dy
self.life-=1
if self.live<0 then
del(bullets,self)
end
end
})
end

P#72912 2020-02-08 16:58 ( Edited 2020-02-08 16:59)

Follow Lexaloffle:          
Generated 2024-03-28 17:32:26 | 0.062s | Q:5