// ------------------------------------------------------------------------------------------------ void Map :: LoadMap(std::string fileName) { std::ifstream mapFile (fileName.c_str()); assert(mapFile.is_open()); int data; for(Tile y = 0; y < MAP_NUM_TILES_Y; y++) { for(Tile x = 0; x < MAP_NUM_TILES_X; x++) { mapFile >> data; if( (TileType)data < TILE_TYPE_BULLET_PICKUP) { tileTypes[x][y] = (TileType)data; } else { tileTypes[x][y] = TILE_TYPE_SPACE; if((TileType)data == TILE_TYPE_BULLET_PICKUP) { game->CreatePickUp(Vector2df(x * MAP_TILE_SIZE + MAP_TILE_SIZE / 2, y * MAP_TILE_SIZE + MAP_TILE_SIZE / 2), PICK_UP_TYPE_BULLETS); } else if((TileType)data == TILE_TYPE_MINE_PICKUP) { game->CreatePickUp(Vector2df(x * MAP_TILE_SIZE + MAP_TILE_SIZE / 2, y * MAP_TILE_SIZE + MAP_TILE_SIZE / 2), PICK_UP_TYPE_MINES); } else if((TileType)data == TILE_TYPE_MISSILE_PICKUP) { game->CreatePickUp(Vector2df(x * MAP_TILE_SIZE + MAP_TILE_SIZE / 2, y * MAP_TILE_SIZE + MAP_TILE_SIZE / 2), PICK_UP_TYPE_MISSILES); } else if((TileType)data == TILE_TYPE_REPAIR_PICKUP) { game->CreatePickUp(Vector2df(x * MAP_TILE_SIZE + MAP_TILE_SIZE / 2, y * MAP_TILE_SIZE + MAP_TILE_SIZE / 2), PICK_UP_TYPE_REPAIR); } else if((TileType)data == TILE_TYPE_SPAWN) { CreateSpawnPoint(Vector2df(x * MAP_TILE_SIZE + MAP_TILE_SIZE / 2, y * MAP_TILE_SIZE + MAP_TILE_SIZE / 2)); } } } } mapFile.close(); CalculateGravityVectors(); } // ----------------------------------------------------------------------------------------------
bool CTrackball::DoTracking(int x, int y) { if (!m_tracking) return false; Vector2df delta = m_start - Vector2df((float)x, (float)y); delta /= 2; Vector3df mouse(delta.x, -delta.y, 0.0f); Vector3df dep(0.0f, 0.0f, 1.0f); Vector3df axis(0.0f, 0.0f, 0.0f); // axis will be perpendicular to mouse and dep vectors // this is our rotation axis axis = mouse ^ dep; axis.Normalize(); // every 100 pixels is 360 degress or rotation //GLfloat len = axis.Magnitude() / 100.0f; GLfloat len = fabs(delta.Magnitude()); while (len > 360.0f) len -= 360.0f; ATLTRACE("delta_x : %f, delta_y: %f\n", mouse.x, mouse.y); ATLTRACE("axis: x:%f y:%f z:%f\n", axis.x, axis.y, axis.z, len); ATLTRACE("angle: %f\n", len); m_rotation_delta.CreateFromAxisAngle(axis.x, axis.y, axis.z, len); m_quat = m_rotation_delta * m_rotation; return true; // still tracking }
const GuiEvent& GUI::update() { // Update events static GuiEvent currentEvent; static SDL_Event event; currentEvent.click = false; if(currentEvent.buttonState == BTN_PRESSED) currentEvent.buttonState = BTN_HOLD; else if(currentEvent.buttonState == BTN_RELEASED) currentEvent.buttonState = BTN_NONE; if(SDL_PollEvent(&event)){ if(event.type == SDL_QUIT) currentEvent.quitEvent = true; else if(event.type == SDL_MOUSEBUTTONDOWN) { currentEvent.buttonState = BTN_PRESSED; currentEvent.clickStart = converter.deconvert(Vector2df(event.button.x, event.button.y)); } else if(event.type == SDL_MOUSEBUTTONUP) { currentEvent.buttonState = BTN_RELEASED; currentEvent.click = true; currentEvent.clickEnd = converter.deconvert(Vector2df(event.button.x, event.button.y)); //cout << Vector2df(event.button.x, event.button.y) << '\t' << convert(currentEvent.clickEnd) << endl; //cout << currentEvent.clickEnd << endl; } } // Draw force vector /*if(currentEvent.buttonState == BTN_HOLD) lineRGBA(display, convert(currentEvent.clickStart).x(), convert(currentEvent.clickStart).y(), event.button.x, event.button.y, 255, 255, 255, 255);*/ if(currentEvent.buttonState == BTN_HOLD) forceMeter.drawForceVector(display, converter.convert(currentEvent.clickStart) , Vector2Df(event.button.x , event.button.y)); // Flip the screen SDL_Flip(display); return currentEvent; }
// ---------------------------------------------------------------------------------------------- Vector2df Map :: GetRandomSpawnPointPos() const { if(currentSpawnPoint != 0) { int spawnPointID = rand() % currentSpawnPoint; return spawnPoints[spawnPointID]; } else { return Vector2df(0,0); } } // --------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------- Vector2df Map :: GetPosGravity(Vector2df atPos) const { // Out of bounds positions are always considered to have 0 gravity: if(atPos.x < MAP_MIN_POS_X || atPos.x >= MAP_MAX_POS_X || atPos.y < MAP_MIN_POS_Y || atPos.y >= MAP_MAX_POS_Y) { return Vector2df(); } else { // This is probly fucky: int tileX = (atPos.x - screenPos.x) / MAP_TILE_SIZE; int tileY = (atPos.y - screenPos.y) / MAP_TILE_SIZE; return GetTileGravity(tileX, tileY); } } // --------------------------------------------------------------------------------------------
void ArenaMonster::SetDead(int herox, int heroy) { m_IsDead = true; m_bmpCurrentPtr = &m_bmpSpinning; //---------------------------------------------------------- // Calculate the Speed - "Math-gic" by foxblock //---------------------------------------------------------- // Insert the desired moving speed here: const double speed = 25.0; // Position difference between monster and hero const Vector2df diff = Vector2df((m_X + m_bmpCurrentPtr->getWidth() / 2)-(herox + 96.0),(m_Y + m_bmpCurrentPtr->getHeight() / 2)-(heroy + 112.0)); // Math magic m_DeathSpeedX = round( diff.x / sqrt( pow(diff.x,2) + pow(diff.y,2) ) * speed ); m_DeathSpeedY = round( diff.y / sqrt( pow(diff.x,2) + pow(diff.y,2) ) * speed ); }
// ------------------------------------------------------------------------------------------------ bool ProjectileBase :: IsSolid(Vector2df atPos) const { return type != PROJECTILE_TYPE_SMOKE && Vector2df(Pos() - atPos).Length() < radius; } // ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------ Vector2df ProjectileBase :: Heading() const { return Vector2df(headingDeg); } // ----------------------------------------------------------------------------------------------