;This section basically handles checks for the corners and passing GO landProperty: call drawTextTop push hl pop ix ;ix points to text label ld hl,textLandedOn call drawText ld a,(ix+4) ;textlabel + 4: owned by byte inc a ld hl,textPropertyPrice jr nz,propertyOwned ;if byte != $FF, it is owned call drawText ld l,(ix+2) ;mortgage price ld h,0 add hl,hl ;the price is 2*mortgage call dispNumber call newLine ld hl,textYouHave call drawText ld e,P_MONEY call getCurrentPlayer ld a,(hl) inc hl ld h,(hl) ld l,a call dispNumber call newLine ld hl,textBuy call drawText call drawTextBottom or a ret z ;buy property ld e,P_MONEY call getCurrentPlayer ld e,(hl) inc hl ld d,(hl) ;player's money ld l,(ix+2) ld h,0 add hl,hl ;property price ex de,hl ;hl=player's money, de=property price sbc hl,de ;subtract pMoney-propPrice jr c,needMoreMoney ld a,(currentPlayer) ld (ix+4),a ;owned by ld e,P_MONEY push hl call getCurrentPlayer pop de ld (hl),e inc hl ld (hl),d ret propertyOwned: ld a,(currentPlayer) ld c,(ix+3) ;rent price ld b,0 push bc ;save rent price call takeMoney ;subtract rent price from current player ld a,(ix+4) call giveMoney ;give the money to the player who owns the property ld hl,textPropertyOwned call drawText pop hl ;recall rent price into hl ld h,0 call dispNumber call drawTextBottom ret ;input: a=player ; bc=amount of money giveMoney: push bc ld e,P_MONEY call getPlayer ;returns hl=player's money address push hl ld a,(hl) inc hl ld h,(hl) ld l,a ;ld hl,(hl) add hl,bc ld c,l ld b,h ;ld bc,hl pop hl ld (hl),c inc hl ld (hl),b pop bc ret ;input: a=player ; bc=amount of money takeMoney: push bc ld e,P_MONEY call getPlayer ;returns hl=player's money address push hl ld a,(hl) inc hl ld h,(hl) ld l,a ;ld hl,(hl) sbc hl,bc ld c,l ld b,h ;ld bc,hl pop hl ld (hl),c inc hl ld (hl),b pop bc ret needMoreMoney: call drawTextTop ld hl,textNeedMoney call drawText jp drawTextBottom passedGo: push af ld a,(currentPlayer) ld bc,200 call giveMoney ;a=player, c=amount call drawTextTop ld hl,textGO call drawText call drawTextBottom pop af ret landChance: call drawTextTop ld hl,textChance call drawText call newLine ld hl,chanceDeck call drawCard call drawText call drawTextBottom ;dT_chance_move: ; pop bc ;clear stack ; inc hl ; ld b,$FF ; ld a,(hl) ;where to move to ;dT_c_m_loop: ; push af ; call mP_move ; call retrievePlayerMap ; pop af ; cp (hl) ; jr nz,dT_c_m_loop ; ret ret landCommChest: call drawTextTop ld hl,textCommChest call drawText call newLine ld hl,commChestDeck call drawCard call drawText call drawTextBottom ret mP_return: call retrievePlayerBrush inc hl ;first byte is the sprite# byte ld a,(hl) inc hl ;skip the action byte rra ;check if bit 0=1 (%00000001), aka change of direction jr nc,$+8 ex af,af' ld a,(hl) ld (playerDir),a ;update player direction ex af,af' rra ;bit 1, GO call c,passedGo ;passedGo saves the value of a pop bc djnz mP_loop ld bc,changePlayer ;after landing on the property, switch to next player push bc rra ;bit 2, chance jr c,landChance rra ;bit 3, comm chest jr c,landCommChest rra ;bit 4, property jp c,landProperty rra ;bit 5, rr rra ;bit 6, util ret ;############################# ;#MOVEPLAYER ;#Advance player through the board ;############################# movePlayer: ld b,(255/6)+1 ;255/6 = 42.xx, so we round up. call randomNumber ld l,c call randomNumber ld h,c push hl ld a,h add a,a ;x2 add a,a ;x4 add a,h ;x5 add a,a ;x10 add a,l ld l,a ld h,0 call dispNumberAlign call wait2nd pop hl ld a,l add a,h ld b,a ;#####DEBUGGING ; ld b,1 ;##### mP_loop: push bc ld hl,mP_return push hl ;ret jumps to the last address on the stack, so ret will now return us to mP_return mP_move: playerDir = $+1 ld a,0 or a ;check player direction jr z,movePlayerLeft dec a jr z,movePlayerUp dec a jr z,movePlayerRight jp movePlayerDown ;########################## ;#MOVEPLAYERLEFT ;#As the name suggests, moves the player left one ;# tile, scrolling 2 pixels at a time. ;#input: none ;#output: none ;########################## movePlayerLeft: ld a,HRZ_SCROLL ;when to scroll the map with the player ld (mPL_adjustCP),a ;really ugly way to solve the problem, but it'll have to do for now ld hl,playerX dec (hl) ld b,8 mPL_loop: ld hl,playerXOff ld a,(hl) sub 2 and $0F ld (hl),a ld hl,xCoord ld a,(playerX) sub (hl) mPL_adjustCP = $+1 cp HRZ_SCROLL push bc call c,mapLeft call drawMap call drawPlayer call drawGbuf pop bc djnz mPL_loop ret ;########################## ;#MOVEPLAYERUP ;#Moves the player up one tile, scrolling 2 pixels ;# at a time. ;#input: none ;#output: none ;########################## movePlayerUp: ld a,VERT_SCROLL ld (mPU_adjustCP),a ;really ugly way to solve the problem, but it'll have to do for now ld hl,playerY dec (hl) ld b,8 mPU_loop: ld hl,playerYOff ld a,(hl) sub 2 and $0F ld (hl),a ld hl,yCoord ld a,(playerY) sub (hl) mPU_adjustCP = $+1 cp VERT_SCROLL push bc call c,mapUp call drawMap call drawPlayer call drawGbuf pop bc djnz mPU_loop ret ;########################## ;#MOVEPLAYERRIGHT ;#Moves the player right one tile, scrolling 2 pixels ;# at a time. ;#input: none ;#output: none ;########################## movePlayerRight: ld b,8 mPR_loop: ld hl,xCoord ld a,(playerX) sub (hl) cp (COLUMNS_TO_DRAW-2)-HRZ_SCROLL push bc call nc,mapRight ld hl,playerXOff ld a,(hl) add a,2 and $0F ld (hl),a jr nz,$+6 ld hl,playerX inc (hl) call drawMap call drawPlayer call drawGbuf pop bc djnz mPR_loop ret ;########################## ;#MOVEPLAYERDOWN ;#Moves the player down one tile, scrolling 2 pixels ;# at a time. ;#input: none ;#output: none ;########################## movePlayerDown: ld b,8 mPD_loop: ld hl,yCoord ld a,(playerY) sub (hl) cp 3-VERT_SCROLL push bc call nc,mapDown ld hl,playerYOff ld a,(hl) add a,2 and $0F ld (hl),a jr nz,$+6 ld hl,playerY inc (hl) call drawMap call drawPlayer call drawGbuf pop bc djnz mPD_loop ret ;################## ;#RANDOMNUMBER ;#Returns a random numbers between 1 and 255/b ;#input: b = range, essentially from 1 to (255/b) ;#output: c = "random" number ;################## randomNumber: seed = $+1 ld c,0 ;the "seed" ld a,r ;our random number base add a,c inc a ;just playing with the number ld (seed),a ;update the seed ld c,0 inc c ;inc b every time we subtract 43 from a. (0-42=1, 43-85=2, 85-127=3, etc.) sub b ;Basically, we are dividing the number by 6 and storing the result in b. jr nc,$-2 ;repeat until ret