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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
Loading…
Reference in new issue