Sunday, September 12, 2010

Why COF is so great

This is most of the instructions for the game drawing a cyan enemy, as it stands right now:


dir=direction

x+=lengthdir_x(1,dir+180)
y+=lengthdir_y(1,dir+180)


temp=lengthdir_x(2.4,dir-22)
temp2=lengthdir_y(2.4,dir-22)
temp3=lengthdir_x(2.4,dir+22)
temp4=lengthdir_y(2.4,dir+22)



tx[0]=x+temp*6
ty[0]=y+temp2*6
tx[1]=x+temp3*6
ty[1]=y+temp4*6
tx[2]=x+lengthdir_x(10.8,dir-90)+lengthdir_x(6.48,dir)
ty[2]=y+lengthdir_y(10.8,dir-90)+lengthdir_y(6.48,dir)
tx[3]=x+lengthdir_x(10.8,dir+90)+lengthdir_x(6.48,dir)
ty[3]=y+lengthdir_y(10.8,dir+90)+lengthdir_y(6.48,dir)
tx[4]=x-temp3*5
ty[4]=y-temp4*5
tx[5]=x-temp*5
ty[5]=y-temp2*5

tx[6]=x+temp*10
ty[6]=y+temp2*10
tx[7]=tx[6]+lengthdir_x(4.8,dir+90)
ty[7]=ty[6]+lengthdir_y(4.8,dir+90)
tx[8]=x+temp3*10
ty[8]=y+temp4*10
tx[9]=tx[8]+lengthdir_x(4.8,dir-90)
ty[9]=ty[8]+lengthdir_y(4.8,dir-90)

tx[10]=x+lengthdir_x(13.44,dir+133)
ty[10]=y+lengthdir_y(13.44,dir+133)
tx[11]=x+lengthdir_x(13.44,dir-133)
ty[11]=y+lengthdir_y(13.44,dir-133)
tx[12]=tx[10]+lengthdir_x(12.24,dir)
ty[12]=ty[10]+lengthdir_y(12.24,dir)
tx[13]=tx[10]+lengthdir_x(4.8,dir-90)
ty[13]=ty[10]+lengthdir_y(4.8,dir-90)
tx[14]=tx[11]+lengthdir_x(12.24,dir)
ty[14]=ty[11]+lengthdir_y(12.24,dir)
tx[15]=tx[11]+lengthdir_x(4.8,dir+90)
ty[15]=ty[11]+lengthdir_y(4.8,dir+90)

draw_line(tx[6],ty[6],tx[7],ty[7])
draw_line(tx[8],ty[8],tx[9],ty[9])
draw_line(tx[0],ty[0],tx[1],ty[1])
draw_line(tx[0],ty[0],tx[6],ty[6])
draw_line(tx[1],ty[1],tx[8],ty[8])
draw_line(tx[0],ty[0],tx[2],ty[2])
draw_line(tx[1],ty[1],tx[3],ty[3])
draw_line(tx[2],ty[2],tx[4],ty[4])
draw_line(tx[3],ty[3],tx[5],ty[5])
draw_line(tx[4],ty[4],tx[5],ty[5])

draw_line(tx[10],ty[10],tx[12],ty[12])
draw_line(tx[10],ty[10],tx[13],ty[13])
draw_line(tx[11],ty[11],tx[14],ty[14])
draw_line(tx[11],ty[11],tx[15],ty[15])

draw_set_alpha(alph/1.2)
draw_triangle(tx[0],ty[0],tx[1],ty[1],tx[2],ty[2],0)
draw_triangle(tx[3],ty[3],tx[1],ty[1],tx[2],ty[2],0)
draw_triangle(tx[2],ty[2],tx[3],ty[3],tx[4],ty[4],0)
draw_triangle(tx[5],ty[5],tx[3],ty[3],tx[4],ty[4],0)
draw_triangle(tx[10],ty[10],tx[12],ty[12],tx[13],ty[13],0)
draw_triangle(tx[11],ty[11],tx[14],ty[14],tx[15],ty[15],0)

x-=lengthdir_x(1,dir+180)
y-=lengthdir_y(1,dir+180)




And that was a pain because I had to figure out all the angles and everything. Now I have a much nicer, general algorithm that I'm not going to post for various reasons, and I just have to tell an object what model file to use and it will draw it.
For some of the enemies, I used values calculated based on other values in order to determine coordinates of vertices, which is hard to translate directly into a COF-readable file. My options are to make a piece of code for each enemy that outputs coordinates, or to just remake the models using COF. I've chosen to do the latter (because dang it's fast and effective), but I'll keep the crazy instructions I made for each one (like you see above), for posterity's sake.