From b6cbd3ef96f69fc34ac459f4f898c4c6a3c02e2d Mon Sep 17 00:00:00 2001 From: Yaroslav Orlianskyi Date: Sun, 5 Jun 2022 20:49:05 +0200 Subject: [PATCH] SAD --- final/Makefile | 14 ------------ final/game.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 14 deletions(-) delete mode 100644 final/Makefile diff --git a/final/Makefile b/final/Makefile deleted file mode 100644 index 8c35442..0000000 --- a/final/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -CFLAGS=-std=c99 -Wall -g - -all: game - -%.o: %.c - gcc $(CFLAGS) -c $< -o $@ - -clean: - rm *.o - rm game - -game: main.o game.o world.o - gcc main.o game.o world.o -lcurses -lm -o game - diff --git a/final/game.c b/final/game.c index fbfff34..f66c671 100644 --- a/final/game.c +++ b/final/game.c @@ -1,2 +1,60 @@ #include #include +#include +//#include + +#define mapWidth 80 +#define mapHeight 25 + +typedef struct SObject{ + float x,y; + float Witdth, Height; +}TObject; + +char map[mapHeight][mapWidth+1]; +TObject mario; + +void ClearMap(){ + for(int i = 0; i < mapWidth; i++) + map[0][i] = '.'; + map[0][mapWidth] = '\0'; + for(int j = 0; j < mapHeight; j++) + sprintf(map[j], map[0]); +} + +void ShowMap(){ + map[mapHeight-1][mapWidth-1] = '\0'; + for(int i = 0; i < mapHeight; i++) + printf("%s", map[i]); +} + +void SetObjectPos(TObject *obj, float xPos, float yPos){ + (*obj).x = xPos; + (*obj).y = yPos; +} + +void InitObject(TObject *obj, float xPos, float yPos, float oWidth, float oHeight){ + SetObjectPos(obj, xPos, yPos); + (*obj).Witdth = oWidth; + (*obj).Height = oHeight; +} + +void PutObjectOnMap(TObject obj){ + int ix = (int)round(obj.x); + int iy = (int)round(obj.y); + int iWidth = (int)round(obj.Witdth); + int iHeight = (int)round(obj.Height); + + for(int i = ix; i < (ix + iWidth); i++) + for(int j = iy; j < (iy + iHeight); j++) + map[j][i] = '@'; +} + +int main() +{ + InitObject(&mario, 39, 10, 3, 3); + ClearMap(); + PutObjectOnMap(mario); + ShowMap(); + return 0; +}