因为项目需求做一个捕鱼的游戏而路线的设计就需要五花八门所以想到了一些图形矩阵写的不好不要喷我哈有需要改进的或者有更好的方法的欢迎大家一起研讨
1.简单的一些数学知识如下
2.项目粗劣效果样式
3.原理介绍
①我首先想到的是把一条线段平分成若干个点然后在这个点的坐标位置上面我们放置我们的精灵这里面我们就要用到我们高中所学知识弧度之间的关系和勾股定理的运算了哈
因为我们的五角星本身就是对称图形么所以换算起来不难这里面主要注意点问题就是我们引擎绘制点时候按照定点顺序走的所以坐标确定好了图形也就出来了
②代码片段
--[[ 设半径:r=50,圆心:x=100,y=100
则:最上一个顶点坐标为:x1=100,y1=50
左边第二个顶点坐标为:x2= x-50*sin72度,y2=y-50*cos72度
右边第二个顶点坐标为:x3=x+50*sin72度,y3=y-50*cos72度
左边第三个顶点坐标为:x4=x-50*sin36度,y4=y+50*cos36度
右边第三个顶点坐标为:x5=x+50*sin36度,y5=y+50*cos36度]]
local ch = 72 * math.pi/180
local r = 100
local fish_typeID
local s_DivideEqually = 20 --平分段数
local points = {
{200, 100}, -- point 1
{200 - r * math.sin(ch/2), 200 + r * math.cos(ch/2)}, --point4
{200 + r * math.sin(ch), 200 - r * math.cos(ch)}, -- point 3
{200 - r * math.sin(ch), 200 - r * math.cos(ch)}, -- point 2
{200 + r * math.sin(ch/2), 200 + r * math.cos(ch/2)},} --point5
local distance_1 = cc.pGetDistance(cc.p(points[1][1], points[1][2]), cc.p(points[2][1], points[2][2]))
local s_s = math.floor(distance_1) / s_DivideEqually
for i = 1, s_DivideEqually do
fish_typeID = math.random(1, 1)
local fish = self:createOneFish(fish_typeID)
local startPt = cc.p(points[1][1] - i * s_s * math.cos(ch), points[1][2] + i * s_s * math.sin(ch))
local endPt = cc.p(display.width + startPt.x, startPt.y)
fish:setFishRoute(cc.MoveTo:create(8, cc.p(endPt.x, endPt.y)), startPt, 0, 0)
end