~rabbits/orca-toy

1a5864a48634acecebf2b281eef79fd94838daca — neauoire 2 years ago dd53b62
Progress on SDL client
3 files changed, 33 insertions(+), 4 deletions(-)

M sim.c
M sim.h
M toy.c
M sim.c => sim.c +13 -0
@@ 553,3 553,16 @@ disk(FILE *f, Grid *g)
	}
	return g->w > 2 && g->h > 2;
}

void
create(Grid *g, int w, int h)
{
	int i;
	g->w = w;
	g->h = h;
	g->f = 0;
	g->r = 1;
	for(i = 0; i < w * h; ++i) {
		g->data[i] = '.';
	}
}
\ No newline at end of file

M sim.h => sim.h +2 -1
@@ 12,6 12,7 @@ typedef struct Grid {
	char data[MAXSZ];
} Grid;

void print(Grid *g);
char get(Grid *g, int x, int y);
int run(Grid *g);
int disk(FILE *f, Grid *g);
void create(Grid *g, int w, int h);

M toy.c => toy.c +18 -3
@@ 37,6 37,8 @@ uint32_t *pixels;

Rect2d selection;

Grid g;

Point2d
Pt2d(int x, int y)
{


@@ 46,6 48,14 @@ Pt2d(int x, int y)
	return p;
}

Point2d
clampt(Point2d p, int step)
{
	p.x = abs((p.x + step / 2) / step) * step;
	p.y = abs((p.y + step / 2) / step) * step;
	return p;
}

/* chr */

int


@@ 196,14 206,18 @@ render(void)
void
domouse(SDL_Event *event)
{
	Point2d touch = Pt2d(
		(event->motion.x - (PAD * ZOOM)) / ZOOM,
		(event->motion.y - (PAD * ZOOM)) / ZOOM);
	Point2d touch = clampt(
		Pt2d(
			(event->motion.x - (PAD * ZOOM)) / ZOOM,
			(event->motion.y - (PAD * ZOOM)) / ZOOM),
		8);
	switch(event->type) {
	case SDL_MOUSEBUTTONUP:
		printf("mouse-up\n");
		break;
	case SDL_MOUSEBUTTONDOWN:
		printf("%d,%d\n", touch.x / 8, touch.y / 8);
		select(touch.x / 8, touch.y / 8, 1, 1);
		printf("mouse-down\n");
		break;
	case SDL_MOUSEMOTION:


@@ 276,6 290,7 @@ main(int argc, char *argv[])
	if(!init())
		return error("Init", "Failure");

	create(&g, HOR, VER);
	newchr();
	select(0, 0, 0, 0);
	draw(pixels);