Diffstat (limited to 'noncore/games/snake/target.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/snake/target.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/noncore/games/snake/target.cpp b/noncore/games/snake/target.cpp new file mode 100644 index 0000000..a09af69 --- a/dev/null +++ b/noncore/games/snake/target.cpp | |||
@@ -0,0 +1,77 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "target.h" | ||
22 | #include "codes.h" | ||
23 | |||
24 | #include <qpe/resource.h> | ||
25 | |||
26 | #include <stdlib.h> | ||
27 | |||
28 | Target::Target(QCanvas* canvas) | ||
29 | : QCanvasSprite(0, canvas) | ||
30 | { | ||
31 | mouse = new QCanvasPixmapArray(Resource::findPixmap("snake/mouse")); | ||
32 | setSequence(mouse); | ||
33 | newTarget(); | ||
34 | } | ||
35 | |||
36 | void Target::newTarget() | ||
37 | { | ||
38 | static bool first_time = TRUE; | ||
39 | if (first_time) { | ||
40 | first_time = FALSE; | ||
41 | QTime midnight(0, 0, 0); | ||
42 | srand(midnight.secsTo(QTime::currentTime()) ); | ||
43 | } | ||
44 | do { | ||
45 | int x = rand() % (canvas()->width()-10); | ||
46 | x = x - (x % 16) + 2; | ||
47 | int y = rand() % (canvas()->height()-10); | ||
48 | y = y - (y % 16) + 2; | ||
49 | move(x, y); | ||
50 | } while (onTop()); | ||
51 | show(); | ||
52 | } | ||
53 | |||
54 | bool Target::onTop() | ||
55 | { | ||
56 | QCanvasItem* item; | ||
57 | QCanvasItemList l= canvas()->allItems(); //collisions(FALSE); | ||
58 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | ||
59 | item = *it; | ||
60 | if (item != this && item->collidesWith(this)) return true; | ||
61 | } | ||
62 | return false; | ||
63 | } | ||
64 | |||
65 | void Target::done() | ||
66 | { | ||
67 | delete this; | ||
68 | } | ||
69 | |||
70 | int Target::rtti() const | ||
71 | { | ||
72 | return target_rtti; | ||
73 | } | ||
74 | |||
75 | Target::~Target() | ||
76 | { | ||
77 | } | ||