Skip to content

Commit

Permalink
Add IDE support for solid collision
Browse files Browse the repository at this point in the history
  • Loading branch information
um3k committed Jan 31, 2022
1 parent 4ca9670 commit 28260b5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion appData/src/gb/include/gbs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef struct actor_t

// Collisions
collision_group_e collision_group;
uint8_t solid : 4;
uint8_t solid : 4; // direction mask support

// Linked list
struct actor_t *next;
Expand Down
8 changes: 4 additions & 4 deletions appData/src/gb/src/states/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void platform_update() BANKED {
new_pos.x = PLAYER.pos.x;
new_pos.y = new_y + 2;
hit_actor = actor_overlapping_bb(&PLAYER.bounds, &new_pos, &PLAYER, FALSE);
if (hit_actor != NULL && hit_actor->collision_group) {
if (hit_actor != NULL && hit_actor->solid) {
new_y = (((hit_actor->pos.y >> 4) + hit_actor->bounds.top - PLAYER.bounds.bottom) << 4) - 1;
grounded = TRUE;
pl_vel_y = 0;
Expand All @@ -242,7 +242,7 @@ void platform_update() BANKED {
new_pos.x = PLAYER.pos.x;
new_pos.y = new_y;
hit_actor = actor_overlapping_bb(&PLAYER.bounds, &new_pos, &PLAYER, FALSE);
if (hit_actor != NULL && hit_actor->collision_group) {
if (hit_actor != NULL && hit_actor->solid) {
new_y = (((hit_actor->pos.y >> 4) + hit_actor->bounds.bottom - PLAYER.bounds.top + 1) << 4);
pl_vel_y = 0;
}
Expand All @@ -267,7 +267,7 @@ void platform_update() BANKED {
new_pos.x = new_x;
new_pos.y = PLAYER.pos.y;
hit_actor = actor_overlapping_bb(&PLAYER.bounds, &new_pos, &PLAYER, FALSE);
if (hit_actor != NULL && hit_actor != standing_on && hit_actor->collision_group) {
if (hit_actor != NULL && hit_actor != standing_on && hit_actor->solid) {
new_x = (((hit_actor->pos.x >> 4) + hit_actor->bounds.left - PLAYER.bounds.right) << 4) - 1;
pl_vel_x = 0;
}
Expand All @@ -286,7 +286,7 @@ void platform_update() BANKED {
new_pos.x = new_x;
new_pos.y = PLAYER.pos.y;
hit_actor = actor_overlapping_bb(&PLAYER.bounds, &new_pos, &PLAYER, FALSE);
if (hit_actor != NULL && hit_actor != standing_on && hit_actor->collision_group) {
if (hit_actor != NULL && hit_actor != standing_on && hit_actor->solid) {
new_x = (((hit_actor->pos.x >> 4) + hit_actor->bounds.right - PLAYER.bounds.left + 1) << 4);
pl_vel_x = 0;
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/editors/ActorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ export const ActorEditor: FC<ActorEditorProps> = ({
/>
</FormField>
</FormRow>
<FormRow>
<CheckboxField
name="actorSolid"
label={l10n("FIELD_ACTOR_SOLID")}
checked={actor.solid}
onChange={onChangeFieldInput("solid")}
/>
</FormRow>
</>
)}
</FormContainer>
Expand Down
1 change: 1 addition & 0 deletions src/lib/compiler/compileData2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export const compileSceneActors = (
script_update: maybeScriptFarPtr(events.actorsMovement[actorIndex]),
script: maybeScriptFarPtr(events.actors[actorIndex]),
reserve_tiles: scene.actorsExclusiveLookup[actor.id] ?? 0,
solid: actor.solid ? "TRUE" : "FALSE",
};
})
),
Expand Down
1 change: 1 addition & 0 deletions src/store/features/entities/entitiesState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ const addActor: CaseReducer<
id: action.payload.actorId,
x: clamp(action.payload.x, 0, scene.width - 2),
y: clamp(action.payload.y, 0, scene.height - 1),
solid: false,
};

// Add to scene
Expand Down
1 change: 1 addition & 0 deletions src/store/features/entities/entitiesTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type Actor = {
hit1Script: string[];
hit2Script: string[];
hit3Script: string[];
solid: boolean;
};

export type ActorDenormalized = Omit<
Expand Down

0 comments on commit 28260b5

Please sign in to comment.