source: mainline/uspace/app/tetris/shapes.c@ 5ef16903

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5ef16903 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** Attributations
30 *
31 * shapes.c 8.1 (Berkeley) 5/31/93
32 * NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd
33 * OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt
34 *
35 * Based upon BSD Tetris
36 *
37 * Copyright (c) 1992, 1993
38 * The Regents of the University of California.
39 * Distributed under BSD license.
40 *
41 * This code is derived from software contributed to Berkeley by
42 * Chris Torek and Darren F. Provine.
43 *
44 */
45
46/** @addtogroup tetris
47 * @{
48 */
49/** @file
50 */
51
52/*
53 * Tetris shapes and related routines.
54 *
55 * Note that the first 7 are `well known'.
56 */
57
58#include "tetris.h"
59
60#define TL (-B_COLS - 1) /* top left */
61#define TC (-B_COLS) /* top center */
62#define TR (-B_COLS + 1) /* top right */
63#define ML -1 /* middle left */
64#define MR 1 /* middle right */
65#define BL (B_COLS - 1) /* bottom left */
66#define BC B_COLS /* bottom center */
67#define BR (B_COLS + 1) /* bottom right */
68
69const struct shape shapes[] = {
70 /* 0 */ { 7, 7, { TL, TC, MR }, 0x00aaaa},
71 /* 1 */ { 8, 8, { TC, TR, ML }, 0x00aa00},
72 /* 2 */ { 9, 11, { ML, MR, BC }, 0xaa5500},
73 /* 3 */ { 3, 3, { TL, TC, ML }, 0x0000aa},
74 /* 4 */ { 12, 14, { ML, BL, MR }, 0xaa00aa},
75 /* 5 */ { 15, 17, { ML, BR, MR }, 0xffa500},
76 /* 6 */ { 18, 18, { ML, MR, 2 }, 0xaa0000}, /* sticks out */
77 /* 7 */ { 0, 0, { TC, ML, BL }, 0x00aaaa},
78 /* 8 */ { 1, 1, { TC, MR, BR }, 0x00aa00},
79 /* 9 */ { 10, 2, { TC, MR, BC }, 0xaa5500},
80 /* 10 */ { 11, 9, { TC, ML, MR }, 0xaa5500},
81 /* 11 */ { 2, 10, { TC, ML, BC }, 0xaa5500},
82 /* 12 */ { 13, 4, { TC, BC, BR }, 0xaa00aa},
83 /* 13 */ { 14, 12, { TR, ML, MR }, 0xaa00aa},
84 /* 14 */ { 4, 13, { TL, TC, BC }, 0xaa00aa},
85 /* 15 */ { 16, 5, { TR, TC, BC }, 0xffa500},
86 /* 16 */ { 17, 15, { TL, MR, ML }, 0xffa500},
87 /* 17 */ { 5, 16, { TC, BC, BL }, 0xffa500},
88 /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0xaa0000} /* sticks out */
89};
90
91/*
92 * Return true iff the given shape fits in the given position,
93 * taking the current board into account.
94 */
95int fits_in(const struct shape *shape, int pos)
96{
97 const int *o = shape->off;
98
99 if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) ||
100 (board[pos + *o]))
101 return 0;
102
103 return 1;
104}
105
106/*
107 * Write the given shape into the current board, turning it on
108 * if `onoff' is 1, and off if `onoff' is 0.
109 */
110void place(const struct shape *shape, int pos, int onoff)
111{
112 const int *o = shape->off;
113
114 board[pos] = onoff ? shape->color : 0x000000;
115 board[pos + *o++] = onoff ? shape->color : 0x000000;
116 board[pos + *o++] = onoff ? shape->color : 0x000000;
117 board[pos + *o] = onoff ? shape->color : 0x000000;
118}
119
120/** @}
121 */
Note: See TracBrowser for help on using the repository browser.