From 15318cad33835e4e2dc620d033e43cd930676cdd Mon Sep 17 00:00:00 2001 From: kergoth Date: Fri, 25 Jan 2002 22:14:26 +0000 Subject: Initial revision --- (limited to 'noncore/games/parashoot') diff --git a/noncore/games/parashoot/.cvsignore b/noncore/games/parashoot/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/noncore/games/parashoot/.cvsignore @@ -0,0 +1,3 @@ +moc_* +*.moc +Makefile diff --git a/noncore/games/parashoot/Makefile.in b/noncore/games/parashoot/Makefile.in new file mode 100644 index 0000000..ff7397e --- a/dev/null +++ b/noncore/games/parashoot/Makefile.in @@ -0,0 +1,203 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) +INCPATH = -I$(QPEDIR)/include +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = $(QPEDIR)/bin/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = parashoot +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = interface.h \ + man.h \ + cannon.h \ + base.h \ + bullet.h \ + helicopter.h +SOURCES = main.cpp \ + interface.cpp \ + man.cpp \ + cannon.cpp \ + base.cpp \ + bullet.cpp \ + helicopter.cpp +OBJECTS = main.o \ + interface.o \ + man.o \ + cannon.o \ + base.o \ + bullet.o \ + helicopter.o +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = moc_interface.cpp \ + moc_cannon.cpp \ + moc_bullet.cpp +OBJMOC = moc_interface.o \ + moc_cannon.o \ + moc_bullet.o + + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(DESTDIR)$(TARGET) + +$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: + tmake parashoot.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +main.o: main.cpp \ + interface.h \ + cannon.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h \ + base.h \ + helicopter.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +interface.o: interface.cpp \ + interface.h \ + cannon.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h \ + base.h \ + helicopter.h \ + man.h \ + $(QPEDIR)/include/qpe/resource.h \ + $(QPEDIR)/include/qpe/qpetoolbar.h + +man.o: man.cpp \ + codes.h \ + man.h \ + $(QPEDIR)/include/qpe/sound.h \ + base.h \ + $(QPEDIR)/include/qpe/resource.h + +cannon.o: cannon.cpp \ + $(QPEDIR)/include/qpe/resource.h \ + codes.h \ + cannon.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h + +base.o: base.cpp \ + codes.h \ + base.h \ + $(QPEDIR)/include/qpe/sound.h \ + man.h \ + $(QPEDIR)/include/qpe/resource.h + +bullet.o: bullet.cpp \ + codes.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h \ + man.h \ + helicopter.h \ + $(QPEDIR)/include/qpe/resource.h \ + $(QPEDIR)/include/qpe/qmath.h + +helicopter.o: helicopter.cpp \ + helicopter.h \ + $(QPEDIR)/include/qpe/sound.h \ + man.h \ + codes.h \ + $(QPEDIR)/include/qpe/resource.h + +moc_interface.o: moc_interface.cpp \ + interface.h \ + cannon.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h \ + base.h \ + helicopter.h + +moc_cannon.o: moc_cannon.cpp \ + cannon.h \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h + +moc_bullet.o: moc_bullet.cpp \ + bullet.h \ + $(QPEDIR)/include/qpe/sound.h + +moc_interface.cpp: interface.h + $(MOC) interface.h -o moc_interface.cpp + +moc_cannon.cpp: cannon.h + $(MOC) cannon.h -o moc_cannon.cpp + +moc_bullet.cpp: bullet.h + $(MOC) bullet.h -o moc_bullet.cpp + + diff --git a/noncore/games/parashoot/base.cpp b/noncore/games/parashoot/base.cpp new file mode 100644 index 0000000..c03802f --- a/dev/null +++ b/noncore/games/parashoot/base.cpp @@ -0,0 +1,71 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "codes.h" +#include "base.h" +#include "man.h" + +#include + +#include + +int damage; + +Base::Base(QCanvas* canvas) : + QCanvasSprite(0, canvas), + kaboom("landmine"), + ohdear("crmble01") +{ + basearray = new QCanvasPixmapArray(); + QString b0 = Resource::findPixmap("parashoot/b0001"); + b0.replace(QRegExp("0001"),"%1"); + basearray->readPixmaps(b0, 4); + setSequence(basearray); + setFrame(0); + move(2, canvas->height()-50); + setZ(10); + show(); + damage = 0; +} + +void Base::damageBase() +{ + damage++; + + switch(damage) { + case 1: setFrame(1); ohdear.play(); break; + case 2: setFrame(2); ohdear.play(); break; + case 3: setFrame(3); kaboom.play(); break; + } + show(); +} + +bool Base::baseDestroyed() +{ + return (damage >= 3); +} + +Base::~Base() +{ +} + +int Base::rtti() const +{ + return base_rtti; +} diff --git a/noncore/games/parashoot/base.h b/noncore/games/parashoot/base.h new file mode 100644 index 0000000..ee7f166 --- a/dev/null +++ b/noncore/games/parashoot/base.h @@ -0,0 +1,38 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include + +#include + +class Base : public QCanvasSprite +{ + +public: + Base(QCanvas*); + ~Base(); + void damageBase(); + int rtti() const; + static bool baseDestroyed(); + +private: + QCanvasPixmapArray* basearray; + Sound kaboom, ohdear; +}; diff --git a/noncore/games/parashoot/bullet.cpp b/noncore/games/parashoot/bullet.cpp new file mode 100644 index 0000000..584f564 --- a/dev/null +++ b/noncore/games/parashoot/bullet.cpp @@ -0,0 +1,142 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "codes.h" +#include "bullet.h" +#include "man.h" +#include "helicopter.h" + +#include +#include + + +int limit; +int shotcount; +int nobullets; + +Bullet::Bullet(QCanvas* canvas, double angle, int cannonx, int cannony) : + QCanvasSprite(0, canvas), + bang("collide01") +{ + QCanvasPixmapArray* bulletarray = new QCanvasPixmapArray(Resource::findPixmap("parashoot/bullet")); + setSequence(bulletarray); + if (nobullets < limit) { + nobullets++; + move(cannonx, cannony); + dy = 0; + dx = 0; + show(); + setXY(angle); + setVelocity(-dx, -dy); + bang.play(); + } else + return; +} + +void Bullet::setXY(double angle) +{ + double ang = angle; + if ( (y() < 0) || (x() < 0) || (y() > canvas()->height()) || + (x() > canvas()->width()) ) + delete this; + else { + double radians = 0; + radians = ang * 3.14159265/180; + dx = (qCos(radians)) *7; + dy = (qSin(radians)) *7; + } +} + +void Bullet::setLimit(int amount) +{ + limit = amount; +} + +void Bullet::setNobullets(int amount) +{ + nobullets = amount; +} + +void Bullet::checkCollision() +{ + QCanvasItem* item; + QCanvasItemList l=collisions(FALSE); + for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { + item = *it; + if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) { + Man* deadman = (Man*)item; + if (deadman->frame() != 5) return; + deadman->done(); + emit score(10); + setShotCount(shotcount+1); + setAnimated(false); + nobullets--; + delete this; + return; + } + else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) { + Helicopter* deadchopper = (Helicopter*) item; + deadchopper->done(); + emit score(50); + setAnimated(false); + nobullets--; + delete this; + return; + } + } + //check shot is not out of bounds + if ( (y() < 0) || (x() < 0) || + (y() > canvas()->height()) || + ( x() > canvas()->width())) { + setAnimated(false); + nobullets--; + delete this; + return; + } +} + +void Bullet::advance(int phase) +{ + QCanvasSprite::advance(phase); + + if (phase == 0) + checkCollision(); + +} + +int Bullet::getShotCount() +{ + return shotcount; +} + +void Bullet::setShotCount(int amount) +{ + shotcount = amount; +} + +Bullet::~Bullet() +{ + +} + +int Bullet::rtti() const +{ + return bullet_rtti; +} diff --git a/noncore/games/parashoot/bullet.h b/noncore/games/parashoot/bullet.h new file mode 100644 index 0000000..7d15899 --- a/dev/null +++ b/noncore/games/parashoot/bullet.h @@ -0,0 +1,51 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include + +#include +#include + +#include + +class Bullet : public QObject, public QCanvasSprite +{ + Q_OBJECT +public: + Bullet(QCanvas*, double angle, int cannonx, int cannony); + ~Bullet(); + void setXY(double angle); + void checkCollision(); + void advance(int phase); + int rtti() const; + static int getShotCount(); + static void setShotCount(int amount); + static void setLimit(int amount); + static void setNobullets(int amount); + +signals: + void score(int); + +private: + double dx; + double dy; + int damage; + Sound bang; +}; diff --git a/noncore/games/parashoot/cannon.cpp b/noncore/games/parashoot/cannon.cpp new file mode 100644 index 0000000..3c0a5fe --- a/dev/null +++ b/noncore/games/parashoot/cannon.cpp @@ -0,0 +1,140 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include + +#include + +#include "codes.h" +#include "cannon.h" + +Cannon::Cannon(QCanvas* canvas) : + QCanvasSprite(0, canvas) +{ +shotsfired=0; + index = 8; + cannonx = 0; + cannony = 0; + cannonarray = new QCanvasPixmapArray(); + QString c0 = Resource::findPixmap("parashoot/can0001"); + c0.replace(QRegExp("0001"),"%1"); + cannonarray->readPixmaps(c0,17); + setSequence(cannonarray); + setFrame(index); + move(canvas->width()/2-20, canvas->height()-32); + // co ords for barrel of cannon when upright + barrelypos = canvas->height()-32; + barrelxpos = canvas->width()/2; + movedir = NoDir; + moveDelay = 0; + setAnimated(TRUE); + show(); +} + +void Cannon::advance(int stage) +{ + if ( stage == 1 && moveDelay-- == 0 ) { + if (movedir == Left) { + if (index > 0) { + setFrame(index-1); + index--; + } + } + if (movedir == Right) { + if (index < 16) { + setFrame(index+1); + index++; + } + } + moveDelay = 0; + } +} + +void Cannon::pointCannon(Direction dir) +{ + movedir = dir; + moveDelay = 0; + advance(1); + moveDelay = 1; +} + +void Cannon::setCoords() +{ + switch(index) { + case 0: cannonx = barrelxpos-29; cannony = barrelypos-8; break; + case 1: cannonx = barrelxpos-27; cannony = barrelypos-8; break; + case 2: cannonx = barrelxpos-25; cannony = barrelypos-6; break; + case 3: cannonx = barrelxpos-23; cannony = barrelypos-4; break; + case 4: cannonx = barrelxpos-21; cannony = barrelypos-2; break; + case 5: cannonx = barrelxpos-19; cannony = barrelypos; break; + case 6: cannonx = barrelxpos-15; cannony = barrelypos; break; + case 7: cannonx = barrelxpos-10; cannony = barrelypos; break; + case 8: cannonx = barrelxpos; cannony = barrelypos; break; + case 9: cannonx = barrelxpos+2; cannony = barrelypos; break; + case 10: cannonx = barrelxpos+6; cannony = barrelypos; break; + case 11: cannonx = barrelxpos+8; cannony = barrelypos; break; + case 12: cannonx = barrelxpos+12; cannony = barrelypos-2; break; + case 13: cannonx = barrelxpos+18; cannony = barrelypos-4; break; + case 14: cannonx = barrelxpos+22; cannony = barrelypos-6; break; + case 15: cannonx = barrelxpos+26; cannony = barrelypos-8; break; + case 16: cannonx = barrelxpos+28; cannony = barrelypos-8; break; + } +} + +double Cannon::shootAngle() +{ + switch(index) { + case 0: return 30.0; + case 1: return 37.5; + case 2: return 45.0; + case 3: return 52.5; + case 4: return 60.0; + case 5: return 67.5; + case 6: return 75.0; + case 7: return 82.5; + case 8: return 90.0; + case 9: return 97.5; + case 10: return 105.0; + case 11: return 112.5; + case 12: return 120.0; + case 13: return 127.5; + case 14: return 135.0; + case 15: return 142.5; + case 16: return 150.0; + } + return 0; +} + +void Cannon::shoot() +{ + setCoords(); + Bullet* bullet = new Bullet(canvas(), shootAngle(), cannonx, cannony); + connect(bullet, SIGNAL(score(int)), this, SIGNAL(score(int))); + shotsfired++; +} + +Cannon::~Cannon() +{ +} + +int Cannon::rtti() const +{ + return cannon_rtti; +} diff --git a/noncore/games/parashoot/cannon.h b/noncore/games/parashoot/cannon.h new file mode 100644 index 0000000..44d0c65 --- a/dev/null +++ b/noncore/games/parashoot/cannon.h @@ -0,0 +1,58 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include + +#include "bullet.h" + +class Cannon : public QObject, public QCanvasSprite +{ + Q_OBJECT + +public: + Cannon(QCanvas*); //create cannon + ~Cannon(); //destroy cannon + + enum Direction{ Left, Right, NoDir }; + + void pointCannon(Direction dir); + void setCoords(); + double shootAngle(); + void shoot(); + int rtti() const; + +int shotsFired() { return shotsfired; }; + +protected: + void advance(int stage); + +signals: + void score(int); + +private: + QCanvasPixmapArray* cannonarray; + int index; + int cannonx; + int cannony; + int barrelxpos; + int barrelypos; + int moveDelay; + Direction movedir; + int shotsfired; +}; diff --git a/noncore/games/parashoot/codes.h b/noncore/games/parashoot/codes.h new file mode 100644 index 0000000..68acb3f --- a/dev/null +++ b/noncore/games/parashoot/codes.h @@ -0,0 +1,25 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +const int man_rtti = 1500; +const int bullet_rtti = 1600; +const int cannon_rtti = 1700; +const int base_rtti = 1800; +const int helicopter_rtti = 1900; diff --git a/noncore/games/parashoot/helicopter.cpp b/noncore/games/parashoot/helicopter.cpp new file mode 100644 index 0000000..0923124 --- a/dev/null +++ b/noncore/games/parashoot/helicopter.cpp @@ -0,0 +1,114 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "helicopter.h" +#include "man.h" +#include "codes.h" + +#include + +#include + +static QList all; + +Helicopter::Helicopter(QCanvas* canvas) : + QCanvasSprite(0, canvas), + chikachika("aland01") +{ + all.append(this); + hits = 0; + QCanvasPixmapArray* helicopterarray = new QCanvasPixmapArray(); + QString h0 = Resource::findPixmap("parashoot/helicopter0001"); + h0.replace(QRegExp("0001"),"%1"); + helicopterarray->readPixmaps(h0,3 ); + setSequence(helicopterarray); + setAnimated(true); + move(canvas->width(), 5); + setVelocity(-2, 0); + chikachika.playLoop(); + show(); +} + +Helicopter::~Helicopter() +{ + all.remove(this); +} + +int fr = 0; + +void Helicopter::advance(int phase) +{ + QCanvasSprite::advance(phase); + if (phase == 0) { + setFrame(fr%3); + fr++; + checkCollision(); + } +} + +void Helicopter::checkCollision() +{ + if (x() == 6) { + setAnimated(false); //setVelocity(0, 0); + dropman(); + } + if (x() < 0) + done(); +} + +void Helicopter::dropman() +{ + (void)new Man(canvas(), 15, 25); + (void)new Man(canvas(), 35, 25); + takeOff(); +} + +void Helicopter::done() +{ + hits++; + if (hits >= 2) { + setAnimated(false); + delete this; + } +} + +void Helicopter::takeOff() +{ + setVelocity(-1, 0); +} + +int Helicopter::rtti() const +{ + return helicopter_rtti; +} + +void Helicopter::silenceAll() +{ + for (Helicopter* h = all.first(); h; h = all.next()) + h->chikachika.stop(); +} + +void Helicopter::deleteAll() +{ + Helicopter* h; + while ((h = all.first())) + delete h; +} + diff --git a/noncore/games/parashoot/helicopter.h b/noncore/games/parashoot/helicopter.h new file mode 100644 index 0000000..5cb92de --- a/dev/null +++ b/noncore/games/parashoot/helicopter.h @@ -0,0 +1,45 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include + +#include + +class Helicopter : public QCanvasSprite +{ + +public: + Helicopter(QCanvas*); + ~Helicopter(); + void advance(int phase); + void checkCollision(); + void dropman(); + void takeOff(); + void done(); + + static void silenceAll(); + static void deleteAll(); + + int rtti() const; + +private: + int hits; + Sound chikachika; +}; diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp new file mode 100644 index 0000000..84e5e60 --- a/dev/null +++ b/noncore/games/parashoot/interface.cpp @@ -0,0 +1,247 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "interface.h" +#include "man.h" + +#include + +#include +#include +#include +#include +#include +#include + +ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : + QMainWindow(parent,name,f), + canvas(232, 258), + fanfare("level_up"), + score(0) +{ + canvas.setAdvancePeriod(80); + QPixmap bg = Resource::loadPixmap("parashoot/sky"); + canvas.setBackgroundPixmap(bg); + + pb = new QCanvasView(&canvas, this); + pb->setFocus(); + + setToolBarsMovable( FALSE ); + + QPEToolBar* toolbar = new QPEToolBar(this); + toolbar->setHorizontalStretchable( TRUE ); + + setCaption( tr("ParaShoot") ); + QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); + setIcon(newicon); + new QToolButton(newicon, tr("New Game"), 0, + this, SLOT(newGame()), toolbar, "New Game"); + + levelscore = new QLabel(toolbar); + levelscore->setBackgroundMode( PaletteButton ); + levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); + toolbar->setStretchableWidget( levelscore ); + showScore(0,0); + + setCentralWidget(pb); + + autoDropTimer = new QTimer(this); + connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); + + pauseTimer = new QTimer(this); + connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); + + setFocusPolicy(StrongFocus); + + newGame(); +} + + +void ParaShoot::resizeEvent(QResizeEvent *) +{ + QSize s = centralWidget()->size(); + int fw = style().defaultFrameWidth(); + canvas.resize( s.width() - fw - 2, s.height() - fw - 2); +} + + +void ParaShoot::showScore( int score, int level ) +{ + levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); +} + + +void ParaShoot::newGame() +{ + clear(); + if (pauseTimer->isActive()) + pauseTimer->stop(); + clear(); + Man::setManCount(0); + score = 0; + Bullet::setShotCount(0); + Bullet::setNobullets(0); + nomen = 2; + Bullet::setLimit(nomen); + level = 0; + updatespeed = 80; + showScore(0,0); + gamestopped = false; + Helicopter::deleteAll(); + waitover = true; + base = new Base(&canvas); + cannon = new Cannon(&canvas); + connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); + autoDropTimer->start(100); +} + + +void ParaShoot::clear() +{ + autoDropTimer->stop(); +// QCanvasItem* item; + QCanvasItemList l = canvas.allItems(); + for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { + delete *it; + } +} + +void ParaShoot::gameOver() +{ + QCanvasItem* item; + QCanvasItemList l = canvas.allItems(); + for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { + item = *it; + if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) + item->setAnimated(false); + } + autoDropTimer->stop(); + Helicopter::silenceAll(); + + int shots = Bullet::getShotCount(); + + int shotsFired = cannon->shotsFired(); + if ( shotsFired == 0 ) + shotsFired = 1; + QCanvasText* gameover = new QCanvasText( + tr( " GAME OVER!\n" + " Your Score: %1\n" + " Parachuters Killed: %2\n" + " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), + &canvas); + gameover->setColor(red); + gameover->setFont( QFont("times", 18, QFont::Bold) ); + gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); + gameover->setZ(500); + gameover->show(); + gamestopped = true; + waitover = false; + pauseTimer->start(3000); +} + +void ParaShoot::wait() +{ + waitover = true; + pauseTimer->stop(); +} + +void ParaShoot::play() +{ + if (Man::getManCount() < nomen ) { + new Man(&canvas); + } + if (Base::baseDestroyed()) { + gameOver(); + return; + } +} + +void ParaShoot::increaseScore(int x) +{ + score += x; + if ( score / 150 != (score-x) / 150 ) + levelUp(); + showScore(level,score); +} + +void ParaShoot::levelUp() +{ + level++; + int stage = level % 3; + switch(stage) { + case 0: + nomen++; + Bullet::setLimit(nomen); + fanfare.play(); + break; + case 1: + new Helicopter(&canvas); + break; + case 2: + moveFaster(); + fanfare.play(); + break; + default: return; + } +} + +void ParaShoot::moveFaster() +{ + if (updatespeed > 50) + updatespeed = updatespeed-5; + else + updatespeed = updatespeed-3; + canvas.setAdvancePeriod(updatespeed); +} + +void ParaShoot::keyPressEvent(QKeyEvent* event) +{ + if (gamestopped) { + if (waitover) + newGame(); + else + return; + } else { + switch(event->key()) { + case Key_Up: + case Key_F1: + case Key_F9: + case Key_Space: + cannon->shoot(); + break; + case Key_Left: + cannon->pointCannon(Cannon::Left); + lastcannonkey=Key_Left; + break; + case Key_Right: + cannon->pointCannon(Cannon::Right); + lastcannonkey=Key_Right; + break; + default: + return; + } + } +} + +void ParaShoot::keyReleaseEvent(QKeyEvent* event) +{ + if ( lastcannonkey == event->key() ) + cannon->pointCannon(Cannon::NoDir); +} diff --git a/noncore/games/parashoot/interface.h b/noncore/games/parashoot/interface.h new file mode 100644 index 0000000..3f36d0b --- a/dev/null +++ b/noncore/games/parashoot/interface.h @@ -0,0 +1,79 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "cannon.h" +#include "base.h" +#include "helicopter.h" + +#include + +#include +#include +#include + +class QCanvas; +class Helicopter; + +//enum Direction{ +// left, right, up, down }; + +class ParaShoot : public QMainWindow { + Q_OBJECT + +public: + ParaShoot(QWidget* parent=0, const char* name=0, WFlags f=0); + + void clear(); + void gameOver(); + int mancount; + void levelUp(); + void moveFaster(); + +protected: + virtual void keyPressEvent(QKeyEvent*); + virtual void keyReleaseEvent(QKeyEvent*); + virtual void resizeEvent(QResizeEvent *e); + +private slots: + void increaseScore(int); + void newGame(); + void play(); + void wait(); + +private: + void showScore( int score, int level ); + QCanvasView* pb; + QCanvas canvas; + Cannon* cannon; + Base* base; + QCanvasText* gameover; + QLabel* levelscore; + int nomen; + int level; + int oldscore; + int updatespeed; + QTimer* autoDropTimer; + QTimer* pauseTimer; + bool gamestopped; + bool waitover; + Sound fanfare; + int score; + int lastcannonkey; +}; diff --git a/noncore/games/parashoot/main.cpp b/noncore/games/parashoot/main.cpp new file mode 100644 index 0000000..60eea18 --- a/dev/null +++ b/noncore/games/parashoot/main.cpp @@ -0,0 +1,36 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "interface.h" + +#include + +int main(int argc, char **argv) +{ + QPEApplication app(argc,argv); + + QPEApplication::grabKeyboard(); + + ParaShoot m; + QPEApplication::setInputMethodHint( &m, QPEApplication::AlwaysOff ); + app.showMainWidget(&m); + + return app.exec(); +} diff --git a/noncore/games/parashoot/man.cpp b/noncore/games/parashoot/man.cpp new file mode 100644 index 0000000..8435572 --- a/dev/null +++ b/noncore/games/parashoot/man.cpp @@ -0,0 +1,174 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "codes.h" +#include "man.h" +#include "base.h" + +#include + +#include + +int mancount; + +Man::Man(QCanvas* canvas) : + QCanvasSprite(0, canvas), + splat("lose") +{ + manarray = new QCanvasPixmapArray(); + QString m0 = Resource::findPixmap("parashoot/man0001"); + m0.replace(QRegExp("0001"),"%1"); + manarray->readPixmaps(m0, 7); + setSequence(manarray); + setAnimated(true); + mancount++; + dead = false; + start(); +} + +Man::Man(QCanvas* canvas, int x, int y) : + QCanvasSprite(0, canvas), + splat("bang") +{ + manarray = new QCanvasPixmapArray(); + QString m0 = Resource::findPixmap("parashoot/man0001"); + m0.replace(QString("0001"),"%1"); + manarray->readPixmaps(m0, 7); + setSequence(manarray); + move(x, y); + setFrame(5); + setZ(300); + show(); + + static bool first_time = TRUE; + if (first_time) { + first_time = FALSE; + QTime midnight(0, 0, 0); + srand(midnight.secsTo(QTime::currentTime()) ); + } + int yfallspeed = 0; + yfallspeed = (rand() % 3) + 1; + setVelocity(0, yfallspeed); + + mancount++; + dead = false; +} +int f = 0; + +void Man::advance(int phase) +{ + QCanvasSprite::advance(phase); + if (phase == 0) { + checkCollision(); + if (dead) { + if (count < 10) { + setFrame(6); + setVelocity(0,0); + count++; + } else { + delete this; + return; + } + } + if (y() > canvas()->height()-43) { + setFrame(f%5); + f++; + move(x(), canvas()->height()-26); + setVelocity(-2, 0); + } + } +} + +void Man::setInitialCoords() +{ + static bool first_time = TRUE; + if (first_time) { + first_time = FALSE; + QTime midnight(0, 0, 0); + srand(midnight.secsTo(QTime::currentTime()) ); + } + dx = rand() % (canvas()->width()-16); + dy = -43; //height of a man off the screen +} + +//check if man has reached the base +void Man::checkCollision() +{ + if ( (x() < 23) && (y() == canvas()->height()-26)) { + QCanvasItem* item; + QCanvasItemList l=collisions(FALSE); + for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { + item = *it; + if ( (item->rtti()== 1800) && (item->collidesWith(this)) ) { + Base* base = (Base*) item; + base->damageBase(); + start(); + } + } + } +} + +void Man::start() +{ + setInitialCoords(); + move(dx, dy); + setFrame(5); + setZ(300); + show(); + + static bool first_time = TRUE; + if (first_time) { + first_time = FALSE; + QTime midnight(0, 0, 0); + srand(midnight.secsTo(QTime::currentTime()) ); + } + int yfallspeed = 0; + yfallspeed = (rand() % 3) + 1; + setVelocity(0, yfallspeed); +} + +void Man::done() +{ + splat.play(); + count = 0; + dead = true; + setFrame(6); +} + +int Man::getManCount() +{ + return mancount; +} + +void Man::setManCount(int count) +{ + mancount = count; +} + + +int Man::rtti() const +{ + return man_rtti; +} + +Man::~Man() +{ + mancount--; +} diff --git a/noncore/games/parashoot/man.h b/noncore/games/parashoot/man.h new file mode 100644 index 0000000..e48fc20 --- a/dev/null +++ b/noncore/games/parashoot/man.h @@ -0,0 +1,52 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include + +#include +#include + +#include + +class Man : public QCanvasSprite +{ + +public: + Man (QCanvas*); + Man (QCanvas*, int x, int y); + ~Man(); + void advance(int phase); + void setInitialCoords(); + void checkCollision(); + void start(); + void done(); + static int getManCount(); + static void setManCount(int count); + int rtti() const; +// int mancount; + +private: + QCanvasPixmapArray* manarray; + int dx; + int dy; + bool dead; + int count; + Sound splat; +}; diff --git a/noncore/games/parashoot/parashoot.pro b/noncore/games/parashoot/parashoot.pro new file mode 100644 index 0000000..631560b --- a/dev/null +++ b/noncore/games/parashoot/parashoot.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +CONFIG += qt warn_on release +DESTDIR = $(QPEDIR)/bin +HEADERS = interface.h man.h cannon.h base.h bullet.h helicopter.h +SOURCES = main.cpp interface.cpp man.cpp cannon.cpp base.cpp bullet.cpp helicopter.cpp +TARGET = parashoot +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += $(QPEDIR)/include +LIBS += -lqpe + +TRANSLATIONS = ../i18n/de/parashoot.ts diff --git a/noncore/games/parashoot/qpe-parashoot.control b/noncore/games/parashoot/qpe-parashoot.control new file mode 100644 index 0000000..82e9421 --- a/dev/null +++ b/noncore/games/parashoot/qpe-parashoot.control @@ -0,0 +1,9 @@ +Files: bin/parashoot apps/Games/parashoot.desktop pics/parashoot +Priority: optional +Section: qpe/games +Maintainer: Warwick Allison +Architecture: arm +Version: $QPE_VERSION-3 +Depends: qpe-base ($QPE_VERSION) +Description: Game: shoot the parachutists + A game for the Qtopia environment. -- cgit v0.9.0.2