mirror of
https://github.com/robmcmullen/fujirun.git
synced 2025-01-01 04:29:14 +00:00
Added 2 player controls & fixed scoring for 2nd player * maze can be updated at the time of change, only the screen update needs to be delayed until it's ready for background mods
This commit is contained in:
parent
ce1f98a073
commit
635fd95528
@ -43,11 +43,13 @@ import curses
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
init_log = logging.getLogger("init")
|
init_log = logging.getLogger("init")
|
||||||
logic_log = logging.getLogger("logic")
|
logic_log = logging.getLogger("logic")
|
||||||
draw_log = logging.getLogger("draw")
|
draw_log = logging.getLogger("draw")
|
||||||
maze_log = logging.getLogger("maze")
|
maze_log = logging.getLogger("maze")
|
||||||
box_log = logging.getLogger("maze")
|
box_log = logging.getLogger("maze")
|
||||||
|
box_log.setLevel(logging.DEBUG)
|
||||||
game_log = logging.getLogger("game")
|
game_log = logging.getLogger("game")
|
||||||
|
|
||||||
CURSES = 1
|
CURSES = 1
|
||||||
@ -69,7 +71,7 @@ def init_screen(*args, **kwargs):
|
|||||||
curses.start_color()
|
curses.start_color()
|
||||||
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
|
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
pad = curses.newpad(30, 80)
|
pad = curses.newpad(40, 80)
|
||||||
pad.timeout(0)
|
pad.timeout(0)
|
||||||
pad.keypad(1)
|
pad.keypad(1)
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ def main():
|
|||||||
|
|
||||||
level = 1
|
level = 1
|
||||||
cur_enemies = level_enemies[level]
|
cur_enemies = level_enemies[level]
|
||||||
cur_players = 1
|
cur_players = 2
|
||||||
init_enemies()
|
init_enemies()
|
||||||
init_players()
|
init_players()
|
||||||
init_static_background()
|
init_static_background()
|
||||||
@ -437,8 +439,9 @@ box_row_save = 0
|
|||||||
# a dot, and because it will take multiple frames to paint a box there may be
|
# a dot, and because it will take multiple frames to paint a box there may be
|
||||||
# even more active at one time, so for safety use 16 as possible max.
|
# even more active at one time, so for safety use 16 as possible max.
|
||||||
#
|
#
|
||||||
# xbyte, ytop, ybot
|
# player #, xbyte, ytop, ybot
|
||||||
box_painting = [0] * 3 * 16
|
num_box_painting_params = 4
|
||||||
|
box_painting = [0] * num_box_painting_params * 16
|
||||||
|
|
||||||
def init_boxes():
|
def init_boxes():
|
||||||
next_level_box = 0
|
next_level_box = 0
|
||||||
@ -490,24 +493,25 @@ def check_boxes(i):
|
|||||||
|
|
||||||
if (dot & tiledot) == 0:
|
if (dot & tiledot) == 0:
|
||||||
# No dots anywhere! Start painting
|
# No dots anywhere! Start painting
|
||||||
mark_box_for_painting(r1_save, r2, c + 1)
|
mark_box_for_painting(i, r1_save, r2, c + 1)
|
||||||
num_rows = r2 - r1_save
|
num_rows = r2 - r1_save
|
||||||
player_score[i] += num_rows * 100
|
player_score[i] += num_rows * 100
|
||||||
level_boxes[x] = 0 # Set flag so we don't check this box again
|
level_boxes[x] = 0 # Set flag so we don't check this box again
|
||||||
|
|
||||||
x += 3
|
x += 3
|
||||||
|
|
||||||
def mark_box_for_painting(r1, r2, c):
|
def mark_box_for_painting(i, r1, r2, c):
|
||||||
box_log.debug("Marking box at %d,%d -> %d,%d" % (r1, c, r2, c + box_width))
|
box_log.debug("Marking box, player $%d @ %d,%d -> %d,%d" % (i, r1, c, r2, c + box_width))
|
||||||
x = 0
|
x = 0
|
||||||
while x < 3 * 16:
|
while x < num_box_painting_params * 16:
|
||||||
if box_painting[x] == 0:
|
if box_painting[x] == 0:
|
||||||
box_painting[x] = c
|
box_painting[x] = c
|
||||||
box_painting[x + 1] = r1
|
box_painting[x + 1] = r1
|
||||||
box_painting[x + 2] = r2
|
box_painting[x + 2] = r2
|
||||||
|
box_painting[x + 3] = i
|
||||||
break
|
break
|
||||||
x += 3
|
x += num_box_painting_params
|
||||||
pad.addstr(27, 0, "starting box %d,%d -> %d,%d" % (r1, c, r2, c + box_width))
|
pad.addstr(27, 0, "starting box, player @ %d %d,%d -> %d,%d" % (i, r1, c, r2, c + box_width))
|
||||||
|
|
||||||
|
|
||||||
##### Gameplay storage
|
##### Gameplay storage
|
||||||
@ -904,17 +908,22 @@ def check_dots(i):
|
|||||||
if has_dot(r, c):
|
if has_dot(r, c):
|
||||||
dot_eaten_row[i] = r
|
dot_eaten_row[i] = r
|
||||||
dot_eaten_col[i] = c
|
dot_eaten_col[i] = c
|
||||||
|
|
||||||
|
# Update maze here so we can check which player closed off a box
|
||||||
|
addr = mazerow(r)
|
||||||
|
addr[c] &= ~tiledot
|
||||||
|
|
||||||
player_score[i] += dot_score
|
player_score[i] += dot_score
|
||||||
|
|
||||||
def update_background():
|
def update_background():
|
||||||
for i in range(cur_players):
|
for i in range(cur_players):
|
||||||
if dot_eaten_col[i] < 128:
|
if dot_eaten_col[i] < 128:
|
||||||
# dot has been marked as being eaten, so deal with it. Somehow.
|
# Here we update the screen; note the maze has already been updated
|
||||||
|
# but we don't change the background until now so sprites can
|
||||||
|
# restore their saved backgrounds first.
|
||||||
|
|
||||||
r = dot_eaten_row[i]
|
r = dot_eaten_row[i]
|
||||||
c = dot_eaten_col[i]
|
c = dot_eaten_col[i]
|
||||||
addr = mazerow(r)
|
|
||||||
addr[c] &= ~tiledot
|
|
||||||
addr = screenrow(r)
|
addr = screenrow(r)
|
||||||
addr[c] &= ~tiledot
|
addr[c] &= ~tiledot
|
||||||
|
|
||||||
@ -927,23 +936,27 @@ def update_background():
|
|||||||
def paint_boxes():
|
def paint_boxes():
|
||||||
x = 0
|
x = 0
|
||||||
pad.addstr(28, 0, "Checking box:")
|
pad.addstr(28, 0, "Checking box:")
|
||||||
while x < 3 * 16:
|
while x < num_box_painting_params * 16:
|
||||||
pad.addstr(28, 20 + x, "%d " % x)
|
pad.addstr(29, x, "%d " % x)
|
||||||
if box_painting[x] > 0:
|
if box_painting[x] > 0:
|
||||||
c1 = box_painting[x]
|
c1 = box_painting[x]
|
||||||
r1 = box_painting[x + 1]
|
r1 = box_painting[x + 1]
|
||||||
r2 = box_painting[x + 2]
|
r2 = box_painting[x + 2]
|
||||||
box_log.debug("Painting box line at %d,%d" % (r1, c1))
|
i = box_painting[x + 3]
|
||||||
pad.addstr(29, 0, "painting box line at %d,%d" % (r1, c1))
|
box_log.debug("Painting box line, player %d at %d,%d" % (i, r1, c1))
|
||||||
|
pad.addstr(30, 0, "painting box line at %d,%d" % (r1, c1))
|
||||||
addr = screenrow(r1)
|
addr = screenrow(r1)
|
||||||
for i in range(box_width):
|
for c in range(box_width):
|
||||||
addr[c1 + i] = ord("X")
|
if i == 0:
|
||||||
|
addr[c1 + c] = ord("X")
|
||||||
|
else:
|
||||||
|
addr[c1 + c] = ord(".")
|
||||||
r1 += 1
|
r1 += 1
|
||||||
print "ROW", r1
|
print "ROW", r1
|
||||||
box_painting[x + 1] = r1
|
box_painting[x + 1] = r1
|
||||||
if r1 >= r2:
|
if r1 >= r2:
|
||||||
box_painting[x] = 0
|
box_painting[x] = 0
|
||||||
x += 3
|
x += num_box_painting_params
|
||||||
|
|
||||||
def init_static_background():
|
def init_static_background():
|
||||||
pad.addstr(p1scorerow, mazescorecol, "Player1")
|
pad.addstr(p1scorerow, mazescorecol, "Player1")
|
||||||
@ -986,6 +999,17 @@ def read_curses():
|
|||||||
else:
|
else:
|
||||||
player_input_dir[0] = 0
|
player_input_dir[0] = 0
|
||||||
|
|
||||||
|
if key == ord(',') or key == ord('.'):
|
||||||
|
player_input_dir[1] = tileup
|
||||||
|
elif key == ord('o'):
|
||||||
|
player_input_dir[1] = tiledown
|
||||||
|
elif key == ord('a'):
|
||||||
|
player_input_dir[1] = tileleft
|
||||||
|
elif key == ord('e'):
|
||||||
|
player_input_dir[1] = tileright
|
||||||
|
else:
|
||||||
|
player_input_dir[1] = 0
|
||||||
|
|
||||||
|
|
||||||
##### Game loop
|
##### Game loop
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user