09-29-2003, 02:46 AM
Ladies, Gents, Convertables
I'm new around here but am having some major problems while starting a Rogue Like. There is something but I can't tell what wrong with my Door-Opening and Shutting abilities. From certain angles, it makes doors that wern't there suddenly appear open(or closed as the case is for the Door.Close Proc). I can't find why its happening and I would be incredibly greatful if someone can work it out. The Whole working, unfinished, door-buggy source is listed below because I'm sure I've done something really stupid but can't work it out.
Cheers
I'm new around here but am having some major problems while starting a Rogue Like. There is something but I can't tell what wrong with my Door-Opening and Shutting abilities. From certain angles, it makes doors that wern't there suddenly appear open(or closed as the case is for the Door.Close Proc). I can't find why its happening and I would be incredibly greatful if someone can work it out. The Whole working, unfinished, door-buggy source is listed below because I'm sure I've done something really stupid but can't work it out.
Cheers
Code:
'A Quest beyond the Dragons Lair
'Lachlan Kingsford
'Declares
DECLARE SUB Movechar (Direction)
DECLARE SUB Door.Close ()
DECLARE SUB Keyloop ()
DECLARE FUNCTION Checkmove (x AS INTEGER, y AS INTEGER)
DECLARE FUNCTION GetDir! ()
DECLARE SUB Msg.Print (Text$)
DECLARE SUB Door.Open ()
'User Defined Types
TYPE Position
x AS INTEGER
y AS INTEGER
END TYPE
'Variables
DIM SHARED Charloc AS Position
DIM SHARED Curmap(1 TO 80, 1 TO 20) AS INTEGER
DIM SHARED Messages(1 TO 3) AS STRING
'Initialize Screen
WIDTH 80, 25
'Get some Constants
CONST NW = 7
CONST N = 8
CONST NE = 9
CONST E = 5
CONST W = 6
CONST SW = 1
CONST S = 2
CONST SE = 3
CONST True = 1
CONST False = 0
CONST DIRKEYS$ = "1-9 Z=Abort"
'Create a Tempory Testing Map
Curmap(7, 7) = 2
Curmap(7, 9) = 2
Curmap(9, 7) = 2
Curmap(9, 9) = 2
FOR a = 1 TO 15
Curmap(a + 4, 11) = 1
Curmap(a + 4, 13) = 1
Curmap(a + 4, 15) = 1
NEXT
FOR a = 1 TO 5
Curmap(a * 3 + 4, 13) = 2
NEXT
'Set a starting Character Location
Charloc.x = 10
Charloc.y = 10
10
CLS
'Draw the Map
FOR x = 1 TO 80
FOR y = 1 TO 20
LOCATE y, x
IF Curmap(x, y) = 1 THEN PRINT "#"
IF Curmap(x, y) = 2 THEN PRINT "+"
IF Curmap(x, y) = 3 THEN PRINT "/"
NEXT
NEXT
'Draw the Message Buffer
LOCATE 21, 2: PRINT Messages(1)
LOCATE 22, 2: PRINT Messages(2)
LOCATE 23, 2: PRINT Messages(3)
'Draw the Character
LOCATE Charloc.y, Charloc.x
PRINT "@"
Keyloop
GOTO 10
FUNCTION Checkmove (x AS INTEGER, y AS INTEGER)
DIM Checktemp
Checktemp = True
IF x >= 80 THEN Checktemp = False
IF x <= 0 THEN Checktemp = False
IF y <= 0 THEN Checktemp = False
IF y >= 20 THEN Checktemp = False
IF Checktemp = True THEN
IF Curmap(x, y) = 1 THEN Checktemp = False
IF Curmap(x, y) = 2 THEN Checktemp = False
END IF
Checkmove = Checktemp
END FUNCTION
SUB Door.Close
DIM Doortemp(1 TO 9) AS INTEGER
DIM NoofDoors AS INTEGER
DIM DoorDir AS INTEGER
'Which Door?
IF Curmap(Charloc.x - 1, Charloc.y - 1) = 3 THEN Doortemp(NW) = True ELSE Doortemp(7) = False
IF Curmap(Charloc.x - 1, Charloc.y) = 3 THEN Doortemp(W) = True ELSE Doortemp(4) = False
IF Curmap(Charloc.x - 1, Charloc.y + 1) = 3 THEN Doortemp(SW) = True ELSE Doortemp(1) = False
IF Curmap(Charloc.x, Charloc.y - 1) = 3 THEN Doortemp(N) = True ELSE Doortemp(8) = False
IF Curmap(Charloc.x, Charloc.y + 1) = 3 THEN Doortemp(S) = True ELSE Doortemp(2) = False
IF Curmap(Charloc.x + 1, Charloc.y + 1) = 3 THEN Doortemp(NE) = True ELSE Doortemp(9) = False
IF Curmap(Charloc.x + 1, Charloc.y - 1) = 3 THEN Doortemp(E) = True ELSE Doortemp(3) = False
IF Curmap(Charloc.x + 1, Charloc.y) = 3 THEN Doortemp(NW) = True ELSE Doortemp(6) = False
NoofDoors = 0
FOR a = 1 TO 9
NoofDoors = NoofDoors + Doortemp(a)
NEXT
'No Closed Doors
IF NoofDoors = 0 THEN
Msg.Print "No Open Doors!"
EXIT SUB
END IF
'One Closed Door
IF NoofDoors = 1 THEN
FOR a = 1 TO 9
IF Doortemp(a) = True THEN DoorDir = a
NEXT
END IF
'Multiple Closed Doors
IF NoofDoors > 1 THEN
Msg.Print "Which Door? (" + DIRKEYS + ")"
DoorDir = GetDir
IF DoorDir = 0 THEN
Msg.Print "Door Closing Aborted"
EXIT SUB
END IF
IF DoorDir = 5 THEN
Msg.Print "You can't close a door when you're standing on it"
EXIT SUB
END IF
END IF
'Open the Door
SELECT CASE DoorDir
CASE NW
Curmap(Charloc.x - 1, Charloc.y - 1) = 2
CASE N
Curmap(Charloc.x, Charloc.y - 1) = 2
CASE NE
Curmap(Charloc.x + 1, Charloc.y - 1) = 2
CASE W
Curmap(Charloc.x - 1, Charloc.y) = 2
CASE E
Curmap(Charloc.x + 1, Charloc.y) = 2
CASE SW
Curmap(Charloc.x - 1, Charloc.y + 1) = 2
CASE S
Curmap(Charloc.x, Charloc.y + 1) = 2
CASE SE
Curmap(Charloc.x + 1, Charloc.y + 1) = 2
END SELECT
END SUB
SUB Door.Open
DIM Doortemp(1 TO 9) AS INTEGER
DIM NoofDoors AS INTEGER
DIM DoorDir AS INTEGER
'Which Door?
IF Curmap(Charloc.x - 1, Charloc.y - 1) = 2 THEN Doortemp(7) = True ELSE Doortemp(7) = False
IF Curmap(Charloc.x - 1, Charloc.y) = 2 THEN Doortemp(4) = True ELSE Doortemp(4) = False
IF Curmap(Charloc.x - 1, Charloc.y + 1) = 2 THEN Doortemp(1) = True ELSE Doortemp(1) = False
IF Curmap(Charloc.x, Charloc.y - 1) = 2 THEN Doortemp(8) = True ELSE Doortemp(8) = False
IF Curmap(Charloc.x, Charloc.y + 1) = 2 THEN Doortemp(2) = True ELSE Doortemp(2) = False
IF Curmap(Charloc.x + 1, Charloc.y + 1) = 2 THEN Doortemp(9) = True ELSE Doortemp(9) = False
IF Curmap(Charloc.x + 1, Charloc.y - 1) = 2 THEN Doortemp(3) = True ELSE Doortemp(3) = False
IF Curmap(Charloc.x + 1, Charloc.y) = 2 THEN Doortemp(6) = True ELSE Doortemp(6) = False
NoofDoors = 0
FOR a = 1 TO 9
NoofDoors = NoofDoors + Doortemp(a)
NEXT
'No Closed Doors
IF NoofDoors = 0 THEN
Msg.Print "No Closed Doors!"
EXIT SUB
END IF
'One Closed Door
IF NoofDoors = 1 THEN
FOR a = 1 TO 9
IF Doortemp(a) = True THEN DoorDir = a
NEXT
END IF
'Multiple Closed Doors
IF NoofDoors > 1 THEN
Msg.Print "Which Door? (" + DIRKEYS + ")"
DoorDir = GetDir
IF DoorDir = 0 THEN
Msg.Print "Door Opening Aborted"
EXIT SUB
END IF
IF DoorDir = 5 THEN
Msg.Print "You're Not Standing on a Closed Door!"
EXIT SUB
END IF
END IF
'Open the Door
SELECT CASE DoorDir
CASE NW
Curmap(Charloc.x - 1, Charloc.y - 1) = 3
CASE N
Curmap(Charloc.x, Charloc.y - 1) = 3
CASE NE
Curmap(Charloc.x + 1, Charloc.y - 1) = 3
CASE W
Curmap(Charloc.x - 1, Charloc.y) = 3
CASE E
Curmap(Charloc.x + 1, Charloc.y) = 3
CASE SW
Curmap(Charloc.x - 1, Charloc.y + 1) = 3
CASE S
Curmap(Charloc.x, Charloc.y + 1) = 3
CASE SE
Curmap(Charloc.x + 1, Charloc.y + 1) = 3
END SELECT
END SUB
FUNCTION GetDir
DIM Keyin AS STRING
30
Keyin = INKEY$
SELECT CASE Keyin
CASE "4"
GetDir = W
CASE "8"
GetDir = N
CASE "6"
GetDir = E
CASE "2"
GetDir = S
CASE "7"
GetDir = NW
CASE "9"
GetDir = NE
CASE "1"
GetDir = SW
CASE "3"
GetDir = SE
CASE "z"
GetDir = 0
CASE "Z"
GetDir = 0
CASE ELSE
SELECT CASE LEN(Keyin)
CASE 0
GOTO 30
CASE 1
Msg.Print "Bad Direction (" + DIRKEYS + ")"
GOTO 30
CASE 2
SELECT CASE ASC(RIGHT$(Keyin, 1))
CASE 72
GetDir = N
CASE 75
GetDir = W
CASE 80
GetDir = S
CASE 77
GetDir = E
END SELECT
END SELECT
END SELECT
END FUNCTION
SUB Keyloop
DIM Keyin AS STRING
20
'Keyboard Part
Keyin = INKEY$
SELECT CASE Keyin
CASE "4"
Movechar W
CASE "8"
Movechar N
CASE "6"
Movechar E
CASE "2"
Movechar S
CASE "7"
Movechar NW
CASE "9"
Movechar NE
CASE "1"
Movechar SW
CASE "3"
Movechar SE
CASE "o"
Door.Open
CASE "c"
Door.Close
CASE "Q"
'Note: MAKE THIS BIT BETTER
END
CASE ELSE
SELECT CASE LEN(Keyin)
CASE 0
GOTO 20
CASE 1
GOTO 20
CASE 2
SELECT CASE ASC(RIGHT$(Keyin, 1))
CASE 72
Movechar N
CASE 75
Movechar W
CASE 80
Movechar S
CASE 77
Movechar E
END SELECT
END SELECT
END SELECT
END SUB
'
SUB Movechar (Direction)
DIM Proppos AS Position
SELECT CASE Direction
CASE NW
Proppos.x = Charloc.x - 1
Proppos.y = Charloc.y - 1
CASE N
Proppos.x = Charloc.x
Proppos.y = Charloc.y - 1
CASE NE
Proppos.x = Charloc.x + 1
Proppos.y = Charloc.y - 1
CASE W
Proppos.y = Charloc.y
Proppos.x = Charloc.x - 1
CASE E
Proppos.y = Charloc.y
Proppos.x = Charloc.x + 1
CASE SW
Proppos.x = Charloc.x - 1
Proppos.y = Charloc.y + 1
CASE S
Proppos.x = Charloc.x
Proppos.y = Charloc.y + 1
CASE SE
Proppos.x = Charloc.x + 1
Proppos.y = Charloc.y + 1
END SELECT
IF Checkmove(Proppos.x, Proppos.y) = True THEN
Charloc.x = Proppos.x
Charloc.y = Proppos.y
END IF
END SUB
SUB Msg.Print (Text$)
Messages(3) = Messages(2)
Messages(2) = Messages(1)
Messages(1) = Text$
LOCATE 21, 2: PRINT Messages(1)
LOCATE 22, 2: PRINT Messages(2)
LOCATE 23, 2: PRINT Messages(3)
END SUB
------/--------------------------------------------
|
| The Lochok Shall Rule Forevermore!
|
/----------/----------------------------------------
|
| The Lochok Shall Rule Forevermore!
|
/----------/----------------------------------------