Author Topic: [ph3] - Visible collision boxes for custom shotsheets (by Drake)  (Read 1756 times)

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Ph3 Visible collision for custom shot sheets, by Drake

In adventure towards the full game I've got extremely bothered with the collisions for my ZUN sheet and had a talk with Drake on IRC. He has been supreme helpful with creating this piece of code so all credits goes to Drake. I think this will help a lot of people getting their shotsheets better.

Usage
Use this piece of code in either the system_default.txt and call TRenderHitboxes once (inside @initialize for example). Or use the code anywhere where you desire. Upon activation it will show visible collision boxes for all bullets, including ones that have multiple collision lines in them. They will even follow the bullet along and angle proper.

Note: Don't forget to edit the path to the image file and sprite size if you use the original paste or bcol.png if you use my sprite + adjusted code. (It is added as attachment in this post)

If you don't want a blue color you can replace it with your own desired one. ( I should've probably add grayish alpha color so you can use ObjRender_SetColor to modify the desired colors)



Original paste: https://gist.github.com/drakeirving/c4c12533fd7814d405e1

Slightly modified to add toggle key, pressing Y button (or change to desired) toggles on/off.
Code: [Select]
task TRenderHitboxes() {
let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
let colTex = "PATH TO bcol.png";
let toggleCol = false;

ObjPrim_SetTexture(obj,colTex);
ObjSpriteList2D_SetSourceRect(obj, 0, 0, 16, 16);
Obj_SetRenderPriorityI(obj, 80);
ObjRender_SetAlpha(obj,0);
ObjRender_SetPosition(obj, 0, 0, 0);
ObjRender_SetColor(obj, 255, 255, 255);
ObjRender_SetBlendType(obj, BLEND_ALPHA);

let cx = GetStgFrameWidth() / 2;
let cy = GetStgFrameHeight() / 2;

loop {
RenderHitboxes();
yield;
}

function RenderHitboxes() {

// Toggle visibility
if(GetKeyState(KEY_Y) == KEY_PULL) {
if(!toggleCol) { ObjRender_SetAlpha(obj,255); toggleCol = true; }
else if(toggleCol) { ObjRender_SetAlpha(obj,0); toggleCol = false; }
}
ObjSpriteList2D_ClearVertexCount(obj);

let shots = GetShotIdInCircleA2(cx, cy, cy*2, TARGET_ENEMY);

ascent(i in 0..length(shots)) {
let origin = [ObjMove_GetX(shots[i]), ObjMove_GetY(shots[i])];
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);
}
}
}
}



« Last Edit: March 30, 2015, 04:46:15 PM by Helepolis »