Sie sind auf Seite 1von 17

// Libraries

#include <TVout.h>
#include <fontALL.h>
//#include "stc.h"
//#include "platform.h"
//#include "bitmaps.h"
#include "tones.h"
//#include <avr/pgmspace.h>
#include <i2cmaster.h>
#include <nunchuc.h>
!unchuc controller"
// # assume these are defining the output dimmensions of our screen.
//#define $ %&&2'
//#define ( %)*'
#define +,A-./L01T/2 %23'
#define +,A-./T,4/5 %6'
#define +,A-./$#.T( %32'
#define +,A-./(0#7(T %8&'
#define +L,9:/$#.T( %3'
#define +L,9:/L01T/,11;0T %<'
#define +L,9:/T,4/,11;0T %2'
#define ;TA-T/2 %<'
#define ;TA-T/5 %*'
unsigned int #/=4/.,$! > *b&***&***&***&***"
unsigned int #/L01T/-#7(T > *b&&&&************"
unsigned int ,/A!5 > *b&&**&&**********"
unsigned int T/=4 > *b*&**&&&*********"
unsigned int T/-#7(T > *b&***&&**&*******"
unsigned int T/.,$! > *b&&&**&**********"
unsigned int T/L01T > *b*&**&&***&******"
unsigned int ;/=4/.,$! > *b&***&&***&******"
unsigned int ;/L01T/-#7(T > *b*&&*&&**********"
unsigned int ?/=4/.,$! > *b*&**&&**&*******"
unsigned int ?/L01T/-#7(T > *b&&***&&*********"
unsigned int L/=4 > *b**&*&&&*********"
unsigned int L/.,$! > *b&&&*&***********"
unsigned int L/L01T > *b&&***&***&******"
unsigned int L/-#7(T > *b&***&***&&******"
unsigned int @/=4 > *b&***&&&*********"
unsigned int @/.,$! > *b&&&***&*********"
unsigned int @/L01T > *b*&***&**&&******"
unsigned int @/-#7(T > *b&&**&***&*******"
boolean get+ool%unsigned int arraAB int C#ndB int A#nd' D
int to;hift > *"
to;hift E> %<FC#nd'"
to;hift E> 3G%<FA#nd'"
int bit!oH > %arraA >> to;hift' I *b&"
return %bit!oH >> &'"
J
unsigned int set+ool%unsigned int arraAB boolean to;etB int C#ndB int A#nd' D
int to;hift > *"
to;hift E> %<FC#nd'"
to;hift E> 3G%<FA#nd'"
int bit!oH > *"
if %to;et' bit!oH > &"
int current+it > % arraA >> to;hift ' I *b&"
//bit!oH > bit!oH << to;hift"

if %current+it >> bit!oH' D J
else if %current+it >> *' D
arraA E> & << to;hift"
J
else D // current+it >> &
arraA F> & << to;hift"
J

return arraA"
J
enum piece D
# > *B
, > &B
T > 2B
; > <B
? > 3B
@ > KB
L > L J"

TVout TV" //declaring the obMect to send signals to
boolean gameboardN&*ON2*O" // The arraA that stores Hich blocs are active
int level > *" // ;tores the current level
int score > *" // ;tores the current score
int lines > *" // ;tores the number of lines completed
boolean current4ieceN3ON3O"
boolean neCt4ieceN3ON3O"
int current4iece2 > ;TA-T/2"
int current4iece5 > ;TA-T/5"
boolean c4ressed > false"
boolean P4ressed > false"
boolean up4ressed > false"
boolean doHn4ressed > false"
int cAcle9ount > *"
int cAclesTo.rop > &**"
boolean readA1or!eCt4iece > true"
int orientation > *"
int neCt;hape > F&"
int current;hape > F&"
boolean readA1orLeft > true"
int left9ount > *"
boolean readA1or-ight > true"
int right9ount > *"
int temp9Acle > *"
int roHs1ullN3O"
boolean game,ver > false"
boolean firstTime > true"
//void intro%'"
//void printboard%'"
//void set9ell%char CB char ABchar bCB char bAB char cB char f'"
void setup%' D
//;erial.begin%)L**'"

// #nitialiPe random number generator
random;eed%analog-ead%*''"
random%*B6'"
random%*B6'"

// #nitialiPes the ArraA bA setting the entire gameboard to off
setAll+locs%false'"

// #nitialiPe !unchuc 9ontroller
if %controller.begin%!=!9(=9:/4LA50-/&'' D
TV.print%"!unchuc begin error"'"
Hhile%&'"
J

// #nitialiPe TVout
TV.begin%/!T;9B&&2B)*'"
TV.select/font%fontLC8'"
draH+oardTeCt%'"
// #nitialiPe Tetris ;creen
draH+oardLines%'"
draH+locs%'"
mae!eH4iece%'"
draH!eCt4iece%'"
J
void loop%' D
if %firstTime' D
hold;creen%'"
firstTime > false"
J
if %Qgame,ver' D
update7ame%'"
J
else D
start!eH7ame%'"
J
J
// =pdates the game
void update7ame%' D
get9ontroller#nput%'"
move.oHn%'"
updateRusic%'"
J
void updateRusic%'
D
static unsigned char current/note > *"
static long neCt/note/start/time > *"
if %TV.millis%' >> neCt/note/start/time'
D
if %current/note >> ;,!7/L0!7T('
D
//itSs the end of the songQ
current/note > *"
J

int note/duration > %pgm/read/Hord/near%duration/t&/c& E current/note'/&L'GK"
neCt/note/start/time > TV.millis%'Enote/durationE4A=;0/+0T$00!/!,T0;"
TV.tone%pgm/read/Hord/near%melodA/t&/c& E current/note'B note/duration'"
if %current/note >> ;,!7/L0!7T(F&'
D
neCt/note/start/time E> 4A=;0/+0T$00!/;,!7;"
neCt/note/start/time F> 4A=;0/+0T$00!/!,T0;"
J
current/noteEE"

J
J
void start!eH7ame%' D
TV.draH/rect%<*B&<B<3B3)B+LA9:B+LA9:'"
TV.print47R%<KB&KB4;T-%"7ame"''"
TV.print47R%<KB26B4;T-%",ver"''"
TV.print47R%<2B32B4;T-%"4ress"''"
TV.print47R%32BK3B4;T-%"?"''"

controller.update%'"

Hhile% Q %controller.button/P%'' ' D
controller.update%'"
J

TV.clear/screen%'"
setAll+locs%false'"
level > *"
score > *"
lines > *"
current4iece2 > ;TA-T/2"
current4iece5 > ;TA-T/5"
c4ressed > false"
P4ressed > false"
up4ressed > false"
doHn4ressed > false"
cAcle9ount > *"
cAclesTo.rop > &**"
readA1or!eCt4iece > true"
orientation > *"
neCt;hape > F&"
current;hape > F&"
readA1orLeft > true"
left9ount > *"
readA1or-ight > true"
right9ount > *"
temp9Acle > *"
game,ver > false"
firstTime > true"
draH+oardTeCt%'"
draH+oardLines%'"
draH+locs%'"
mae!eH4iece%'"
draH!eCt4iece%'"
J
void hold;creen%' D
TV.print47R%<2B2)B4;T-%"4ress"''"
TV.print47R%32B3&B4;T-%"?"''"

controller.update%'"

Hhile% Q %controller.button/P%' ' ' D
controller.update%'"
J

TV.draH/rect%<*B2)B<*B&8B+LA9:B+LA9:'"
J
// -eads the controller input
void get9ontroller#nput%' D
controller.update%'"

boolean c!oHB P!oHB left!oHB right!oHB doHn!oH"

c!oH > controller.button/c%'"
P!oH > controller.button/P%'"
left!oH > controller.MoA/left%'"
right!oH > controller.MoA/right%'"
doHn!oH > controller.MoA/doHn%'"

if %c!oH II Qc4ressed' D
Hhile%controller.button/c%'' D
controller.update%'" J
pause%'" J
else if %P!oH II QP4ressed' rotate;hape%'"
else if %left!oH II readA1orLeft' D
move;hapeLeft%'"
readA1orLeft > false"
J
else if %QreadA1orLeft' D
if %left!oH' D
left9ountEE"
J
else D
readA1orLeft > true"
J
if %left9ount >> <*' D
readA1orLeft > true"
left9ount > *"
J
J
else if %right!oH II readA1or-ight' D
move;hape-ight%'"
readA1or-ight > false"
J
else if %QreadA1or-ight' D
if %right!oH' D
right9ountEE"
J
else D
readA1or-ight > true"
J
if %right9ount >> <*' D
readA1or-ight > true"
right9ount > *"
J
J
else if %doHn!oH II QdoHn4ressed' accelerate.oHn%'"
else if %QdoHn!oH II doHn4ressed' normal.oHn%'"

c4ressed > c!oH"
P4ressed > P!oH"
doHn4ressed > doHn!oH"
J
// -otates the shapeB if legal
void rotate;hape%' D
if %current;hape >> #' D
if %%orientation >> =4 TT orientation >> .,$!' II is-oomTo-otateTo%#/L01T/-#7(T'' D
sHap;hape%#/L01T/-#7(T'"
orientation > -#7(T"
J
else if %%orientation >> -#7(T TT orientation >> L01T' II is-oomTo-otateTo%#/=4/.,$!'' D
sHap;hape%#/=4/.,$!'"
orientation > =4"
J
J
else if %current;hape >> *' D

J
else if %current;hape >> T' D
if %orientation >> =4 II is-oomTo-otateTo%T/-#7(T'' D
sHap;hape%T/-#7(T'"
orientation > -#7(T"
J
else if %orientation >> -#7(T II is-oomTo-otateTo%T/.,$!'' D
sHap;hape%T/.,$!'"
orientation > .,$!"
J
else if %orientation >> .,$! II is-oomTo-otateTo%T/L01T'' D
sHap;hape%T/L01T'"
orientation > L01T"
J
else if %orientation >> L01T II is-oomTo-otateTo%T/=4'' D
sHap;hape%T/=4'"
orientation > =4"
J
J
else if %current;hape >> ;' D
if %%orientation >> =4 TT orientation >> .,$!' II is-oomTo-otateTo%;/L01T/-#7(T'' D
sHap;hape%;/L01T/-#7(T'"
orientation > -#7(T"
J
else if %orientation >> -#7(T II is-oomTo-otateTo%;/=4/.,$!'' D
sHap;hape%;/=4/.,$!'"
orientation > =4"
J
J
else if %current;hape >> ?' D
if %%orientation >> =4 TT orientation >> .,$!' II is-oomTo-otateTo%?/L01T/-#7(T'' D
sHap;hape%?/L01T/-#7(T'"
orientation > -#7(T"
J
else if %%orientation >> -#7(T TT orientation >> L01T' II is-oomTo-otateTo%?/=4/.,$!'' D
sHap;hape%?/=4/.,$!'"
orientation > =4"
J
J
else if %current;hape >> @' D
if %orientation >> =4 II is-oomTo-otateTo%@/-#7(T'' D
sHap;hape%@/-#7(T'"
orientation > -#7(T"
J
else if %orientation >> -#7(T II is-oomTo-otateTo%@/.,$!'' D
sHap;hape%@/.,$!'"
orientation > .,$!"
J
else if %orientation >> .,$! II is-oomTo-otateTo%@/L01T'' D
sHap;hape%@/L01T'"
orientation > L01T"
J
else if %orientation >> L01T II is-oomTo-otateTo%@/=4'' D
sHap;hape%@/=4'"
orientation > =4"
J
J
else if %current;hape >> L' D // current;hape >> L
if %orientation >> =4 II is-oomTo-otateTo%L/-#7(T'' D
sHap;hape%L/-#7(T'"
orientation > -#7(T"
J
else if %orientation >> -#7(T II is-oomTo-otateTo%L/.,$!'' D
sHap;hape%L/.,$!'"
orientation > .,$!"
J
else if %orientation >> .,$! II is-oomTo-otateTo%L/L01T'' D
sHap;hape%L/L01T'"
orientation > L01T"
J
else if %orientation >> L01T II is-oomTo-otateTo%L/=4'' D
sHap;hape%L/=4'"
orientation > =4"
J
J
J
// eCchanges the old shape for the neH oneB as for a rotation
// does not chec if the sHap is legal
void sHap;hape%unsigned int neH;hape' D
for %int C#nd > *" C#nd <> <" C#ndEE' D
for %int A#nd > *" A#nd <> <" A#ndEE' D
boolean neH+ool > get+ool%neH;hapeBC#ndBA#nd'"
if %current4ieceNC#ndONA#ndO II neH+ool' DJ // #f Has on before and on noHB do nothing
else if %current4ieceNC#ndONA#ndO' D // #f on before and off noHB turn off
erase7rid+loc%current4iece2 E C#ndB current4iece5 E A#nd'"
J
else if %neH+ool' D // #f Has off before and on noHB turn on
draH7rid+loc%current4iece2 E C#ndB current4iece5 E A#nd'"
J
current4ieceNC#ndONA#ndO > neH+ool"
J
J
J
boolean is-oomTo-otateTo%unsigned int neH;hape' D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %gameboardNcurrent4iece2 E C4osONcurrent4iece5 E A4osO II get+ool%neH;hapeB C4osB A4os''
return false"
if %get+ool%neH;hapeB C4osB A4os' II %current4iece2 E C4os > )'' return false"
if %get+ool%neH;hapeB C4osB A4os' II %current4iece5 E A4os > &)'' return false"
J
J
return true"
J
// moves the shape leftB if legal
void move;hapeLeft%' D
if %current4iece2 > * II is-oomToRoveLeft%'' D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' erase7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
current4iece2 > current4iece2 F &"
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' draH7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
J
J
boolean is-oomToRoveLeft%' D
for %int A4os > *" A4os <> <" A4osEE' D
for %int C4os > *" C4os <> <" C4osEE' D
if %current4ieceNC4osONA4osO II gameboardNcurrent4iece2 E C4os F &ONcurrent4iece5 E A4osO'
return false"
J
J
return true"
J
// Roves the shape rightB if legal
void move;hape-ight%' D
if %is-oomToRove-ight%'' D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' erase7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
current4iece2 > current4iece2 E &"
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' draH7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
J
J
boolean is-oomToRove-ight%' D
int far-ight > farthest-ight4osition%'"
if %far-ight E current4iece2 E & > )' return false"
for %int A4os > *" A4os <> <" A4osEE' D
for %int C4os > far-ight" C4os >> *" C4os FF' D
if %current4ieceNC4osONA4osO II gameboardNcurrent4iece2 E C4os E &ONcurrent4iece5 E A4osO'
return false"
J
J
return true"
J
int farthest-ight4osition%' D
for%int C4os > <" C4os >> *" C4osFF' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' return C4os"
J
J
return F&"
J
// Roves the shape doHn at a faster pace
void accelerate.oHn%' D
temp9Acle > cAclesTo.rop"
cAclesTo.rop > &*"
J
// -eturns the shapeSs doHnHard velocitA to normal levels
void normal.oHn%' D
cAclesTo.rop > temp9Acle"
J
void move.oHn%' D
if %readA1or!eCt4iece' D
load!eCt4iece%'"
current4iece2 > ;TA-T/2"
current4iece5 > ;TA-T/5"
mae!eH4iece%'"
draH!eCt4iece%'"
readA1or!eCt4iece > false"
draH9urrent4iece%'"
if %game,ver' return"
J

if %cAcle9ount >> cAclesTo.rop' D
cAcle9ount > *"
if %is-oomToRove.oHn%'' D
//if %current4iece5 E farthest.oHn4osition%' < &)' D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' erase7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
current4iece5 > current4iece5 E &"
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' draH7rid+loc%current4iece2 E C4osB current4iece5 E A4os'"
J
J
J
else D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %current4ieceNC4osONA4osO' gameboardNcurrent4iece2 E C4osONcurrent4iece5 E A4osO > true"
J
J
chec1or-oHs%'"
readA1or!eCt4iece > true"
J
J
cAcle9ountEE"
J
void chec1or-oHs%' D
emptA-oHList%'"
int num > *"
boolean done > false"
boolean roH!ot0mptA > false"
boolean roH1ull > true"
for %int A4os > &)" A4os >>*" A4osFF' D
for %int C4os > *" C4os <> )" C4osEE' D
roH!ot0mptA > roH!ot0mptA TT gameboardNC4osONA4osO"
roH1ull > roH1ull II gameboardNC4osONA4osO"
J
if %QroH!ot0mptA' brea"
roH!ot0mptA > false"
if %roH1ull' D
marAs1ull%A4osB num'"
numEE"
J
roH1ull > true"
J
score4oints%'"
J
void emptA-oHList%' D
for %int i > *" i<><" iEE' D
roHs1ullNiO > F&"
J
J
void marAs1ull%int roHB int num' D
roHs1ullNnumO > roH"
J
void score4oints%' D
int num > *"
for %int i > *" i<><" iEE' D
if %roHs1ullNiO Q> F&' D
erase-oHAnd;hift%roHs1ullNiO E num'"
numEE"
J
J
score E> numGnumG2*"
lines E> num"
TV.print%6KB2*B score'"
TV.print%6KB3*B lines'"
updateLevel%'"
J
void updateLevel%' D
level > min%2)Bfloor%lines/&*''"
TV.print%)KB*B level'"
cAclesTo.rop > &** F < G level"
J
void erase-oHAnd;hift%int roH' D
int current-oH > roH"
boolean roH!ot0mptA > false"

for %int A4os > roH" A4os >> *" A4osFF' D
for %int C4os > *" C4os <>)" C4osEE' D
roH!ot0mptA > roH!ot0mptA TT gameboardNC4osONA4osO"
if %gameboardNC4osONA4osO' erase7rid+loc%C4osB A4os'"
if %A4os > *' D
if %gameboardNC4osONA4os F &O' draH7rid+loc%C4osB A4os'"
gameboardNC4osONA4osO > gameboardNC4osONA4os F &O"
J
J
if %QroH!ot0mptA' brea"
roH!ot0mptA > false"
J
J
boolean is-oomToRove.oHn%' D
int bottom > farthest.oHn4osition%'"
if %bottom E current4iece5 E & > &)' return false"
for %int A4os > bottom" A4os >> *" A4osFF' D
for %int C4os > *" C4os <> <" C4osEE' D
if %current4ieceNC4osONA4osO II gameboardNcurrent4iece2 E C4osONcurrent4iece5 E A4os E &O'
return false"
J
J
return true"
J
int farthest.oHn4osition%' D
for%int A4os > <" A4os >> *" A4osFF' D
for %int C4os > *" C4os <> <" C4osEE' D
if %current4ieceNC4osONA4osO' return A4os"
J
J
return F&"
J
void draH9urrent4iece%' D
for %int C#nd > *" C#nd <> <" C#ndEE' D
for %int A#nd > *" A#nd <> <" A#ndEE' D
if %current4ieceNC#ndONA#ndO' D
draH7rid+loc%current4iece2 E C#ndB current4iece5 E A#nd'"
if %gameboardNcurrent4iece2 E C#ndONcurrent4iece5 E A#ndO' game,ver > true"
J J J J


// Loads neCt piece
void load!eCt4iece%' D
for %int C#nd > *" C#nd <> <" C#ndEE' D
for %int A#nd > *" A#nd <> <" A#ndEE' D
current4ieceNC#ndONA#ndO > neCt4ieceNC#ndONA#ndO"
J J J
// 4auses the game until the plaAer pushes the 9 button
void pause%' D
TV.print%*B2KB"4aus"'"

controller.update%'"
Hhile%Qcontroller.button/c%'' D
controller.update%'"
updateRusic%'"
J
Hhile%controller.button/c%'' D
controller.update%'"
updateRusic%'"
J

TV.draH/rect%*B2KB22B8B+LA9:B+LA9:'"
J
// .raHs the lines around the tetris board
void draH+oardLines%' D
TV.draH/line%+,A-./L01T/2B +,A-./T,4/5B +,A-./L01T/2B +,A-./T,4/5 E
+,A-./(0#7(TB $(#T0'"
TV.draH/line%+,A-./L01T/2B +,A-./T,4/5 E +,A-./(0#7(TB +,A-./L01T/2 E
+,A-./$#.T(B +,A-./T,4/5 E +,A-./(0#7(TB$(#T0'"
TV.draH/line%+,A-./L01T/2 E +,A-./$#.T(B +,A-./T,4/5B +,A-./L01T/2 E
+,A-./$#.T(B +,A-./T,4/5 E +,A-./(0#7(TB$(#T0'"
J
void draH+oardTeCt%' D
TV.print47R%*B*B4;T-%"!eCt"''"
TV.print47R%6*B*B4;T-%"lvl"''"
TV.print%)KB*B level'"
TV.print47R%6*B&&B4;T-%";core"''"
TV.print%6KB2*B score'"
TV.print47R%6*B<&B4;T-%"Lines"''"
TV.print%6KB3*B lines'"
J
// .raHs a bloc around the specified coordinates
void draH+loc%int C/posB int A/pos' D
TV.set/piCel%C/posE&B A/posE&B $(#T0'"
TV.set/piCel%C/posE&B A/posB $(#T0'"
TV.set/piCel%C/posE&B A/posF&B $(#T0'"
TV.set/piCel%C/posB A/posE&B $(#T0'"
TV.set/piCel%C/posB A/posF&B $(#T0'"
TV.set/piCel%C/posF&B A/posE&B $(#T0'"
TV.set/piCel%C/posF&B A/posB $(#T0'"
TV.set/piCel%C/posF&B A/posF&B $(#T0'"
J
void draH7rid+loc%int C#ndeCB int A#ndeC' D
draH+loc%+L,9:/$#.T(GC#ndeC E +,A-./L01T/2 E +L,9:/L01T/,11;0TB
%+L,9:/$#.T(GA#ndeC'E +,A-./T,4/5 E +L,9:/T,4/,11;0T'"
J
void erase7rid+loc%int C#ndeCB int A#ndeC' D
erase+loc%+L,9:/$#.T(GC#ndeC E +,A-./L01T/2 E +L,9:/L01T/,11;0TB
%+L,9:/$#.T(GA#ndeC'E +,A-./T,4/5 E +L,9:/T,4/,11;0T'"
J
// 0rases a bloc around the specified coordinates
void erase+loc%int C/posB int A/pos' D
TV.set/piCel%C/posE&B A/posE&B +LA9:'"
TV.set/piCel%C/posE&B A/posB +LA9:'"
TV.set/piCel%C/posE&B A/posF&B +LA9:'"
TV.set/piCel%C/posB A/posE&B +LA9:'"
TV.set/piCel%C/posB A/posF&B +LA9:'"
TV.set/piCel%C/posF&B A/posE&B +LA9:'"
TV.set/piCel%C/posF&B A/posB +LA9:'"
TV.set/piCel%C/posF&B A/posF&B +LA9:'"
J
// Turns on or off all blocs
void setAll+locs%boolean to;et' D
for%int C#ndeC > *" C#ndeC <>)" C#ndeCEE' D
for%int A#ndeC > *" A#ndeC<>&)" A#ndeCEE' D
gameboardNC#ndeCONA#ndeCO>to;et"
J
J
J
// .raHs blocs based on the grid stored in the gameboard arraA
void draH+locs%' D
TV.draH/rect%2LB8B<)B6)B+LA9:B+LA9:'"
for%int C#ndeC > *" C#ndeC <>)" C#ndeCEE' D
for%int A#ndeC > *" A#ndeC<>&)" A#ndeCEE' D
if %gameboardNC#ndeCONA#ndeCO' D
draH+loc%+L,9:/$#.T(GC#ndeC E +,A-./L01T/2 E +L,9:/L01T/,11;0TB
%+L,9:/$#.T(GA#ndeC'E +,A-./T,4/5 E +L,9:/T,4/,11;0T'"
J J J J
// .raHs the piCel art of $=B that fits Hithin a <) C 32 bloc
void draH$=%' D

J
// 7enerates a neH random piece and stores it in the neCt4iece ArraA
void mae!eH4iece%' D
int rand > %int'%random%*B6''"
fill!eCt4iece%false'"
if %rand >> #' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%#/L01T/-#7(TB CiB Ai'"
J
J
orientation > -#7(T"
J
else if %rand >> ,' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%,/A!5B CiB Ai'"
J
J
orientation > =4"
J
else if %rand >> T' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%T/=4B CiB Ai'"
J
J
orientation > =4"
J
else if %rand >> ;' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%;/L01T/-#7(TB CiB Ai'"
J
J
orientation > -#7(T"
J
else if %rand >> ?' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%?/L01T/-#7(TB CiB Ai'"
J
J
orientation > -#7(T"
J
else if %rand >> @' D
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%@/=4B CiB Ai'"
J
J
orientation > =4"
J
else if %rand >> L' D // rand >> L
for %int Ci > *" Ci<><" CiEE' D
for %int Ai > *" Ai<><" AiEE' D
neCt4ieceNCiONAiO > get+ool%L/.,$!B CiB Ai'"
J
J
orientation > .,$!"
J
current;hape > neCt;hape"
neCt;hape > rand"
J
// 1ills the neCt4iece arraA Hith the given value
void fill!eCt4iece%boolean to1ill'
D
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
neCt4ieceNC4osONA4osO > to1ill"
J J J
// .raHs the neCt piece under the "!eCt" heading
void draH!eCt4iece%'
D
TV.draH/rect%2B)B&6B&6B+LA9:B+LA9:'"
for %int C4os > *" C4os <> <" C4osEE' D
for %int A4os > *" A4os <> <" A4osEE' D
if %neCt4ieceNC4osONA4osO' D
draH+loc%3 E +L,9:/$#.T(GC4osB &2 E +L,9:/$#.T(GA4os'"
J J J J

Das könnte Ihnen auch gefallen