Neues hinzugefügt und so

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

@ -9,6 +9,7 @@
#include "../IsometricMap/tile.h" #include "../IsometricMap/tile.h"
#include "../game.h" #include "../game.h"
#include "../definitions.h" #include "../definitions.h"
#include "../MapObject/staticobjects.h"
void DrawRect(Vector2 rectStart, Vector2 *mousePosition){ void DrawRect(Vector2 rectStart, Vector2 *mousePosition){
float width = GetMousePosition().x - rectStart.x; float width = GetMousePosition().x - rectStart.x;
@ -65,6 +66,20 @@ void mouseInput(Game *game){
camera->zoom -= 0.2f; camera->zoom -= 0.2f;
} }
} }
// Temp code for testing HOLZHACKERLEUTE, weil ich net versteh wie die iButtons hmmpf. früher bescheid wisse!
if(IsKeyPressed(KEY_G)){
//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
}
// resetting last selected Tile to grass texture // resetting last selected Tile to grass texture
if(inputHandler->selectedLayer != -1){ if(inputHandler->selectedLayer != -1){
IsometricMapChangeTextureIdOfTile(map, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0); IsometricMapChangeTextureIdOfTile(map, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0);

@ -1,6 +1,6 @@
CC = gcc CC = gcc
FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -g
OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o building.o entity.o selectable.o task.o entityacts.o onClickFunctions.o OBJS = main.o sprite.o inputHandler.o isometricMap.o game.o textureatlas.o animation.o animationHandler.o button.o uiContainer.o debug.o building.o entity.o selectable.o task.o entityacts.o onClickFunctions.o staticobjects.o
spiel: $(OBJS) spiel: $(OBJS)
$(CC) -o spiel $(OBJS) $(FLAGS) $(CC) -o spiel $(OBJS) $(FLAGS)
@ -56,5 +56,8 @@ entityacts.o: Entity/entityacts.c
onClickFunctions.o: Ui/onClickFunctions.c onClickFunctions.o: Ui/onClickFunctions.c
$(CC) -c Ui/onClickFunctions.c $(FLAGS) $(CC) -c Ui/onClickFunctions.c $(FLAGS)
staticobjects.o: MapObject/staticobjects.c
$(CC) -c MapObject/staticobjects.c $(FLAGS)
clean: clean:
rm *.o spiel rm *.o spiel

@ -0,0 +1,77 @@
#include "staticobjects.h"
#include <stdlib.h>
#include "../game.h"
#include "../Sprite/sprite.h"
StaticObject * StaticObjectInit(Game *game, int id, int x, int y){
int textureId = 0;
switch(id){
case SO_PINETREE:
textureId = TE_PINETREE;
break;
default:
printf("WARNING: STATICOBJECTINIT MIT FALSCHER ID AUFGERUFEN\n");
}
Sprite *newSprite = SpriteCreate(game->textures, textureId, x, y);
SpriteListInsert(game->sprites, newSprite);
StaticObject *new = malloc(sizeof(StaticObject));
new->sprite = newSprite;
new->id = id;
new->next = 0;
new->prev = 0;
return new;
}
StaticObjectList * StaticObjectListInit(){
StaticObjectList *new = malloc(sizeof(StaticObjectList));
new->head = 0;
new->tail = 0;
return new;
}
void StaticObjectListPrintForward(StaticObjectList *objects){
}
void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data){
if(objects->head == 0){
objects->head = data;
objects->tail = data;
}
else{
objects->tail->next = data;
data->prev = objects->tail;
objects->tail = data;
}
}
void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove){
if(remove == 0){
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
}
else if(objects->head == remove && objects->tail == remove){
objects->head = 0;
objects->tail = 0;
}
else if(objects->head == remove){
remove->next->prev = 0;
objects->head = remove->next;
}
else if(objects->tail == remove){
remove->prev->next = 0;
objects->tail = remove->prev;
}
else{
remove->prev->next = remove->next;
remove->next->prev = remove->prev;
}
remove->next = 0;
remove->prev = 0;
}

@ -0,0 +1,26 @@
#ifndef STATICOBJECTS_H_
#define STATICOBJECTS_H_
#include "../Sprite/sprite.h"
#include "../game.h"
typedef struct StaticObject{
Sprite *sprite;
int id;
struct StaticObject *next;
struct StaticObject *prev;
} StaticObject;
typedef struct StaticObjectList {
StaticObject *head;
StaticObject *tail;
} StaticObjectList;
StaticObject * StaticObjectInit(Game *game, int id, int x, int y);
StaticObjectList * StaticObjectListInit();
void StaticObjectListPrintForward(StaticObjectList *objects);
void StaticObjectListInsert(StaticObjectList *objects, StaticObject *data);
void StaticObjectListRemove(StaticObjectList *objects, StaticObject *remove);
#endif

@ -17,6 +17,8 @@ KI Gegner ist erstmal zu aufwändig, ein wenig Ackern muss man aber immer!
[turn off EXIT on ESC Key, for later](https://github.com/raysan5/raylib/issues/520) [turn off EXIT on ESC Key, for later](https://github.com/raysan5/raylib/issues/520)
[Texturentyp](https://opengameart.org/content/germanic-worker)
## TODO ## TODO
Zu Function Pointern: Zu Function Pointern:

@ -82,6 +82,8 @@ void SpriteListInsertBefore(SpriteList *list, Sprite *new, Sprite *current){
else{ else{
new->prev->next = new; new->prev->next = new;
} }
list->spriteAmount++;
} }
void SpriteListInsertAfter(SpriteList *list, Sprite *new, Sprite *current){ void SpriteListInsertAfter(SpriteList *list, Sprite *new, Sprite *current){
@ -95,6 +97,8 @@ void SpriteListInsertAfter(SpriteList *list, Sprite *new, Sprite *current){
else{ else{
new->next->prev = new; new->next->prev = new;
} }
list->spriteAmount++;
} }
void SpriteListInsert(SpriteList *list, Sprite *new){ void SpriteListInsert(SpriteList *list, Sprite *new){
@ -102,6 +106,8 @@ void SpriteListInsert(SpriteList *list, Sprite *new){
if(list->head == 0){ if(list->head == 0){
list->head = new; list->head = new;
list->tail = new; list->tail = new;
list->spriteAmount++;
} }
else{ else{
Sprite *current = list->head; Sprite *current = list->head;
@ -116,6 +122,7 @@ void SpriteListInsert(SpriteList *list, Sprite *new){
SpriteListInsertAfter(list, new, list->tail); SpriteListInsertAfter(list, new, list->tail);
} }
} }
void SpriteListSpriteChanged(SpriteList *list, Sprite *changed){ void SpriteListSpriteChanged(SpriteList *list, Sprite *changed){
@ -160,18 +167,22 @@ void SpriteListRemove(SpriteList *list, Sprite *remove){
else if(list->head == remove && list->tail == remove){ else if(list->head == remove && list->tail == remove){
list->head = 0; list->head = 0;
list->tail = 0; list->tail = 0;
list->spriteAmount--;
} }
else if(list->head == remove){ else if(list->head == remove){
remove->next->prev = 0; remove->next->prev = 0;
list->head = remove->next; list->head = remove->next;
list->spriteAmount--;
} }
else if(list->tail == remove){ else if(list->tail == remove){
remove->prev->next = 0; remove->prev->next = 0;
list->tail = remove->prev; list->tail = remove->prev;
list->spriteAmount--;
} }
else{ else{
remove->prev->next = remove->next; remove->prev->next = remove->next;
remove->next->prev = remove->prev; remove->next->prev = remove->prev;
list->spriteAmount--;
} }
remove->next = 0; remove->next = 0;
@ -182,6 +193,7 @@ SpriteList * SpriteListInit(){
SpriteList *newSpriteList = malloc(sizeof(SpriteList)); SpriteList *newSpriteList = malloc(sizeof(SpriteList));
newSpriteList->head = 0; newSpriteList->head = 0;
newSpriteList->tail = 0; newSpriteList->tail = 0;
newSpriteList->spriteAmount = 0;
return newSpriteList; return newSpriteList;
} }

@ -22,6 +22,7 @@ typedef struct Sprite {
typedef struct SpriteList { typedef struct SpriteList {
Sprite *head; Sprite *head;
Sprite *tail; Sprite *tail;
int spriteAmount;
} SpriteList; } SpriteList;
void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera); void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera);

@ -34,6 +34,9 @@ void TextureAtlasLoadTextures(Texture2D **textures){
textures[TE_BAUSTELLE] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D)); textures[TE_BAUSTELLE] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D));
LoadMapObjectTextures(textures[TE_BAUSTELLE], "baustelle"); LoadMapObjectTextures(textures[TE_BAUSTELLE], "baustelle");
break; break;
case TE_PINETREE:
textures[TE_PINETREE] = malloc(TE_MAPOBJECT_LENGTH * sizeof(Texture2D));
LoadMapObjectTextures(textures[TE_PINETREE], "pinetree");
default: default:
printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n"); printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n");
} }

@ -23,6 +23,7 @@ void DebugDraw(Game *game){
sprintf(strings[lineamount++], "Selected Layer: %d", game->inputHandler->selectedLayer); sprintf(strings[lineamount++], "Selected Layer: %d", game->inputHandler->selectedLayer);
sprintf(strings[lineamount++], "DEPTH: %d", (int)(game->inputHandler->cursorWorldPos.x + game->inputHandler->cursorWorldPos.y + game->inputHandler->selectedLayer)); sprintf(strings[lineamount++], "DEPTH: %d", (int)(game->inputHandler->cursorWorldPos.x + game->inputHandler->cursorWorldPos.y + game->inputHandler->selectedLayer));
sprintf(strings[lineamount++], "Camera Zoom: %f", game->camera->zoom); sprintf(strings[lineamount++], "Camera Zoom: %f", game->camera->zoom);
sprintf(strings[lineamount++], "Sprite Amount: %d", game->sprites->spriteAmount);
// Hier müssten wir eine bessere Lösung finden, das flackert weil pressed nur für einen Frame gilt. Eine ähnliche Funktion gibt es für CharDown leider nicht, müssten wir selbst programmieren. Ich habe es erstmal nicht auskommentiert. Kann man aber easy machen sollte es stören // Hier müssten wir eine bessere Lösung finden, das flackert weil pressed nur für einen Frame gilt. Eine ähnliche Funktion gibt es für CharDown leider nicht, müssten wir selbst programmieren. Ich habe es erstmal nicht auskommentiert. Kann man aber easy machen sollte es stören
int pressed = GetCharPressed(); int pressed = GetCharPressed();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@ -16,8 +16,9 @@
#define TE_WORKER 1 #define TE_WORKER 1
#define TE_BUILDING 2 #define TE_BUILDING 2
#define TE_BAUSTELLE 3 #define TE_BAUSTELLE 3
#define TE_PINETREE 4
#define TE_AMOUNT 4 #define TE_AMOUNT 5
#define TE_ENTITY_LENGTH 104 #define TE_ENTITY_LENGTH 104
#define TE_MAPOBJECT_LENGTH 1 #define TE_MAPOBJECT_LENGTH 1
@ -34,10 +35,12 @@
// Definitions for buildings // Definitions for buildings
#define BU_HOUSE 0 #define BU_HOUSE 0
// Defintions for static map objects
#define SO_PINETREE 0
// Defintions for professions // Defintions for professions
#define PR_BUILDER 0 #define PR_BUILDER 0
// Definitions for Screen / View / Ui Stuff // Definitions for Screen / View / Ui Stuff
#define DEBUG_FONT_SIZE 20 #define DEBUG_FONT_SIZE 20

@ -9,6 +9,7 @@
#include "Entity/entity.h" #include "Entity/entity.h"
#include "MapObject/building.h" #include "MapObject/building.h"
#include "Ui/uiContainer.h" #include "Ui/uiContainer.h"
#include "MapObject/staticobjects.h"
// returns pointer to new Game instance // returns pointer to new Game instance
Game *GameInit() Game *GameInit()
@ -46,6 +47,7 @@ Game *GameInit()
game->entities = EntityListInit(); game->entities = EntityListInit();
game->buildings = BuildingListInit(); game->buildings = BuildingListInit();
game->objects = StaticObjectListInit();
game->map = IsometricMapInit(); game->map = IsometricMapInit();
//das du es weißt man kann wenn du nicht auf hört was machen und dann bist du leise es gibt was das nett sich rufmord //das du es weißt man kann wenn du nicht auf hört was machen und dann bist du leise es gibt was das nett sich rufmord

@ -14,6 +14,7 @@ typedef struct Game{
struct Camera2D *camera; struct Camera2D *camera;
struct IsometricMap *map; struct IsometricMap *map;
struct BuildingList *buildings; struct BuildingList *buildings;
struct StaticObjectList *objects;
struct EntityList *entities; struct EntityList *entities;
struct UiContainer *UiContainers[SCREEN_AMOUNT]; struct UiContainer *UiContainers[SCREEN_AMOUNT];
int screen; int screen;

@ -53,7 +53,6 @@ int main(){
printf("OPTIONS \n"); printf("OPTIONS \n");
return 0; return 0;
case SCREEN_GAME: case SCREEN_GAME:
// Updating Entities // Updating Entities
EntityListActAllEntities(game); EntityListActAllEntities(game);

Loading…
Cancel
Save