-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added PCManager which creates and manages a player character. Viewpor…
…t now fiollows the character hurray
- Loading branch information
Showing
10 changed files
with
129 additions
and
105 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "Managers.h" | ||
#include "Entities/Entities.h" | ||
#include "CoreComponents.h" | ||
#include "WorldView.h" | ||
#include "LightGrid.h" | ||
#include "segashared/CheckedMemory.h" | ||
|
||
|
||
struct PCManager_t { | ||
Manager m; | ||
WorldView *view; | ||
|
||
Entity *pc; | ||
}; | ||
|
||
ImplManagerVTable(PCManager) | ||
|
||
PCManager *createPCManager(WorldView *view) { | ||
PCManager *out = checkedCalloc(1, sizeof(PCManager)); | ||
out->view = view; | ||
out->m.vTable = CreateManagerVTable(PCManager); | ||
return out; | ||
} | ||
|
||
void _destroy(PCManager *self) { | ||
checkedFree(self); | ||
} | ||
void _onDestroy(PCManager *self, Entity *e) {} | ||
void _onUpdate(PCManager *self, Entity *e) {} | ||
|
||
void pcManagerUpdate(PCManager *self) { | ||
Viewport *vp = &self->view->viewport; | ||
PositionComponent *pc = entityGet(PositionComponent)(self->pc); | ||
short gridWidth = gridManagerWidth(self->view->managers->gridManager); | ||
short gridHeight = gridManagerHeight(self->view->managers->gridManager); | ||
short xCenter = (GRID_WIDTH / 2) * GRID_CELL_SIZE; | ||
short yCenter = (GRID_HEIGHT / 2) * GRID_CELL_SIZE; | ||
int xOffset = MIN(gridWidth, MAX(0, pc->x - xCenter)); | ||
int yOffset = MIN(gridHeight, MAX(0, pc->y - yCenter)); | ||
|
||
|
||
vp->worldPos = (Int2) { xOffset, yOffset }; | ||
} | ||
|
||
void pcManagerCreatePC(PCManager *self) { | ||
self->pc = entityCreate(self->view->entitySystem); | ||
COMPONENT_ADD(self->pc, PositionComponent, 0, 0); | ||
COMPONENT_ADD(self->pc, ImageComponent, stringIntern("assets/img/cursor.ega")); | ||
COMPONENT_ADD(self->pc, LayerComponent, LayerGrid); | ||
COMPONENT_ADD(self->pc, InViewComponent, 0); | ||
COMPONENT_ADD(self->pc, GridComponent, 11, 6); | ||
COMPONENT_ADD(self->pc, LightComponent, 0, MAX_BRIGHTNESS); | ||
|
||
entityUpdate(self->pc); | ||
} | ||
|
||
void pcManagerMove(PCManager *self, short x, short y) { | ||
gridMovementManagerMoveEntity(self->view->managers->gridMovementManager, self->pc, x, y); | ||
} | ||
|
||
void pcManagerMoveRelative(PCManager *self, short x, short y) { | ||
gridMovementManagerMoveEntityRelative(self->view->managers->gridMovementManager, self->pc, x, y); | ||
} |
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
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