Skip to content

Commit

Permalink
Sun Feb 6 22:55:16 PST 2005
Browse files Browse the repository at this point in the history
    Applied Dave Dodge's patch (but renamed the levels). He writes:

This patch against netwalk-0.4.6 adds several features:

  - A new "Giant" difficulty level with a 50x50 arena.

  - A new "Absurd" difficulty level with a 50x50 wrapped arena.

  - The high score window now computes its height instead of
    using fixed values, so that it can adapt to the number of
    difficulty levels.

  - The middle mouse button toggles marking of a cell.  A marked
    cell simply renders with a different background color.  This makes
    it practical to play very large arenas, because you can (for example)
    mark the cells that you know are have the correct orientation.

  - When working with a wrapped arena and pointing the mouse at an edge
    cell, the corresponding cells on the opposite edges will have
    a very light highlight applied to their border.  This makes it
    practical to play very large wrapped arenas.

                                                  -Dave Dodge

    [netwalk-0.4.7.tgz]
  • Loading branch information
Ben Lynn committed Feb 7, 2005
1 parent 4f21cd8 commit 1e8a163
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.4.6 VERSION=0.4.7
ALLFILES = *.[ch] Makefile LICENSE README NEWS linux/*.[ch] win32/*.[ch] helmetr.ttf ALLFILES = *.[ch] Makefile LICENSE README NEWS linux/*.[ch] win32/*.[ch] helmetr.ttf
PROJNAME = netwalk PROJNAME = netwalk
OS ?= linux OS ?= linux
Expand Down
29 changes: 29 additions & 0 deletions NEWS
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,35 @@
Sun Feb 6 22:55:16 PST 2005
Applied Dave Dodge's patch (but renamed the levels). He writes:

This patch against netwalk-0.4.6 adds several features:

- A new "Giant" difficulty level with a 50x50 arena.

- A new "Absurd" difficulty level with a 50x50 wrapped arena.

- The high score window now computes its height instead of
using fixed values, so that it can adapt to the number of
difficulty levels.

- The middle mouse button toggles marking of a cell. A marked
cell simply renders with a different background color. This makes
it practical to play very large arenas, because you can (for example)
mark the cells that you know are have the correct orientation.

- When working with a wrapped arena and pointing the mouse at an edge
cell, the corresponding cells on the opposite edges will have
a very light highlight applied to their border. This makes it
practical to play very large wrapped arenas.

-Dave Dodge

[netwalk-0.4.7.tgz]

Mon Aug 16 16:25:47 PDT 2004 Mon Aug 16 16:25:47 PDT 2004
Allowed key repeating (to aid textbox editing). Allowed key repeating (to aid textbox editing).


[netwalk-0.4.6.tgz]

Fri Aug 6 13:01:45 PDT 2004 Fri Aug 6 13:01:45 PDT 2004
Implemented suggestions from Denis Klykvin: now loads config file Implemented suggestions from Denis Klykvin: now loads config file
from $HOME/.netwalk/ and if it doesn't exist, a default one will be from $HOME/.netwalk/ and if it doesn't exist, a default one will be
Expand Down
5 changes: 4 additions & 1 deletion README
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
README for NetWalk v0.4.6 README for NetWalk v0.4.7
Ben Lynn Ben Lynn


INTRODUCTION INTRODUCTION
Expand All @@ -14,6 +14,9 @@ USAGE


Click on a square to rotate its contents. A left click performs an Click on a square to rotate its contents. A left click performs an
anticlockwise rotation and a right click performs a clockwise rotation. anticlockwise rotation and a right click performs a clockwise rotation.
A middle click marks a square which has no effect on gameplay but may
be useful. For example, one could mark cells that are known to have the
correct orientation.


There is one shortcut key: F2 starts a new game. There is one shortcut key: F2 starts a new game.


Expand Down
7 changes: 7 additions & 0 deletions colour.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void init_rgbtable()
init_rgb(c_menubg, 0, 50, 0); init_rgb(c_menubg, 0, 50, 0);
init_rgb(c_shadow, 20, 100, 20); init_rgb(c_shadow, 20, 100, 20);
init_rgb(c_darkshadow, 0, 0, 0); init_rgb(c_darkshadow, 0, 0, 0);
/* border highlight for cell that the mouse is pointing at */
init_rgb(c_highlight, 180, 255, 180); init_rgb(c_highlight, 180, 255, 180);
/* border highlight for cell on an opposite edge */
init_rgb(c_edgematch, 127, 127, 127);
init_rgb(c_text, 255, 255, 255); init_rgb(c_text, 255, 255, 255);
init_rgb(c_invtext, 0, 0, 0); init_rgb(c_invtext, 0, 0, 0);
init_rgb(c_canvas, 0, 0, 0); init_rgb(c_canvas, 0, 0, 0);
Expand All @@ -51,6 +54,10 @@ void init_rgbtable()
init_rgb(c_pulse, 255, 255, 255); init_rgb(c_pulse, 255, 255, 255);
init_rgb(c_borderwon, 0, 127, 127); init_rgb(c_borderwon, 0, 127, 127);
init_rgb(c_border, 0, 127, 0); init_rgb(c_border, 0, 127, 0);
/* background color for unmarked tile */
init_rgb(c_unmarkedbg, 0, 0, 0);
/* background color for marked tile */
init_rgb(c_markedbg, 0, 0, 127);
} }


void init_ctable(SDL_PixelFormat *format) void init_ctable(SDL_PixelFormat *format)
Expand Down
3 changes: 3 additions & 0 deletions colour.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ enum {
c_border, c_border,
c_borderwon, c_borderwon,
c_highlight, c_highlight,
c_edgematch,
c_pulse, c_pulse,
c_unmarkedbg,
c_markedbg,
c_max c_max
}; };


Expand Down
12 changes: 12 additions & 0 deletions game.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int boardw = 10, boardh = 9; int boardw = 10, boardh = 9;
int board[boardmaxw][boardmaxh]; int board[boardmaxw][boardmaxh];
int neighbourcount[boardmaxw][boardmaxh]; int neighbourcount[boardmaxw][boardmaxh];
int flags[boardmaxw][boardmaxh];
int sourcex, sourceytop, sourceybottom; int sourcex, sourceytop, sourceybottom;


int wrap_flag = 0; int wrap_flag = 0;
Expand Down Expand Up @@ -63,6 +64,17 @@ void add_dir(int *x, int *y, int x1, int y1, int d)
} }
} }


void clear_flags()
{
int i;
for(i = 0;i < boardw;i++)
{
int j;
for(j = 0;j < boardh;j++)
flags[i][j] = 0;
}
}

void generate_maze() void generate_maze()
{ {
coord_s opentile[boardmaxw * boardmaxh]; coord_s opentile[boardmaxw * boardmaxh];
Expand Down
6 changes: 4 additions & 2 deletions game.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define GAME_H #define GAME_H


enum { enum {
boardmaxw = 20, boardmaxw = 50,
boardmaxh = 20, boardmaxh = 50,
}; };
extern int boardw, boardh; extern int boardw, boardh;
extern int board[boardmaxw][boardmaxh]; extern int board[boardmaxw][boardmaxh];
extern int neighbourcount[boardmaxw][boardmaxh]; extern int neighbourcount[boardmaxw][boardmaxh];
extern int flags[boardmaxw][boardmaxh];
extern int sourcex, sourceytop, sourceybottom; extern int sourcex, sourceytop, sourceybottom;
extern int wrap_flag; extern int wrap_flag;
extern int no_fourway; extern int no_fourway;
Expand All @@ -46,6 +47,7 @@ extern coord_s dir[4];
// | // |
// 2 // 2


void clear_flags();
void generate_maze(); void generate_maze();
int rotatecw(int d, int n); int rotatecw(int d, int n);
void scramble(); void scramble();
Expand Down
155 changes: 135 additions & 20 deletions main.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ enum {
level_medium, level_medium,
level_hard, level_hard,
level_veryhard, level_veryhard,
level_giant,
level_absurd,
level_max, level_max,
level_custom level_custom
}; };
Expand Down Expand Up @@ -623,7 +625,8 @@ void init()
SDL_EnableKeyRepeat(150, 50); SDL_EnableKeyRepeat(150, 50);
} }


SDL_Surface *tileimg[64]; SDL_Surface *unmarked_tileimg[64];
SDL_Surface *marked_tileimg[64];
int level = level_medium; int level = level_medium;
int tick; int tick;
int tick_old; int tick_old;
Expand All @@ -642,8 +645,12 @@ void draw_tile(widget_ptr wid, int i, int j)
rect.x = padding + border + i * (cellw + border); rect.x = padding + border + i * (cellw + border);
rect.y = padding + border + j * (cellh + border); rect.y = padding + border + j * (cellh + border);


int const marked = flags[i][j] & 0x1;
index = board[i][j] - 1; index = board[i][j] - 1;
widget_blit(wid, tileimg[index], NULL, &rect); widget_blit(wid,
(marked?marked_tileimg:unmarked_tileimg)[index],
NULL,
&rect);
} }


typedef struct { typedef struct {
Expand Down Expand Up @@ -738,6 +745,57 @@ void animate_pulse(widget_ptr wid)
} }
} }


/** \brief Determine which cell of the arena the mouse is currently
* pointing at, if any.
* \param wid The arena widget.
* \param mousex The mouse X position.
* \param mousey The mouse Y position.
* \param[out] col_p Returns the current cell's column in the arena.
* \param[out] row_p Returns the current cell's row in the arena.
* \retval 0 The mouse is over the arena and the cell index is returned
* through \a row_p and \a col_p.
* \retval -1 The mouse is not over the area.
*/

int get_cell_from_mouse_position(widget_ptr const wid,
int const mousex,int const mousey,
unsigned int * const col_p,unsigned int * const row_p)
{
if((mousex < wid->x) || (mousey < wid->y))
return -1;

unsigned int const col =
(mousex - padding - border - wid->x) / (cellw + border);
unsigned int const row =
(mousey - padding - border - wid->y) / (cellh + border);

if((col >= boardw) || (row >= boardh))
return -1;

*col_p = col;
*row_p = row;
return 0;
}

/** \brief Fill a cell (including border) in the arena with a color.
* \param wid The arena widget.
* \param col The column of the cell to be filled.
* \param row The row of the cell to be filled.
* \param coloridx The index of the color to use when filling.
*/

void fill_arena_cell(widget_ptr const wid,
unsigned int const col,unsigned int const row,int const coloridx)
{
SDL_Rect rect = {
.x = (cellw + border) * col + padding,
.y = (cellh + border) * row + padding,
.w = cellw + 2 * border,
.h = cellh + 2 * border
};
widget_fillrect(wid, &rect, coloridx);
}

void arena_update(widget_ptr wid) void arena_update(widget_ptr wid)
{ {
int i, j; int i, j;
Expand Down Expand Up @@ -768,15 +826,32 @@ void arena_update(widget_ptr wid)
} }


//highlight cursor //highlight cursor
if (lastmousex > wid->x && lastmousey > wid->y) { unsigned int col;
i = (lastmousex - padding - border - wid->x) / (cellw + border); unsigned int row;
j = (lastmousey - padding - border - wid->y) / (cellh + border); if(get_cell_from_mouse_position(wid,lastmousex,lastmousey,&col,&row) == 0)
if (i < boardw && j < boardh) { {
rect.x = (cellw + border) * i + padding; /* highlight the cell the mouse is pointing at */
rect.y = (cellh + border) * j + padding; fill_arena_cell(wid,col,row,c_highlight);
rect.w = cellw + 2 * border;
rect.h = cellh + 2 * border; if(wrap_flag)
widget_fillrect(wid, &rect, c_highlight); {
/*
* If the highlighted cell is an edge cell, also
* highlight the corresponding cells on opposite
* edges. This will make it easier to work with large
* wrapped grids.
*/
if(col == 0)
fill_arena_cell(wid,boardw - 1,row,c_edgematch);
else
if(col == boardw - 1)
fill_arena_cell(wid,0,row,c_edgematch);

if(row == 0)
fill_arena_cell(wid,col,boardh - 1,c_edgematch);
else
if(row == boardh - 1)
fill_arena_cell(wid,col,0,c_edgematch);
} }
} }


Expand Down Expand Up @@ -939,7 +1014,7 @@ void check_hs()
} }
} }


void init_tileimg() void init_tileimg(SDL_Surface * tileimg[64],int bgcolor)
{ {
int i, j; int i, j;
SDL_PixelFormat *fmt = screen->format; SDL_PixelFormat *fmt = screen->format;
Expand All @@ -951,9 +1026,19 @@ void init_tileimg()
pipew = cellw / 2 + pipet / 2; pipew = cellw / 2 + pipet / 2;
pipeh = cellh / 2 + pipet / 2; pipeh = cellh / 2 + pipet / 2;


SDL_Rect entirecell = (SDL_Rect){
.x = 0,
.y = 0,
.w = cellw,
.h = cellh
};

for (i=0; i<64; i++) { for (i=0; i<64; i++) {
tileimg[i] = SDL_CreateRGBSurface(0, cellw, cellh, fmt->BitsPerPixel, tileimg[i] = SDL_CreateRGBSurface(0, cellw, cellh, fmt->BitsPerPixel,
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask); fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);

SDL_FillRect(tileimg[i], &entirecell, ctable[bgcolor]);

for (j=0; j<4; j++) { for (j=0; j<4; j++) {
if ((i + 1) & (1 << j)) { if ((i + 1) & (1 << j)) {
switch (j) { switch (j) {
Expand Down Expand Up @@ -1071,18 +1156,31 @@ void resize()
widget_put_geometry((widget_ptr) l_about2, 10, 30, 60, vsize); widget_put_geometry((widget_ptr) l_about2, 10, 30, 60, vsize);
widget_put_geometry((widget_ptr) b_about1, 30, 80, 30, vsize); widget_put_geometry((widget_ptr) b_about1, 30, 80, 30, vsize);


/* vertical sizes and positions for the high score window */
int const hslabely = 5;
int const hslabelheight = vsize;
int const hslisty = hslabely + hslabelheight + 8;
int const hslisteachheight = vsize;
int const hslistheight = hslisteachheight * level_max;
int const hsoky = hslisty + hslistheight + 8;
int const hsokheight = vsize;
int const hswindowheight = hsoky + hsokheight + 5;

widget_put_geometry((widget_ptr) hs_window, widget_put_geometry((widget_ptr) hs_window,
w/2 - 75, h/2 - 60, 150, 120); w/2 - 75, h/2 - 60, 170, hswindowheight);
widget_put_geometry((widget_ptr) l_hs1, 10, 5, 60, vsize); widget_put_geometry((widget_ptr) l_hs1, 10, hslabely, 60, hslabelheight);
widget_put_geometry((widget_ptr) b_hs1, 100, 100, 30, vsize); widget_put_geometry((widget_ptr) b_hs1, 100, hsoky, 30, hsokheight);


{ {
int i; int i;
for (i=0; i<level_max; i++) { for (i=0; i<level_max; i++) {
int y = vsize * i + 8 + vsize; int y = hslisty + (hslisteachheight * i);
widget_put_geometry((widget_ptr) hsw[i]->level, 10, y, 20, vsize); widget_put_geometry((widget_ptr) hsw[i]->level,
widget_put_geometry((widget_ptr) hsw[i]->time, 60, y, 20, vsize); 10, y, 20, hslisteachheight);
widget_put_geometry((widget_ptr) hsw[i]->name, 90, y, 20, vsize); widget_put_geometry((widget_ptr) hsw[i]->time,
60, y, 20, hslisteachheight);
widget_put_geometry((widget_ptr) hsw[i]->name,
90, y, 20, hslisteachheight);
} }
} }


Expand Down Expand Up @@ -1121,12 +1219,23 @@ void new_game()
wrap_flag = 1; wrap_flag = 1;
no_fourway = 1; no_fourway = 1;
break; break;
case level_giant:
boardw = 50; boardh = 50;
wrap_flag = 0;
no_fourway = 1;
break;
case level_absurd:
boardw = 50; boardh = 50;
wrap_flag = 1;
no_fourway = 1;
break;
default: default:
break; break;
} }
resize(); resize();
srand(time(NULL)); srand(time(NULL));
generate_maze(); generate_maze();
clear_flags();
scramble(); scramble();
check_live(); check_live();
reset_move_count(); reset_move_count();
Expand Down Expand Up @@ -1225,6 +1334,9 @@ void arena_handle_click(widget_ptr p, int button, int x, int y)
board[sourcex][sourceytop] |= board[sourcex][sourceybottom] & 1; board[sourcex][sourceytop] |= board[sourcex][sourceybottom] & 1;
board[sourcex][sourceybottom] &= ~1; board[sourcex][sourceybottom] &= ~1;


if(button == SDL_BUTTON_MIDDLE)
flags[i][j] ^= 0x1;

check_live(); check_live();
if (game_won) { if (game_won) {
pulse_count = 0; pulse_count = 0;
Expand Down Expand Up @@ -1432,6 +1544,8 @@ int main(int argc, char *argv[])
level_name[level_medium] = "Normal"; level_name[level_medium] = "Normal";
level_name[level_hard] = "Nerd"; level_name[level_hard] = "Nerd";
level_name[level_veryhard] = "Nutcase"; level_name[level_veryhard] = "Nutcase";
level_name[level_giant] = "Nonsense";
level_name[level_absurd] = "No Sleep";


//setup shifttable //setup shifttable
{ {
Expand Down Expand Up @@ -1605,7 +1719,8 @@ int main(int argc, char *argv[])


update_hsw(); update_hsw();


init_tileimg(); init_tileimg(unmarked_tileimg,c_unmarkedbg);
init_tileimg(marked_tileimg,c_markedbg);
new_game(); new_game();


while (state != state_quit && !interrupted) { while (state != state_quit && !interrupted) {
Expand Down

0 comments on commit 1e8a163

Please sign in to comment.