Преглед на файлове

Bariere, Drop, GameObjekt, Gegenstand, Geschoss und Schalter fertiggestellt

Kolja Strohm преди 5 години
родител
ревизия
1bd82a198f

+ 17 - 4
StickmanWorldOnline/Bariere.cpp

@@ -1,4 +1,6 @@
 #include "Bariere.h"
+#include "Spiel.h"
+#include "Ereignis.h"
 
 
 Bariere::Bariere( int id, int x, int y, int breite, int height, int style, int verschiebungWeite, int autoSchaltungMaxTime, Team *team )
@@ -34,12 +36,16 @@ void Bariere::setAutoVerschiebungWeite( int pixel )
     autoSchaltungMaxTime = pixel;
 }
 
-void Bariere::startAutoVerschiebung()
+void Bariere::startAutoVerschiebung( Spiel *zSpiel )
 {
-    if( hatStyle( Style::AutoVerschiebung ) )
+    if( !hatStyle( Style::AutoVerschiebung ) || hatStyle( Style::InVerschiebung ) )
         return;
     currentWeite = 0;
     setStyle( Style::InVerschiebung, 1 );
+    Ereignis *e = new Ereignis( BARIERE_WIRD_VERSCHOBEN );
+    e->addParameter( "Betroffene Bariere", getThis() );
+    e->addParameter( "Status", new String( "Start" ) );
+    zSpiel->throwEvent( e );
 }
 
 void Bariere::setAutoSchaltungMaxTime( int seconds )
@@ -49,7 +55,7 @@ void Bariere::setAutoSchaltungMaxTime( int seconds )
 
 void Bariere::startAutoSchaltung()
 {
-    if( hatStyle( Style::AutoSchaltung ) )
+    if( !hatStyle( Style::AutoSchaltung ) || hatStyle( Style::InSchaltung ) )
         return;
     autoSchaltungCurrentTime = (float)autoSchaltungMaxTime;
     setStyle( Style::InSchaltung, 1 );
@@ -62,7 +68,7 @@ void Bariere::setTeam( Team *team )
     this->team = team;
 }
 
-void Bariere::tick( double time )
+void Bariere::tick( double time, Spiel* zSpiel)
 {
     if( hatStyle( Style::InSchaltung ) )
     {
@@ -72,6 +78,9 @@ void Bariere::tick( double time )
             setStyle( Style::InSchaltung, 0 );
             setStyle( Style::Aktiv, !hatStyle( Style::Aktiv ) );
             schaltungAnzahl++;
+			Ereignis* e = new Ereignis(BARIERE_SWITCHED);
+			e->addParameter("Betroffene Bariere", getThis());
+			zSpiel->throwEvent(e);
         }
     }
     if( hatStyle( Style::InVerschiebung ) )
@@ -84,6 +93,10 @@ void Bariere::tick( double time )
             setStyle( Style::InVerschiebung, 0 );
             setStyle( Style::NextVerschiebungLinksOben, !hatStyle( Style::NextVerschiebungLinksOben ) );
             verschiebungAnzahl++;
+			Ereignis* e = new Ereignis(BARIERE_WIRD_VERSCHOBEN);
+			e->addParameter( "Betroffene Bariere", getThis() );
+			e->addParameter( "Status", new String( "Feritg" ) );
+			zSpiel->throwEvent(e);
         }
         if( hatStyle( Style::VerschiebungWaagerecht ) )
         {

+ 5 - 3
StickmanWorldOnline/Bariere.h

@@ -4,6 +4,8 @@
 #include "Team.h"
 #include "Timer.h"
 
+class Spiel;
+
 class Bariere : public GameObject
 {
 public:
@@ -30,15 +32,15 @@ private:
     Team *team;
 
 public:
-    Bariere( int id, int x, int y, int breite, int height, int style, int verschiebungWeite = 0, int autoSchaltungMaxTime = 0, Team *team = 0 );
+    Bariere( int id, int x, int y, int breite, int height, int style, int verschiebungWeite = 0, int autoSchaltungMaxTime = 0, Team * team = 0 );
     ~Bariere();
     void setStyle( int style, bool add );
     void setAutoVerschiebungWeite( int pixel );
-    void startAutoVerschiebung();
+    void startAutoVerschiebung( Spiel *zSpiel );
     void setAutoSchaltungMaxTime( int seconds );
     void startAutoSchaltung();
     void setTeam( Team *team );
-    void tick( double time );
+    void tick( double time, Spiel *zSpiel );
     bool hatStyle( int style ) const;
     int getVerschiebungAnzahl() const;
     int getSchaltungAnzahl() const;

+ 105 - 0
StickmanWorldOnline/Drop.cpp

@@ -0,0 +1,105 @@
+#include "Drop.h"
+#include "Spiel.h"
+#include "Ereignis.h"
+
+Drop::Drop( int id, int minX, int maxX, int minY, int maxY, int maxTime, int numDrops, const char *name, float wkeit[ ITEMANZAHL ] )
+    : Variable( DROP )
+{
+    this->name = name;
+    this->minX = minX;
+    this->maxX = maxX;
+    this->minY = minY;
+    this->maxY = maxY;
+    this->maxTime = maxTime;
+    this->nextDrop = maxTime;
+    this->numDrops = numDrops;
+    memcpy( wahrscheinlichkeit, wkeit, sizeof( float ) * ITEMANZAHL );
+}
+
+Drop::~Drop()
+{}
+
+void Drop::setMinX( int x )
+{
+    minX = x;
+}
+
+void Drop::setMaxX( int x )
+{
+    maxX = x;
+}
+
+void Drop::setMinY( int y )
+{
+    minY = y;
+}
+
+void Drop::setMaxY( int y )
+{
+    maxY = y;
+}
+
+void Drop::setMaxTime( int seconds )
+{
+    maxTime = seconds;
+}
+
+void Drop::doDrop( Spiel *zSpiel )
+{
+    nextDrop = maxTime;
+    Ereignis *e = new Ereignis( DROP_AKTION );
+    e->addParameter( "Betroffener Drop", getThis() );
+    zSpiel->throwEvent( e );
+    for( int i = 0; i < numDrops; i++ )
+    {
+        double p = zSpiel->getRand();
+        int typ = 0;
+        for( ; typ < ITEMANZAHL; typ++ )
+        {
+            if( p <= wahrscheinlichkeit[ typ ] )
+                break;
+            p -= wahrscheinlichkeit[ typ ];
+        }
+        int x = (int)( zSpiel->getRand() * ( maxX - minX - 100 ) + minX + 50 );
+        int y = (int)( zSpiel->getRand() * ( maxY - minY - 100 ) + minY + 50 );
+        if( x >= minX + 50 && x < maxX - 50 && y >= minY + 50 && y < maxY - 50 )
+            zSpiel->addGegenstand( new Gegenstand( zSpiel->getNextId(), (GegenstandTyp)typ, 1, x, y, 50, 50 ) );
+    }
+}
+
+void Drop::tick( double time, Spiel *zSpiel )
+{
+    nextDrop -= time;
+    if( nextDrop <= 0 )
+        doDrop( zSpiel );
+}
+
+int Drop::getNumDrops() const
+{
+    return numDrops;
+}
+
+int Drop::getMinX() const
+{
+    return minX;
+}
+
+int Drop::getMaxX() const
+{
+    return maxX;
+}
+
+int Drop::getMinY() const
+{
+    return minY;
+}
+
+int Drop::getMaxY() const
+{
+    return maxY;
+}
+
+int Drop::getMaxTime() const
+{
+    return maxTime;
+}

+ 1 - 1
StickmanWorldOnline/Drop.h

@@ -19,7 +19,7 @@ private:
     float wahrscheinlichkeit[ ITEMANZAHL ];
 
 public:
-    Drop( int minX, int maxX, int minY, int maxY, int maxTime, int numDrops, const char *name, float wkeit[ ITEMANZAHL ] );
+    Drop( int id, int minX, int maxX, int minY, int maxY, int maxTime, int numDrops, const char *name, float wkeit[ ITEMANZAHL ] );
     ~Drop();
     void setMinX( int x );
     void setMaxX( int x );

+ 4 - 3
StickmanWorldOnline/Ereignis.h

@@ -8,10 +8,11 @@ class VarPointer;
 enum EreignisTyp
 {
     AUSLOESER_RUNNED, // "Betroffener Auslöser"
-    BARIERE_SWITCHED,
-    BARIERE_WIRD_VERSCHOBEN,
+    BARIERE_SWITCHED, // "Betroffene Bariere"
+    BARIERE_WIRD_VERSCHOBEN, // "Betroffene Bariere", "Status"
     BASIS_BESITZERWECHSEL, // "Betroffene Basis", "Vorheriges Team", "Nächstes Team"
-    GEGENSTAND_ERSCHEINT,
+    DROP_AKTION, // "Betroffener Drop"
+    GEGENSTAND_DROPED, // "Betroffener Gegenstand"
     INITIALISIERUNG, //
     SCHALTER_AKTIVIERT, // "Betroffener Schalter"
     SPIELER_BENUTZT_GEGENSTAND,

+ 56 - 0
StickmanWorldOnline/GameObject.cpp

@@ -0,0 +1,56 @@
+#include "GameObject.h"
+
+
+GameObject::GameObject( VariableTyp typ, int x, int y, int width, int height )
+    : Variable( typ )
+{
+    this->x = x;
+    this->y = y;
+    w = width;
+    h = height;
+}
+
+void GameObject::setX( int x )
+{
+    this->x = x;
+}
+
+void GameObject::setY( int y )
+{
+    this->y = y;
+}
+
+void GameObject::setWidth( int width )
+{
+    w = width;
+}
+
+void GameObject::setHeight( int height )
+{
+    h = height;
+}
+
+bool GameObject::intersectsWith( GameObject *zObj )
+{
+    return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
+}
+
+int GameObject::getX() const
+{
+    return x;
+}
+
+int GameObject::getY() const
+{
+    return y;
+}
+
+int GameObject::getWidth() const
+{
+    return w;
+}
+
+int GameObject::getHeight() const
+{
+    return h;
+}

+ 1 - 2
StickmanWorldOnline/GameObject.h

@@ -16,8 +16,7 @@ protected:
     float x, y, w, h;
 
 public:
-    GameObject();
-    GameObject( int x, int y, int width, int height );
+    GameObject( VariableTyp typ, int x, int y, int width, int height );
     void setX( int x );
     void setY( int y );
     void setWidth( int width );

+ 42 - 0
StickmanWorldOnline/Gegenstand.cpp

@@ -0,0 +1,42 @@
+#include "Gegenstand.h"
+
+
+GegenstandTypVar::GegenstandTypVar( GegenstandTyp value )
+    : Variable( GEGENSTAND_TYP )
+{
+    this->value = value;
+}
+
+void GegenstandTypVar::setValue( GegenstandTyp value )
+{
+    this->value = value;
+}
+
+GegenstandTyp GegenstandTypVar::getValue() const
+{
+    return value;
+}
+
+
+Gegenstand::Gegenstand( int id, GegenstandTyp typ, bool onMap = 0, int x = 0, int y = 0, int w = 50, int h = 50 )
+    : GameObject( GEGENSTAND, x, y, w, h )
+{
+    this->id = id;
+    this->onMap = onMap;
+    this->typ = typ;
+}
+
+int Gegenstand::getId() const
+{
+    return id;
+}
+
+GegenstandTyp Gegenstand::getTyp() const
+{
+    return typ;
+}
+
+bool Gegenstand::isOnMap() const
+{
+    return onMap;
+}

+ 2 - 1
StickmanWorldOnline/Gegenstand.h

@@ -45,6 +45,7 @@ private:
 
 public:
     Gegenstand( int id, GegenstandTyp typ, bool onMap = 0, int x = 0, int y = 0, int w = 50, int h = 50 );
-    ~Gegenstand();
+    int getId() const;
+    GegenstandTyp getTyp() const;
     bool isOnMap() const;
 };

+ 100 - 0
StickmanWorldOnline/Geschoss.cpp

@@ -0,0 +1,100 @@
+#include "Geschoss.h"
+
+
+Geschoss::Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer )
+    : GameObject( GESCHOSS, x, y, 20, 20 )
+{
+    if( typ == GESCHOSS_PFEIL )
+    {
+        if( r == OBEN || r == UNTEN )
+            setHeight( 50 );
+        else
+            setWidth( 50 );
+    }
+    this->speed = speed;
+    this->richtung = richtung;
+    this->besitzer = besitzer;
+    this->typ = typ;
+    tunnelBenutzt = 0;
+    umgelenkt = 0;
+    geschosseGetroffen = 0;
+    schalter = 0;
+    this->id = id;
+}
+
+Geschoss::~Geschoss()
+{
+    if( besitzer )
+        besitzer->release();
+}
+
+void Geschoss::invertDirection()
+{
+    if( richtung == OBEN )
+        richtung = UNTEN;
+    else if( richtung == RECHTS )
+        richtung = LINKS;
+    else if( richtung == UNTEN )
+        richtung = OBEN;
+    else if( richtung == LINKS )
+        richtung = RECHTS;
+}
+
+void Geschoss::addUmlenkung()
+{
+    umgelenkt++;
+}
+
+void Geschoss::addGeschossTreffer()
+{
+    geschosseGetroffen++;
+}
+
+void Geschoss::addTunnel()
+{
+    schalter++;
+}
+
+void Geschoss::addSchalter()
+{
+    id++;
+}
+
+void Geschoss::setRichtung( Richtung r )
+{
+    richtung = r;
+}
+
+void Geschoss::tick( double zeit )
+{
+    switch( richtung )
+    {
+    case OBEN:
+        y -= zeit * speed;
+        break;
+    case UNTEN:
+        y += zeit * speed;
+        break;
+    case RECHTS:
+        x += zeit * speed;
+        break;
+    case LINKS:
+        x -= zeit * speed;
+        break;
+    }
+}
+
+GeschossTyp Geschoss::getTyp() const
+{
+    return typ;
+}
+
+Spieler *Geschoss::zBesitzer() const
+{
+    return besitzer;
+}
+
+Spieler *Geschoss::getBesitzer() const
+{
+    return besitzer ? (Spieler *)besitzer->getThis() : 0;
+}

+ 5 - 0
StickmanWorldOnline/Geschoss.h

@@ -21,12 +21,17 @@ private:
     int tunnelBenutzt;
     int umgelenkt;
     int geschosseGetroffen;
+    int schalter;
     int id;
 
 public:
     Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer );
     ~Geschoss();
     void invertDirection();
+    void addUmlenkung();
+    void addGeschossTreffer();
+    void addTunnel();
+    void addSchalter();
     void setRichtung( Richtung r );
     void tick( double zeit );
     GeschossTyp getTyp() const;

+ 35 - 0
StickmanWorldOnline/Schalter.cpp

@@ -0,0 +1,35 @@
+#include "Schalter.h"
+
+
+Schalter::Schalter( int id, int x, int y, int width, int height, bool aktive )
+    : GameObject( SCHALTER, x, y, width, height )
+{
+    this->id = id;
+    this->aktiv = aktive;
+    aktivierungen = 0;
+}
+
+void Schalter::setAktive( bool aktiv )
+{
+    this->aktiv = aktiv;
+}
+
+void Schalter::press()
+{
+    aktivierungen++;
+}
+
+int Schalter::getAnzahlAktivierungen() const
+{
+    return aktivierungen;
+}
+
+bool Schalter::isAktive() const
+{
+    return aktiv;
+}
+
+int Schalter::getId() const
+{
+    return id;
+}

+ 3 - 4
StickmanWorldOnline/Schalter.h

@@ -6,13 +6,12 @@ class Schalter : public GameObject
 {
 private:
     int id;
-    bool aktiv = true;
-    int aktivierungen = 0;
+    bool aktiv;
+    int aktivierungen;
 
 public:
     Schalter( int id, int x, int y, int width, int height, bool aktive );
-    ~Schalter();
-    void setAktive() const;
+    void setAktive( bool aktiv );
     void press();
     int getAnzahlAktivierungen() const;
     bool isAktive() const;

+ 59 - 30
StickmanWorldOnline/Spiel.cpp

@@ -363,7 +363,7 @@ void Spiel::tick( double zeit )
     }
     // barieren bewegung
     for( auto b = barieren.getIterator(); b; b++ )
-        b->tick( zeit );
+        b->tick( zeit, this );
     // geschoss bewegung
     for( int i = 0; i < shots.getEintragAnzahl(); i++ )
     {
@@ -413,12 +413,13 @@ void Spiel::tick( double zeit )
             {
                 if( t->istAktiv() && t->intersectsWith( g ) )
                 {
+                    g->setX( g->getX() + t->getZielX() - t->getX() );
+                    g->setY( g->getY() + t->getZielY() - t->getY() );
+                    g->addTunnel();
                     Ereignis *e = new Ereignis( TUNNEL_BENUTZT );
                     e->addParameter( "Betroffes Geschoss", g->getThis() );
                     e->addParameter( "Betroffer Tunnel", t->getThis() );
                     throwEvent( e );
-                    g->setX( g->getX() + t->getZielX() - t->getX() );
-                    g->setY( g->getY() + t->getZielY() - t->getY() );
                 }
             }
             // geschoss - schalter intersection
@@ -431,6 +432,7 @@ void Spiel::tick( double zeit )
                         shots.remove( i );
                         i--;
                         removed = 1;
+                        g->addSchalter();
                         activateShalter( s->getId() );
                     }
                 }
@@ -444,47 +446,70 @@ void Spiel::tick( double zeit )
                     {
                         if( u->isAktive() && !u->hatAbklingzeit() && g->getTyp() != GESCHOSS_PFEIL && u->intersectsWith( g ) )
                         {
+                            g->setRichtung( u->getRichtung() );
+                            g->addUmlenkung();
+                            u->addBenutzt();
                             Ereignis *e = new Ereignis( UMLENKUNG_LENKT_UM );
                             e->addParameter( "Betroffes Geschoss", g->getThis() );
                             e->addParameter( "Betroffe Umlenkung", u->getThis() );
                             throwEvent( e );
-                            g->setRichtung( u->getRichtung() );
-                            u->addBenutzt();
                         }
                     }
                 }
-                // geschoss - spieler intersection
-                for( auto s = spieler.getIterator(); s; s++ )
+                // geschoss - geschoss intersection
+                if( g->getTyp() == GESCHOSS_PFEIL )
                 {
-                    if( s->istAmLeben() && s != g->zBesitzer() )
+                    for( int j = 0; j < shots.getEintragAnzahl(); j++ )
                     {
-                        switch( g->getTyp() )
+                        if( i == j )
+                            continue;
+                        Geschoss *g2 = shots.z( j );
+                        if( g2->intersectsWith( g ) )
                         {
-                        case GESCHOSS_PFEIL:
-                        case GESCHOSS_KUGEL:
+                            if( g2->getTyp() == GESCHOSS_PFEIL )
+                                removed = 1;
+                            g->addGeschossTreffer();
+                            if( j < i )
+                                i--;
+                            shots.remove( j );
+                        }
+                    }
+                }
+                if( !removed )
+                {
+                    // geschoss - spieler intersection
+                    for( auto s = spieler.getIterator(); s; s++ )
+                    {
+                        if( s->istAmLeben() && s != g->zBesitzer() )
                         {
-                            double schaden = 100 + ( g->zBesitzer() ? g->zBesitzer()->getSchadenBonus() : 0 );
-                            s->nimmSchaden( schaden );
-                            if( g->zBesitzer() )
+                            switch( g->getTyp() )
+                            {
+                            case GESCHOSS_PFEIL:
+                            case GESCHOSS_KUGEL:
                             {
-                                g->zBesitzer()->addGemachterSchaden( schaden );
-                                if( !s->istAmLeben() )
-                                    g->zBesitzer()->addKill();
+                                double schaden = 100 + ( g->zBesitzer() ? g->zBesitzer()->getSchadenBonus() : 0 );
+                                s->nimmSchaden( schaden );
+                                if( g->zBesitzer() )
+                                {
+                                    g->zBesitzer()->addGemachterSchaden( schaden );
+                                    if( !s->istAmLeben() )
+                                        g->zBesitzer()->addKill();
+                                }
+                                break;
                             }
-                            break;
-                        }
-                        case GESCHOSS_DRACHENAUGE:
-                            s->addEffekt( new DrachenAugeEffekt( g->zBesitzer(), s._, 10 ) );
-                            break;
-                        case GESCHOSS_FEUERBALL:
-                            feuer.add( new FeuerballTreffer( ++nextId, g->getX() - 70, g->getY() - 70, g->getBesitzer(), 10 ) );
+                            case GESCHOSS_DRACHENAUGE:
+                                s->addEffekt( new DrachenAugeEffekt( g->zBesitzer(), s._, 10 ) );
+                                break;
+                            case GESCHOSS_FEUERBALL:
+                                feuer.add( new FeuerballTreffer( ++nextId, g->getX() - 70, g->getY() - 70, g->getBesitzer(), 10 ) );
+                            }
+                            if( g->zBesitzer() )
+                                g->zBesitzer()->addTreffer();
+                            s->addGetroffen();
+                            shots.remove( i );
+                            i--;
+                            removed = 1;
                         }
-                        if( g->zBesitzer() )
-                            g->zBesitzer()->addTreffer();
-                        s->addGetroffen();
-                        shots.remove( i );
-                        i--;
-                        removed = 1;
                     }
                 }
             }
@@ -576,6 +601,9 @@ void Spiel::addDrop( Drop * drop )
 void Spiel::addGegenstand( Gegenstand * gegenstand )
 {
     items.add( gegenstand );
+    Ereignis *e = new Ereignis( GEGENSTAND_DROPED );
+    e->addParameter( "Betroffener Gegenstand", gegenstand->getThis() );
+    throwEvent( e );
 }
 
 void Spiel::addGeschoss( Geschoss * geschoss )
@@ -659,6 +687,7 @@ void Spiel::activateShalter( int id )
     {
         if( s->getId() == id )
         {
+            s->press();
             Ereignis *e = new Ereignis( SCHALTER_AKTIVIERT );
             e->addParameter( "Betroffener Schalter", s->getThis() );
             throwEvent( e );

+ 1 - 0
StickmanWorldOnline/Spiel.h

@@ -114,6 +114,7 @@ public:
     Umlenkung *getUmlenkung( int id ) const;
     Trigger *getTrigger( int id ) const;
     int getNextId();
+    double getRand();
     // constant
     StatistikV *getStatistik() const override;
     // Reference Counting 

+ 5 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj

@@ -80,7 +80,12 @@
     <ClCompile Include="Bariere.cpp" />
     <ClCompile Include="Base.cpp" />
     <ClCompile Include="DllStart.cpp" />
+    <ClCompile Include="Drop.cpp" />
+    <ClCompile Include="GameObject.cpp" />
+    <ClCompile Include="Gegenstand.cpp" />
+    <ClCompile Include="Geschoss.cpp" />
     <ClCompile Include="Reader.cpp" />
+    <ClCompile Include="Schalter.cpp" />
     <ClCompile Include="Spiel.cpp" />
     <ClCompile Include="Team.cpp" />
     <ClCompile Include="Timer.cpp" />

+ 15 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj.filters

@@ -57,6 +57,21 @@
     <ClCompile Include="Base.cpp">
       <Filter>Spiel\Objekte</Filter>
     </ClCompile>
+    <ClCompile Include="Drop.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
+    <ClCompile Include="GameObject.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
+    <ClCompile Include="Gegenstand.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
+    <ClCompile Include="Geschoss.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
+    <ClCompile Include="Schalter.cpp">
+      <Filter>Spiel\Objekte</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="SpielKlasse.h">

+ 3 - 0
StickmanWorldOnline/Variablen.h

@@ -19,7 +19,10 @@ enum VariableTyp
     BARIERE,
     SCHALTER,
     BASE,
+    DROP,
     GEGENSTAND,
+    GEGENSTAND_TYP,
+    GESCHOSS,
     SCHIENE,
     TUNNEL,
     UMLENKUNG,