Skip to content

Instantly share code, notes, and snippets.

@drakeirving
Created October 11, 2016 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drakeirving/21d142646e9588a694bab30b5f968b31 to your computer and use it in GitHub Desktop.
Save drakeirving/21d142646e9588a694bab30b5f968b31 to your computer and use it in GitHub Desktop.
Player laser example
task TShot(){
let obj = ObjShot_Create(OBJ_STRAIGHT_LASER);
ObjShot_Regist(obj);
ObjShot_SetDamage(obj, 1);
ObjShot_SetGraphic(obj, 1);
ObjLaser_SetLength(obj, 512);
ObjLaser_SetIntersectionWidth(obj, 8);
ObjMove_SetAngle(obj, 270);
ObjShot_SetIntersectionEnable(obj,false);
let STATE_SHOT_OFF = 0;
let STATE_SHOT_ON = 1;
let STATE_SHOT_COOL = 2;
let state = STATE_SHOT_OFF;
let width = 0;
while(!Obj_IsDeleted(objPlayer)){
while(state == STATE_SHOT_OFF){
if(GetVirtualKeyState(VK_SHOT) % 2 == 1 && GetPlayerState() != STATE_DOWN){
state = STATE_SHOT_ON;
}
yield;
}
ObjShot_SetIntersectionEnable(obj,true);
ObjLaser_SetRenderWidth(obj, 16);
while(state == STATE_SHOT_ON){
ObjMove_SetPosition(obj, ObjMove_GetX(objPlayer), ObjMove_GetY(objPlayer) - 16);
// animate
if(GetVirtualKeyState(VK_SHOT) % 2 == 0 || GetPlayerState() == STATE_DOWN){
state = STATE_SHOT_COOL;
}
yield;
}
ObjShot_SetIntersectionEnable(obj,false);
width = 16;
while(state == STATE_SHOT_COOL){
ObjMove_SetPosition(obj, ObjMove_GetX(objPlayer), ObjMove_GetY(objPlayer) - 16);
// animate
if(width > 0){
width--;
}else if(width <= 0){
state = STATE_SHOT_OFF;
}
ObjLaser_SetRenderWidth(obj, width);
if(GetVirtualKeyState(VK_SHOT) % 2 == 1 && GetPlayerState() != STATE_DOWN){
state = STATE_SHOT_ON;
}
yield;
}
ObjLaser_SetRenderWidth(obj, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment