#include <screen.h>
#include <nbrandom.h>
#include <config.h>
+#include <collision.h>
#include <mmrarray.h>
int main(int, char **);
static void usage(void);
-static void shape_draw(int, int, int);
+static void shape_draw(int, int, int, bool);
static void anim_init(void);
static void anim_redraw(void);
static void anim_update(void);
/* Color related */
static bool cfg_use_color = true;
static bool cfg_use_attributes = true;
-static bool use_color = false;
-static bool use_attributes = false;
static short ncolpairs = -1;
/* Loaded shapes */
/* 2d text shape blitting routine */
static void
-shape_draw(int shape, int y, int x)
+shape_draw(int shape, int y, int x, bool rev)
{
- screen_blitpad(spads[shape], y, x);
+ screen_blitpad(spads[shape], y, x, rev);
}
static void
anim_redraw(void)
{
int i;
+ chtype ch;
/* Redraw screen with all objects */
if (use_color)
for (i = 0; i < NOBJECTS; i++) {
aobject_t *o = &objects[i];
- if (o->t == AOT_SHAPE)
- shape_draw(o->s, o->y, o->x);
- else {
+ if (o->t == AOT_SHAPE) {
+ bool rev = false;
+ int y1, x1, y2, x2;
+
+ /* Verify if collision with avatar */
+ screen_blitpad_rect(spads[o->s], o->y, o->x,
+ &y1, &x1, &y2, &x2);
+ rev = point_in_rect(avatar.x, avatar.y,
+ x1 - 1, y1 - 1, x2 + 1, y2 + 1);
+ shape_draw(o->s, o->y, o->x, rev);
+ } else {
if (use_color && o->col != -1)
(void)attrset(COLOR_PAIR(o->col));
(void)mvaddch(o->y, o->x, o->c);
/* Avatar */
/* XXX */
- (void)attr_on(A_REVERSE, NULL);
- (void)mvaddch(avatar.y, avatar.x, avatar.c);
- (void)attr_off(A_REVERSE, NULL);
+ ch = avatar.c;
+ if (use_attributes)
+ ch |= A_REVERSE;
+ (void)mvaddch(avatar.y, avatar.x, ch);
(void)doupdate();
}
static void screen_cleanup(void);
static inline int int_min(int, int);
+static void screen_blitfill(WINDOW *, int, int);
/* Error to display after screen cleanup if any */
static bool curses_initialized = false;
static WINDOW *screen_window = NULL;
+bool use_color = false;
+bool use_attributes = false;
+
void
screen_init(void)
return (a < b ? a : b);
}
-/* 2d text shape blitting routine */
void
-screen_blitpad(WINDOW *pad, int y, int x)
+screen_blitpad_rect(WINDOW *pad, int y, int x,
+ int *y1, int *x1, int *y2, int *x2)
+{
+ int xs, ys, xo, yo;
+
+ getmaxyx(pad, ys, xs);
+ xo = xs / 2;
+ yo = ys / 2;
+
+ *y1 = y - yo;
+ *y2 = int_min((y - yo) + ys - 1, TERM_LINES - 1);
+ *x1 = x - xo;
+ *x2 = int_min((x - xo) + xs - 1, TERM_COLUMNS - 1);
+}
+
+/*
+ * 2d text shape blitting routine.
+ * XXX
+ * Currently the center of the object is used for its position, but perhaps we
+ * really want to keep the upper-left corner for this.
+ */
+void
+screen_blitpad(WINDOW *pad, int y, int x, bool reverse)
{
int xs, ys, xo, yo;
int_min((y - yo) + ys - 1, TERM_LINES - 1),
int_min((x - xo) + xs - 1, TERM_COLUMNS - 1),
TRUE);
+ if (reverse)
+ screen_blitfill(pad, y, x);
+}
+
+/*
+ * Fills what would normally be the area of the pad to blit by reverse
+ * attribute. Used for collision detection tests visual feedback.
+ */
+static void
+screen_blitfill(WINDOW *pad, int y, int x)
+{
+ int xs, ys, xo, yo, xp, yp, xt, yt;
+ chtype ch;
+
+ if (!use_attributes)
+ return;
+
+ getmaxyx(pad, ys, xs);
+ xo = xs / 2;
+ yo = ys / 2;
+
+ for (yp = y - yo,
+ yt = int_min((y - yo) + ys - 1, TERM_LINES - 1);
+ yp <= yt; yp++) {
+ if (yp < 0)
+ continue;
+ for (xp = x - xo,
+ xt = int_min((x - xo) + xs - 1, TERM_COLUMNS - 1);
+ xp <= xt; xp++) {
+ if (x < 0)
+ continue;
+ ch = mvwinch(screen_window, yp, xp);
+ ch |= A_REVERSE;
+ (void)mvwaddch(screen_window, yp, xp, ch);
+ }
+ }
}
#include <curses.h>
+#include <stdbool.h>
#include <config.h>
void screen_init(void);
int screen_getchar(void);
void screen_error(const char *, ...);
-void screen_blitpad(WINDOW *, int, int);
+void screen_blitpad_rect(WINDOW *, int, int, int *, int *, int *, int *);
+void screen_blitpad(WINDOW *, int, int, bool);
+
+
+extern bool use_color;
+extern bool use_attributes;
#endif
T \---*---Y--+-----+---+--/(
T \------*---*--*---*--/
T '~~ ~~~~~~~~~~~~~~~
-F 24
+F 22
F 2 3
F 2
F 2 2
F 333333333333333333333332
F 33333333333333333333
F
-B 6
+B 1
B
B
B
T ^
F 3 3
F 3
-A EEE
-A EEE
+A BBB
+A E
T o_O
F 444
F 5233325
F 1
+A
+A E
+A B
T Nooooo!
F 1111111
A BBBBBBB
-T _
-T _> >=
-T O-<_--<=
-T >_>=
-T
+T ____
+T o<__ >=
+T /\___/ <
+T < ___ )
+T \/ _\ <
+T o<____>=
+F 11111
+F 5111 17
+F 311111 1
+F 3 111 1
+F 31 11 1
+F 51111117
+A
+A B
+A
+A
+A
+A B
T _
T -=<_>=-
F 7
F 7777777
+A
+A B B