Jelajahi Sumber

Timer werden jetzt angezeigt

Kolja Strohm 4 tahun lalu
induk
melakukan
e3a9a96e26

+ 1 - 1
StickmanWorldOnline/Reader.cpp

@@ -825,7 +825,7 @@ void MapReader::ladeKarte( Spiel *zSpiel )
         char *name = new char[ (int)len + 1 ];
         mapFile.lese( name, len );
         name[ (int)len ] = 0;
-        zSpiel->addTimer( new Timer( zSpiel->getNextId(), name, maxZeit, x, y, sichtbar, autoWiederhohlung, runns, farbe ) );
+        zSpiel->addTimer( new Timer( zSpiel->zResources()->zSchrift(), zSpiel->getNextId(), name, maxZeit, x, y, sichtbar, autoWiederhohlung, runns, farbe ) );
         delete[] name;
     }
     // Tunnel

+ 11 - 1
StickmanWorldOnline/Timer.cpp

@@ -1,7 +1,7 @@
 #include "Timer.h"
 #include "Spiel.h"
 
-Timer::Timer( int id, const char *name, int maxZeit, int x, int y, bool visible, bool autoWiederhohlung, bool runns, int farbe )
+Timer::Timer( Schrift *zSchrift, int id, const char *name, int maxZeit, int x, int y, bool visible, bool autoWiederhohlung, bool runns, int farbe )
     : GameObject( TIMER, x, y, 0, 0 )
 {
     this->id = id;
@@ -10,6 +10,8 @@ Timer::Timer( int id, const char *name, int maxZeit, int x, int y, bool visible,
     currentTime = (float)maxZeit;
     sichtbar = visible;
     this->autoWiederhohlung = autoWiederhohlung;
+    tr.setSchriftSize( 12 );
+    tr.setSchriftZ( zSchrift->getThis() );
     this->runns = runns;
     this->pause = 0;
     this->farbe = farbe;
@@ -75,6 +77,14 @@ void Timer::tick( double time, Spiel *zSpiel )
     }
 }
 
+void Timer::render( Bild &rObj )
+{
+    w = (float)tr.getTextBreite( Text( (int)( currentTime * 100 ) / 100.0 ) );
+    h = (float)tr.getTextHeight( Text( (int)( currentTime * 100 ) / 100.0 ) );
+    if( sichtbar && runns )
+        tr.renderText( (int)x, (int)y, Text( (int)( currentTime * 100 ) / 100.0 ), rObj, farbe );
+}
+
 void Timer::setZeit( float zeit )
 {
     currentTime = zeit;

+ 4 - 1
StickmanWorldOnline/Timer.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "GameObject.h"
+#include <Schrift.h>
 
 class Spiel;
 
@@ -9,6 +10,7 @@ class Timer : public GameObject
 private:
     int id;
     Text name;
+    TextRenderer tr;
     bool runns;
     bool pause;
     int farbe;
@@ -18,7 +20,7 @@ private:
     bool sichtbar;
 
 public:
-    Timer( int id, const char *name, int maxZeit, int x, int y, bool visible = 1, bool autoWiederhohlung = 0, bool runns = 0, int farbe = 0xFFFFFFFF );
+    Timer( Schrift *zSchrift, int id, const char *name, int maxZeit, int x, int y, bool visible = 1, bool autoWiederhohlung = 0, bool runns = 0, int farbe = 0xFFFFFFFF );
     void start( Spiel *zSpiel, bool restart = 0 );
     void setPause( Spiel *zSpiel, bool pause );
     void setMaxZeit( int sekunden );
@@ -26,6 +28,7 @@ public:
     void setSichtbar( bool visible );
     void setFarbe( int farbe );
     void tick( double time, Spiel *zSpiel );
+    void render( Bild &rObj ) override;
     void setZeit( float zeit );
     float getTimeLeft() const;
     bool istSichtbar() const;