Fixed sub-tile movement for player

This commit is contained in:
Rob McMullen 2017-07-22 12:02:45 -07:00
parent 552ee3b894
commit e38d57d144
5 changed files with 227 additions and 53 deletions

View File

@ -102,6 +102,10 @@ X_TILEMAX = 7
Y_MIDPOINT = 3
Y_TILEMAX = 8
; defines the zone around the midpoint where the player can change to any direction, not just backtracking.
x_allowed_turn .byte 0, 0, 1, 1, 1, 0, 0
y_allowed_turn .byte 0, 0, 1, 1, 1, 0, 0, 0
NOT_VISIBLE = 0
PLAYER_DEAD = 1
PLAYER_ALIVE = 2
@ -215,6 +219,7 @@ init_actor nop
sta actor_frame_counter,x
sta actor_target_col,x
sta actor_input_dir,x
sta actor_turn_zone,x
lda #MAZE_BOT_ROW
sta actor_row,x
lda #TILE_UP

View File

@ -112,10 +112,10 @@ debug_player nop
ldy scratch_row
jsr debughex
ldx #0
lda actor_row,x
lda actor_turn_zone,x
ldx #38
ldy scratch_row
;jsr debughex
jsr debughex
; dec scratch_row
; ldx #34

158
logic.s
View File

@ -355,7 +355,7 @@ move_enemy nop
jsr crossed_midpoint ; save this for later
lda crossed
beq ?left
beq move_tile
; if check_midpoint(current):
; # crossed the midpoint! Make a decision on the next allowed direction
@ -367,9 +367,10 @@ move_enemy nop
cmp #ORBITER_TYPE
bne ?dir
jsr decide_orbiter
jmp ?left
jmp move_tile
?dir jsr decide_direction
move_tile nop
; # check if moved to next tile. pixel fraction stays the same to keep
; # the speed consistent, only the pixel gets adjusted
; if actor_xpixel[zp.current_actor] < 0:
@ -797,6 +798,7 @@ move_player nop
sta r
lda actor_col,x
sta c
; allowed = get_allowed_dirs(r, c)
jsr get_allowed_dirs
; current = actor_dir[zp.current_actor]
@ -805,41 +807,139 @@ move_player nop
; d = actor_input_dir[zp.current_actor]
lda actor_input_dir,x
sta d
; pad.addstr(26, 0, "r=%d c=%d allowed=%s d=%s current=%s " % (r, c, str_dirs(allowed), str_dirs(d), str_dirs(current)))
; if d:
beq ?end
; if allowed & d:
and allowed
beq ?illegal
; # player wants to go in an allowed direction, so go!
; actor_dir[zp.current_actor] = d
; r, c = get_next_tile(r, c, d)
; actor_row[zp.current_actor] = r
; actor_col[zp.current_actor] = c
lda d
sta actor_dir,x
jmp ?continue
bne ?1
rts ; no direction => no movement
; else:
; # player wants to go in an illegal direction. instead, continue in
; # direction that was last requested
;
; if allowed & current:
; r, c = get_next_tile(r, c, current)
; actor_row[zp.current_actor] = r
; actor_col[zp.current_actor] = c
; # player wants to go in an illegal direction. instead, continue in
; # direction that was last requested
?illegal lda allowed
and current
bne ?continue
bne ?not_turn_zone
rts
?continue jsr get_next_tile
lda r
sta actor_row,x
lda c
sta actor_col,x
?1 lda #0
sta actor_turn_zone,x
lda actor_xpixel,x
tay
lda x_allowed_turn,y
beq ?not_zone
lda actor_ypixel,x
beq ?not_zone
lda #1
sta actor_turn_zone,x
?end rts
; if allowed & d:
?not_zone lda allowed
and d
beq ?illegal
; # player wants to go in an allowed direction
; # is desired direction a change in axes?
; if current & TILE_VERT: # current is vertical
lda current
and #TILE_VERT
beq ?allowed_horz
; if d & TILE_HORZ: # dir change; wants horizontal
lda d
and #TILE_HORZ
beq ?cur_dir_wants_same_axis
; if turn_zone:
; actor_ypixel[zp.current_actor] = 3
; actor_yfrac[zp.current_actor] = 0
; actor_dir[zp.current_actor] = d
; set_speed(d)
; pixel_move(d)
lda actor_turn_zone,x
beq ?not_turn_zone
lda d
sta current
sta actor_dir,x
lda #Y_MIDPOINT
sta actor_ypixel,x
lda #0
sta actor_yfrac,x
jsr set_speed
jmp pixel_move
; else: # wants horz but not in turn zone
?not_turn_zone
lda current
?not_turn_zone2
sta actor_dir,x
jsr set_speed
jsr pixel_move
jmp move_tile
; if current & allowed:
; player_log.debug("same")
; actor_dir[zp.current_actor] = current
; set_speed(current)
; pixel_move(current)
; move_tile()
; else: # opposite of allowed; valid before turn zone
; player_log.debug("opposite!")
; actor_dir[zp.current_actor] = current
; set_speed(current)
; pixel_move(current)
; move_tile()
; else: # current vertical, wants vertical, allowed
?cur_dir_wants_same_axis
; actor_dir[zp.current_actor] = d
; set_speed(d)
; pixel_move(d)
; move_tile()
lda d
jmp ?not_turn_zone2
; else: # current is horizontal
?allowed_horz
; if d & TILE_VERT: # dir change; wants vertical
; y = actor_ypixel[zp.current_actor]
; if y in [2, 3, 4]:
; actor_xpixel[zp.current_actor] = 3
; actor_xfrac[zp.current_actor] = 0
; actor_dir[zp.current_actor] = d
; set_speed(d)
; pixel_move(d)
; else: # wants vert but not in turn zone
; if current & allowed:
; actor_dir[zp.current_actor] = current
; set_speed(current)
; pixel_move(current)
; move_tile()
; else: # opposite of allowed; valid before turn zone
; player_log.debug("opposite!")
; actor_dir[zp.current_actor] = current
; set_speed(current)
; pixel_move(current)
; move_tile()
; else: # current horz, wants horz, allowed
; actor_dir[zp.current_actor] = d
; pixel_move(d)
; move_tile()
lda d
and #TILE_VERT
beq ?cur_dir_wants_same_axis
lda actor_turn_zone,x
beq ?not_turn_zone
lda d
sta current
sta actor_dir,x
lda #X_MIDPOINT
sta actor_xpixel,x
lda #0
sta actor_xfrac,x
jsr set_speed
jmp pixel_move
;

View File

@ -46,13 +46,14 @@ import logging
logging.basicConfig(level=logging.WARNING)
init_log = logging.getLogger("init")
logic_log = logging.getLogger("logic")
logic_log.setLevel(logging.DEBUG)
#logic_log.setLevel(logging.DEBUG)
draw_log = logging.getLogger("draw")
maze_log = logging.getLogger("maze")
box_log = logging.getLogger("maze")
game_log = logging.getLogger("game")
collision_log = logging.getLogger("collision")
collision_log.setLevel(logging.DEBUG)
player_log = logging.getLogger("player")
player_log.setLevel(logging.DEBUG)
CURSES = 1
@ -116,7 +117,8 @@ def init_screen(*args, **kwargs):
curses.ACS_CKBOARD,
]
main()
#main()
play_game()
def main():
@ -719,7 +721,7 @@ def init_orbiter():
actor_row[zp.current_actor] = ORBITER_START_ROW
actor_dir[zp.current_actor] = TILE_UP
actor_status[zp.current_actor] = ORBITER_NORMAL
set_speed(TILE_UP)
#set_speed(TILE_UP)
def init_amidar():
init_actor()
@ -730,7 +732,7 @@ def init_amidar():
actor_updown[zp.current_actor] = TILE_DOWN
actor_dir[zp.current_actor] = TILE_DOWN
actor_status[zp.current_actor] = AMIDAR_NORMAL
set_speed(TILE_DOWN)
#set_speed(TILE_DOWN)
def init_player():
init_actor()
@ -738,6 +740,7 @@ def init_player():
actor_col[zp.current_actor] = addr[zp.current_actor]
actor_row[zp.current_actor] = MAZE_BOT_ROW
actor_status[zp.current_actor] = PLAYER_ALIVE
set_speed(TILE_DOWN)
def init_actors():
get_col_randomizer(amidar_start_col)
@ -935,13 +938,7 @@ def check_midpoint(current):
sub = actor_xpixel[zp.current_actor]
return sub == X_MIDPOINT
# Move enemy given the enemy index
def move_enemy():
current = actor_dir[zp.current_actor]
# check sub-pixel location to see if we've reached a decision point
temp = check_midpoint(current)
pixel_move(current)
def move_tile():
# check if moved to next tile. pixel fraction stays the same to keep
# the speed consistent, only the pixel gets adjusted
if actor_xpixel[zp.current_actor] < 0:
@ -956,6 +953,15 @@ def move_enemy():
elif actor_ypixel[zp.current_actor] >= Y_TILEMAX:
actor_row[zp.current_actor] += 1
actor_ypixel[zp.current_actor] -= Y_TILEMAX
# Move enemy given the enemy index
def move_enemy():
current = actor_dir[zp.current_actor]
# check sub-pixel location to see if we've reached a decision point
temp = check_midpoint(current)
pixel_move(current)
move_tile()
s = "#%d: tile=%d,%d pix=%d,%d frac=%d,%d " % (zp.current_actor, actor_col[zp.current_actor], actor_row[zp.current_actor], actor_xpixel[zp.current_actor], actor_ypixel[zp.current_actor], actor_xfrac[zp.current_actor], actor_yfrac[zp.current_actor])
logic_log.debug(s)
pad.addstr(0 + zp.current_actor, 40, s)
@ -1136,21 +1142,83 @@ def move_player():
current = actor_dir[zp.current_actor]
d = actor_input_dir[zp.current_actor]
pad.addstr(26, 0, "r=%d c=%d allowed=%s d=%s current=%s " % (r, c, str_dirs(allowed), str_dirs(d), str_dirs(current)))
turn_zone = False
x = actor_xpixel[zp.current_actor]
if x in [2, 3, 4]:
y = actor_ypixel[zp.current_actor]
if y in [2, 3, 4]:
turn_zone = True
if d:
if allowed & d:
# player wants to go in an allowed direction, so go!
actor_dir[zp.current_actor] = d
r, c = get_next_tile(r, c, d)
actor_row[zp.current_actor] = r
actor_col[zp.current_actor] = c
# player wants to go in an allowed direction
player_log.debug("allowed, cur=%s, d=%s, turnzone=%s x=%d.%d y=%d.%d, r=%d c=%d" % (current, d, turn_zone, actor_xpixel[zp.current_actor], actor_xfrac[zp.current_actor], actor_ypixel[zp.current_actor], actor_yfrac[zp.current_actor], actor_col[zp.current_actor], actor_row[zp.current_actor]))
# is desired direction a change in axes?
if current & TILE_VERT: # current is vertical
if d & TILE_HORZ: # dir change; wants horizontal
if turn_zone:
actor_ypixel[zp.current_actor] = 3
actor_yfrac[zp.current_actor] = 0
actor_dir[zp.current_actor] = d
set_speed(d)
pixel_move(d)
else: # wants horz but not in turn zone
if current & allowed:
player_log.debug("same")
actor_dir[zp.current_actor] = current
set_speed(current)
pixel_move(current)
move_tile()
else: # opposite of allowed; valid before turn zone
player_log.debug("opposite!")
actor_dir[zp.current_actor] = current
set_speed(current)
pixel_move(current)
move_tile()
else: # current vertical, wants vertical, allowed
actor_dir[zp.current_actor] = d
set_speed(d)
pixel_move(d)
move_tile()
else: # current is horizontal
if d & TILE_VERT: # dir change; wants vertical
y = actor_ypixel[zp.current_actor]
if y in [2, 3, 4]:
actor_xpixel[zp.current_actor] = 3
actor_xfrac[zp.current_actor] = 0
actor_dir[zp.current_actor] = d
set_speed(d)
pixel_move(d)
else: # wants vert but not in turn zone
if current & allowed:
actor_dir[zp.current_actor] = current
set_speed(current)
pixel_move(current)
move_tile()
else: # opposite of allowed; valid before turn zone
player_log.debug("opposite!")
actor_dir[zp.current_actor] = current
set_speed(current)
pixel_move(current)
move_tile()
else: # current horz, wants horz, allowed
actor_dir[zp.current_actor] = d
pixel_move(d)
move_tile()
else:
# player wants to go in an illegal direction. instead, continue in
# direction that was last requested
player_log.debug("illegal: allowed=%s cur=%s, d=%s, turnzone=%s x=%d.%d y=%d.%d, r=%d c=%d" % (allowed, current, d, turn_zone, actor_xpixel[zp.current_actor], actor_xfrac[zp.current_actor], actor_ypixel[zp.current_actor], actor_yfrac[zp.current_actor], actor_col[zp.current_actor], actor_row[zp.current_actor]))
if allowed & current:
r, c = get_next_tile(r, c, current)
actor_row[zp.current_actor] = r
actor_col[zp.current_actor] = c
player_log.debug("continuing current dir")
actor_dir[zp.current_actor] = current
set_speed(current)
pixel_move(current)
move_tile()
# r, c = get_next_tile(r, c, current)
# actor_row[zp.current_actor] = r
# actor_col[zp.current_actor] = c
##### Collision detection
@ -1358,7 +1426,7 @@ def game_loop():
update_background()
draw_actors()
show_screen()
time.sleep(.01)
#time.sleep(.01)
if count % 50 == 0:
pad.addstr(20, MAZE_SCORE_COL, "%f" % (time.time() - time_0))

1
vars.s
View File

@ -21,6 +21,7 @@ actor_input_dir .ds MAX_ACTORS ; # current joystick input direction
actor_active .ds MAX_ACTORS ; 1 = active, 0 = skip, $ff = end
actor_l .ds MAX_ACTORS
actor_h .ds MAX_ACTORS
actor_turn_zone .ds MAX_ACTORS ; debugging; is player in turn zone:
player_score .ds 4
player_next_target_score .ds 4