thinking about updatePos()

This commit is contained in:
2009-09-12 17:28:17 +04:00
parent d3064428c3
commit 835518ce1a
9 changed files with 127 additions and 103 deletions

View File

@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: aliendefender
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 7 13:03:43 2009
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 12 14:04:38 2009
# Project: aliendefender.pro
# Template: app
# Command: /usr/bin/qmake -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro

Binary file not shown.

View File

@@ -98,7 +98,7 @@
<value type="QString" >ANT_HOME=/usr/share/ant</value>
<value type="QString" >CONFIG_PROTECT_MASK=/etc/gentoo-release /etc/sandbox.d /etc/env.d/java/ /etc/udev/rules.d /etc/fonts/fonts.conf /etc/gconf /etc/terminfo /etc/ca-certificates.conf /etc/revdep-rebuild</value>
<value type="QString" >CVS_RSH=ssh</value>
<value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-AeC9SnkuDH,guid=58c439d9d488d5b7b47be9744aa39c4d</value>
<value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-OomOx141X7,guid=4e8fac1ae1f40787aeb1f16e4aa53a4f</value>
<value type="QString" >DESKTOP_SESSION=gnome</value>
<value type="QString" >DESKTOP_STARTUP_ID=</value>
<value type="QString" >DISPLAY=:0.0</value>
@@ -109,7 +109,7 @@
<value type="QString" >GDM_LANG=ru_RU.UTF-8</value>
<value type="QString" >GDM_XSERVER_LOCATION=local</value>
<value type="QString" >GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
<value type="QString" >GNOME_KEYRING_SOCKET=/tmp/keyring-ngsecP/socket</value>
<value type="QString" >GNOME_KEYRING_SOCKET=/tmp/keyring-qB4w8J/socket</value>
<value type="QString" >GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2</value>
<value type="QString" >HOME=/home/andrey</value>
<value type="QString" >INFOPATH=/usr/share/info:/usr/share/binutils-data/i686-pc-linux-gnu/2.19.1/info:/usr/share/gcc-data/i486-pc-linux-gnu/4.1.2/info:/usr/share/gcc-data/i686-pc-linux-gnu/4.3.3/info</value>
@@ -128,18 +128,18 @@
<value type="QString" >PWD=/home/andrey</value>
<value type="QString" >QMAKESPEC=linux-g++</value>
<value type="QString" >QTDIR=/usr</value>
<value type="QString" >SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/9926,unix/buull-eeePC:/tmp/.ICE-unix/9926</value>
<value type="QString" >SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/5720,unix/buull-eeePC:/tmp/.ICE-unix/5720</value>
<value type="QString" >SHELL=/bin/bash</value>
<value type="QString" >SHLVL=0</value>
<value type="QString" >SSH_AGENT_PID=9952</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-ngsecP/socket.ssh</value>
<value type="QString" >SSH_AGENT_PID=5745</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-qB4w8J/socket.ssh</value>
<value type="QString" >USER=andrey</value>
<value type="QString" >USERNAME=andrey</value>
<value type="QString" >WINDOWPATH=7</value>
<value type="QString" >WINDOWPATH=7:7</value>
<value type="QString" >XAUTHORITY=/home/andrey/.Xauthority</value>
<value type="QString" >XDG_CONFIG_DIRS=/etc/xdg</value>
<value type="QString" >XDG_DATA_DIRS=/usr/local/share:/usr/share:/usr/share/gdm</value>
<value type="QString" >XDG_SESSION_COOKIE=998ded06c94c2e848fb0b05949c4e51c-1252236364.946962-291284020</value>
<value type="QString" >XDG_SESSION_COOKIE=998ded06c94c2e848fb0b05949c4e51c-1252342350.758829-1556553659</value>
<value type="QString" >XSESSION=icewm</value>
</valuelist>
<valuelist key="abstractProcess.arguments" type="QVariantList" >
@@ -167,7 +167,7 @@
<value type="QString" >ANT_HOME=/usr/share/ant</value>
<value type="QString" >CONFIG_PROTECT_MASK=/etc/gentoo-release /etc/sandbox.d /etc/env.d/java/ /etc/udev/rules.d /etc/fonts/fonts.conf /etc/gconf /etc/terminfo /etc/ca-certificates.conf /etc/revdep-rebuild</value>
<value type="QString" >CVS_RSH=ssh</value>
<value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-AeC9SnkuDH,guid=58c439d9d488d5b7b47be9744aa39c4d</value>
<value type="QString" >DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-OomOx141X7,guid=4e8fac1ae1f40787aeb1f16e4aa53a4f</value>
<value type="QString" >DESKTOP_SESSION=gnome</value>
<value type="QString" >DESKTOP_STARTUP_ID=</value>
<value type="QString" >DISPLAY=:0.0</value>
@@ -178,7 +178,7 @@
<value type="QString" >GDM_LANG=ru_RU.UTF-8</value>
<value type="QString" >GDM_XSERVER_LOCATION=local</value>
<value type="QString" >GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
<value type="QString" >GNOME_KEYRING_SOCKET=/tmp/keyring-ngsecP/socket</value>
<value type="QString" >GNOME_KEYRING_SOCKET=/tmp/keyring-qB4w8J/socket</value>
<value type="QString" >GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2</value>
<value type="QString" >HOME=/home/andrey</value>
<value type="QString" >INFOPATH=/usr/share/info:/usr/share/binutils-data/i686-pc-linux-gnu/2.19.1/info:/usr/share/gcc-data/i486-pc-linux-gnu/4.1.2/info:/usr/share/gcc-data/i686-pc-linux-gnu/4.3.3/info</value>
@@ -197,18 +197,18 @@
<value type="QString" >PWD=/home/andrey</value>
<value type="QString" >QMAKESPEC=linux-g++</value>
<value type="QString" >QTDIR=/usr</value>
<value type="QString" >SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/9926,unix/buull-eeePC:/tmp/.ICE-unix/9926</value>
<value type="QString" >SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/5720,unix/buull-eeePC:/tmp/.ICE-unix/5720</value>
<value type="QString" >SHELL=/bin/bash</value>
<value type="QString" >SHLVL=0</value>
<value type="QString" >SSH_AGENT_PID=9952</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-ngsecP/socket.ssh</value>
<value type="QString" >SSH_AGENT_PID=5745</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-qB4w8J/socket.ssh</value>
<value type="QString" >USER=andrey</value>
<value type="QString" >USERNAME=andrey</value>
<value type="QString" >WINDOWPATH=7</value>
<value type="QString" >WINDOWPATH=7:7</value>
<value type="QString" >XAUTHORITY=/home/andrey/.Xauthority</value>
<value type="QString" >XDG_CONFIG_DIRS=/etc/xdg</value>
<value type="QString" >XDG_DATA_DIRS=/usr/local/share:/usr/share:/usr/share/gdm</value>
<value type="QString" >XDG_SESSION_COOKIE=998ded06c94c2e848fb0b05949c4e51c-1252236364.946962-291284020</value>
<value type="QString" >XDG_SESSION_COOKIE=998ded06c94c2e848fb0b05949c4e51c-1252342350.758829-1556553659</value>
<value type="QString" >XSESSION=icewm</value>
</valuelist>
<valuelist key="abstractProcess.arguments" type="QVariantList" >

View File

@@ -90,7 +90,14 @@ bool Aliens::AddAlien()
for (int i = 0; i < fw; i++) {
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
}
return (CreatePath(&curAliens[curAliens.size()-1]));
if (CreatePath(&curAliens[curAliens.size()-1])) {
curAliens[curAliens.size()-1].Position.pnt.setX(
curAliens[curAliens.size()-1].path[0].x()*cellsize);
curAliens[curAliens.size()-1].Position.pnt.setY(
curAliens[curAliens.size()-1].path[0].y()*cellsize);
return true;
}
return false;
}
@@ -118,8 +125,6 @@ bool Aliens::CreatePath(Alien * al)
al->path = tmpPnt;
}
tmpPnt.clear();
al->Position.pnt.setX(al->path[0].x()*cellsize);
al->Position.pnt.setY(al->path[0].y()*cellsize);
return true;
}
return false;
@@ -128,22 +133,24 @@ bool Aliens::CreatePath(Alien * al)
void Aliens::updateAliens()
{
qDebug("=========");
qDebug("*********************");
//qDebug() << curAliens[0].path;
for (int i = 0; i < curAliens.size(); i++) updateAlienPos(&curAliens[i]);
qDebug("*********************");
}
void Aliens::updateAlienPos(Alien * al)
{
float arctg = 0;
float px,py;
float px,py,dk;
float dx,dy,fdx,fdy;
//qDebug() << cellsize;
px = al->path[al->PathIndex].x() - al->path[al->PathIndex - 1].x();
py = al->path[al->PathIndex].y() - al->path[al->PathIndex - 1].y();
dx = al->Position.pnt.x() - al->path[al->PathIndex].x() * (cellsize);
dy = al->Position.pnt.y() - al->path[al->PathIndex].y() * (cellsize);
dx = al->Position.pnt.x() - al->path[al->PathIndex].x() * cellsize;
dy = al->Position.pnt.y() - al->path[al->PathIndex].y() * cellsize;
dk = cellsize / sqrtf(px * px + py * py);
qDebug() << dx << ";" << dy;
qDebug() << px << ";" << py;
//qDebug() << al->path;//[al->PathIndex];
@@ -162,7 +169,7 @@ void Aliens::updateAlienPos(Alien * al)
if (fdy < 0) al->Position.angle = 180 + al->Position.angle;
//qDebug() << al->Position.angle;
qDebug() << al->Position.pnt;
if (qAbs(dx) <= al->Speed && qAbs(dy) <= al->Speed) {
if (qAbs(dx) <= al->Speed * dk && qAbs(dy) <= al->Speed * dk) {
qDebug("next");
al->Position.pnt.setX(al->path[al->PathIndex].x() * cellsize);
al->Position.pnt.setY(al->path[al->PathIndex].y() * cellsize);
@@ -170,17 +177,17 @@ void Aliens::updateAlienPos(Alien * al)
}
else {
qDebug("go");
al->Position.pnt.setX(al->Position.pnt.x()+px * al->Speed * cellsize);
al->Position.pnt.setY(al->Position.pnt.y()+py * al->Speed * cellsize);
al->Position.pnt.setX(al->Position.pnt.x()+px * al->Speed * dk);
al->Position.pnt.setY(al->Position.pnt.y()+py * al->Speed * dk);
}
qDebug() << al->Position.pnt;
al->PicIndex++;
qDebug() << "PicIndex" << al->PicIndex;
qDebug() << "PicType" << al->PicType;
qDebug() << AliensPixmaps[al->PicType].size();
//qDebug() << "PicIndex" << al->PicIndex;
//qDebug() << "PicType" << al->PicType;
//qDebug() << AliensPixmaps[al->PicType].size();
if (al->PicIndex >= AliensPixmaps[al->PicType].size()) al->PicIndex = 0;
if (al->PathIndex >= al->path.size()) {
qDebug() << "run agan";
//qDebug() << "run agan";
al->PathIndex = 1;
al->Position.pnt.setX(al->path.value(0).x()*cellsize);
al->Position.pnt.setY(al->path.value(0).y()*cellsize);
@@ -202,24 +209,41 @@ void Aliens::updateAlienPos(Alien * al)
bool Aliens::recreatePath()
{
QVector <QPointF> tmpPath;
bool trace;
QPointF tmppnt;
//bool trace;
for (int i = 0; i < fw; i++)
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
for (int i = 0; i < curAliens.size(); i++) {
qDebug() << "##############";
qDebug() << "Alinen N" << i;
qDebug() << curAliens[i].Position.pnt;
qDebug() << curAliens[i].PathIndex;
if (curAliens[i].Position.pnt.x() - curAliens[i].path[curAliens[i].PathIndex].x()*cellsize < cellsize/2
&& curAliens[i].Position.pnt.y() - curAliens[i].path[curAliens[i].PathIndex].y()*cellsize < cellsize/2)
qDebug() << "Yes!!";
else qDebug() << "NO!!";
tmppnt = curAliens[i].Position.pnt;
curAliens[i].Position.pnt.setX(curAliens[i].path[curAliens[i].PathIndex - 1].x() * cellsize);
curAliens[i].Position.pnt.setY(curAliens[i].path[curAliens[i].PathIndex - 1].y() * cellsize);
curAliens[i].PathIndex = 1;
qDebug() << curAliens[i].Position.pnt;
tmpPath = curAliens[i].path;
curAliens[i].path.clear();
trace = CreatePath(&curAliens[i]);
if (!trace) {
//trace = CreatePath(&curAliens[i]);
if (!CreatePath(&curAliens[i])) {
curAliens[i].path = tmpPath;
curAliens[i].Position.pnt = tmppnt;
tmpPath.clear();
//trace = false;
qDebug() << "##############";
return false;
}
curAliens[i].Position.pnt = tmppnt;
qDebug() << curAliens[i].Position.pnt;
qDebug() << "===============";
}
qDebug() << trace;
tmpPath.clear();
qDebug() << "Re-create path sucsess!";
return true;
}

BIN
aliens.o

Binary file not shown.

View File

@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'mainwindow.h'
**
** Created: Mon Sep 7 13:03:55 2009
** Created: Sat Sep 12 14:04:46 2009
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
**
** WARNING! All changes made in this file will be lost!

View File

@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'udpsender.h'
**
** Created: Thu Sep 3 23:47:54 2009
** Created: Sat Sep 12 14:04:47 2009
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
**
** WARNING! All changes made in this file will be lost!

View File

@@ -1,7 +1,7 @@
/****************************************************************************
** Resource object code
**
** Created: Mon Sep 7 13:03:55 2009
** Created: Sat Sep 12 14:04:47 2009
** by: The Resource Compiler for Qt version 4.5.2
**
** WARNING! All changes made in this file will be lost!

View File

@@ -1,67 +1,67 @@
/********************************************************************************
** Form generated from reading ui file 'mainwindow.ui'
**
** Created: Sun 6. Sep 19:03:05 2009
** by: Qt User Interface Compiler version 4.5.2
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *widget;
QWidget *paintWidget;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 400);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
MainWindow->setMinimumSize(QSize(800, 400));
MainWindow->setBaseSize(QSize(800, 400));
widget = new QWidget(MainWindow);
widget->setObjectName(QString::fromUtf8("widget"));
paintWidget = new QWidget(widget);
paintWidget->setObjectName(QString::fromUtf8("paintWidget"));
paintWidget->setGeometry(QRect(40, 20, 361, 181));
MainWindow->setCentralWidget(widget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
/********************************************************************************
** Form generated from reading ui file 'mainwindow.ui'
**
** Created: Sat Sep 12 14:04:38 2009
** by: Qt User Interface Compiler version 4.5.2
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *widget;
QWidget *paintWidget;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 400);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
MainWindow->setMinimumSize(QSize(800, 400));
MainWindow->setBaseSize(QSize(800, 400));
widget = new QWidget(MainWindow);
widget->setObjectName(QString::fromUtf8("widget"));
paintWidget = new QWidget(widget);
paintWidget->setObjectName(QString::fromUtf8("paintWidget"));
paintWidget->setGeometry(QRect(40, 20, 361, 181));
MainWindow->setCentralWidget(widget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H