00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "target.h"
00022 #include "codes.h"
00023
00024 #include <opie2/oresource.h>
00025
00026 #include <stdlib.h>
00027
00028 Target::Target(QCanvas* canvas)
00029 : QCanvasSprite(0, canvas)
00030 {
00031 mouse = new QCanvasPixmapArray(Opie::Core::OResource::findPixmap("snake/mouse"));
00032 setSequence(mouse);
00033 newTarget();
00034 }
00035
00036 void Target::newTarget()
00037 {
00038 static bool first_time = TRUE;
00039 if (first_time) {
00040 first_time = FALSE;
00041 QTime midnight(0, 0, 0);
00042 srand(midnight.secsTo(QTime::currentTime()) );
00043 }
00044 do {
00045 int x = rand() % (canvas()->width()-10);
00046 x = x - (x % 16) + 2;
00047 int y = rand() % (canvas()->height()-10);
00048 y = y - (y % 16) + 2;
00049 move(x, y);
00050 } while (onTop());
00051 show();
00052 }
00053
00054 bool Target::onTop()
00055 {
00056 QCanvasItem* item;
00057 QCanvasItemList l= canvas()->allItems();
00058 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
00059 item = *it;
00060 if (item != this && item->collidesWith(this)) return true;
00061 }
00062 return false;
00063 }
00064
00065 void Target::done()
00066 {
00067 delete this;
00068 }
00069
00070 int Target::rtti() const
00071 {
00072 return target_rtti;
00073 }
00074
00075 Target::~Target()
00076 {
00077 }