Beispiel #1
0
Scrn *titlescrnnew(Gfx *g){
	static Tit t = {0};
	static Scrn s = {0};

	t.title = resrcacq(imgs, "img/title.png", 0);
	if(!t.title)
		return NULL;

	Txtinfo ti = { TxtSzMedium };
	t.f = resrcacq(txt, TxtStyleMenu, &ti);
	if(!t.f)
		return NULL;

	ti.size = TxtSzSmall;
	Txt *f = resrcacq(txt, TxtStyleMenu, &ti);
	if(!f)
		return NULL;

	t.copy = txt2img(g, f, "Copyright 2011 Steve McCoy and Ethan Burns");
	if(!t.copy)
		return NULL;

	t.titlepos = (Point){
		gfxdims(g).x / 2 - imgdims(t.title).x / 2,
		0
	};

	Point sd = txtdims(t.f, "Press 'x' to Start a new game");
	t.startpos = (Point){
		gfxdims(g).x / 2 - sd.x / 2,
		t.titlepos.y + imgdims(t.title).y
	};

	Point ld = txtdims(t.f, "Press 'x' to Load the saved game");
	t.loadpos = (Point){
		gfxdims(g).x / 2 - ld.x / 2,
		t.startpos.y + sd.y + 16
	};

	Point od = txtdims(t.f, "Press 'x' for Options");
	t.optspos = (Point){
		gfxdims(g).x / 2 - od.x / 2,
		t.loadpos.y + ld.y + 16
	};

	t.copypos = (Point){
		gfxdims(g).x / 2 - imgdims(t.copy).x / 2,
		gfxdims(g).y - imgdims(t.copy).y - 8
	};

	s.mt = &titmt;
	s.data = &t;
	return &s;
}
Beispiel #2
0
static void draw(Scrn *s, Gfx *g){
	extern char *statname[];

	Statup *sup = s->data;

	gfxclear(g, (Color){ 127, 200, 255 });

	enum { Bufsz = 256 };
	char buf[Bufsz];

	int mh = TxtSzMedium/2;
	int Pad = 4;
	Point sloc = { Pad, Pad };
	for(int i = StatHp; i < StatMax; i++){
		Meter meter = {
			.base = sup->p->stats[i],
			.extra = sup->p->eqp[i],
			.max = statmax[i],
			.xscale = 2,
			.h = mh,
			.cbg = {0x65, 0x65, 0x65},
			.cbase = {0x1E, 0x94, 0x22},
			.cextra = {0x1B, 0xAF, 0xE0},
			.cborder = {}
		};

		Point mloc = { sloc.x + mh*2, sloc.y };
		Rect ma = meterarea(&meter, mloc);

		if(rectcontains(ma, sup->mouse))
			meter.cbg = (Color){ 255, 219, 0 };

		txtdraw(g, sup->txt, sloc, statname[i]);
		meterdraw(g, &meter, mloc);

		if(rectcontains(ma, sup->mouse) && sup->inc && sup->p->stats[i] < statmax[i]){
			if(i == StatHp){
				sup->p->stats[i] += 5;
				sup->p->curhp += 5;
			}else
				sup->p->stats[i]++;

			sup->norbs--;
			sup->uorbs++;
			sup->inc = 0;
		}

		sloc = vecadd(sloc, (Point){0, mh + Pad});
	}

	snprintf(buf, Bufsz, "Orbs: %d", sup->norbs);
	Point o = txtdims(sup->txt, buf);
	txtdraw(g, sup->txt, (Point){ Scrnw - o.x, 1 }, buf);

	gfxflip(g);
}

static void handle(Scrn *s, Scrnstk *stk, Event *e){
	Statup *sup = s->data;

	if(e->type == Mousemv){
		sup->mouse = projpt((Point){ e->x, e->y });
		sup->inc = 0;
		return;
	}

	if(e->type == Mousebt && sup->uorbs == 0){
		if(sup->norbs == 0)
			return;
		sup->mouse = projpt((Point){ e->x, e->y });
		sup->inc = 1;
		return;
	}

	if(e->type != Keychng || e->repeat)
		return;

	if(e->down && e->key == kmap[Mvinv]){
		Player *p = sup->p;
		int u = 0;
		for(Invit *i = p->inv; i != p->inv + Maxinv && u < sup->uorbs; i++){
			if(i->id == ItemStatup){
				i->id = 0;
				sup->norbs--;
				u++;
			}
		}
		gamesave(sup->g);
		scrnstkpop(stk);
		return;
	}
}