Sprite not found

main
Jonathan Hager 3 years ago
parent 4a1a2cb4e3
commit e97e905c1e
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -1,6 +1,7 @@
{ {
"C_Cpp.errorSquiggles": "Disabled", "C_Cpp.errorSquiggles": "Disabled",
"files.associations": { "files.associations": {
"isometricrenderer.h": "c" "isometricrenderer.h": "c",
"sprite.h": "c"
} }
} }

@ -1,8 +1,9 @@
#include "list.h" #include "list.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../sprite.h"
Node * ListCreateNode(int *data){ Node * ListCreateNode(Sprite *data){
Node *new = (Node *) malloc(sizeof(Node)); Node *new = (Node *) malloc(sizeof(Node));
new->data = *data; new->data = *data;
return new; return new;
@ -11,16 +12,16 @@ Node * ListCreateNode(int *data){
void ListPrintForward(List *list){ void ListPrintForward(List *list){
Node *current = list->head; Node *current = list->head;
printf("\n["); printf("\n[\n");
while(current != 0){ while(current != 0){
printf("%d,", current->data); printf("(%f | %f),\n", current->data.x, current->data.y);
current = current->next; current = current->next;
} }
printf("]\n"); printf("]\n");
} }
void ListInsertFront(List *list, int data){ void ListInsertFront(List *list, Sprite *data){
Node *new = ListCreateNode(&data); Node *new = ListCreateNode(data);
if(list->head == 0){ if(list->head == 0){
list->head = new; list->head = new;
@ -38,8 +39,8 @@ void ListInsertFront(List *list, int data){
} }
} }
void ListInsertBack(List *list, int data){ void ListInsertBack(List *list, Sprite *data){
Node *new = ListCreateNode(&data); Node *new = ListCreateNode(data);
if(list->head == 0){ if(list->head == 0){
list->head = new; list->head = new;
@ -55,4 +56,11 @@ void ListInsertBack(List *list, int data){
new->prev = list->tail; new->prev = list->tail;
list->tail = new; list->tail = new;
} }
} }
List * ListInit(){
List *newList = (List *) malloc(sizeof(List));
newList->head = 0;
newList->tail = 0;
return newList;
}

@ -1,6 +1,6 @@
#ifndef LIST_H_ #ifndef LIST_H_
#define LIST_H_ #define LIST_H_
#include "nodeData.h" #include "../sprite.h"
typedef struct Node Node; typedef struct Node Node;
typedef struct List List; typedef struct List List;
@ -11,19 +11,20 @@ typedef struct List {
} List; } List;
typedef struct Node { typedef struct Node {
int data; Sprite data;
Node *next; Node *next;
Node *prev; Node *prev;
} Node; } Node;
//Only for internal purpose //Only for internal purpose
Node * ListCreateNode(int *data); Node * ListCreateNode(Sprite *data);
//Print the list in order //Print the list in order
void ListPrintForward(List *list); void ListPrintForward(List *list);
void ListInsertFront(List *list, int data); void ListInsertFront(List *list, Sprite *data);
void ListInsertBack(List *list, int data); void ListInsertBack(List *list, Sprite *data);
List * ListInit();
#endif #endif

@ -11,7 +11,7 @@ inputHandler.o: Input/inputHandler.c
gcc -c Input/inputHandler.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 gcc -c Input/inputHandler.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
list.o: List/list.c list.o: List/list.c
gcc -c List/list.c gcc -c List/list.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
isometricRenderer.o: IsometricMap/isometricRenderer.c isometricRenderer.o: IsometricMap/isometricRenderer.c
gcc -c IsometricMap/isometricRenderer.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 gcc -c IsometricMap/isometricRenderer.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

@ -1,5 +1,5 @@
#include "raylib.h" #include "raylib.h"
#include "stdio.h" #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "sprite.h" #include "sprite.h"
#include "Input/inputHandler.h" #include "Input/inputHandler.h"
@ -18,7 +18,12 @@ int main(){
Texture2D texture; Texture2D texture;
texture = LoadTexture("assets/amulet.png"); texture = LoadTexture("assets/amulet.png");
List *spritesL = ListInit();
ListInsertBack(spritesL, SpriteCreate(&texture, 0, 0));
Sprite cursorSprite = {&texture, 450, 225}; Sprite cursorSprite = {&texture, 450, 225};
SpriteAdd(sprites, &spriteAmount, &texture, 0, 0); SpriteAdd(sprites, &spriteAmount, &texture, 0, 0);
InputHandler inputHandler; InputHandler inputHandler;
@ -40,11 +45,14 @@ int main(){
BeginMode2D(camera); BeginMode2D(camera);
IsometricRendererRenderIsometricMap(map); IsometricRendererRenderIsometricMap(map);
int i; int i;
/*
for(i=0; i < spriteAmount; i++){ for(i=0; i < spriteAmount; i++){
DrawSprite(sprites + i); DrawSprite(sprites + i);
} }
*/
DrawAllSpritesInList(spritesL);
EndMode2D(); EndMode2D();

@ -1,6 +1,8 @@
#include "sprite.h" #include "sprite.h"
#include "raylib.h" #include "raylib.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "List/list.h"
void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){
if(*spriteAmount < 100){ if(*spriteAmount < 100){
@ -27,3 +29,31 @@ void DrawSprite(Sprite *sprite){
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE); DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);
} }
} }
void DrawAllSpritesInList(List *list){
Node *current = list->head;
while(current != 0){
if(current->data.selected){
DrawTexture(current->data.texture, current->data.x, current->data.y, BLACK);
}
else{
DrawTexture(current->data.texture, current->data.x, current->data.y, WHITE);
}
current = current->next;
}
}
Sprite * SpriteCreate(Texture2D *texture, int x, int y){
Sprite newSprite = (Sprite *) malloc(sizeof(Sprite));
newSprite->texture = texture;
newSprite->x = x;
newSprite->y = y;
newSprite->destX = x;
newSprite->destY = y;
newSprite->hasDestination = 0;
newSprite->selected = 0;
return newSprite;
}

@ -1,5 +1,6 @@
#ifndef SPRITE_H_ #ifndef SPRITE_H_
#define SPRITE_H_ #define SPRITE_H_
#include "List/list.h"
#include "raylib.h" #include "raylib.h"
typedef struct Sprite { typedef struct Sprite {
@ -16,4 +17,8 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in
void DrawSprite(Sprite *sprite); void DrawSprite(Sprite *sprite);
void DrawAllSpritesInList(List *list);
Sprite * SpriteCreate(Texture2D *texture, int x, int y);
#endif #endif

Loading…
Cancel
Save