Diffstat (limited to 'noncore/games/snake/snake.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/snake/snake.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/noncore/games/snake/snake.cpp b/noncore/games/snake/snake.cpp index 8a683ab..802951c 100644 --- a/noncore/games/snake/snake.cpp +++ b/noncore/games/snake/snake.cpp | |||
@@ -1,90 +1,89 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "snake.h" | 21 | #include "snake.h" |
22 | #include "target.h" | 22 | #include "target.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <opie2/oresource.h> |
25 | |||
26 | 25 | ||
27 | static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } }; | 26 | static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } }; |
28 | 27 | ||
29 | Snake::Snake(QCanvas* c) | 28 | Snake::Snake(QCanvas* c) |
30 | { | 29 | { |
31 | canvas = c; | 30 | canvas = c; |
32 | score = 0; | 31 | score = 0; |
33 | snakelist.setAutoDelete(true); | 32 | snakelist.setAutoDelete(true); |
34 | autoMoveTimer = new QTimer(this); | 33 | autoMoveTimer = new QTimer(this); |
35 | connect( autoMoveTimer, SIGNAL(timeout()), this, SLOT(moveSnake()) ); | 34 | connect( autoMoveTimer, SIGNAL(timeout()), this, SLOT(moveSnake()) ); |
36 | createSnake(); | 35 | createSnake(); |
37 | } | 36 | } |
38 | 37 | ||
39 | void Snake::createSnake() | 38 | void Snake::createSnake() |
40 | { | 39 | { |
41 | snakeparts = new QCanvasPixmapArray(); | 40 | snakeparts = new QCanvasPixmapArray(); |
42 | QString s0 = Resource::findPixmap("snake/s0001"); | 41 | QString s0 = Opie::Core::OResource::findPixmap("snake/s0001"); |
43 | s0.replace(QRegExp("0001"),"%1"); | 42 | s0.replace(QRegExp("0001"),"%1"); |
44 | snakeparts->readPixmaps(s0, 15); | 43 | snakeparts->readPixmaps(s0, 15); |
45 | 44 | ||
46 | grow = 0; | 45 | grow = 0; |
47 | last = Key_Right; | 46 | last = Key_Right; |
48 | 47 | ||
49 | QCanvasSprite* head = new QCanvasSprite(snakeparts, canvas ); | 48 | QCanvasSprite* head = new QCanvasSprite(snakeparts, canvas ); |
50 | head->setFrame(7); | 49 | head->setFrame(7); |
51 | snakelist.insert(0, head); | 50 | snakelist.insert(0, head); |
52 | head->show(); | 51 | head->show(); |
53 | head->move(34, 16); | 52 | head->move(34, 16); |
54 | 53 | ||
55 | QCanvasSprite* body = new QCanvasSprite(snakeparts, canvas ); | 54 | QCanvasSprite* body = new QCanvasSprite(snakeparts, canvas ); |
56 | body->setFrame(6); | 55 | body->setFrame(6); |
57 | snakelist.append( body ); | 56 | snakelist.append( body ); |
58 | body->show(); | 57 | body->show(); |
59 | body->move(18, 16); | 58 | body->move(18, 16); |
60 | 59 | ||
61 | QCanvasSprite* end = new QCanvasSprite(snakeparts, canvas ); | 60 | QCanvasSprite* end = new QCanvasSprite(snakeparts, canvas ); |
62 | end->setFrame(11); | 61 | end->setFrame(11); |
63 | snakelist.append( end ); | 62 | snakelist.append( end ); |
64 | end->show(); | 63 | end->show(); |
65 | end->move(2, 16); | 64 | end->move(2, 16); |
66 | 65 | ||
67 | currentdir = right; | 66 | currentdir = right; |
68 | speed = 250; | 67 | speed = 250; |
69 | autoMoveTimer->start(speed); | 68 | autoMoveTimer->start(speed); |
70 | moveSnake(); | 69 | moveSnake(); |
71 | } | 70 | } |
72 | 71 | ||
73 | void Snake::increaseSpeed() | 72 | void Snake::increaseSpeed() |
74 | { | 73 | { |
75 | if (speed > 150) | 74 | if (speed > 150) |
76 | speed = speed - 5; | 75 | speed = speed - 5; |
77 | autoMoveTimer->start(speed); | 76 | autoMoveTimer->start(speed); |
78 | } | 77 | } |
79 | 78 | ||
80 | void Snake::go(int newkey) | 79 | void Snake::go(int newkey) |
81 | { | 80 | { |
82 | // check key is a direction | 81 | // check key is a direction |
83 | if (!( (newkey == Key_Up) || (newkey == Key_Left) || | 82 | if (!( (newkey == Key_Up) || (newkey == Key_Left) || |
84 | (newkey == Key_Right) || (newkey == Key_Down) )) | 83 | (newkey == Key_Right) || (newkey == Key_Down) )) |
85 | return; | 84 | return; |
86 | // check move is possible | 85 | // check move is possible |
87 | if ( ((currentdir == left) && ((newkey == Key_Right) || (newkey == Key_Left)) ) || | 86 | if ( ((currentdir == left) && ((newkey == Key_Right) || (newkey == Key_Left)) ) || |
88 | ((currentdir == right) && ((newkey == Key_Left) || (newkey == Key_Right)) ) || | 87 | ((currentdir == right) && ((newkey == Key_Left) || (newkey == Key_Right)) ) || |
89 | ((currentdir == up) && ((newkey == Key_Down) || (newkey == Key_Up)) ) || | 88 | ((currentdir == up) && ((newkey == Key_Down) || (newkey == Key_Up)) ) || |
90 | ((currentdir == down) && ((newkey == Key_Up) || (newkey == Key_Down)) ) ) | 89 | ((currentdir == down) && ((newkey == Key_Up) || (newkey == Key_Down)) ) ) |