I was working on a train game when it hit me that i have no idea how to make a smooth curve.
So I came across bezier curves and after reading some math articles I managed to write a function myself.
Even though many other people have shared thier version here is my bezier curve, with only a single control point sadly (I will figure out the rest later).
Here is the code i have tried to make it very eazy to implement into other projects (since I was gonna use it for my train haha).
function lv(v1,v2,t) return (1-t)*v1+t*v2 end --Quadratic Bezier Curve Vector function qbcvector(v1,v2,v3,t) return lv(lv(v1,v3,t), lv(v3,v2,t),t) end --draw Quadratic Bezier Curve --x1,y1 = starting point --x2,y2 = end point --x3,y3 = 3rd manipulating point --n = "amount of pixels in curve"(just put it higher than you expect) --c = color function drawqbc(x1,y1,x2,y2,x3,y3,n,c) for i = 1,n do local t = i/n pset(qbcvector(x1,x2,x3,t),qbcvector(y1,y2,y3,t),c) end end
update: ive added cubic aswell here is the code:
function lv(v1,v2,t) return (1-t)*v1+t*v2 end --Quadratic Bezier Curve Vector function qbcvector(v1,v2,v3,t) return lv(lv(v1,v3,t), lv(v3,v2,t),t) end -- cubic bezier curve vector function cbcvector(v1,v2,v3,v4,t) return lv(qbcvector(v1,v2,v3,t), qbcvector(v1,v2,v4,t),t) end --draw cubic bezier curve function drawcbc(x1,y1,x2,y2,x3,y3,x4,y4,n,c) for i = 1,n do local t = i/n pset(cbcvector(x1,x2,x3,x4,t),cbcvector(y1,y2,y3,y4,t),c) end end
Hi, I wanted to make a pirate game and I thought it would be cool if there were actual sailing mechanics.
So I decided that I would start with that.
I'm quite happy with the results so far but would no like to add land, birds and also make a bigger ship with some cannons or something.But i think the basics are here.
left and right - sailing
Z - sail up or down
If you have any suggestions feel free to give them.
its gonna be a race
update:I added more sattelites and a cow (very productive I know).
Still thinking about the gameplay, I think I am going to make them be able to bump into eachother and collide with astroids and maybe sattelites aswell. and when they eventually get to the moon. maybe do a moonlander mini-game or something.