LUMBERJÄCKES

main
Jonathan Hager 3 years ago
parent 2a9feb24e2
commit 060761dbb8
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -5,41 +5,45 @@
#include "../Sprite/sprite.h"
#include "../MapObject/building.h"
#include "../definitions.h"
#include "../Textures/textureatlas.h"
#include "entityacts.h"
#include "../game.h"
Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas){
Entity * EntityInit(Game *game, int profession, int x, int y){
Entity *new = malloc(sizeof(Entity));
new->angle = 0;
new->sprite = sprite;
new->destX = 0;
new->destY = 0;
new->hasDestination = 0;
new->selected = 0;
new->next = 0;
new->prev = 0;
new->task = TaskInit(profession);
new->profession = profession;
int textureId = 0;
Animation ***animations = 0;
switch(profession){
case PR_BUILDER:
new->act = BuilderAct;
textureId = TE_WORKER;
animations = game->textures->animations[AN_WORKER];
break;
case PR_LUMBERJACK:
new->act = LumberjackAct;
textureId = TE_LUMBERJACK;
animations = game->textures->animations[AN_LUMBERJACK];
break;
default:
printf("WARNING: ENTITYINIT MIT FALSCHER ID AUFGERUFEN!\n");
}
Sprite *newSprite = SpriteCreate(game->textures, textureId, x, y);
SpriteListInsert(game->sprites, newSprite);
new->sprite = newSprite;
Animation ***animations = 0;
new->animationHandler = AnimationHandlerInit(animations, &new->sprite->texture);
if(profession == PR_BUILDER){
animations = atlas->animations[AN_WORKER];
}
else{
printf("\n\n\n\n\n\n\n\nEntityCreate mit falscher ID (%d) aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n", profession);
}
new->angle = 0;
new->destX = 0;
new->destY = 0;
new->hasDestination = 0;
new->selected = 0;
new->next = 0;
new->prev = 0;
new->animationHandler = AnimationHandlerInit(animations, &new->sprite->texture);
new->task = TaskInit(profession);
new->profession = profession;
return new;
}

@ -30,7 +30,7 @@ typedef struct EntityList{
Entity *tail;
} EntityList;
Entity * EntityInit(Sprite *sprite, int profession, TextureAtlas *atlas);
Entity * EntityInit(Game *game, int profession, int x, int y);
EntityList * EntityListInit();
void EntityMoveToDestination(Entity *entity);

@ -1,6 +1,7 @@
#include "entityacts.h"
#include "../Textures/animationHandler.h"
#include "../MapObject/building.h"
#include "../MapObject/staticobjects.h"
void BuilderAct(Game *game, Entity *entity){
Building *target = (Building *) entity->task->target;
@ -50,3 +51,56 @@ void BuilderAct(Game *game, Entity *entity){
}
}
}
void LumberjackAct(Game *game, Entity *entity){
StaticObject *target = (StaticObject *) entity->task->target;
// Hat noch keinen Baum
if(entity->task->target == 0){
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
if(entity->hasDestination == 1){
entity->hasDestination = 0;
}
// Prüft, ob einen Baum existiert
StaticObject *current = game->objects->head;
while(current != 0){
if(current->id == SO_PINETREE){
entity->hasDestination = 1;
entity->destX = current->sprite->x;
entity->destY = current->sprite->y;
entity->task->target = current;
entity->task->progress = 0;
break;
}
current = current->next;
}
}
else if(entity->hasDestination == 1){
EntityMoveToDestination(entity);
}
else{
printf("%f\n", entity->task->progress);
// Is beim target angekommen
if(entity->task->progress == 0){
// Angekommen, noch nicht mit arbeiten begonnen
AnimationChangeType(entity->animationHandler, AN_ENTITY_ARBEITEN);
entity->task->progress = 0.01;
}
else if(entity->task->progress >= 1.0){
// Fertig mit arbeiten, Animation zu Idle zurück
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
printf("Fertig\n");
StaticObjectListRemove(game, entity->task->target);
entity->task->target = 0;
entity->task->progress = 0;
}
else{
entity->task->progress += 0.2 * GetFrameTime();
}
}
}

@ -4,5 +4,6 @@
#include "../game.h"
void BuilderAct(Game *game, Entity *entity);
void LumberjackAct(Game *game, Entity *entity);
#endif

@ -72,12 +72,12 @@ void mouseInput(Game *game){
//Baum
StaticObject *tree = StaticObjectInit(game, SO_PINETREE, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y);
StaticObjectListInsert(game->objects, tree);
SpriteListPrintForward(game->sprites);
}
if(IsKeyPressed(KEY_H)){
//Holzkacker
Entity *lumberjack = EntityInit(game, PR_LUMBERJACK, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y);
EntityListInsert(game->entities, lumberjack);
}
// resetting last selected Tile to grass texture

@ -51,21 +51,22 @@ void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data){
}
}
void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove){
void StaticObjectListRemove(Game *game, StaticObject *remove){
if(remove == 0){
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
return;
}
else if(objects->head == remove && objects->tail == remove){
objects->head = 0;
objects->tail = 0;
else if(game->objects->head == remove && game->objects->tail == remove){
game->objects->head = 0;
game->objects->tail = 0;
}
else if(objects->head == remove){
else if(game->objects->head == remove){
remove->next->prev = 0;
objects->head = remove->next;
game->objects->head = remove->next;
}
else if(objects->tail == remove){
else if(game->objects->tail == remove){
remove->prev->next = 0;
objects->tail = remove->prev;
game->objects->tail = remove->prev;
}
else{
remove->prev->next = remove->next;
@ -74,4 +75,8 @@ void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove){
remove->next = 0;
remove->prev = 0;
SpriteListRemove(game->sprites, remove->sprite);
free(remove->sprite);
free(remove);
}

@ -21,6 +21,6 @@ StaticObjectList * StaticObjectListInit();
void StaticObjectListPrintForward(StaticObjectList *objects);
void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data);
void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove);
void StaticObjectListRemove(Game *game, StaticObject *remove);
#endif

@ -37,6 +37,11 @@ void TextureAtlasLoadTextures(Texture2D **textures){
case TE_PINETREE:
textures[TE_PINETREE] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D));
LoadMapObjectTextures(textures[TE_PINETREE], "pinetree");
break;
case TE_LUMBERJACK:
textures[TE_LUMBERJACK] = malloc(TE_ENTITY_LENGTH * sizeof(Texture2D));
LoadEntityTextures(textures[TE_LUMBERJACK], "lumberjack");
break;
default:
printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n");
}
@ -158,6 +163,10 @@ void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures){
animations[AN_WORKER] = malloc(AN_ENTITY_AMOUNT * sizeof(Animation *));
LoadEntityAnimations(animations[AN_WORKER], textures[TE_WORKER], AN_WORKER);
break;
case AN_LUMBERJACK:
animations[AN_LUMBERJACK] = malloc(AN_ENTITY_AMOUNT * sizeof(Animation *));
LoadEntityAnimations(animations[AN_LUMBERJACK], textures[TE_LUMBERJACK], AN_LUMBERJACK);
break;
default:
printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED ANIMATION!!\n");
}

@ -42,11 +42,9 @@ void OnSelectedSpawnBuilding(Game *game, Selectable *selectable){
}
void OnSelectedSpawnWorker(Game *game, Selectable *selectable){
if(IsMouseButtonDown(MOUSE_BUTTON_LEFT) && game->mouseOnUI == 0){
Sprite *newSprite = SpriteCreate(game->textures, TE_WORKER, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
Entity *entity = EntityInit(newSprite, PR_BUILDER, game->textures);
EntityListInsert(game->entities, entity);
SpriteListInsert(game->sprites, newSprite);
Entity *lumberjack = EntityInit(game, PR_BUILDER, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
EntityListInsert(game->entities, lumberjack);
selectable->state = SELECTABLE_STATE_DEFAULT;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1019 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1019 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

@ -0,0 +1,20 @@
#!/bin/bash
convertAnimation(){
convert $1 +repage -crop 72x72 $1
}
mkdir assets/entities/$2
convert $1 +repage -crop 360x360 assets/entities/$2/tmp.png
mv $1 assets/entities/$2/$2.png
cd assets/entities/$2
mv tmp-0.png walk.png
mv tmp-1.png arbeiten.png
mv tmp-2.png die.png
convertAnimation walk.png
convertAnimation arbeiten.png
convertAnimation die.png

@ -17,15 +17,17 @@
#define TE_BUILDING 2
#define TE_BAUSTELLE 3
#define TE_PINETREE 4
#define TE_LUMBERJACK 5
#define TE_AMOUNT 5
#define TE_AMOUNT 6
#define TE_ENTITY_LENGTH 104
#define TE_MAPOBJECT_LENGTH 1
// Definitions for animations
#define AN_WORKER 0
#define AN_AMOUNT 1
#define AN_LUMBERJACK 1
#define AN_AMOUNT 2
#define AN_ENTITY_AMOUNT 3
#define AN_ENTITY_IDLE 0
@ -40,6 +42,7 @@
// Defintions for professions
#define PR_BUILDER 0
#define PR_LUMBERJACK 1
// Definitions for Screen / View / Ui Stuff

Loading…
Cancel
Save