SAD
This commit is contained in:
parent
f0115060ed
commit
b6cbd3ef96
@ -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
|
||||
|
58
final/game.c
58
final/game.c
@ -1,2 +1,60 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user