summaryrefslogtreecommitdiff
authordrw <drw>2005-05-20 21:17:24 (UTC)
committer drw <drw>2005-05-20 21:17:24 (UTC)
commit5e7bbe42671f565bef961b44862ddbf68beed774 (patch) (unidiff)
treeccf157157cec64314bae8cbdf846dd9ccefdd4a6
parent3394f57eac978fa97ad60fb96bebc67b3783cfc6 (diff)
downloadopie-5e7bbe42671f565bef961b44862ddbf68beed774.zip
opie-5e7bbe42671f565bef961b44862ddbf68beed774.tar.gz
opie-5e7bbe42671f565bef961b44862ddbf68beed774.tar.bz2
Resource -> OResource
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/snake/interface.cpp8
-rw-r--r--noncore/games/snake/obstacle.cpp6
-rw-r--r--noncore/games/snake/snake.cpp5
-rw-r--r--noncore/games/snake/target.cpp4
4 files changed, 10 insertions, 13 deletions
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp
index 9d9550a..1eeb337 100644
--- a/noncore/games/snake/interface.cpp
+++ b/noncore/games/snake/interface.cpp
@@ -1,137 +1,137 @@
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 "interface.h" 21#include "interface.h"
22 22
23#include <qpe/resource.h> 23#include <opie2/oresource.h>
24 24
25#include <qtoolbar.h> 25#include <qtoolbar.h>
26#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27 27
28SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : 28SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) :
29 QMainWindow(parent,name,f), 29 QMainWindow(parent,name,f),
30 canvas(232, 258) 30 canvas(232, 258)
31{ 31{
32 setCaption( tr("Snake") ); 32 setCaption( tr("Snake") );
33 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); 33 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
34 QPixmap bg = Resource::loadPixmap("snake/grass"); 34 QPixmap bg = Opie::Core::OResource::loadPixmap("snake/grass");
35 canvas.setBackgroundPixmap(bg); 35 canvas.setBackgroundPixmap(bg);
36 canvas.setUpdatePeriod(100); 36 canvas.setUpdatePeriod(100);
37 snake = 0; 37 snake = 0;
38 38
39 cv = new QCanvasView(&canvas, this); 39 cv = new QCanvasView(&canvas, this);
40 40
41 pauseTimer = new QTimer(this); 41 pauseTimer = new QTimer(this);
42 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); 42 connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) );
43 43
44 setToolBarsMovable( FALSE ); 44 setToolBarsMovable( FALSE );
45 45
46 QToolBar* toolbar = new QToolBar( this); 46 QToolBar* toolbar = new QToolBar( this);
47 toolbar->setHorizontalStretchable( TRUE ); 47 toolbar->setHorizontalStretchable( TRUE );
48 48
49 QPixmap newicon = Resource::loadPixmap("ksnake"); 49 QPixmap newicon = Opie::Core::OResource::loadPixmap("ksnake");
50 setIcon(newicon); 50 setIcon(newicon);
51 (void)new QToolButton(newicon, tr("New Game"), 0, 51 (void)new QToolButton(newicon, tr("New Game"), 0,
52 this, SLOT(newGame()), toolbar, "New Game"); 52 this, SLOT(newGame()), toolbar, "New Game");
53 53
54 scorelabel = new QLabel(toolbar); 54 scorelabel = new QLabel(toolbar);
55 showScore(0); 55 showScore(0);
56 scorelabel->setBackgroundMode( PaletteButton ); 56 scorelabel->setBackgroundMode( PaletteButton );
57 scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); 57 scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs );
58 toolbar->setStretchableWidget( scorelabel ); 58 toolbar->setStretchableWidget( scorelabel );
59 59
60 setFocusPolicy(StrongFocus); 60 setFocusPolicy(StrongFocus);
61 61
62 setCentralWidget(cv); 62 setCentralWidget(cv);
63 63
64 QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); 64 QTimer::singleShot( 16, this, SLOT(welcomescreen()) );
65 gamestopped = true; 65 gamestopped = true;
66 waitover = true; 66 waitover = true;
67} 67}
68 68
69SnakeGame::~SnakeGame() 69SnakeGame::~SnakeGame()
70{ 70{
71 delete snake; 71 delete snake;
72} 72}
73 73
74void SnakeGame::resizeEvent(QResizeEvent *) 74void SnakeGame::resizeEvent(QResizeEvent *)
75{ 75{
76 QSize s = centralWidget()->size(); 76 QSize s = centralWidget()->size();
77 int fw = style().defaultFrameWidth(); 77 int fw = style().defaultFrameWidth();
78 canvas.resize( s.width() - fw - 2, s.height() - fw - 2); 78 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
79} 79}
80 80
81void SnakeGame::welcomescreen() 81void SnakeGame::welcomescreen()
82{ 82{
83 QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); 83 QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas);
84 title->setColor(yellow); 84 title->setColor(yellow);
85 title->setFont( QFont("times", 18, QFont::Bold) ); 85 title->setFont( QFont("times", 18, QFont::Bold) );
86 int w = title->boundingRect().width(); 86 int w = title->boundingRect().width();
87 title->move(canvas.width()/2 -w/2, canvas.height()/2-110); 87 title->move(canvas.width()/2 -w/2, canvas.height()/2-110);
88 title->show(); 88 title->show();
89 QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); 89 QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Opie::Core::OResource::findPixmap("snake/title"));
90 QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); 90 QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas);
91 titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); 91 titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85);
92 titlepic->show(); 92 titlepic->show();
93 QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" 93 QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n"
94 "snake to eat the mouse. You must not\n" 94 "snake to eat the mouse. You must not\n"
95 "crash into the walls, edges or its tail."), 95 "crash into the walls, edges or its tail."),
96 &canvas); 96 &canvas);
97 w = instr->boundingRect().width(); 97 w = instr->boundingRect().width();
98 instr->move(canvas.width()/2-w/2, canvas.height()/2-20); 98 instr->move(canvas.width()/2-w/2, canvas.height()/2-20);
99 instr->setColor(white); 99 instr->setColor(white);
100 instr->show(); 100 instr->show();
101 QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); 101 QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas);
102 w = cont->boundingRect().width(); 102 w = cont->boundingRect().width();
103 cont->move(canvas.width()/2-w/2, canvas.height()-20); 103 cont->move(canvas.width()/2-w/2, canvas.height()-20);
104 cont->setColor(yellow); 104 cont->setColor(yellow);
105 cont->show(); 105 cont->show();
106 106
107} 107}
108 108
109void SnakeGame::newGame() 109void SnakeGame::newGame()
110{ 110{
111 clear(); 111 clear();
112 snake = new Snake(&canvas); 112 snake = new Snake(&canvas);
113 connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); 113 connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) );
114 connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); 114 connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) );
115 connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); 115 connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) );
116 connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); 116 connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) );
117 last = 0; 117 last = 0;
118 targetamount = 1; 118 targetamount = 1;
119 notargets = 1; 119 notargets = 1;
120 level = 1; 120 level = 1;
121 stage = 1; 121 stage = 1;
122 showScore(0); 122 showScore(0);
123 gamestopped = false; 123 gamestopped = false;
124 waitover = true; 124 waitover = true;
125 int y = canvas.height()-50; 125 int y = canvas.height()-50;
126 (void)new Obstacle(&canvas, 32); 126 (void)new Obstacle(&canvas, 32);
127 (void)new Obstacle(&canvas, y); 127 (void)new Obstacle(&canvas, y);
128 createTargets(); 128 createTargets();
129} 129}
130 130
131 131
132void SnakeGame::showScore(int score) 132void SnakeGame::showScore(int score)
133{ 133{
134 scorelabel->setText(tr(" Score : %1 ").arg(score) ); 134 scorelabel->setText(tr(" Score : %1 ").arg(score) );
135} 135}
136 136
137 137
diff --git a/noncore/games/snake/obstacle.cpp b/noncore/games/snake/obstacle.cpp
index 4bdefa5..4639f5c 100644
--- a/noncore/games/snake/obstacle.cpp
+++ b/noncore/games/snake/obstacle.cpp
@@ -1,70 +1,68 @@
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 "obstacle.h" 21#include "obstacle.h"
22#include "codes.h" 22#include "codes.h"
23 23
24#include <qpe/resource.h> 24#include <opie2/oresource.h>
25
26
27 25
28Obstacle::Obstacle(QCanvas* canvas, int y) 26Obstacle::Obstacle(QCanvas* canvas, int y)
29 : QCanvasSprite(0,canvas) 27 : QCanvasSprite(0,canvas)
30{ 28{
31 newObstacle(y); 29 newObstacle(y);
32} 30}
33 31
34void Obstacle::newObstacle(int y) 32void Obstacle::newObstacle(int y)
35{ 33{
36 QPixmap obstaclePix( Resource::findPixmap("snake/wall.png") ); 34 QPixmap obstaclePix( Opie::Core::OResource::findPixmap("snake/wall") );
37 35
38 if ( obstaclePix.width() > canvas()->width()*3/5 ) { 36 if ( obstaclePix.width() > canvas()->width()*3/5 ) {
39 int w = canvas()->width()*3/5; 37 int w = canvas()->width()*3/5;
40 w = w - w % 16; 38 w = w - w % 16;
41 obstaclePix.resize( w, obstaclePix.height() ); 39 obstaclePix.resize( w, obstaclePix.height() );
42 } 40 }
43 41
44 QList<QPixmap> pixl; 42 QList<QPixmap> pixl;
45 pixl.append( &obstaclePix ); 43 pixl.append( &obstaclePix );
46 44
47 QPoint nullp; 45 QPoint nullp;
48 QList<QPoint> pl; 46 QList<QPoint> pl;
49 pl.append( &nullp ); 47 pl.append( &nullp );
50 48
51 QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(pixl, pl); 49 QCanvasPixmapArray* obstaclearray = new QCanvasPixmapArray(pixl, pl);
52 setSequence(obstaclearray); 50 setSequence(obstaclearray);
53 51
54 int x = ( canvas()->width() - obstaclePix.width() )/2; 52 int x = ( canvas()->width() - obstaclePix.width() )/2;
55 x = x - x % 16; 53 x = x - x % 16;
56 y = y - y % 16; 54 y = y - y % 16;
57 move(x, y); 55 move(x, y);
58 setZ( -100 ); 56 setZ( -100 );
59 show(); 57 show();
60 canvas()->update(); 58 canvas()->update();
61} 59}
62 60
63int Obstacle::rtti() const 61int Obstacle::rtti() const
64{ 62{
65 return obstacle_rtti; 63 return obstacle_rtti;
66} 64}
67 65
68Obstacle::~Obstacle() 66Obstacle::~Obstacle()
69{ 67{
70} 68}
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
27static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } }; 26static int Piecekey[4][4] = { {6, 0, 4, 3 }, {0, 6, 2, 1 }, { 1, 3, 5, 0 }, {2, 4, 0, 5 } };
28 27
29Snake::Snake(QCanvas* c) 28Snake::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
39void Snake::createSnake() 38void 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
73void Snake::increaseSpeed() 72void 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
80void Snake::go(int newkey) 79void 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)) ) )
diff --git a/noncore/games/snake/target.cpp b/noncore/games/snake/target.cpp
index a09af69..f20eb93 100644
--- a/noncore/games/snake/target.cpp
+++ b/noncore/games/snake/target.cpp
@@ -1,77 +1,77 @@
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 "target.h" 21#include "target.h"
22#include "codes.h" 22#include "codes.h"
23 23
24#include <qpe/resource.h> 24#include <opie2/oresource.h>
25 25
26#include <stdlib.h> 26#include <stdlib.h>
27 27
28Target::Target(QCanvas* canvas) 28Target::Target(QCanvas* canvas)
29 : QCanvasSprite(0, canvas) 29 : QCanvasSprite(0, canvas)
30{ 30{
31 mouse = new QCanvasPixmapArray(Resource::findPixmap("snake/mouse")); 31 mouse = new QCanvasPixmapArray(Opie::Core::OResource::findPixmap("snake/mouse"));
32 setSequence(mouse); 32 setSequence(mouse);
33 newTarget(); 33 newTarget();
34} 34}
35 35
36void Target::newTarget() 36void Target::newTarget()
37{ 37{
38 static bool first_time = TRUE; 38 static bool first_time = TRUE;
39 if (first_time) { 39 if (first_time) {
40 first_time = FALSE; 40 first_time = FALSE;
41 QTime midnight(0, 0, 0); 41 QTime midnight(0, 0, 0);
42 srand(midnight.secsTo(QTime::currentTime()) ); 42 srand(midnight.secsTo(QTime::currentTime()) );
43 } 43 }
44 do { 44 do {
45 int x = rand() % (canvas()->width()-10); 45 int x = rand() % (canvas()->width()-10);
46 x = x - (x % 16) + 2; 46 x = x - (x % 16) + 2;
47 int y = rand() % (canvas()->height()-10); 47 int y = rand() % (canvas()->height()-10);
48 y = y - (y % 16) + 2; 48 y = y - (y % 16) + 2;
49 move(x, y); 49 move(x, y);
50 } while (onTop()); 50 } while (onTop());
51 show(); 51 show();
52} 52}
53 53
54bool Target::onTop() 54bool Target::onTop()
55{ 55{
56 QCanvasItem* item; 56 QCanvasItem* item;
57 QCanvasItemList l= canvas()->allItems(); //collisions(FALSE); 57 QCanvasItemList l= canvas()->allItems(); //collisions(FALSE);
58 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { 58 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
59 item = *it; 59 item = *it;
60 if (item != this && item->collidesWith(this)) return true; 60 if (item != this && item->collidesWith(this)) return true;
61 } 61 }
62 return false; 62 return false;
63} 63}
64 64
65void Target::done() 65void Target::done()
66{ 66{
67 delete this; 67 delete this;
68} 68}
69 69
70int Target::rtti() const 70int Target::rtti() const
71{ 71{
72 return target_rtti; 72 return target_rtti;
73} 73}
74 74
75Target::~Target() 75Target::~Target()
76{ 76{
77} 77}