Log In  
Follow
Macronaut

Hello everyone, how are you doing? I'm trying to do something here and if you guys could help me somehow it'd be nice, I'm already grateful for your attention.

The thing is I was able to achieve the "rotation around a point" for Sprites ( in this case a circle ), but the issue is that I want to have multiple objects rotating around a point while starting at different "steps" of the rotation itself ( I'm attaching a image to explain it in more detail).

The code I'm using is the following:

MAIN.LUA

--sincos math

timer=0

scr={
	w=128,
	h=128
}

opt={
	spd=.5
}

pix={
	c=12,
	x=0,
	y=0
}

cir={
	timer=0,
	a=false,
	spd=.5,
	init=3,
	o=20,
	c=12,
	x=0,
	y=0,
	r=6
}

function _init()
	cir.x=scr.w/2
	cir.y=scr.h/2
	pix.x=scr.w/2
	pix.y=scr.h/2
end

function _draw()
	cls(1)
	pset(pix.x,pix.y,pix.c)
	print("speed "..opt.spd)
	for entry in all(circles) do
		circ(entry.x,entry.y,entry.r,entry.c)
	end
end

function _update60()

	update_keys()

	for entry in all(circles) do
			entry.timer+= entry.spd/60
			entry.x= pix.x+cos(entry.timer)*entry.o
			entry.y= pix.y-sin(entry.timer)*entry.o
	end

	if(keys.down) then opt.spd-=.1
	elseif(keys.up) then opt.spd+=.1	end

	if(keys.right) then pix.x+=1 end
	if(keys.left) then pix.x-=1 end

		if(keys.activate) then
			make_circle(pix.x,pix.y,opt.spd,15,12)
		end

		if(keys.delete) then
			circles={}
		end
end

-- methods --

-- make_circle(x,y,s,o,c)

UTILS.LUA

--utils

circles={}

function make_circle(x,y,s,o,c)
	local obj={
		timer=0,
		a=false,
		spd=s,
		o=o,
		c=c,
		x=x,
		y=y,
		r=6
	}

	add(circles,obj)
end

function update_keys()
 keys={
		activate=btnp(🅾️),
		delete=btnp(❎),
		right=btn(1),
		down=btnp(3),
		left=btn(0),
		up=btnp(2),
	}
end

Thanks in advance for any help and have a good day!

3 comments