Okay... hmm... let's see...
EDIT: If you want a better bouncing effect, use the sinuate laser code at the bottom rather than the regular laser code up here.
-Use ObjLaser functions
-Can't use Obj_SetSpeed,so must use Obj_SetPosition continuously
-Need to bounce laser off of walls once
Okay, let's do this:
function ObjLaser_Create(x, y, angle, length, width, graphic, delay){
let obj = Obj_Create(OBJ_LASER);
Obj_SetPosition(obj, x, y);
//Obj_SetSpeed is skipped because it is ignored by laser objects.
Obj_SetAngle(obj, angle);
ObjLaser_SetLength(obj, length);
ObjLaser_SetWidth(obj, width);
ObjShot_SetGraphic(obj, graphic);
ObjShot_SetDelay(obj, delay);
return obj;
}
Use the above for making an object laser and put the obj id value into a variable, code snippet is thanks to Blargel :3
Don't forget to use ObjLaser_SetSource to turn off the base source thingy.
task ObjLaser_SetSpeed(id, v){
while(!Obj_BeDeleted(id)){
Obj_SetPosition(id,Obj_GetX(id)+v*cos(Obj_GetAngle(id)),Obj_GetY(id)+v*sin(Obj_GetAngle(id)));
yield;}
}
Use the obj id variable from before to use this above snippet for speed and movement.
task Obj_Bounce(id){
while(!Obj_BeDeleted(id)){
if(Obj_GetX(id)<=GetClipMinX||Obj_GetX(id)>=GetClipMaxX){Obj_SetAngle(id,180-Obj_GetAngle(id)); return;}
if(Obj_GetY(id)<=GetClipMinY||Obj_GetY(id)>=GetClipMaxY){Obj_SetAngle(id,360-Obj_GetAngle(id)); return;}
yield;}
}
This would bounce the laser(er, any object, actually) once. If you want it to bounce an infinite number of times, remove the "return;" at the end of each if statement.
I feel like a curvy laser would have a better effect of bouncing, since it leaves a tail behind it. With this one, the laser suddenly snaps around when it "bounces" and changes direction.
Also, can anyone explain to ME how the angles are found using 180 for x boundaries and 360 for y boundaries? I don't get it... ._." Bouncing snippet of code was from Awe Striker.
EDIT: yeah, I just tested, a sinuate laser looks MUCH better than this. Use the sinuate laser create code by Blargel:
function ObjSinuateLaser_Create(x, y, speed, angle, length, width, graphic, delay){
let obj = Obj_Create(OBJ_SINUATE_LASER);
Obj_SetPosition(obj, x, y);
Obj_SetSpeed(obj, speed);
Obj_SetAngle(obj, angle);
ObjSinuateLaser_SetLength(obj, length);
ObjSinuateLaser_SetWidth(obj, width);
ObjShot_SetGraphic(obj, graphic);
ObjShot_SetDelay(obj, delay);
return obj;
}
Ignore my setspeed code, and use the bounce code from before. Just remember, sinuate lasers' length is based on its speed and the length value you give it, so if you want a short one moving slow, give it a small length value. If you want a long one moving slow, a large length value. Fast and long laser would be lower length value. Fast and short laser would be a very low length value.