snippet of code

Posted by Taizen Chisou on April 29, 2012, 8:54 p.m.

needed to post this somewhere before I forgot

inc = random(360);

for(a=0;a<360;a+=10)
{
aa=instance_create(x,y,ball);
aa.speed = 3*(1 + (sqrt(2)-1))*abs(sin(2*degtorad(a+inc)));
aa.direction = a+inc;
}

it's supposed to create a square of projectiles

um

does someone mind checking it to see if it works :V

It might be a little bit before I can use a computer again :(

Comments

firestormx 12 years, 7 months ago

Why will it be a little bit before you get to the computer?

Also, without even reading the code (just "360", "sin", and "degtorad" popped out at me), I'm going to guess it makes a circle, and not a square.

Also, I glanced at it again and saw "aa.direction = a+inc", and that's definitely not something you'd do to a square.

Do you want me to write you something for creating a square?

Taizen Chisou 12 years, 7 months ago

My father's doing an excellent job sharing the computer :D

School computers reserved for testing :D

I need to work for a couple more weeks before I can afford that laptop which is like a thousand bucks :D

The square comes from the difference in speed values…

firestormx 12 years, 7 months ago

Do you want like a perfect square? I didn't even look that the speed was being set. =/

That makes a lot more sense. My trig is faaaar too rusty to tell you if that's correct or not. It doesn't look you can change the width/height of the square though. It'll fire 360 projectiles.

Edit: I wanted to see how I would do it in a simple grid-based manner, and this is what I came up with in a few minutes (Sorry about the code tag not indenting. T_T):

width = 100;
height = 100;

//Loop through the height of the box
for (i=0; i<height; i+=1)
{
	//Is this the very top or very bottom of the box?
	//"columns" represents the width
	if (i == 0 || i == (width-1)) //Yes
	{columns = width;}
	else //No
	{columns = 2;}
	
	//Loop through the columns of the square
	for (j=0; j<columns; j+=1)
	{
		//Modify the x/y for alignment
		aa = instance_create(x, y, ball);
		
		//Is this the last bullet on the far right of the square?
		//Force it to the far right, in case it's not the first/last row
		if (x == (columns-1))
		{aa.x += (width-1);}
		else
		{aa.x += j;}
	}
}

Taizen Chisou 12 years, 7 months ago

It's for Lunacy Star 2.

The idea would be that there are bursts of squares that you move through. They'd be at different angles and stuff.

They expand out from the center, that's it, really.

firestormx 12 years, 7 months ago

Whoops, that snippet of code doesn't take into account that it's all generated at once, and isn't actually grid based (I'm used to output in html. =/)

Also, it doesn't actually shoot squares at angles. The square can move in different directions, but it wouldn't form a square in all directions.

Never mind what I have written.

Alert Games 12 years, 7 months ago

i love the number of people who tested this out for you to see if this works. Including me. :(

poultry 12 years, 7 months ago

Howdy! This message is to prime the new Recent Activity List system. Please ignore!

Thanks,

Not-a-bot.