Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

target.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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(); //collisions(FALSE);
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 }

Generated on Sat Nov 5 16:17:25 2005 for OPIE by  doxygen 1.4.2