Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple games in 1 hour...
#11
Small Sokobhan clone written in about half an hour (entering the map data and playtesting took the other half hour ;-)). The map is stolen from Gnomekobhan but you can make you own if you want. The object of the game is to push all of the boxes(brown things) onto the holders(green things) in the least number of moves. Use the arrow keys to move around.

Code:
'**** Sokobhan clone ****
'****  LooseCaboose  ****

DECLARE SUB updateMoves ()
DECLARE SUB moveBox (x AS INTEGER, Y AS INTEGER)
DECLARE SUB gameLoop ()
DECLARE SUB movePlayer (x AS INTEGER, Y AS INTEGER)
DECLARE SUB initBlockTypes ()
DECLARE SUB loadMap ()
DECLARE SUB drawMap ()
DECLARE SUB playGame ()
DECLARE SUB winGame ()

CONST MAPWIDTH = 20
CONST MAPHEIGHT = 12

CONST BPLAYER = 1
CONST BWALL = 2
CONST BBOX = 3
CONST BBOXHELD = 4
CONST BHOLDER = 5

TYPE blockType
  colour AS INTEGER
  char AS STRING * 1
END TYPE

TYPE playerType
  x AS INTEGER
  Y AS INTEGER
  moves AS INTEGER
END TYPE

DIM SHARED block(5) AS blockType
DIM SHARED player AS playerType
DIM SHARED map(20, 12)
DIM SHARED numMoves, numHeld, numHolders

playGame

DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2
DATA 2, 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 2, 2, 0, 2, 2, 2, 2, 2
DATA 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2
DATA 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 2, 2, 2, 2
DATA 2, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 5, 2
DATA 2, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 5, 2
DATA 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

SUB drawMap

  SCREEN 7: CLS

  numHolders = 0

  FOR i = 1 TO MAPWIDTH
    FOR j = 1 TO MAPHEIGHT
    
      LOCATE j, i
      COLOR block(map(i, j)).colour
      PRINT block(map(i, j)).char;
    
      IF map(i, j) = BPLAYER THEN
        player.x = i
        player.Y = j
        map(i, j) = 0
      END IF

      IF map(i, j) = BHOLDER THEN
        numHolders = numHolders + 1
      END IF

    NEXT
  NEXT

  updateMoves

END SUB

SUB gameLoop

  DO
    i$ = INKEY$
    SELECT CASE i$
    CASE CHR$(0) + "H"
      IF map(player.x, player.Y - 1) = 0 OR map(player.x, player.Y - 1) = BHOLDER THEN
        movePlayer 0, -1
      END IF

      IF map(player.x, player.Y - 1) = BBOX THEN
        IF map(player.x, player.Y - 2) = 0 OR map(player.x, player.Y - 2) = BHOLDER THEN
          movePlayer 0, -1
          moveBox 0, -1
        END IF
      END IF

    CASE CHR$(0) + "P"
      IF map(player.x, player.Y + 1) = 0 OR map(player.x, player.Y + 1) = BHOLDER THEN
        movePlayer 0, 1
      END IF

      IF map(player.x, player.Y + 1) = BBOX THEN
        IF map(player.x, player.Y + 2) = 0 OR map(player.x, player.Y + 2) = BHOLDER THEN
          movePlayer 0, 1
          moveBox 0, 1
        END IF
      END IF

    CASE CHR$(0) + "K"
      IF map(player.x - 1, player.Y) = 0 OR map(player.x - 1, player.Y) = BHOLDER THEN
        movePlayer -1, 0
      END IF

      IF map(player.x - 1, player.Y) = BBOX THEN
        IF map(player.x - 2, player.Y) = 0 OR map(player.x - 2, player.Y) = BHOLDER THEN
          movePlayer -1, 0
          moveBox -1, 0
        END IF
      END IF

    CASE CHR$(0) + "M"
      IF map(player.x + 1, player.Y) = 0 OR map(player.x + 1, player.Y) = BHOLDER THEN
        movePlayer 1, 0
      END IF

      IF map(player.x + 1, player.Y) = BBOX THEN
        IF map(player.x + 2, player.Y) = 0 OR map(player.x + 2, player.Y) = BHOLDER THEN
          movePlayer 1, 0
          moveBox 1, 0
        END IF
      END IF
  
    CASE CHR$(27)
      END
    END SELECT
  LOOP

END SUB

SUB initBlockTypes

  '**** Player ****
  block(BPLAYER).colour = 14
  block(BPLAYER).char = CHR$(1)

  '**** Wall ****
  block(BWALL).colour = 9
  block(BWALL).char = CHR$(219)

  '**** Box ****
  block(BBOX).colour = 6
  block(BBOX).char = CHR$(177)

  '**** Box in holder ****
  block(BBOXHELD).colour = 7
  block(BBOXHELD).char = CHR$(178)

  '**** Box holder ****
  block(BHOLDER).colour = 10
  block(BHOLDER).char = CHR$(254)

END SUB

SUB loadMap

  FOR i = 1 TO MAPHEIGHT
    FOR j = 1 TO MAPWIDTH
      READ map(j, i)
    NEXT
  NEXT

END SUB

SUB moveBox (x AS INTEGER, Y AS INTEGER)

  '**** Box is at player position ****
  map(player.x, player.Y) = 0

  '**** Check if the box is on a holder ****
  IF map(player.x + x, player.Y + Y) = BHOLDER THEN
    '**** Box turns to concrete ****
    SOUND 100, .2
    map(player.x + x, player.Y + Y) = BBOXHELD
    numHeld = numHeld + 1

  ELSE
    map(player.x + x, player.Y + Y) = BBOX
  END IF

  LOCATE player.Y + Y, player.x + x
  COLOR block(map(player.x + x, player.Y + Y)).colour
  PRINT block(map(player.x + x, player.Y + Y)).char;
  
  '**** Check if all boxes are in their holders ****
  IF numHeld = numHolders THEN
    winGame
  END IF
  

END SUB

SUB movePlayer (x AS INTEGER, Y AS INTEGER)

  numMoves = numMoves + 1
  updateMoves

  '**** Remove old image ****
  LOCATE player.Y, player.x
  IF map(player.x, player.Y) = BHOLDER THEN
    COLOR block(BHOLDER).colour
    PRINT block(BHOLDER).char;
  ELSE
    PRINT " ";
  END IF

  '**** Draw new image ****
  player.x = player.x + x
  player.Y = player.Y + Y

  COLOR block(BPLAYER).colour
  LOCATE player.Y, player.x
  PRINT block(BPLAYER).char;


END SUB

SUB playGame

  numMoves = 0
  numHeld = 0

  '**** Allow data to be read in subsequent games ****
  RESTORE

  loadMap
  initBlockTypes
  drawMap
  gameLoop

END SUB

SUB updateMoves

  LOCATE 14, 1
  COLOR 15
  PRINT "Moves:"; numMoves

END SUB

SUB winGame

  LOCATE 15, 1
  COLOR 15
  PRINT "Congratulations, you won"
  PRINT "Play again? (Y/N)"

  DO
    i$ = INKEY$
    SELECT CASE i$
    CASE "Y", "y"
      CLS
      playGame
    CASE "N", "n", CHR$(27)
      END
    END SELECT
  LOOP
    
END SUB
esus saves.... Passes to Moses, shoots, he scores!
Reply
#12
That's cool...make some more levels...
B 4 EVER
Reply
#13
Really neat, LooseCaboose. And very well coded.

My intention with this thread is to provide people with nice source code of simple games. Yours fits perfectly Smile

It is also for the challenge of finishing the game in just 1 hour Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#14
I prefer bad source code when copying things, actually.

I used to fix up horribly hopeless games and make 'em nice. I never finished most of them, though. :king:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#15
Argh I was gonna do a sokoban...

Hmm

How about pacman? LOL tictactoe Big GrinBig Grin

Ill probably just do a sokoban as well...

Can i post exe's? I have horrible code Big GrinBig Grin I'm embarrased

And if I HAVE to post code, I dont have to comment do i?
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#16
Post code in your "own style" *Wink
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#17
here's my entry. you play the fbi agent happyface. you must infiltrate a house where two madmen are holding 12 people hostage. you must rescue the people and make it out of the house without getting caught. has some useless subs. the ai's stupid. you could walk in front of them and they wouldn't notice. must be all the crack... heh. kinda a dark woods ripoff that's watered down.

Code:
DECLARE SUB tryagaina ()
DECLARE SUB newmap ()
DECLARE SUB enemymove ()
DECLARE SUB drawmap ()
SCREEN 7
RANDOMIZE TIMER
DIM SHARED tryagain AS INTEGER
DIM SHARED playerx AS INTEGER
DIM SHARED playery AS INTEGER
DIM SHARED enemyy(2) AS INTEGER
DIM SHARED enemyx(2) AS INTEGER
DIM SHARED oldex1 AS INTEGER
DIM SHARED oldex2 AS INTEGER
DIM SHARED oldey1 AS INTEGER
DIM SHARED oldey2 AS INTEGER
DIM SHARED k AS STRING
DIM SHARED map(15, 15) AS INTEGER
newmap
DO
enemyy(1) = 5
enemyx(1) = 2
enemyy(2) = 13
enemyx(2) = 12
saved = 0
left = 11
playerx = 15
playery = 7

DIM SHARED character AS STRING
DIM SHARED enemies AS STRING


character = CHR$(1)
enemies = CHR$(2)
LOCATE 7, 8
PRINT character

drawmap

DO
DO
key$ = INKEY$
LOOP UNTIL key$ <> ""

IF key$ = CHR$(0) + CHR$(80) THEN
IF playerx + 1 < 16 THEN
playerx = playerx + 1
IF map(playerx, playery) = 1 THEN
playerx = playerx - 1
END IF
END IF

ELSEIF key$ = CHR$(0) + CHR$(72) THEN
IF playerx - 1 > 0 THEN
playerx = playerx - 1
IF map(playerx, playery) = 1 THEN
playerx = playerx + 1
END IF
END IF

ELSEIF key$ = CHR$(0) + CHR$(75) THEN
IF playery - 1 > 0 THEN
playery = playery - 1
IF map(playerx, playery) = 1 THEN
playery = playery + 1
END IF
END IF

ELSEIF key$ = CHR$(0) + CHR$(77) THEN
IF playery + 1 < 16 THEN
playery = playery + 1
IF map(playerx, playery) = 1 THEN
playery = playery - 1
END IF
END IF

ELSEIF key$ = CHR$(27) THEN
END
END IF
IF map(playerx, playery) = 2 THEN
map(playerx, playery) = 0
left = left - 1
saved = saved + 1
END IF
LOCATE 16
PRINT "you have saved"; saved

LOCATE 17
PRINT "there are still"; left; "people left."
FOR x = 1 TO 15
FOR y = 1 TO 15

NEXT
NEXT
enemymove
drawmap
IF left = 0 AND playerx = 15 AND playery = 7 THEN
LOCATE 18
PRINT "YOU WIN!!"
END
tryagain = 1
END IF
key$ = ""

IF tryagain = 1 THEN
tryagaina
END IF

LOOP UNTIL k = "y"
k = ""
drawmap
LOOP
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,2,0,0,3,1,0,2,0,0,0,0,0,2,1
DATA 1,0,0,0,0,1,0,1,1,0,1,1,1,0,1
DATA 1,0,0,0,0,0,0,1,0,0,0,0,1,0,1
DATA 1,2,0,0,0,1,0,1,0,0,0,2,1,0,1
DATA 1,1,1,1,1,1,0,1,0,1,1,1,1,0,1
DATA 1,0,0,0,0,0,0,1,0,0,0,0,0,0,1
DATA 1,0,1,2,1,1,0,1,2,1,1,1,1,2,1
DATA 1,0,1,0,0,1,0,0,0,0,0,0,0,0,1
DATA 1,0,1,0,0,1,0,1,1,1,1,1,0,0,1
DATA 1,0,1,0,0,1,0,1,0,0,2,1,0,0,1
DATA 1,0,1,1,0,1,0,1,0,0,0,1,3,0,1
DATA 1,0,0,0,0,0,0,1,0,1,1,1,0,0,1
DATA 1,2,0,0,0,1,0,1,0,0,0,0,0,2,1
DATA 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1

SUB drawmap
FOR x = 1 TO 15
FOR y = 1 TO 15
IF map(x, y) = 0 THEN
LOCATE x, y
PRINT " "
ELSEIF map(x, y) = 1 THEN
LOCATE x, y
COLOR 3
PRINT CHR$(219)
COLOR 15
ELSEIF map(x, y) = 2 THEN
LOCATE x, y
COLOR 5
PRINT CHR$(1)
COLOR 15
ELSEIF map(x, y) = 3 THEN
LOCATE x, y
COLOR 7
PRINT CHR$(2)
COLOR 15
END IF
NEXT
NEXT
LOCATE playerx, playery
PRINT CHR$(1)
END SUB

SUB enemymove
dice = INT(RND * 10)

IF dice = 1 THEN
oldex1 = enemyx(1)
enemyx(1) = enemyx(1) + 1
IF map(enemyx(1), enemyy(1)) = 1 OR map(enemyx(1), enemyy(1)) = 2 THEN
oldex1 = oldex1 - 1
enemyx(1) = enemyx(1) - 1
ELSE
map(enemyx(1) - 1, enemyy(1)) = 0
END IF

ELSEIF dice = 2 THEN
oldex1 = enemyx(1)
enemyx(1) = enemyx(1) - 1
IF map(enemyx(1), enemyy(1)) = 1 OR map(enemyx(1), enemyy(1)) = 2 THEN
oldex1 = oldex1 + 1
enemyx(1) = enemyx(1) + 1
ELSE
map(enemyx(1) + 1, enemyy(1)) = 0
END IF

ELSEIF dice = 3 THEN
oldey1 = enemyy(1)
enemyy(1) = enemyy(1) + 1
IF map(enemyx(1), enemyy(1)) = 1 OR map(enemyx(1), enemyy(1)) = 2 THEN
enemyy(1) = enemyy(1) - 1
oldey1 = oldey1 - 1
ELSE
map(enemyx(1), enemyy(1) - 1) = 0
END IF

ELSEIF dice = 4 THEN
oldey1 = enemyy(1)
enemyy(1) = enemyy(1) - 1
IF map(enemyx(1), enemyy(1)) = 1 OR map(enemyx(1), enemyy(1)) = 2 THEN
enemyy(1) = enemyy(1) + 1
oldey1 = oldey1 + 1
ELSE
map(enemyx(1), enemyy(1) + 1) = 0
END IF


ELSEIF dice = 5 THEN
oldex2 = enemyx(2)
enemyx(2) = enemyx(2) + 1
IF map(enemyx(2), enemyy(2)) = 1 OR map(enemyx(2), enemyy(2)) = 2 THEN
enemyx(2) = enemyx(2) - 1
oldex2 = oldex2 - 1
ELSE
map(enemyx(2) - 1, enemyy(2)) = 0
END IF

ELSEIF dice = 6 THEN
oldex2 = enemyx(2)
enemyx(2) = enemyx(2) - 1
IF map(enemyx(2), enemyy(2)) = 1 OR map(enemyx(2), enemyy(2)) = 2 THEN
enemyx(2) = enemyx(2) + 1
oldex2 = oldex2 + 1
ELSE
map(enemyx(2) + 1, enemyy(2)) = 0
END IF


ELSEIF dice = 7 THEN
oldey2 = enemyy(2)
enemyy(2) = enemyy(2) + 1
IF map(enemyx(2), enemyy(2)) = 1 OR map(enemyx(2), enemyy(2)) = 2 THEN
enemyy(2) = enemyy(2) - 1
oldey2 = oldey2 - 1
ELSE
map(enemyx(2), enemyy(2) - 1) = 0
END IF


ELSEIF dice = 8 THEN
oldey2 = enemyy(2)
enemyy(2) = enemyy(2) - 1
IF map(enemyx(2), enemyy(2)) = 1 OR map(enemyx(2), enemyy(2)) = 2 THEN
enemyy(2) = enemyy(2) + 1
oldey2 = oldey2 + 1
ELSE
map(enemyx(2), enemyy(2) + 1) = 0
END IF


END IF

map(enemyx(1), enemyy(1)) = 3

map(enemyx(2), enemyy(2)) = 3



IF enemyy(1) = playery AND enemyx(1) = playerx OR enemyy(2) = playery AND enemyx(2) = playerx THEN
LOCATE 18
PRINT "You've been caught.  Game over."
END
tryagain = 1
EXIT SUB
END IF

END SUB

SUB newmap
FOR x = 1 TO 15
FOR y = 1 TO 15
READ map(x, y)
NEXT
NEXT

END SUB

SUB restorer


END SUB

SUB tryagaina
LOCATE 19
PRINT "Try again?"
DO
k = INKEY$
IF k = "n" THEN END
LOOP UNTIL k = "y" OR k = "n"
tryagain = 0
END SUB
Jumping Jahoolipers!
Reply
#18
cool [Image: KkatCool.txt]
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#19
Nice one, barolk Smile We are getting nice pieces here.

This is stuff for your QBNZ, Mr. Oracle Smile or for the Geekery source code section, Mr. Zack.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#20
thanks. it's too easy though, because the ai is random, and the enemies are in rooms, so there's pretty much no chance of them getting out. i like your asteroids. that was pretty good. but i prefer the use of the arrow keys.
Jumping Jahoolipers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)