pvjc22/final/game.c

61 lines
1.1 KiB
C
Raw Normal View History

2022-06-05 15:38:05 +00:00
#include <stdio.h>
#include <stdlib.h>
2022-06-05 18:49:05 +00:00
#include <math.h>
//#include <curses.h>
#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;
}