void World::Initialize() { for (int i = 0; i < kMaxEnemies; ++i) { myEnemies[i] = nullptr; } for (int i = 0; i < kMaxBullets; ++i) { myBullets[i].Load(); } for (int i = 0; i < kMaxBullets; ++i) { mCollidables[i].Load(); } for (int i = 0; i < MaxEnemyBullets; ++i) { mEnemyBullets1[i].Load(); } for (int i = 0; i < MaxEnemyBullets2; ++i) { mEnemyBullets2[i].Load(); } for (int i = 0; i < MaxGenkidama; ++i) { mGenkidama[i].Load(); } for (int i = 0; i < kMaxExplosions; ++i) { myExplosions[i].Load("explosion.txt"); } myFighter.Load(); Score.Load(30); HighestScore.Load(30); myBackground.Load("namek_water.jpg"); myFireSound1.Load("photongun1.wav"); myFireSound2.Load("deathball_fire.wav"); myExplosionSound.Load("explosion.wav"); //mCollidable.Load(); const int kWinWidth = IniFile_GetInt("WinWidth", 800); const int kWinHeight = IniFile_GetInt("WinHeight", 600); const float x = kWinWidth * 0.5f; const float y = kWinHeight * 0.75f; myFighter.SetPosition(Vector2(x, y)); myFighter.SetSpeed(SGE::IniFile_GetFloat("DefaultSpeed", 200.0f)); }
void Raknet::Connect() { // Get the ip address const char* mIP = IniFile_GetString("SERVER_IP", "127.0.0.1"); int port = IniFile_GetInt("SERVER_PORT", 1337); mPeer->Startup(1,&mSD, 1); mPeer->Connect(mIP, port, 0,0); }
void Bullet::Update(float deltaTime) { if (mActive) { mPosition += mVelocity * deltaTime; const float threshold = mSprite.GetWidth() * 0.5f; const float left = -threshold; const float top = -threshold; const float right = IniFile_GetInt("WinWidth", 800) + threshold; const float bottom = IniFile_GetInt("WinHeight", 600) + threshold; const Rect boundary(left, top, right, bottom); if (!Math_PointInRect(mPosition, boundary)) { Kill(); } } }
void CharacterCombat::Load() { mSprite.Unload(); char temp[CHAR_MAX]; // Get the right frames mFrames.WalkDownStart = IniFile_GetInt("WALK_DOWN_START", 1); mFrames.WalkLeftStart = IniFile_GetInt("WALK_LEFT_START", 5); mFrames.WalkUpStart = IniFile_GetInt("WALK_UP_START", 9); sprintf(temp, "Sprites/%d/%d.png", mPlayerInfo.GetSpriteNumber(), mFrames.WalkDownStart); mSprite.Add(temp); sprintf(temp, "Sprites/%d/%d.png", mPlayerInfo.GetSpriteNumber(), mFrames.WalkLeftStart); mSprite.Add(temp); sprintf(temp, "Sprites/%d/%d.png", mPlayerInfo.GetSpriteNumber(), mFrames.WalkUpStart); mSprite.Add(temp); }
void NPC::ReloadGraphic() { mSprite.Unload(); int walkAnimations = IniFile_GetInt("SPRITE_WALK_ANIMATIONS", 16); char temp[CHAR_MAX]; for (int a = 1; a < walkAnimations; ++a) { sprintf(temp, "Sprites/%d/%d.png", mNPCData.mSpriteNumber, a); mSprite.Add(temp); } }
void MinionEnemy::Spawn() { const float kWinWidth = (float)IniFile_GetInt("WinWidth", 800); const float threshold = 100.0f; const float x = Random_GetFloat(threshold, kWinWidth - threshold); const float y = -(float)mSprite.GetHeight(); mPosition = Vector2(x, y); mVelocity = Vector2(100.0f, 100.0f); mTimer = Random_GetFloat(0.0f, 1.5f); mActive = true; }
void Map::Init() { char temp[CHAR_MAX]; sprintf(temp, "Maps/Maps%d.oel", mPlayerInfo.GetMap()); FILE* pFile = fopen(temp, "rb"); mTilesetWidth = IniFile_GetInt("TILESET_WIDTH", 5); mTilesetHeight = IniFile_GetInt("TILESET_HEIGHT", 5); // We already have the map if (pFile) { Load(); } //else // We dont have the map better get it RakNet::BitStream bsOut; bsOut.Write((RakNet::MessageID) ID_MAP_DATA); mRaknet.mPeer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, mRaknet.mServerAddress, false); mWeather.Init(); }
bool MinionEnemy::Update(float deltaTime) { if (mActive) { mTimer -= deltaTime; if (mTimer <= 0.0f) { mVelocity.x *= -1.0f; mTimer = Random_GetFloat(0.0f, 1.5f); } mPosition += mVelocity * deltaTime; const float threshold = (float)mSprite.GetHeight(); const float bottom = IniFile_GetInt("WinHeight", 600) + threshold; if (mPosition.y > bottom) { Kill(); } } return mActive; }
void Player::Init() { mSprite.Unload(); int walkAnimations = IniFile_GetInt("SPRITE_WALK_ANIMATIONS", 16); char temp[CHAR_MAX]; for(int a = 1; a < walkAnimations; ++a) { sprintf(temp,"Sprites/%d/%d.png", mPlayerInfo.GetSpriteNumber(), a); mSprite.Add(temp); } // Get the right frames mFrames.WalkDownStart = IniFile_GetInt("WALK_DOWN_START", 1); mFrames.WalkDownEnd = IniFile_GetInt("WALK_DOWN_END", 4); mFrames.WalkLeftStart = IniFile_GetInt("WALK_LEFT_START", 5); mFrames.WalkLeftEnd = IniFile_GetInt("WALK_LEFT_END", 8); mFrames.WalkUpStart = IniFile_GetInt("WALK_UP_START", 9); mFrames.WalkUpEnd = IniFile_GetInt("WALK_UP_END", 12); mInit = true; mNewPosition = mPlayerInfo.GetPosition(); }
void NPC::Init(int mapWidth, int mapHeight, Graph* graph) { mGraph = graph; mMapWidth = mapWidth / 32; mMapHeight = mapHeight / 32; int walkAnimations = IniFile_GetInt("SPRITE_WALK_ANIMATIONS", 16); char temp[CHAR_MAX]; for (int a = 1; a < walkAnimations; ++a) { sprintf(temp, "Sprites/%d/%d.png", mNPCData.mSpriteNumber, a); mSprite.Add(temp); } // Get the right frames mFrames.WalkDownStart = IniFile_GetInt("WALK_DOWN_START", 1); mFrames.WalkDownEnd = IniFile_GetInt("WALK_DOWN_END", 4); mFrames.WalkLeftStart = IniFile_GetInt("WALK_LEFT_START", 5); mFrames.WalkLeftEnd = IniFile_GetInt("WALK_LEFT_END", 8); mFrames.WalkUpStart = IniFile_GetInt("WALK_UP_START", 9); mFrames.WalkUpEnd = IniFile_GetInt("WALK_UP_END", 12); mFont.SetColor(255, 0, 255); mInit = true; }
BaseState::BaseState(GameContext& gc) : mGameContext(gc) , kScreenWidth(IniFile_GetInt("WinWidth", 1280)) , kScreenHeight(IniFile_GetInt("WinHeight", 720)) { }
void Map::UpdateRaknet() { switch (mRaknet.mPacket->data[0]) { case ID_ITEM_TAKEN: { int itemIndex = 0; RakNet::BitStream bsIn(mRaknet.mPacket->data, mRaknet.mPacket->length, false); bsIn.IgnoreBytes(sizeof(RakNet::MessageID)); bsIn.Read(itemIndex); mMapData.mLayer1[itemIndex].SetActive(false); break; } case ID_DROP_ITEM: { int imageNumber = 0; int index = 0; RakNet::BitStream bsIn(mRaknet.mPacket->data, mRaknet.mPacket->length, false); bsIn.IgnoreBytes(sizeof(RakNet::MessageID)); bsIn.Read(imageNumber); bsIn.Read(index); AddItem(imageNumber, index); break; } case ID_MAP_DATA: { int map = 0; int width = 0; int height = 0; int tiles = 0; RakNet::BitStream bsIn(mRaknet.mPacket->data, mRaknet.mPacket->length, false); bsIn.IgnoreBytes(sizeof(RakNet::MessageID)); bsIn.Read(map); bsIn.Read(width); bsIn.Read(height); bsIn.Read(tiles); mMapData.SetWidth(width); mMapData.SetHeight(height); mMapData.SetNumberOfTiles(tiles); mMapData.CreateTiles(); for (int a = 0; a < tiles; ++a) { bsIn.Read(mMapData.mLayer1[a]); bsIn.Read(mMapData.mLayer2[a]); bsIn.Read(mMapData.mLayer3[a]); bsIn.Read(mMapData.mLayer4[a]); } bsIn.Read(mNumberOfNPCS); for (int a = 0; a < mNumberOfNPCS; ++a) { NPC* temp = new NPC(mRaknet, a); bsIn.Read(temp->GetData()); mNPCS.push_back(temp); } // Save map so we dont need to retrieve it every time Save(); // Create are tiles for the map mNumberOfItems = IniFile_GetInt("Number_Of_items", 5); LoadTiles(); LoadItems(); mPathFinding.Init(GetWidth(), GetHeight(), &mMapData.mLayer1[0]); // Load npcs for (int a = 0; a < mNumberOfNPCS; ++a) { NPC* temp = mNPCS[a]; NPCData& tempData = temp->GetData(); temp->Init(width, height, mPathFinding.GetGraph()); temp->ReloadGraphic(); if (!tempData.mHost) { temp->CreatePath(); } } int north = 0; int east = 0; int south = 0; int west = 0; bsIn.Read(north); bsIn.Read(east); bsIn.Read(south); bsIn.Read(west); mMapData.SetNorth(north); mMapData.SetEast(east); mMapData.SetSouth(south); mMapData.SetWest(west); break; } case ID_NPC_NEW_PATH: { int npcSlot = 0; int endIndex = 0; SVector2 position(0.0f, 0.0f); RakNet::BitStream bsIn(mRaknet.mPacket->data, mRaknet.mPacket->length, false); bsIn.IgnoreBytes(sizeof(RakNet::MessageID)); bsIn.Read(npcSlot); bsIn.Read(endIndex); bsIn.Read(position); NPC* tempNPC = mNPCS[npcSlot]; tempNPC->SetEndPath(endIndex); tempNPC->CreatePath(); tempNPC->GetData().SetPosition(position); break; } case ID_NPC_HOST: { for (int a = 0; a < mNumberOfNPCS; ++a) { mNPCS[a]->GetData().SetHost(true); } break; } case ID_NPC_STOP: { if (!mMemoryCreated) break; int npcSlot = 0; bool stop = false; RakNet::BitStream bsIn(mRaknet.mPacket->data, mRaknet.mPacket->length, false); bsIn.IgnoreBytes(sizeof(RakNet::MessageID)); bsIn.Read(npcSlot); bsIn.Read(stop); if (stop) { int test = 0; } mNPCS[npcSlot]->SetStop(stop); break; } } }