@dave1707 thanks! I’ll post an image of your rocket in use in the game I’m making. Here are the changes I made to your code so that it suits the style of my game, I’m very happy with how it’s turned out.
--# Main
-- Rocket V3
displayMode(FULLSCREEN)
function setup()
mx,my=0,0
x,y=WIDTH/2,0
vx,vy=0,1
speed=4
gas = {}
--backingMode(RETAINED)
end
function draw()
aim = vec2(vx,vy)
angle = angleMachine(aim)
background(0)
fumes(x,y)
fill(255)
pushMatrix()
translate(x,y)
rotate(-angle)
rect(-5,-15,10,30)
popMatrix()
if px~=nil then
fill(255,0,0)
ellipse(px,py,10)
dx=px-x
dy=py-y
if not hit then
move()
if math.abs(dx)<3 and math.abs(dy)<3 then
hit=true
end
end
end
x=x+vx*speed
y=y+vy*speed
end
function move()
v1=vec2(dx,dy)
v1=v1:normalize()
if vx<v1.x then
vx=vx+speed*.005
else
vx=vx-speed*.005
end
if vy<v1.y then
vy=vy+speed*.005
else
vy=vy-speed*.005
end
end
function touched(t)
if t.state==BEGAN then
px=t.x
py=t.y
hit=false
end
end
function angleMachine(aim)
angle = math.deg(math.atan(aim.x/aim.y))
if aim.x > 0 and aim.y > 0 then
angle = angle
elseif aim.x > 0 and aim.y < 0 then
angle = 180 + angle
elseif aim.x < 0 and aim.y < 0 then
angle = 180 + angle
elseif aim.x < 0 and aim.y > 0 then
angle = 360 + angle
end
return angle
end
function fumes(xx,yy)
randomNum = math.random(1,10)
if randomNum > 5 then
table.insert(gas,Smoke(xx,yy))
end
for a,b in pairs(gas) do
b:draw()
if b.status == "delete" then
table.remove(gas)
end
end
end
--# Smoke
Smoke = class()
function Smoke:init(xx,yy)
-- you can accept and set parameters here
self.startPos = vec2(xx,yy)
self.radius = math.random(1,30)
self.alpha = 255
self.angle = angle
self.timer = 0
self.status = "alive"
pushMatrix()
translate(x,y)
rotate(-angle)
fill(255,0,228,255)
ellipse(0,-15,self.radius)
popMatrix()
end
function Smoke:draw()
self.r = math.random(1,255)
self.g = math.random(1,255)
self.b = math.random(1,255)
pushMatrix()
translate(self.startPos.x,self.startPos.y)
rotate(-self.angle)
self.alpha = self.alpha*0.97
fill(self.r, self.g,self.b, self.alpha)
ellipse(0,-15,self.radius)
popMatrix()
self.timer = self.timer + 1
if self.timer > 800 then
self.status = "delete"
end
end