-rw-r--r-- | noncore/games/snake/interface.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp index c9b4931..c824543 100644 --- a/noncore/games/snake/interface.cpp +++ b/noncore/games/snake/interface.cpp | |||
@@ -64,6 +64,6 @@ SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : | |||
64 | setCentralWidget(cv); | 64 | setCentralWidget(cv); |
65 | 65 | ||
66 | welcomescreen(); | 66 | QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); |
67 | gamestopped = true; | 67 | gamestopped = true; |
68 | waitover = true; | 68 | waitover = true; |
69 | } | 69 | } |
@@ -85,12 +85,12 @@ void SnakeGame::welcomescreen() | |||
85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); | 85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); |
86 | title->setColor(yellow); | 86 | title->setColor(yellow); |
87 | title->setFont( QFont("times", 18, QFont::Bold) ); | 87 | title->setFont( QFont("times", 18, QFont::Bold) ); |
88 | int w = title->boundingRect().width(); | 88 | int w = title->boundingRect().width(); |
89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); | 89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); |
90 | title->show(); | 90 | title->show(); |
91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("title")); | 91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); |
92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); | 92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); |
93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); | 93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); |
94 | titlepic->show(); | 94 | titlepic->show(); |
95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" | 95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" |
96 | "snake to eat the mouse. You must not\n" | 96 | "snake to eat the mouse. You must not\n" |
@@ -103,12 +103,12 @@ void SnakeGame::welcomescreen() | |||
103 | QCanvasText* cont = new QCanvasText(tr("Press Any Key To Start"), &canvas); | 103 | QCanvasText* cont = new QCanvasText(tr("Press Any Key To Start"), &canvas); |
104 | w = cont->boundingRect().width(); | 104 | w = cont->boundingRect().width(); |
105 | cont->move(canvas.width()/2-w/2, canvas.height()/2+80); | 105 | cont->move(canvas.width()/2-w/2, canvas.height()-20); |
106 | cont->setColor(yellow); | 106 | cont->setColor(yellow); |
107 | cont->show(); | 107 | cont->show(); |
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | void SnakeGame::newGame() | 111 | void SnakeGame::newGame() |
112 | { | 112 | { |
113 | clear(); | 113 | clear(); |
114 | snake = new Snake(&canvas); | 114 | snake = new Snake(&canvas); |
@@ -125,10 +125,7 @@ void SnakeGame::newGame() | |||
125 | gamestopped = false; | 125 | gamestopped = false; |
126 | waitover = true; | 126 | waitover = true; |
127 | int x = canvas.width()/2 - 70; | ||
128 | x = x - x % 16; | ||
129 | int y = canvas.height()-50; | 127 | int y = canvas.height()-50; |
130 | y = y - y % 16; | 128 | (void)new Obstacle(&canvas, 32); |
131 | (void)new Obstacle(&canvas, x, 32); | 129 | (void)new Obstacle(&canvas, y); |
132 | (void)new Obstacle(&canvas, x, y); | ||
133 | createTargets(); | 130 | createTargets(); |
134 | } | 131 | } |
@@ -162,5 +159,5 @@ void SnakeGame::levelUp() | |||
162 | 159 | ||
163 | void SnakeGame::createTargets() | 160 | void SnakeGame::createTargets() |
164 | { | 161 | { |
165 | for (int i = 0; i < targetamount; i++) | 162 | for (int i = 0; i < targetamount; i++) |
166 | (void)new Target(&canvas); | 163 | (void)new Target(&canvas); |
@@ -175,5 +172,5 @@ void SnakeGame::clear() | |||
175 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 172 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
176 | delete *it; | 173 | delete *it; |
177 | } | 174 | } |
178 | } | 175 | } |
179 | 176 | ||
@@ -183,6 +180,6 @@ void SnakeGame::gameOver() | |||
183 | QString scoreoutput=""; | 180 | QString scoreoutput=""; |
184 | scoreoutput.setNum(score); | 181 | scoreoutput.setNum(score); |
185 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); | 182 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); |
186 | 183 | ||
187 | gameover->setZ(100); | 184 | gameover->setZ(100); |
188 | gameover->setColor(yellow); | 185 | gameover->setColor(yellow); |
@@ -193,5 +190,5 @@ void SnakeGame::gameOver() | |||
193 | gamestopped = true; | 190 | gamestopped = true; |
194 | waitover = false; | 191 | waitover = false; |
195 | pauseTimer->start(2500); | 192 | pauseTimer->start(1500); |
196 | } | 193 | } |
197 | 194 | ||
@@ -201,5 +198,5 @@ void SnakeGame::wait() | |||
201 | pauseTimer->stop(); | 198 | pauseTimer->stop(); |
202 | QCanvasText* cont = new QCanvasText(tr("Press Any Key to Begin a New Game."), | 199 | QCanvasText* cont = new QCanvasText(tr("Press Any Key to Begin a New Game."), |
203 | &canvas); | 200 | &canvas); |
204 | cont->setZ(100); | 201 | cont->setZ(100); |
205 | cont->setColor(white); | 202 | cont->setColor(white); |
@@ -210,12 +207,12 @@ void SnakeGame::wait() | |||
210 | 207 | ||
211 | void SnakeGame::keyPressEvent(QKeyEvent* event) | 208 | void SnakeGame::keyPressEvent(QKeyEvent* event) |
212 | { | 209 | { |
213 | if (gamestopped) { | 210 | if (gamestopped) { |
214 | if (waitover) | 211 | if (waitover) |
215 | newGame(); | 212 | newGame(); |
216 | else | 213 | else |
217 | return; | 214 | return; |
218 | } | 215 | } |
219 | else { | 216 | else { |
220 | int newkey = event->key(); | 217 | int newkey = event->key(); |
221 | snake->go(newkey); | 218 | snake->go(newkey); |