JanEhehalt 3 years ago
commit 8ba6629962

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}

@ -0,0 +1,6 @@
{
"files.associations": {
"inputhandling.h": "c",
"isometricmap.h": "c"
}
}

@ -1,5 +1,5 @@
spiel: main.o sprite.o inputHandler.o list.o
gcc -o spiel main.o list.o sprite.o inputHandler.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
spiel: main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o
gcc -o spiel main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
main.o: main.c
gcc -c main.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
@ -12,6 +12,15 @@ inputHandler.o: inputHandler.c
list.o: List/list.c
gcc -c List/list.c
isometricRenderer.o: isometricRenderer.c
gcc -c isometricRenderer.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
isometricMap.o: isometricMap.c
gcc -c isometricMap.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
tile.o: tile.c
gcc -c tile.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
clean:
rm *.o spiel

@ -13,6 +13,5 @@ Fantasy Welt oder Realistisch?
## TODO
- Bug with movement of sprite after spawning a few other sprites
- Drawn Rectangle problems with negative width/height
- Selecting Sprites for moving all selected to the same destination
- Macht es Sinn ein einzelnes "Game" struct zu haben, das alle möglichen Pointer hat zu allen arrays, camera, textures etc?
- Bug in isometricRenderer.c -> Segmentation Fault

@ -75,7 +75,6 @@ void mouseInput(InputHandler *inputHandler, Sprite *sprites, int *spriteAmount,
// Add Sprite
if(width + height <= 1){
//printf("Klick\n");
SpriteAdd(sprites, spriteAmount, texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2);
}

@ -0,0 +1,60 @@
#include "isometricMap.h"
#include <stdio.h>
#include <stdlib.h>
IsometricMap * IsometricMapInit(int x, int y){
IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap));
map->tileTextures[0] = LoadTexture("assets/grass.png");
map->tileTextures[1] = LoadTexture("assets/tower.png");
Tile* tiles[x];
int n = 0;
for(n=0; n<x; n++){
tiles[n] = (Tile*)malloc(y*sizeof(Tile));
}
map->sizeX = x;
map->sizeY = y;
int i = 0;
int j = 0;
for(i=0; i < x; i++){
for(j=0; j < y; j++){
if(i != j){
Tile tmp = {0, i, j};
tiles[i][j] = tmp;
}
else{
Tile tmp = {1, i, j};
tiles[i][j] = tmp;
}
}
}
map->tiles = tiles;
return map;
}
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
offset->x = x * textureSize/2;
offset->y = x * textureSize/4;
offset->x -= y * textureSize/2;
offset->y += y * textureSize/4;
return offset;
}

@ -0,0 +1,22 @@
#ifndef ISOMETRICMAP_H_
#define ISOMETRICMAP_H_
#include "raylib.h"
#include "tile.c"
typedef struct IsometricMap{
Texture2D tileTextures[10];
Tile **tiles;
int sizeX;
int sizeY;
} IsometricMap;
// TODO:
void IsometricMapAddTile(IsometricMap isometricMap);
Tile IsometricMapGetTileFromArrayPosition(int x, int y);
Tile IsometricMapGetTileFromWorldCoordinates(float x, float y);
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize);
// Working
IsometricMap * IsometricMapInit(int x, int y);
#endif

@ -0,0 +1,61 @@
#include "isometricRenderer.h"
#include "raylib.h"
#include "isometricMap.h"
#include <stdio.h>
//TODO: Isometric Tilemap Struct, which can be scanned for clicked Tile
// General coordinate translation function
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){
float originX = 0.0f;
float originY = 0.0f;
int i = 0;
int j = 0;
int amount = 1;
for(i=0; i<=height; i++){
for(j=0; j<amount; j++){
float x = originX - amount/2 * renderer->texture->width + j * renderer->texture->width;
if(amount%2 == 1){
x -= renderer->texture->width/2;
}
float y = i * renderer->texture->height/4;
DrawTexture(*renderer->texture, x, y, WHITE);
}
if(i < height/2){
amount++;
}
else{
amount--;
}
}
}
void IsometricRendererRenderIsometricMap(IsometricMap *map){
float originX = 0.0f;
float originY = 0.0f;
int i = 0;
int j = 0;
for(i=0; i < map->sizeX; i++){
for(j=0; j < map->sizeY; j++){
Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, map->tileTextures[0].width);
float x = originX + offset->x;
float y = originY + offset->y;
// TODO -> results in Segmentation fault
//int textureId = map->tiles[i][j].textureId;
int textureId = 0;
if(i + j == 9){
textureId = 1;
}
DrawTexture(map->tileTextures[textureId], x, y, WHITE);
}
}
}

@ -0,0 +1,14 @@
#ifndef ISOMETRICRENDERER_H_
#define ISOMETRICRENDERER_H_
#include "raylib.h"
#include "isometricMap.h"
typedef struct IsometricRenderer{
Texture *texture;
} IsometricRenderer;
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height);
void IsometricRendererRenderIsometricMap(IsometricMap *map);
#endif

@ -1,9 +1,15 @@
#include "raylib.h"
#include "stdio.h"
#include <stdlib.h>
#include "sprite.h"
#include "inputHandler.h"
#include "raymath.h"
<<<<<<< HEAD
#include "List/list.h"
=======
#include "isometricRenderer.h"
#include "isometricMap.h"
>>>>>>> IsometricRenderer
int main(){
@ -14,17 +20,23 @@ int main(){
texture = LoadTexture("assets/amulet.png");
Texture2D isometricTexture = LoadTexture("assets/grass.png");
IsometricRenderer *isometricRenderer = (IsometricRenderer *) malloc(sizeof(IsometricRenderer));
isometricRenderer->texture = &isometricTexture;
int spriteAmount = 0;
Sprite cursorSprite = {&texture, 450, 225};
InputHandler inputHandler;
Camera2D camera = { 0 };
camera.target = (Vector2){400, 225};
camera.target = (Vector2){0, 0};
camera.rotation = 0.0f;
camera.zoom = 1.0f;
SpriteAdd(sprites, &spriteAmount, &texture, 400, 400);
SpriteAdd(sprites, &spriteAmount, &texture, 0, 0);
IsometricMap *map = IsometricMapInit(20, 10);
SetTargetFPS(60);
while(!WindowShouldClose()){
@ -34,13 +46,18 @@ int main(){
ClearBackground(RAYWHITE);
BeginMode2D(camera);
IsometricRendererRenderIsometricMap(map);
int i;
//int length = sizeof(sprites)/sizeof(sprites[0]);
for(i=0; i < spriteAmount; i++){
DrawSprite(sprites + i);
}
EndMode2D();
// Moving cursor Sprite to Mouse Pos and drawing it
cursorSprite.x = inputHandler.cursorPos.x - texture.width / 2;
cursorSprite.y = inputHandler.cursorPos.y - texture.height / 2;

@ -0,0 +1,2 @@
#include "tile.h"

@ -0,0 +1,11 @@
#ifndef TILE_H_
#define TILE_H_
#include "raylib.h"
typedef struct Tile{
int textureId;
int x;
int y;
} Tile;
#endif
Loading…
Cancel
Save