-
-
Save drakeirving/c4c12533fd7814d405e1 to your computer and use it in GitHub Desktop.
TRenderHitboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task TDrawHitboxes(){ | |
let path = dir~"eff_circle.png"; | |
let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D); | |
ObjPrim_SetTexture(obj, path); | |
ObjSpriteList2D_SetSourceRect(obj, 0, 0, 256, 256); | |
Obj_SetRenderPriorityI(obj, 51); | |
ObjRender_SetPosition(obj, 0, 0, 0); | |
ObjRender_SetColor(obj, 255, 0, 0); | |
ObjRender_SetBlendType(obj, BLEND_ALPHA); | |
let cx = GetStgFrameWidth() / 2; | |
let cy = GetStgFrameHeight() / 2; | |
let toggle = false; | |
loop{ | |
ObjSpriteList2D_ClearVertexCount(obj); | |
if(GetKeyState(KEY_H) == KEY_PUSH){ toggle = !toggle; } | |
if(toggle){ RenderHitboxes(); } | |
yield; | |
} | |
function RenderHitboxes(){ | |
let shots = GetShotIdInCircleA2(cx, cy, cy*2, TARGET_ENEMY); | |
ascent(i in 0..length(shots)){ | |
let c_angle = ObjMove_GetAngle(shots[i]); | |
let c_speed = ObjMove_GetSpeed(shots[i]); | |
let origin = [ ObjMove_GetX(shots[i]) + c_speed * cos(c_angle), | |
ObjMove_GetY(shots[i]) + c_speed * sin(c_angle) ]; | |
let t = ObjMove_GetAngle(shots[i]) - 90; // 90 offset to match with drawing angle | |
let id = ObjShot_GetImageID(shots[i]); | |
let col = GetShotDataInfoA1(id, TARGET_ENEMY, INFO_COLLISION_LIST); | |
ascent(j in 0..length(col)) { | |
let pos = origin; | |
let r = col[j][0]; | |
if(col[j][1] != 0 || col[j][2] != 0){ | |
pos = pos + [col[j][1]*cos(t) - col[j][2]*sin(t), col[j][1]*sin(t) + col[j][2]*cos(t)]; | |
} | |
ObjSpriteList2D_SetDestRect(obj, pos[0]-r, pos[1]-r, pos[0]+r, pos[1]+r); | |
ObjSpriteList2D_AddVertex(obj); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment