This work presents a study on trajectory optimization for bipedal robots using the direct collocation method on a planar five-link underactuated system. The trajectories are generated using a non-linear program in Python with the aid of the CasADi toolbox. The main objective of the project is to implement optimal dynamic walking for human and ostrich gaits on various types of terrains such as sinusoidal, sloped, staired, and flat. The results of the study show that the proposed method is able to generate efficient and stable trajectories for bipedal robots, making it suitable for real-world applications. A comprehensive analysis of the generated trajectories and their performance on different terrains is also provided to understand the limitations and challenges of the method.