<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit Liste]]></title><description><![CDATA[<p>Hallo,<br />
ich hab ein kleines Problem mit einer Liste und hoffe das mir wer helfen kann. Also ich versuch Momentan mein erstes Spiel in C++ (mit der SDL) zu schreiben und brauch dafür ne liste zum Speichern der Einheiten, wenn eine Einheit einen gewissen Punkt erreicht soll die Einheit sich in eine andere Richtung bewegen oder zerstört werden. Hab dafür auch ne Funktion gebastelt, die aber nicht so funktioniert wie ich das will.</p>
<p>Hab jetzt schon gut nen halben Tag versucht das hinzubekommen, aber da ich noch nicht so viel Erfahrung im Programmieren von Spielen hab, find ich den Fehler nicht.</p>
<p>Also zu dem Fehler: Naja eigentlich recht simpel, wenn eine Einheit einen Punkt erreicht wo diese Einheit die Richtung ändern soll ändert es nicht nur die Richtung von der Einheit sondern von allen, sollte aber eben nur die von der ändern.</p>
<p>Naja hier mal der Code von der Funktion:</p>
<pre><code>[cpp]
void CGame::UpdateCreeps()
{
    list&lt;CCreep&gt;::iterator It;
    SDL_Rect Box_A;
    int tile=-1;
    SDL_Rect Box_B;
    for(It= m_CreepList.begin();It != m_CreepList.end();++It)
    {
        Box_B= It-&gt;Get_Box();

        for(int i=0;i&lt;TOTAL_TILES;++i)
        {
            tile =m_pMap-&gt;GetTileTyp(i);
            if(tile!= TILE_BAUBAR|| tile!=TILE_WEG)
            {
                Box_A= m_pMap-&gt;GetTileBox(i);

                // Start Tiles
                if(It-&gt;Get_LastTile()==-1)
                {
                    if(tile==TILE_START_OBEN)
                    {
                        It-&gt;SetPosition(Box_A.x+(Box_A.w-Box_B.w/2),Box_A.y+Box_A.h-Box_B.h);
                        It-&gt;Set_LastTile(TILE_OBEN);
                    }
                    if(tile==TILE_START_UNTEN)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_UNTEN);
                    }
                    if(tile==TILE_START_RECHTS)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_RECHTS);
                    }

                    if(tile==TILE_START_LINKS)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_LINKS);
                    }
                }

                //Normale Tiles
                else if(   (Box_A.x+(Box_A.w-Box_B.w)/2&lt;Box_B.x+2)
                        &amp;&amp; (Box_A.y+(Box_A.h-Box_B.h)/2&lt;Box_B.y+2)
                        &amp;&amp; (Box_A.x+Box_A.w+2&gt;Box_B.x+Box_B.w+(Box_A.w-Box_B.w)/2)
                        &amp;&amp; (Box_A.y+Box_A.h+2&gt;Box_B.y+Box_B.h+(Box_A.h-Box_B.h)/2)
                       )
                {
                    if(tile==TILE_OBEN)
                    {
                        It-&gt;Set_LastTile(TILE_OBEN);
                    }
                    if(tile==TILE_UNTEN)
                    {
                        It-&gt;Set_LastTile(TILE_UNTEN);
                    }
                    if(tile==TILE_RECHTS)
                    {
                        It-&gt;Set_LastTile(TILE_RECHTS);
                    }

                    if(tile==TILE_LINKS)
                    {
                        It-&gt;Set_LastTile(TILE_LINKS);
                    }

                    //ENDE Tiles
                    if(     tile==TILE_ENDE_OBEN
                        ||  tile==TILE_ENDE_UNTEN
                        ||  tile==TILE_ENDE_RECHTS
                        ||  tile==TILE_ENDE_LINKS)
                    {
                        It-&gt;SetAlive(false);
                        It=m_CreepList.erase(It);
                    }
                }
            }
        }
    }
}
[/cpp]
</code></pre>
<p>Erklärung von den Variablen:<br />
tile: schaut welcher tiletyp grad ausgewählt ist<br />
Box_A: Geht nach und nach alle tiles durch<br />
(Box_A.x: X-Korrdinate von der Grafik<br />
Box_A.y: Y-Korrdinate von der Grafik<br />
Box_A.w: länge von der Grafik<br />
Box_A.h: höhe von der Grafik)<br />
Box_B: Geht alle einheiten in der Liste durch<br />
TILE_...: sind Variablen die Werte speichern, was das für ein tile ist</p>
<p>Naja hoff mal ich konnt das so ungefähr erklären.<br />
Fals ich noch was posten soll einfach bescheid sagen.<br />
Noch n Bild<br />
<a href="http://www.pic-upload.de/view-2149986/fehler.jpg.html" rel="nofollow">http://www.pic-upload.de/view-2149986/fehler.jpg.html</a><br />
weiß zwar nicht ob das Bild so viel hilft</p>
<p>Danke schon mal im voraus<br />
mfg stefen</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/241516/problem-mit-liste</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 11:08:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/241516.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 May 2009 17:31:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Liste on Thu, 21 May 2009 17:40:00 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich hab ein kleines Problem mit einer Liste und hoffe das mir wer helfen kann. Also ich versuch Momentan mein erstes Spiel in C++ (mit der SDL) zu schreiben und brauch dafür ne liste zum Speichern der Einheiten, wenn eine Einheit einen gewissen Punkt erreicht soll die Einheit sich in eine andere Richtung bewegen oder zerstört werden. Hab dafür auch ne Funktion gebastelt, die aber nicht so funktioniert wie ich das will.</p>
<p>Hab jetzt schon gut nen halben Tag versucht das hinzubekommen, aber da ich noch nicht so viel Erfahrung im Programmieren von Spielen hab, find ich den Fehler nicht.</p>
<p>Also zu dem Fehler: Naja eigentlich recht simpel, wenn eine Einheit einen Punkt erreicht wo diese Einheit die Richtung ändern soll ändert es nicht nur die Richtung von der Einheit sondern von allen, sollte aber eben nur die von der ändern.</p>
<p>Naja hier mal der Code von der Funktion:</p>
<pre><code>[cpp]
void CGame::UpdateCreeps()
{
    list&lt;CCreep&gt;::iterator It;
    SDL_Rect Box_A;
    int tile=-1;
    SDL_Rect Box_B;
    for(It= m_CreepList.begin();It != m_CreepList.end();++It)
    {
        Box_B= It-&gt;Get_Box();

        for(int i=0;i&lt;TOTAL_TILES;++i)
        {
            tile =m_pMap-&gt;GetTileTyp(i);
            if(tile!= TILE_BAUBAR|| tile!=TILE_WEG)
            {
                Box_A= m_pMap-&gt;GetTileBox(i);

                // Start Tiles
                if(It-&gt;Get_LastTile()==-1)
                {
                    if(tile==TILE_START_OBEN)
                    {
                        It-&gt;SetPosition(Box_A.x+(Box_A.w-Box_B.w/2),Box_A.y+Box_A.h-Box_B.h);
                        It-&gt;Set_LastTile(TILE_OBEN);
                    }
                    if(tile==TILE_START_UNTEN)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_UNTEN);
                    }
                    if(tile==TILE_START_RECHTS)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_RECHTS);
                    }

                    if(tile==TILE_START_LINKS)
                    {
                        It-&gt;SetPosition(Box_A.x+Box_A.w/2-Box_B.w/2,Box_A.y+Box_A.h/2-Box_B.h/2);
                        It-&gt;Set_LastTile(TILE_LINKS);
                    }
                }

                //Normale Tiles
                else if(   (Box_A.x+(Box_A.w-Box_B.w)/2&lt;Box_B.x+2)
                        &amp;&amp; (Box_A.y+(Box_A.h-Box_B.h)/2&lt;Box_B.y+2)
                        &amp;&amp; (Box_A.x+Box_A.w+2&gt;Box_B.x+Box_B.w+(Box_A.w-Box_B.w)/2)
                        &amp;&amp; (Box_A.y+Box_A.h+2&gt;Box_B.y+Box_B.h+(Box_A.h-Box_B.h)/2)
                       )
                {
                    if(tile==TILE_OBEN)
                    {
                        It-&gt;Set_LastTile(TILE_OBEN);
                    }
                    if(tile==TILE_UNTEN)
                    {
                        It-&gt;Set_LastTile(TILE_UNTEN);
                    }
                    if(tile==TILE_RECHTS)
                    {
                        It-&gt;Set_LastTile(TILE_RECHTS);
                    }

                    if(tile==TILE_LINKS)
                    {
                        It-&gt;Set_LastTile(TILE_LINKS);
                    }

                    //ENDE Tiles
                    if(     tile==TILE_ENDE_OBEN
                        ||  tile==TILE_ENDE_UNTEN
                        ||  tile==TILE_ENDE_RECHTS
                        ||  tile==TILE_ENDE_LINKS)
                    {
                        It-&gt;SetAlive(false);
                        It=m_CreepList.erase(It);
                    }
                }
            }
        }
    }
}
[/cpp]
</code></pre>
<p>Erklärung von den Variablen:<br />
tile: schaut welcher tiletyp grad ausgewählt ist<br />
Box_A: Geht nach und nach alle tiles durch<br />
(Box_A.x: X-Korrdinate von der Grafik<br />
Box_A.y: Y-Korrdinate von der Grafik<br />
Box_A.w: länge von der Grafik<br />
Box_A.h: höhe von der Grafik)<br />
Box_B: Geht alle einheiten in der Liste durch<br />
TILE_...: sind Variablen die Werte speichern, was das für ein tile ist</p>
<p>Naja hoff mal ich konnt das so ungefähr erklären.<br />
Fals ich noch was posten soll einfach bescheid sagen.<br />
Noch n Bild<br />
<a href="http://www.pic-upload.de/view-2149986/fehler.jpg.html" rel="nofollow">http://www.pic-upload.de/view-2149986/fehler.jpg.html</a><br />
weiß zwar nicht ob das Bild so viel hilft</p>
<p>Danke schon mal im voraus<br />
mfg stefen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1713838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1713838</guid><dc:creator><![CDATA[*_stefan_* 0]]></dc:creator><pubDate>Thu, 21 May 2009 17:40:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Liste on Thu, 21 May 2009 18:17:57 GMT]]></title><description><![CDATA[<p>Überreisse den Code jetzt nicht.<br />
Bau doch einfach ein Testprogramm in dem du ein Minimalbeispiel mit Konsolenausgabe machst.<br />
Dann siehst du schon, woran es liegt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1713856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1713856</guid><dc:creator><![CDATA[Derbe]]></dc:creator><pubDate>Thu, 21 May 2009 18:17:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Liste on Fri, 22 May 2009 13:49:27 GMT]]></title><description><![CDATA[<p>ok hab den Fehler gefunden, lag aber nicht an der Liste sondern darann wie ich die Einheiten gerendert hab.<br />
Naja kann das jetzt nicht so gut erklären, aber es geht jetzt auf jeden Fall.</p>
<p>und noch mal ein Danke an Derbe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1713875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1713875</guid><dc:creator><![CDATA[*_stefan_* 0]]></dc:creator><pubDate>Fri, 22 May 2009 13:49:27 GMT</pubDate></item></channel></rss>