Zwischenstand

main
Jonathan Hager 3 years ago
parent 9397431d41
commit e9282a62fb
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -4,13 +4,12 @@
#include <stdlib.h>
#include "../Sprite/sprite.h"
#include "../MapObject/mapobject.h"
#include "../MapObject/mapobjectIDs.h"
#include "../Entity/professions.h"
#include "../Textures/textureIDs.h"
Entity * EntityInit(Sprite *sprite, int profession){
Entity *new = malloc(sizeof(Entity));
new->angle = 0;
new->sprite = sprite;
new->destX = 0;
new->destY = 0;
@ -103,9 +102,40 @@ void EntityListActAllEntities(Game *game){
angle = angle * RAD2DEG;
angle -= 35.26;
current->sprite->angle = angle;
if(angle <= 22.5 && angle >= -22.5){
// E
AnimationChangeAnimation(current->animationHandler, E);
}
else if(angle > 0 && angle <= 67.5){
// NE
AnimationChangeAnimation(current->animationHandler, NE);
}
else if(angle > 0 && angle <= 112.5){
// N
AnimationChangeAnimation(current->animationHandler, N);
}
else if(angle > 0 && angle <= 157.5){
// NW
AnimationChangeAnimation(current->animationHandler, NW);
}
else if(angle < 0 && angle >= -67.5){
// SE
AnimationChangeAnimation(current->animationHandler, SE);
}
else if(angle < 0 && angle >= -112.5){
// S
AnimationChangeAnimation(current->animationHandler, S);
}
else if(angle < 0 && angle >= -157.5){
// SW
AnimationChangeAnimation(current->animationHandler, SW);
}
else{
// W
AnimationChangeAnimation(current->animationHandler, W);
}
}
}
else{
if(current->profession == PR_BUILDER){
@ -142,8 +172,9 @@ void EntityListActAllEntities(Game *game){
}
SpriteUpdate(current->sprite);
AnimationUpdate(current->animationHandler);
SpriteUpdate(current->sprite);
SpriteListSpriteChanged(game->sprites, current->sprite);
current = current->next;

@ -3,11 +3,14 @@
#include "../Sprite/sprite.h"
#include "../game.h"
#include "task.h"
#include "../Textures/animationHandler.h"
typedef struct Entity Entity;
typedef struct Entity{
Sprite *sprite;
AnimationHandler animationHandler;
float angle;
float destX;
float destY;
int hasDestination;

@ -1,7 +0,0 @@
#ifndef PROFESSIONS_H_
#define PROFESSIONS_H_
#define PR_NOWORK 0
#define PR_BUILDER 1
#endif

@ -1,16 +0,0 @@
#ifndef TEXTUREIDS_H_
#define TEXTUREIDS_H_
#define N 0
#define NE 1
#define E 3
#define SE 5
#define S 7
#define SW 6
#define W 4
#define NW 2
#define MO_Baustelle 0
#define MO_Building 1
#endif

@ -43,41 +43,7 @@ void SpriteUpdate(Sprite *sprite){
sprite->depth = sprite->x + sprite->y + sprite->z;
if(sprite->angle <= 22.5 && sprite->angle >= -22.5){
// E
AnimationChangeAnimation(sprite->animationHandler, E);
}
else if(sprite->angle > 0 && sprite->angle <= 67.5){
// NE
AnimationChangeAnimation(sprite->animationHandler, NE);
}
else if(sprite->angle > 0 && sprite->angle <= 112.5){
// N
AnimationChangeAnimation(sprite->animationHandler, N);
}
else if(sprite->angle > 0 && sprite->angle <= 157.5){
// NW
AnimationChangeAnimation(sprite->animationHandler, NW);
}
else if(sprite->angle < 0 && sprite->angle >= -67.5){
// SE
AnimationChangeAnimation(sprite->animationHandler, SE);
}
else if(sprite->angle < 0 && sprite->angle >= -112.5){
// S
AnimationChangeAnimation(sprite->animationHandler, S);
}
else if(sprite->angle < 0 && sprite->angle >= -157.5){
// SW
AnimationChangeAnimation(sprite->animationHandler, SW);
}
else{
// W
AnimationChangeAnimation(sprite->animationHandler, W);
}
AnimationUpdate(sprite->animationHandler);
sprite->texture = sprite->animationHandler->currentFrame->texture;
// sprite->texture = sprite->animationHandler->currentFrame->texture;
}
Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){

@ -9,13 +9,11 @@ typedef struct Sprite Sprite;
typedef struct SpriteList SpriteList;
typedef struct Sprite {
AnimationHandler *animationHandler;
Texture2D *texture;
float x;
float y;
float z;
float depth;
float angle;
Sprite *next;
Sprite *prev;

@ -1,11 +1,12 @@
#include "animationHandler.h"
#include "animation.h"
#include "stdlib.h"
#include "stdio.h"
#include <stdlib.h>
#include <stdio.h>
AnimationHandler * AnimationHandlerInit(Animation **animations){
AnimationHandler * AnimationHandlerInit(Animation **animations, Texture2D **spriteTexture){
AnimationHandler *new = malloc(sizeof(AnimationHandler));
new->spriteTexture = spriteTexture;
new->animations = animations;
new->currentAnimation = 0;
new->currentFrame = new->animations[new->currentAnimation]->head;
@ -17,7 +18,7 @@ AnimationHandler * AnimationHandlerInit(Animation **animations){
void AnimationUpdate(AnimationHandler *animationHandler){
animationHandler->deltaElapsed += GetFrameTime();
if(animationHandler->deltaElapsed >= 0.2){
if(animationHandler->forward == 1){
animationHandler->currentFrame = animationHandler->currentFrame->next;
@ -28,11 +29,13 @@ void AnimationUpdate(AnimationHandler *animationHandler){
animationHandler->deltaElapsed = 0;
}
*(animationHandler->spriteTexture) = animationHandler->currentFrame->texture;
}
void AnimationReset(AnimationHandler *animationHandler){
animationHandler->currentFrame = animationHandler->animations[animationHandler->currentAnimation]->head;
*(animationHandler->spriteTexture) = animationHandler->currentFrame->texture;
}
void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){
@ -40,5 +43,4 @@ void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimati
animationHandler->currentAnimation = newAnimation;
AnimationReset(animationHandler);
}
}

@ -9,14 +9,15 @@ typedef struct AnimationHandler AnimationHandler;
typedef struct AnimationHandler{
Animation **animations;
AnimationFrame *currentFrame;
Texture2D **spriteTexture;
int currentAnimation;
int forward;
float deltaElapsed;
} AnimationHandler;
AnimationHandler * AnimationHandlerInit(Animation **animations);
AnimationHandler * AnimationHandlerInit(Animation **animations, Texture2D **spriteTexture);
void AnimationUpdate(AnimationHandler *animationHandler);
void AnimationReset(AnimationHandler *animationHandler);
void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation);
#endif
#endif

@ -1,18 +0,0 @@
#ifndef TEXTUREIDS_H_
#define TEXTUREIDS_H_
#define N 0
#define NE 1
#define E 3
#define SE 5
#define S 7
#define SW 6
#define W 4
#define NW 2
#define TE_cursor 0
#define TE_worker 1
#define TE_building 2
#define TE_baustelle 3
#endif

@ -41,6 +41,20 @@ TextureAtlas * TextureAtlasInit(){
return textures;
}
void TextureAtlasLoadTextures(TextureAtlas *atlas){
int i;
for(i = 0; i < TE_AMOUNT; i++){
switch(i){
case TE_CURSOR:
//Laden
break;
case TE_WORKER:
// Laden
break;
}
}
}
void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation){
*cursorTextures = LoadTexture("assets/cursor.gif");
*(cursorTextures + 1) = LoadTexture("assets/cursor_down.gif");

@ -2,10 +2,14 @@
#define TEXTUREATLAS_H_
#include "raylib.h"
#include "animation.h"
#include "../definitions.h"
typedef struct TextureAtlas TextureAtlas;
typedef struct TextureAtlas{
Texture2D *textures[TE_AMOUNT];
Texture2D cursorTextures[2];
Animation *cursorAnimation[1];
@ -17,12 +21,11 @@ typedef struct TextureAtlas{
Texture2D baustelle;
Animation *baustelleAnimation[8];
//Texture2D[] mapTextures;
} TextureAtlas;
// Initialize the full TextureAtlas struct with all Textures used in the game
TextureAtlas * TextureAtlasInit();
void TextureAtlasLoadTextures(TextureAtlas *atlas);
void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation);
void LoadWorkerTextures(Texture2D *workerTextures);
void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures);

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 814 B

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 814 B

Before

Width:  |  Height:  |  Size: 814 B

After

Width:  |  Height:  |  Size: 814 B

Before

Width:  |  Height:  |  Size: 820 B

After

Width:  |  Height:  |  Size: 820 B

Before

Width:  |  Height:  |  Size: 820 B

After

Width:  |  Height:  |  Size: 820 B

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 704 B

Before

Width:  |  Height:  |  Size: 757 B

After

Width:  |  Height:  |  Size: 757 B

Before

Width:  |  Height:  |  Size: 757 B

After

Width:  |  Height:  |  Size: 757 B

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

Before

Width:  |  Height:  |  Size: 771 B

After

Width:  |  Height:  |  Size: 771 B

Before

Width:  |  Height:  |  Size: 771 B

After

Width:  |  Height:  |  Size: 771 B

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 760 B

Before

Width:  |  Height:  |  Size: 753 B

After

Width:  |  Height:  |  Size: 753 B

Before

Width:  |  Height:  |  Size: 771 B

After

Width:  |  Height:  |  Size: 771 B

Before

Width:  |  Height:  |  Size: 775 B

After

Width:  |  Height:  |  Size: 775 B

Before

Width:  |  Height:  |  Size: 728 B

After

Width:  |  Height:  |  Size: 728 B

Before

Width:  |  Height:  |  Size: 771 B

After

Width:  |  Height:  |  Size: 771 B

Before

Width:  |  Height:  |  Size: 817 B

After

Width:  |  Height:  |  Size: 817 B

Before

Width:  |  Height:  |  Size: 754 B

After

Width:  |  Height:  |  Size: 754 B

Before

Width:  |  Height:  |  Size: 790 B

After

Width:  |  Height:  |  Size: 790 B

Before

Width:  |  Height:  |  Size: 754 B

After

Width:  |  Height:  |  Size: 754 B

Before

Width:  |  Height:  |  Size: 755 B

After

Width:  |  Height:  |  Size: 755 B

Before

Width:  |  Height:  |  Size: 809 B

After

Width:  |  Height:  |  Size: 809 B

Before

Width:  |  Height:  |  Size: 733 B

After

Width:  |  Height:  |  Size: 733 B

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 749 B

Before

Width:  |  Height:  |  Size: 765 B

After

Width:  |  Height:  |  Size: 765 B

Before

Width:  |  Height:  |  Size: 756 B

After

Width:  |  Height:  |  Size: 756 B

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 738 B

Before

Width:  |  Height:  |  Size: 767 B

After

Width:  |  Height:  |  Size: 767 B

Before

Width:  |  Height:  |  Size: 758 B

After

Width:  |  Height:  |  Size: 758 B

Before

Width:  |  Height:  |  Size: 816 B

After

Width:  |  Height:  |  Size: 816 B

Before

Width:  |  Height:  |  Size: 772 B

After

Width:  |  Height:  |  Size: 772 B

Before

Width:  |  Height:  |  Size: 736 B

After

Width:  |  Height:  |  Size: 736 B

Before

Width:  |  Height:  |  Size: 700 B

After

Width:  |  Height:  |  Size: 700 B

Before

Width:  |  Height:  |  Size: 777 B

After

Width:  |  Height:  |  Size: 777 B

Before

Width:  |  Height:  |  Size: 812 B

After

Width:  |  Height:  |  Size: 812 B

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Before

Width:  |  Height:  |  Size: 692 B

After

Width:  |  Height:  |  Size: 692 B

Before

Width:  |  Height:  |  Size: 700 B

After

Width:  |  Height:  |  Size: 700 B

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 696 B

Before

Width:  |  Height:  |  Size: 688 B

After

Width:  |  Height:  |  Size: 688 B

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 675 B

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 712 B

Before

Width:  |  Height:  |  Size: 764 B

After

Width:  |  Height:  |  Size: 764 B

Before

Width:  |  Height:  |  Size: 689 B

After

Width:  |  Height:  |  Size: 689 B

Before

Width:  |  Height:  |  Size: 670 B

After

Width:  |  Height:  |  Size: 670 B

Before

Width:  |  Height:  |  Size: 695 B

After

Width:  |  Height:  |  Size: 695 B

Before

Width:  |  Height:  |  Size: 713 B

After

Width:  |  Height:  |  Size: 713 B

Before

Width:  |  Height:  |  Size: 756 B

After

Width:  |  Height:  |  Size: 756 B

Before

Width:  |  Height:  |  Size: 664 B

After

Width:  |  Height:  |  Size: 664 B

Before

Width:  |  Height:  |  Size: 688 B

After

Width:  |  Height:  |  Size: 688 B

Before

Width:  |  Height:  |  Size: 679 B

After

Width:  |  Height:  |  Size: 679 B

Before

Width:  |  Height:  |  Size: 682 B

After

Width:  |  Height:  |  Size: 682 B

Before

Width:  |  Height:  |  Size: 715 B

After

Width:  |  Height:  |  Size: 715 B

Before

Width:  |  Height:  |  Size: 770 B

After

Width:  |  Height:  |  Size: 770 B

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 721 B

Before

Width:  |  Height:  |  Size: 761 B

After

Width:  |  Height:  |  Size: 761 B

Before

Width:  |  Height:  |  Size: 692 B

After

Width:  |  Height:  |  Size: 692 B

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 691 B

Before

Width:  |  Height:  |  Size: 698 B

After

Width:  |  Height:  |  Size: 698 B

Before

Width:  |  Height:  |  Size: 701 B

After

Width:  |  Height:  |  Size: 701 B

Before

Width:  |  Height:  |  Size: 753 B

After

Width:  |  Height:  |  Size: 753 B

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

@ -0,0 +1,22 @@
#ifndef DEFINITIONS_H_
#define DEFINITIONS_H_
#define N 0
#define NE 1
#define E 3
#define SE 5
#define S 7
#define SW 6
#define W 4
#define NW 2
#define TE_CURSOR 0
#define TE_WORKER 1
#define TE_BUILDING 2
#define TE_BAUSTELLE 3
#define TE_AMOUNT 4
#define TE_ENTITY_LENGTH 104
#define TE_MAPOBJECT_LENGTH 1
#endif
Loading…
Cancel
Save