Skip to content

Commit

Permalink
canvas: projected collision now use a rect instead of a pos
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
cosmo-ray committed Sep 20, 2024
1 parent d121ab2 commit d567059
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions core/widget/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,23 @@ Entity *ywCanvasNewCollisionsArrayWithRectangle_(Entity *wid, Entity *objRect,


Entity *ywCanvasNewProjectedCollisionsArrayExt(Entity *wid, Entity *obj,
Entity *add_x_y,
Entity *projection_rect,
Entity *colisionFunc,
Entity *colisionFuncArg)
{
if (unlikely(!obj)) {
return NULL;
}

Entity *objRect = ywRectCreatePosSize(ywCanvasObjPos(obj),
ywCanvasObjSize(wid, obj),
NULL, NULL);
ywPosAdd(objRect, add_x_y);
Entity *osize = ywCanvasObjSize(wid, obj);
int w = yeGetIntAt(projection_rect, 2) ? yeGetIntAt(projection_rect, 2) :
ywSizeW(osize);
int h = yeGetIntAt(projection_rect, 3) ? yeGetIntAt(projection_rect, 3) :
ywSizeH(osize);
Entity *opos = ywCanvasObjPos(obj);
Entity *objRect = ywRectCreateInts(ywPosX(opos), ywPosY(opos),
w, h, NULL, NULL);
ywPosAdd(objRect, projection_rect);
Entity *ret =
ywCanvasNewCollisionsArrayWithRectangle_(wid, objRect, obj,
colisionFunc,
Expand Down
4 changes: 3 additions & 1 deletion modules/amap/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ function amap_action(wid, events)
if (yeGetIntAt(pc_canel, PC_PUNCH_LIFE) <= 0) {
ywCanvasRemoveObj(wid, yeGet(pc_canel, PC_PUNCH_OBJ))
yeSetIntAt(pc_canel, PC_PUNCH_LIFE, 0)
yeDestroy(cols)
return true
}

Expand Down Expand Up @@ -741,7 +742,8 @@ function amap_action(wid, events)
}

let pc_canvas_obj = yGenericCurCanvas(pc_handler)
let cols = ywCanvasNewCollisionsArray(wid, pc_canvas_obj)
let projection = wid.get("pc-collision-projection")
let cols = ywCanvasNewProjectedCollisionsArrayExt(wid, pc_canvas_obj, projection)
let direct_ret = false
//yePrint(cols)
if (cols) {
Expand Down

0 comments on commit d567059

Please sign in to comment.