00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PowerUp.hpp"
00020
00021 #include <cstdio>
00022
00023 CPowerUp::CPowerUp()
00024 : m_LastFrameUpdate(0),
00025 m_FrameDelay(0),
00026 m_WeaponGroupInc(-1)
00027 {}
00028
00029 CPowerUp::~CPowerUp()
00030 {}
00031
00032 void CPowerUp::Init(const std::string& FileName)
00033 {
00034 char strBuf[100];
00035 std::string HelpString;
00036 std::string OldString;
00037 std::string DataString;
00038 std::string ImageName;
00039
00040 int FrameCount = 1;
00041 float FrameWidth = -1;
00042 float FrameHeight = -1;
00043
00044 FILE* ShipFile = std::fopen(FileName.c_str(),"r");
00045 if(ShipFile == NULL)
00046 {
00047 return;
00048 }
00049
00050 while(std::feof(ShipFile) == 0)
00051 {
00052 std::fscanf(ShipFile,"%s",strBuf);
00053 HelpString = strBuf;
00054
00055 if(HelpString == "=")
00056 {
00057 if(OldString == "Image")
00058 {
00059 std::fscanf(ShipFile,"%s",strBuf);
00060 ImageName = strBuf;
00061 }
00062
00063 if(OldString == "FrameCount")
00064 {
00065 std::fscanf(ShipFile,"%d",&FrameCount);
00066 }
00067
00068 if(OldString == "FrameWidth")
00069 {
00070 std::fscanf(ShipFile,"%f",&FrameWidth);
00071 }
00072
00073 if(OldString == "FrameHeight")
00074 {
00075 std::fscanf(ShipFile,"%f",&FrameHeight);
00076 }
00077
00078 if(OldString == "FrameDelay")
00079 {
00080 std::fscanf(ShipFile,"%d",&m_FrameDelay);
00081 }
00082
00083 if(OldString == "Speed")
00084 {
00085 std::fscanf(ShipFile,"%f",&m_Speed);
00086 }
00087
00088 if(OldString == "EquipWeapon")
00089 {
00090 std::fscanf(ShipFile,"%s",strBuf);
00091 m_EquipWeapon = strBuf;
00092 }
00093
00094 if(OldString == "IncWeaponGroup")
00095 {
00096 std::fscanf(ShipFile,"%d",&m_WeaponGroupInc);
00097 }
00098
00099 if(OldString == "Repair")
00100 {
00101 std::fscanf(ShipFile,"%d",&m_Repair);
00102 }
00103
00104 if(OldString == "CollisionSystem")
00105 {
00106 std::fscanf(ShipFile,"%s",strBuf);
00107 DataString = strBuf;
00108 m_CollisionSystem.Init(DataString);
00109 }
00110
00111 }
00112
00113 OldString = HelpString;
00114 }
00115
00116 std::fclose(ShipFile);
00117 }
00118
00119 void CPowerUp::Update()
00120 {
00121 if(sgl::get_clock().GetElapsedTime()*1000 - m_LastFrameUpdate > m_FrameDelay)
00122 {
00124 m_LastFrameUpdate = sgl::get_clock().GetElapsedTime()*1000;
00125 }
00126
00127 m_Sprite.Move(0.0f,m_Speed);
00128 }
00129