;############################### ;#CHANGEPLAYER ;#Switches to the next player ;############################### changePlayer: call drawMap call drawPlayer call drawTextTop ld hl,textNextPlayer call drawText call drawTextBottom ld e,P_X ;pass e to getCurrentPlayer call getCurrentPlayer ex de,hl ;swap address into de ld hl,(playerX) ;l=playerX h=playerY ex de,hl ;swap address back into hl ld (hl),e ;store the current player coordinates back into our player inc hl ld (hl),d inc hl ld a,(playerDir) ld (hl),a ld hl,currentPlayer inc (hl) ld a,(hl) numberPlayers = $+1 cp 0 jr nz,loadPlayer ld (hl),0 loadPlayer: ld e,P_X ;what information we want (here, player's xcoord) call getCurrentPlayer ld e,(hl) ;pX inc hl ld d,(hl) ;pY ld (playerX),de ;store pX/pY into routine inc hl ld a,(hl) ld (playerDir),a ld a,e sub 3 ;8-3: 5 jr nc,$+3 xor a cp MAP_WIDTH-7 ;cp 11-7 = 4 jr c,$+4 ld a,MAP_WIDTH-6 ;11-6 5 ld (xCoord),a ld a,d sub 2 ;10-2 8 jr nc,$+3 xor a cp MAP_HEIGHT-4 ;11-4 7 jr c,$+4 ld a,MAP_HEIGHT-4 ld (yCoord),a ret ;############################# ;#GETCURRENTPLAYER ;#input: e=byte of player info (GETPLAYER: a = player number) ;#output: hl=address of current player ;#destroys: a, de ;############################# getCurrentPlayer: ld a,(currentPlayer) getPlayer: ld hl,players ;hl points to current player ld d,0 add hl,de ld e,a add a,a add a,e add a,a ;current player # x 6 ld e,a add hl,de ret