I'm trying to make a game that resembles "Falldown," a TI-83 calculator game that I used to play in high school, using the curses
library in Python. It involves a forever falling ball that you have to manoeuvre through holes and if you don't make it to the hole, the ball will get squished at the top of the screen (YouTube it).
So far, I just have an Obstacle class that doesn't even have holes yet. I just want my obstacles to be forever "scrolling up". I can make it work for one obstacle (obs1
) but when I try to add a second (obs2
), bad things happen. In the code below, both obstacles are on the screen but they are right on top of each other so it only looks like one obstacle.
Basically, how can I start my obs2
when obs1
reaches halfway up the screen?
#!/usr/bin/python
import curses
import time
import random
class obstacle:
def __init__(self):
self.pos = dims[0]-1
self.s = ''
for x in range(0,dims[1]-1):
self.s += '='
def scroll(self):
self.pos -= 1
screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
screen.nodelay(1)
dims = screen.getmaxyx()
q=-1
obs1 = obstacle()
obs2 = obstacle()
while q < 0:
q = screen.getch()
if obs1.pos < 0:
obs1 = obstacle()
if obs2.pos < 0:
obs2 = obstacle()
screen.clear()
screen.addstr(obs1.pos, 0, obs1.s, curses.color_pair(1))
screen.addstr(obs2.pos, 0, obs2.s, curses.color_pair(1))
obs1.scroll()
obs2.scroll()
screen.refresh()
time.sleep(.04)
screen.getch()
curses.endwin()
Eventually I will want about 4 obstacles on the screen at once, forever scrolling upwards. Any hints to get me started with 2?