An attempt to create a first person adventure game engine

Game development specific discussions.
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

An attempt to create a first person adventure game engine

Post by ron77 »

Hello all...

A few days or a week ago MrToad send me by email a collection of digital art (graphics and sound files)... and wished me good luck to try and make a game out of it...

In this thread I will try to do a simple code/program that will take some of the graphic images and sound files into a working code to simulate a first person movement in a place/game scenes...

I will try to create it with a UDT and I got to think of a way to build some sort of movement directions plus order of a world (game) map... one way to do it that comes to mind is using a 2d array for the graphic sprites and the direction plus make an enum for the navigation in this world... that is just my first thought on how to achieve this basic thing... this is basically the program (game) engine... only after that can the program become a game...

Any help or idea will be greatly appreciated.

Ron77 :)
Last edited by ron77 on Feb 05, 2021 11:50, edited 1 time in total.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: An attempt to create a first person game\program

Post by grindstone »

Do you mean a kind of adventure? Or an egoshooter?
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person game\program

Post by ron77 »

Hi @grindstone...

I guess so... yes an adventure game (program)

Any suggestion or help will be greatly appreciated

Ron77
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

hello all...

i've been working on something very very basic... no sprites or graphic just string on text screen - only one room and rotation inside untill you find the door and open it and you are free - game over...

here is the code...

file "main.bas"

Code: Select all

TYPE position
   PRIVATE:
   AS STRING _location
   AS STRING _direction(1 TO 4)
   AS string _view(1 TO 4)
   AS STRING _action
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE SUB centerPrint(row AS INTEGER, s AS STRING)
   DECLARE SUB main()
   'DECLARE SUB moving(_view() as string, _direction() as string, index as integer, direc as string)
END TYPE

CONSTRUCTOR position
   _location = "cell room"
   
   DIM r AS STRING
   FOR i AS INTEGER = 1 TO 4
      READ r
      this._view(i) => r
   NEXT
   FOR x AS INTEGER = 1 TO 4
     READ r
     _direction(x) = r 
   NEXT

END CONSTRUCTOR

DATA "brick wall infront of you"
DATA "closed window with bars infront of you"
DATA "a chair and a table in front of you"
DATA "a closed door is infront of you"
DATA "north", "east", "south", "west"

DESTRUCTOR position

END DESTRUCTOR

SUB position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(100 - LEN(s)) /2 : PRINT s
END SUB

'SUB position.moving(_view() as string, _direction() as string, index as integer, direc as string)
'   IF index < 1 THEN index = 1
'   IF index >4 THEN index = 4
'   IF direc = "east" THEN index += 1
'   IF direc = "west" THEN index -= 1
'   
'END SUB


SUB position.main()
   DIM direc AS STRING
   DIM index AS INTEGER = 1
   DO
   centerprint 15, "press any key to begin..."
   SLEEP
   DO
      CLS
      IF direc = "q" THEN END
      IF index < 1 THEN index = 4
      IF index >4 THEN index = 1
      centerprint 2, "you are in " & _location
      centerprint 4, _direction(index)
      centerprint 6, _view(index)
      
      'IF _direction = "south" AND _action = "open door" THEN
      '   centerprint 15, "door open you are free! game over"
      'ELSEIF 
      IF direc = "east" THEN index += 1
      IF direc = "west" THEN index -= 1
      
      
      IF index = 4 AND direc = "open door" THEN
         centerprint 15, "cell door open! you are free!! game over..."
         SLEEP
      END
      ELSEIF index = 4 THEN
         centerprint 15, "type 'open door' to open door"   
      ENDIF
      'moving(_view(),_direction(),index, direc)
      PRINT
      PRINT
      PRINT
      PRINT
      INPUT "choose direction(east,west) or an action or key 'q' to quit: ", direc
   
   LOOP
   
   LOOP UNTIL INKEY = CHR(27)
END SUB


SCREEN 19

DIM game AS position
game.main()
any help will be greatly appreciated...

ron77
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

hello everyone...

i've improved the basic engine and here is a test run - i'm using a type inside a type now the rooms are a type and i create an array of then inside the main UDT 5 rooms in total that are "the test map" for this simple engine - i use DATA type inside the code and load then into the strings array in the constructor - note that this is just a test... added forward and backwards options to move between the rooms...

here is the code so far (not finished of course:

file "main.bas"

Code: Select all

TYPE locations
   AS STRING _location
   AS string _view(1 TO 4)
END TYPE


TYPE position
   PRIVATE:
   DIM AS locations map(1 TO 5)
   AS STRING _direction(1 TO 4)
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE SUB centerPrint(row AS INTEGER, s AS STRING)
   DECLARE SUB main()
   
END TYPE

CONSTRUCTOR position
   DIM r AS STRING
   
   FOR x AS INTEGER = 1 TO 4
     READ r
     _direction(x) = r 
   NEXT
   
   
   FOR ii AS INTEGER = 1 TO 5
   READ r
   map(ii)._location = r
   NEXT
   
   
   FOR y AS INTEGER = 1 TO 5
   FOR i AS INTEGER = 1 TO 4
      READ r
      map(y)._view(i) = r
   NEXT
   NEXT

END CONSTRUCTOR

'directions data
DATA "north", "east", "south", "west"


'locations data
DATA "cell room", "hall way", "sterway up", "large chamber", "outside"

'cell room data
DATA "brick wall infront of you"
DATA "closed window with bars infront of you"
DATA "a chair and a table in front of you"
DATA "a closed door is infront of you"

'hall way data
DATA "large wall with mirrors"
DATA "an open door to a cell"
DATA "long path forward"
DATA "a wall with portraits"

'starway up data
DATA "rows of candels on a long table"
DATA "a large starway upwards"
DATA "long dark path"
DATA "a lock door with a sign saying 'death to the one who open this door!"

'large chamber data
DATA "chairs and tables with durt on them"
DATA "a gate half open ray of sunlight beems through"
DATA "windows with bars on them"
DATA "a starway downwards"

'outside data
DATA "the sun light is so bright! ields of gold all around"
DATA "a long road to a village"
DATA "some trees and bushes"
DATA "a gate open to a dark prison castel"

DESTRUCTOR position

END DESTRUCTOR

SUB position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(100 - LEN(s)) /2 : PRINT s
END SUB

SUB position.main()
   DIM direc AS STRING
   DIM index AS INTEGER = 1, next_room AS INTEGER = 1 
   DO
   centerprint 15, "press any key to begin..."
   SLEEP
   DO
      CLS
      IF direc = "q" THEN END
     
      centerprint 2, "you are in " & map(next_room)._location
      centerprint 4, _direction(index)
      centerprint 6, map(next_room)._view(index)
      
      'IF _direction = "south" AND _action = "open door" THEN
      '   centerprint 15, "door open you are free! game over"
      'ELSEIF 
      
      
      'IF index = 3 AND direc = "open door" THEN
      '   centerprint 15, "cell door open! you are free!! game over..."
      '   SLEEP
      'END
      'ELSEIF index = 3 THEN
      '   centerprint 15, "type 'open door' to open door"   
      'ENDIF
      'moving(_view(),_direction(),index, direc)
      PRINT
      PRINT
      PRINT
      PRINT
      INPUT "choose direction('e' = east, 'w' = west, 'f' = forward, 'b' = backwards) or an action or key 'q' to quit: ", direc
      IF direc = "e" THEN index += 1
      IF direc = "w" THEN index -= 1
      IF direc = "f" THEN next_room += 1
      IF direc = "b" THEN next_room -= 1
      IF index < 1 THEN index = 4
      IF index > 4 THEN index = 1
      IF next_room < 1 THEN next_room = 1
      IF next_room > 5 THEN next_room = 5 
   LOOP
   
   LOOP UNTIL INKEY = CHR(27)
END SUB


SCREEN 19

DIM game AS position
game.main()
ron77
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

okay... hello again... did further modifications...

now the doors or gates need to be opened otherwise you cannot move forward to the next room... and there is a door you should not open cause if you do you die from an armed soldier that comes out of it...

the code algorithm (if you can call it that) is not perfect yet...

here is the updated code:

file "main.bas":

Code: Select all

TYPE locations
   AS STRING _location
   AS string _view(1 TO 4)
END TYPE


TYPE position
   PRIVATE:
   DIM AS locations map(1 TO 5)
   AS STRING _direction(1 TO 4)
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE SUB centerPrint(row AS INTEGER, s AS STRING)
   DECLARE SUB main()
   
END TYPE

CONSTRUCTOR position
   DIM r AS STRING
   
   FOR x AS INTEGER = 1 TO 4
     READ r
     _direction(x) = r 
   NEXT
   
   
   FOR ii AS INTEGER = 1 TO 5
   READ r
   map(ii)._location = r
   NEXT
   
   
   FOR y AS INTEGER = 1 TO 5
   FOR i AS INTEGER = 1 TO 4
      READ r
      map(y)._view(i) = r
   NEXT
   NEXT

END CONSTRUCTOR

'directions data
DATA "north", "east", "south", "west"


'locations data
DATA "cell room", "hall way", "sterway up", "large chamber", "outside"

'cell room data
DATA "brick wall infront of you"
DATA "closed window with bars infront of you"
DATA "a chair and a table in front of you"
DATA "a closed door is infront of you"

'hall way data
DATA "large wall with mirrors"
DATA "an open door to a cell"
DATA "long path forward"
DATA "a wall with portraits"

'starway up data
DATA "rows of candels on a long table"
DATA "a large starway upwards"
DATA "long dark path"
DATA "a lock door with a sign saying 'death to the one who open this door!"

'large chamber data
DATA "chairs and tables with durt on them"
DATA "a gate half open ray of sunlight beems through"
DATA "windows with bars on them"
DATA "a starway downwards"

'outside data
DATA "the sun light is so bright! ields of gold all around"
DATA "a long road to a village"
DATA "some trees and bushes"
DATA "a gate open to a dark prison castel"

DESTRUCTOR position

END DESTRUCTOR

SUB position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(100 - LEN(s)) /2 : PRINT s
END SUB

SUB position.main()
   DIM direc AS STRING
   DIM index AS INTEGER = 1, next_room AS INTEGER = 1
   DIM AS boolean isenter = FALSE 
   DO
   centerprint 15, "press any key to begin..."
   SLEEP
   DO
      CLS
      IF direc = "q" THEN END
     
      centerprint 2, "you are in " & map(next_room)._location
      centerprint 4, _direction(index)
      centerprint 6, map(next_room)._view(index)
      
            
      
      IF next_room = 1 ANDalso index = 4 ANDalso direc = "open door" THEN
         centerprint 16, "cell door open! you can exit the cell!"
         isenter = TRUE
      
      ELSEIF next_room = 1 ANDALSO index = 4 THEN
         centerprint 15, "type 'open door' to open door"   
         isenter = FALSE
         IF direc = "f" then
            centerprint 14, "door closed you cannot move forwards"
         ENDIF
      ENDIF
      IF next_room = 3 ANDALSO index = 4 ANDALSO direc = "open door" THEN
         centerprint 16, "from the room an armed gurde come and stab you with a sward you die! - RIP"
      ELSEIF next_room = 3 ANDALSO index = 4 THEN
         centerprint 15, "should we try to forcely open this door? if so type 'open door'"
      ENDIF
      IF next_room = 4 ANDALSO index = 2 ANDALSO direc = "open gate" THEN
         centerprint 16, "you made it! you are free! out of the prison cell!"
         isenter = TRUE 
      ELSEIF next_room = 4 ANDALSO index = 2 THEN
         centerprint 15, "shell we try to open this gate? type 'open gate'"
         isenter = FALSE
         IF direc = "f" THEN
            centerprint 14, "first we most open the gate!"
         ENDIF
      
      ENDIF
      
      
      PRINT
      PRINT
      PRINT
      PRINT
      INPUT "choose direction('e' = east, 'w' = west, 'f' = forward, 'b' = backwards) or an action or key 'q' to quit: ", direc
      IF direc = "e" THEN index += 1
      IF direc = "w" THEN index -= 1
      IF direc = "f" ANDALSO isenter = TRUE THEN next_room += 1
      IF direc = "b" THEN next_room -= 1
      IF index < 1 THEN index = 4
      IF index > 4 THEN index = 1
      IF next_room < 1 THEN next_room = 1
      IF next_room > 5 THEN next_room = 5 
   LOOP
   
   LOOP UNTIL INKEY = CHR(27)
END SUB


SCREEN 19

DIM game AS position
game.main()
ron77
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: An attempt to create a first person adventure game engine

Post by MrSwiss »

@ron77,

if your intention is, to learn how to code "propperly" and not just "quick & dirty hacking" then,
you should perhaps start, to listen to what advice from others you're getting.

Example:

Code: Select all

SUB position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(100 - LEN(s)) /2 : PRINT s
END SUB
Static code: will break, as soon as another screensize is used!!! (try: Screen 20 or Screen 18)

Try to come up with "dynamic code" that adapts itself to current conditions.
(Similar to the example, I've given you in the TAMAGOTCHI thread.)
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

hello @MrSwiss thank you for your kind advice :)

i took it upon myself to find a solution...

is this better?

Code: Select all

SUB position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(LOWORD(width) - LEN(s)) /2 : PRINT s
END SUB
ron77
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: An attempt to create a first person adventure game engine

Post by MrSwiss »

ron77 wrote:is this better?
Definitely YES.
(you are using "float division" = slower than "\" aka: "int(eger) division")

But there is still room for more improvement (shift instead of division):

Code: Select all

Sub position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(LOWORD(width) - LEN(s)) Shr 1 : PRINT s
END Sub
Should give quite a bit of speed improvement ...
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: An attempt to create a first person adventure game engine

Post by MrSwiss »

ron77 wrote:i took it upon myself to find a solution...
Isn't this exactly the point, where the "real programming fun" starts?
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

hello all :)

continuing working on the game engine and game - today i started BLOAD the images @mrToad send me... after a few debugging and bugs fixes i managed to make the game engine work...

Image

Image

Image

Image

here is the updated code:

file "main.bas"

Code: Select all

#INCLUDE "fbgfx.bi"

CONST AS SHORT scr_w = 800, scr_h = 600 ' screen constants

TYPE locations
   AS STRING _location
   AS FB.Image PTR _view(1 TO 4)
END TYPE


TYPE position
   PRIVATE:
   DIM AS locations map(1 TO 7)
   AS STRING _direction(1 TO 4)
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE SUB centerPrint(row AS INTEGER, s AS STRING)
   DECLARE SUB display_screen(x AS INTEGER,z AS INTEGER)
   DECLARE SUB main()
   
END TYPE

CONSTRUCTOR position
   DIM r AS STRING
   
   FOR x AS INTEGER = 1 TO 4
     READ r
     _direction(x) = r 
   NEXT
   
   
   'FOR ii AS INTEGER = 1 TO 5
   'READ r
   'map(ii)._location = r
   'NEXT
   
   
   FOR m AS INTEGER = 1 TO 7
      
         FOR i AS INTEGER = 1 TO 4
      'READ r
            map(m)._view(i) = IMAGECREATE(800, 600)
            BLOAD("art\0" & m & "-" & i & ".bmp"), map(m)._view(i)
         
         NEXT
      
   NEXT
END CONSTRUCTOR

'directions data
DATA "north", "east", "south", "west"


''locations data
'DATA "cell room", "hall way", "sterway up", "large chamber", "outside"
'
''cell room data
'DATA "brick wall infront of you"
'DATA "closed window with bars infront of you"
'DATA "a chair and a table in front of you"
'DATA "a closed door is infront of you"
'
''hall way data
'DATA "large wall with mirrors"
'DATA "an open door to a cell"
'DATA "long path forward"
'DATA "a wall with portraits"
'
''starway up data
'DATA "rows of candels on a long table"
'DATA "a large starway upwards"
'DATA "long dark path"
'DATA "a lock door with a sign saying 'death to the one who open this door!"
'
''large chamber data
'DATA "chairs and tables with durt on them"
'DATA "a gate half open ray of sunlight beems through"
'DATA "windows with bars on them"
'DATA "a starway downwards"
'
''outside data
'DATA "the sun light is so bright! ields of gold all around"
'DATA "a long road to a village"
'DATA "some trees and bushes"
'DATA "a gate open to a dark prison castel"

DESTRUCTOR position
   FOR y AS INTEGER = 1 TO 7
      'FOR yy AS INTEGER = 4 TO 6
         FOR i AS INTEGER = 1 TO 4
      'READ r
            IMAGEDESTROY(map(y)._view(i))
         NEXT
      'NEXT
   NEXT
END DESTRUCTOR

Sub position.centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(LOWORD(width) - LEN(s)) Shr 1 : PRINT s
END SUB

SUB position.display_screen(x AS INTEGER, z AS INTEGER)
   
   SCREENLOCK
   PUT (0,0), map(x)._view(z), TRANS
   centerprint 1, _direction(z)
   
   
   SCREENUNLOCK
   SLEEP 1
END SUB



SUB position.main()
   DIM direc AS STRING
   DIM z AS INTEGER = 1, x AS INTEGER = 1
   DIM AS boolean isenter = FALSE 
   DO
   centerprint 15, "press any key to begin..."
   SLEEP
   DO
      CLS
      IF direc = "q" THEN END
     
      'centerprint 2, "you are in " & map(next_room)._location
      'centerprint 4, _direction(index)
      'centerprint 6, map(next_room)._view(index)
      display_screen(x,z)
            
      
      'IF next_room = 1 ANDalso index = 4 ANDalso direc = "open door" THEN
      '   centerprint 16, "cell door open! you can exit the cell!"
      '   isenter = TRUE
      '
      'ELSEIF next_room = 1 ANDALSO index = 4 THEN
      '   centerprint 15, "type 'open door' to open door"   
      '   isenter = FALSE
      '   IF direc = "f" then
      '      centerprint 14, "door closed you cannot move forwards"
      '   ENDIF
      'ENDIF
      'IF next_room = 3 ANDALSO index = 4 ANDALSO direc = "open door" THEN
      '   centerprint 16, "from the room an armed gurde come and stab you with a sward you die! - RIP"
      'ELSEIF next_room = 3 ANDALSO index = 4 THEN
      '   centerprint 15, "should we try to forcely open this door? if so type 'open door'"
      'ENDIF
      'IF next_room = 4 ANDALSO index = 2 ANDALSO direc = "open gate" THEN
      '   centerprint 16, "you made it! you are free! out of the prison cell!"
      '   isenter = TRUE 
      'ELSEIF next_room = 4 ANDALSO index = 2 THEN
      '   centerprint 15, "shell we try to open this gate? type 'open gate'"
      '   isenter = FALSE
      '   IF direc = "f" THEN
      '      centerprint 14, "first we most open the gate!"
      '   ENDIF
      '
      'ENDIF
      
      
      LOCATE 36, 1
      INPUT "choose direction('e' = east, 'w' = west, 'f' = forward, 'b' = backwards) or an action or key 'q' to quit: ", direc
      IF direc = "e" THEN z += 1
      IF direc = "w" THEN z -= 1
      IF direc = "f" THEN x += 1
      IF direc = "b" THEN x -= 1
      IF z < 1 THEN z = 4
      IF z > 4 THEN z = 1
      IF x < 1 THEN x = 1
      IF x > 7 THEN x = 7 
   LOOP
   
   LOOP UNTIL INKEY = CHR(27)
END SUB


SCREENRES scr_w, scr_h, 32
WIDTH scr_w \ 8, scr_h \ 16
DIM game AS position
game.main()


this is just a first text drive still needs a lot lot of work...

any help or suggestions will be greatly appreciated :)

ron77 :)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: An attempt to create a first person adventure game engine

Post by MrSwiss »

ron77 wrote:this is just a first text drive still needs a lot lot of work...
any help or suggestions will be greatly appreciated :)
OK, here we go again ...

It is unfortunate that in most of FB-Documentation everything is coded using INTEGER. :-((
It must be noted, that this is an "old fashioned" way of coding, going back to the 60th of last century.
Reason:
All those shiny and new "int-data-types" that FB has now, simply didn't exist in those days.
This goes likewise for all "unsigned" intergers. Also: Pointers and Booleans.

My advice is: make use of them, especially in Types (where you can save a lot of memory "foot print").
Also: for reasons, already explained, stay away from INTEGER in Types, as much as possible (use U/LONG instead).

IMPORTANT NOTE: FB's LONG is in fact the same, as the most used interger-type in the C-language: INT
(many here still erroneously assume it to be INTEGER, but this is simply INCORRECT since FBC 64-bit appeared)

Example:
A Type for a 2 dimension vector (likewise, for 3d, of course)

Code: Select all

Type V2D
    As short x, y
End Type
uses 4 bytes for the whole type (with Integer on FBC 64-bit: 16 bytes).
While this may sound trivial at first sight, it quickly becomes awesome, if we are using Type-Array's.

Another note on Booleans, assume it to be called _bool_:
If you want to check it to be TRUE write simply:
If _bool_ Then ...
If you want to check it to be FALSE write simply:
If Not _bool_ Then ...
Saves a lot of (unnecessary) typing ... as well as improving code readability.

That's it for the moment. ;-)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: An attempt to create a first person adventure game engine

Post by BasicCoder2 »

@ron77

Here was an beginning attempt at a similar game that might give you some ideas although it is not oop code.

It is much nicer to test code that includes an easy to use interface without the need to guess or try and remember what keys to press for any action.

viewtopic.php?f=15&t=28684
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: An attempt to create a first person adventure game engine

Post by MrSwiss »

@BasicCoder2,

please do us all a favour and, don't mess up beginners brains.
Your coding methodologies are as old as: Uluru / Ayers Rock (with which you being australian, should be familiar with).
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: An attempt to create a first person adventure game engine

Post by ron77 »

hello everyone... hello @BasicCoder2 and @MrSwiss

today i would like to find some better way for the movement of the player in the game engine... right now the player moves with key's "e" - east (should be 'r' for right) key "w" for west (should be "l" for left) key "f" for forwards and "b" for backwards and in the code the movement if done by changing the "x" and "z" integer variables in the "map()" array and the "_view()" array...

here is the updated code:
file "main.bas"

Code: Select all

#INCLUDE "fbgfx.bi"

CONST AS SHORT scr_w = 800, scr_h = 600 ' screen constants

TYPE locations
   AS STRING _location
   AS FB.Image PTR _view(1 TO 4)
END TYPE


TYPE position
   PRIVATE:
   DIM AS locations map(1 TO 7)
   AS STRING _direction(1 TO 4)
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE SUB display_screen(x AS INTEGER,z AS INTEGER)
   DECLARE SUB main()
   
END TYPE

CONSTRUCTOR position
   DIM r AS STRING
   
   FOR x AS INTEGER = 1 TO 4
     READ r
     _direction(x) = r 
   NEXT
   
   
   FOR ii AS INTEGER = 1 TO 7
   READ r
   map(ii)._location = r
   NEXT
   
   
   FOR m AS INTEGER = 1 TO 7
      
         FOR i AS INTEGER = 1 TO 4
      
            map(m)._view(i) = IMAGECREATE(800, 600)
            BLOAD("art\0" & m & "-" & i & ".bmp"), map(m)._view(i)
         
         NEXT
      
   NEXT
END CONSTRUCTOR

'directions data
DATA "north", "east", "south", "west"


''locations data
DATA "stable", "outside - yard", "yard", "yard road", "yard road", "up-stairs", "up-stairs" 


DESTRUCTOR position
   FOR y AS INTEGER = 1 TO 7
      
         FOR i AS INTEGER = 1 TO 4
      
            IMAGEDESTROY(map(y)._view(i))
         NEXT
      
   NEXT
END DESTRUCTOR

Sub centerPrint(row AS INTEGER, s AS STRING)
   LOCATE row ,(LOWORD(width) - LEN(s)) Shr 1 : PRINT s
END SUB

SUB position.display_screen(x AS INTEGER, z AS INTEGER)
   
   SCREENLOCK
   PUT (0,0), map(x)._view(z), TRANS
   centerprint 1, _direction(z)
   CENTERPRINT 3, map(x)._location
   
   SCREENUNLOCK
   SLEEP 1
END SUB



SUB position.main()
   DIM direc AS STRING
   DIM z AS INTEGER = 1, x AS INTEGER = 1
   DIM AS boolean isenter = FALSE 
   DO
   centerprint 15, "press any key to begin..."
   SLEEP
   DO
      CLS
      IF direc = "q" THEN END
     
      display_screen(x,z)
            
      
      'IF next_room = 1 ANDalso index = 4 ANDalso direc = "open door" THEN
      '   centerprint 16, "cell door open! you can exit the cell!"
      '   isenter = TRUE
      '
      'ELSEIF next_room = 1 ANDALSO index = 4 THEN
      '   centerprint 15, "type 'open door' to open door"   
      '   isenter = FALSE
      '   IF direc = "f" then
      '      centerprint 14, "door closed you cannot move forwards"
      '   ENDIF
      'ENDIF
      'IF next_room = 3 ANDALSO index = 4 ANDALSO direc = "open door" THEN
      '   centerprint 16, "from the room an armed gurde come and stab you with a sward you die! - RIP"
      'ELSEIF next_room = 3 ANDALSO index = 4 THEN
      '   centerprint 15, "should we try to forcely open this door? if so type 'open door'"
      'ENDIF
      'IF next_room = 4 ANDALSO index = 2 ANDALSO direc = "open gate" THEN
      '   centerprint 16, "you made it! you are free! out of the prison cell!"
      '   isenter = TRUE 
      'ELSEIF next_room = 4 ANDALSO index = 2 THEN
      '   centerprint 15, "shell we try to open this gate? type 'open gate'"
      '   isenter = FALSE
      '   IF direc = "f" THEN
      '      centerprint 14, "first we most open the gate!"
      '   ENDIF
      '
      'ENDIF
      
      
      LOCATE 36, 1
      INPUT "choose direction('e' = east, 'w' = west, 'f' = forward, 'b' = backwards) or an action or key 'q' to quit: ", direc
      IF direc = "e" THEN z += 1
      IF direc = "w" THEN z -= 1
      IF direc = "f" THEN x += 1
      IF direc = "b" THEN x -= 1
      IF z < 1 THEN z = 4
      IF z > 4 THEN z = 1
      IF x < 1 THEN x = 1
      IF x > 7 THEN x = 7 
   LOOP
   
   LOOP UNTIL INKEY = CHR(27)
END SUB


SCREENRES scr_w, scr_h, 32
WIDTH scr_w \ 8, scr_h \ 16
DIM game AS position
game.main()
any help / suggestions will be greatly appreciated

ron77
Post Reply