As usual, create a directory to hold today's files. All programs that you write today should be stored in this directory.
$ cd ~/cs120/labs $ mkdir lab23 $ cd lab23
Write a function double_all(a_list)
, which takes
a
list of floating point numbers. Your function should
return a
version of a_list with all values doubled.
Write a function remove_all(a_list, an_element)
,
which
takes a list and some element. Your function should remove
all
occurances of an_element from a_list, and return the
resulting list.
Flappy Bird was an incredibly popular game back in the Spring of 2013. It made A LOT of money, especially considering it was a "free" game. The game was suddenly removed from the App Store, but the initial success of the game resulted in many clones being available almost instantly. The overall game is not super difficult to replicate, now that we have lists!
Create a python program in a file called flappy.py. This file will replicate a somewhat simplified version of the Flappy Bird game. Towards this end, you will want to replicate the gravity function demonstrated in class earlier today. Don't forget to place the graphics module and sprite module in your directory.
Every 3 seconds, a new pipe should be generated. It should start at the right side of the screen, and slowly work its way to the left side of the screen. The height of the pipe should be randomly generated. Every pipe generated should be stored in a list, so that all of the pipes can be updated at once.
Create a function called move_pipes(pipe_list)
,
which takes a list of Sprite objects which represent pipes in the
game. This function should move all of the pipes to the left by the
same amount. If a pipe is past the left edge of the screen, you
should remove.
Also create a function called check_collision(bird_sprite,
pipe_list)
, which takes the bird sprite object and a list of
the pipe objects. It should return True if the bird sprite
is colliding with any of the pipes.
Use these two functions to replicate a simple version of flappy bird, with pipes only on one side (bottom) of the screen.
graphics.draw_sprite
.
Modify your program so that there are pipe sprites along the top of the screen as well. You will either need to flip the pipe sprite, or find a different sprite for the top.