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 # 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 # Project: aliendefender.pro
# Template: app # Template: app
# Command: /usr/bin/qmake -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro # 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" >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" >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" >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_SESSION=gnome</value>
<value type="QString" >DESKTOP_STARTUP_ID=</value> <value type="QString" >DESKTOP_STARTUP_ID=</value>
<value type="QString" >DISPLAY=:0.0</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_LANG=ru_RU.UTF-8</value>
<value type="QString" >GDM_XSERVER_LOCATION=local</value> <value type="QString" >GDM_XSERVER_LOCATION=local</value>
<value type="QString" >GNOME_DESKTOP_SESSION_ID=this-is-deprecated</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" >GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2</value>
<value type="QString" >HOME=/home/andrey</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> <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" >PWD=/home/andrey</value>
<value type="QString" >QMAKESPEC=linux-g++</value> <value type="QString" >QMAKESPEC=linux-g++</value>
<value type="QString" >QTDIR=/usr</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" >SHELL=/bin/bash</value>
<value type="QString" >SHLVL=0</value> <value type="QString" >SHLVL=0</value>
<value type="QString" >SSH_AGENT_PID=9952</value> <value type="QString" >SSH_AGENT_PID=5745</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-ngsecP/socket.ssh</value> <value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-qB4w8J/socket.ssh</value>
<value type="QString" >USER=andrey</value> <value type="QString" >USER=andrey</value>
<value type="QString" >USERNAME=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" >XAUTHORITY=/home/andrey/.Xauthority</value>
<value type="QString" >XDG_CONFIG_DIRS=/etc/xdg</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_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> <value type="QString" >XSESSION=icewm</value>
</valuelist> </valuelist>
<valuelist key="abstractProcess.arguments" type="QVariantList" > <valuelist key="abstractProcess.arguments" type="QVariantList" >
@@ -167,7 +167,7 @@
<value type="QString" >ANT_HOME=/usr/share/ant</value> <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" >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" >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_SESSION=gnome</value>
<value type="QString" >DESKTOP_STARTUP_ID=</value> <value type="QString" >DESKTOP_STARTUP_ID=</value>
<value type="QString" >DISPLAY=:0.0</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_LANG=ru_RU.UTF-8</value>
<value type="QString" >GDM_XSERVER_LOCATION=local</value> <value type="QString" >GDM_XSERVER_LOCATION=local</value>
<value type="QString" >GNOME_DESKTOP_SESSION_ID=this-is-deprecated</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" >GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2</value>
<value type="QString" >HOME=/home/andrey</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> <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" >PWD=/home/andrey</value>
<value type="QString" >QMAKESPEC=linux-g++</value> <value type="QString" >QMAKESPEC=linux-g++</value>
<value type="QString" >QTDIR=/usr</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" >SHELL=/bin/bash</value>
<value type="QString" >SHLVL=0</value> <value type="QString" >SHLVL=0</value>
<value type="QString" >SSH_AGENT_PID=9952</value> <value type="QString" >SSH_AGENT_PID=5745</value>
<value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-ngsecP/socket.ssh</value> <value type="QString" >SSH_AUTH_SOCK=/tmp/keyring-qB4w8J/socket.ssh</value>
<value type="QString" >USER=andrey</value> <value type="QString" >USER=andrey</value>
<value type="QString" >USERNAME=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" >XAUTHORITY=/home/andrey/.Xauthority</value>
<value type="QString" >XDG_CONFIG_DIRS=/etc/xdg</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_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> <value type="QString" >XSESSION=icewm</value>
</valuelist> </valuelist>
<valuelist key="abstractProcess.arguments" type="QVariantList" > <valuelist key="abstractProcess.arguments" type="QVariantList" >

View File

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

BIN
aliens.o

Binary file not shown.

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
** Meta object code from reading C++ file 'mainwindow.h' ** 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) ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
** **
** WARNING! All changes made in this file will be lost! ** 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' ** 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) ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
** Resource object code ** 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 ** by: The Resource Compiler for Qt version 4.5.2
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!

View File

@@ -1,7 +1,7 @@
/******************************************************************************** /********************************************************************************
** Form generated from reading ui file 'mainwindow.ui' ** Form generated from reading ui file 'mainwindow.ui'
** **
** Created: Sun 6. Sep 19:03:05 2009 ** Created: Sat Sep 12 14:04:38 2009
** by: Qt User Interface Compiler version 4.5.2 ** by: Qt User Interface Compiler version 4.5.2
** **
** WARNING! All changes made in this file will be lost when recompiling ui file! ** WARNING! All changes made in this file will be lost when recompiling ui file!