HP Forums

Full Version: Sokoban game for HP Prime
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sokoban game for HP Prime

Hello!
I'm still learning a little bit about the commands and possibilities of this excellent machine.

I started working on developing a version of the game Sokoban. Using tiles of 16x16 bits and I'm using the touch screen to control the movements of "pusher".

[Image: Captura+de+pantalla+de+2014-01-03+12%253A18%253A53.png]

I've already finished programming the graphics and movement routines. I need to optimize the compression / decompression of maps and details of the game (score, help, etc).

I made one (the first one!) video of the game:





The video shows how the game works. It is not a particular level, but a sandbox created just to do some testing.

I try finish in a few days.

Regards

PD: Sorry for my bad English language management. My native language is Spanish, and it showsWink
----------------------------
EDIT 14/01/14: Download latest release: ([url=http://www.hpmuseum.org/forum/attachment.php?aid=170[/url])
Hello!
The "Beta 1" version is ready!.
Only has 10 levels, and keeps track of the number of moves made and the amount of pushes made.

They are the first ten levels of the DOS version about 30 years. ... They are difficult to solve, but not impossible. Enjoy! Wink

The pusher moves touching the edges of the screen. I did not use keys courses to preserve the "health" of the keyboard.

Soon more levels. Wink

T.I.A., Ariel.

[Image: level1.png]

[Image: Level3.png]

[Image: Level5.png]

PS: Remember.....is a "Beta", there are features that have not yet been implemented.
This will definitively go in the HP Prime Tribute video with the other games and programs Smile

I will also give this a try for sure.
Going to try it now. Looks good! And, your english is VERY readable, much better than my spanish!
About compression, you can use a simple encoding as commonly used in the game of life
Here is a decoding routine
Code:
RLEMap (Rows, Cols,RLE)
BEGIN
LOCAL Row, Col, Ptr, Cnt, Tmp;
Row:= 1; Col:= 1; Cnt:= 0;
Tmp:= MAKEMAT(0,Rows,Cols);
FOR Ptr FROM 1 TO DIM(RLE) DO
  CASE
  IF INSTRING("0123456789", MID(RLE, Ptr, 1)) <> 0 THEN Cnt:= Cnt*10+EXPR(MID(RLE, Ptr, 1)); END;
  IF MID(RLE, Ptr, 1) == "$" THEN Row:= Row+MAX(1, Cnt); Col:= 1; Cnt:= 0; END;
  IF INSTRING("b.", MID(RLE, Ptr, 1)) <> 0 THEN Col:= Col+MAX(1, Cnt); Cnt:= 0; END;
  IF INSTRING("w", MID(RLE, Ptr, 1)) <> 0 THEN // Wall
    FOR Col FROM Col TO Col+MAX(1, Cnt)-1 DO Tmp(Row,Col):=1; END; Cnt:= 0; END;
  IF INSTRING("c", MID(RLE, Ptr, 1)) <> 0 THEN // Cube
    FOR Col FROM Col TO Col+MAX(1, Cnt)-1 DO Tmp(Row,Col):=2; END; Cnt:= 0; END;
  IF INSTRING("d", MID(RLE, Ptr, 1)) <> 0 THEN // Destination
    FOR Col FROM Col TO Col+MAX(1, Cnt)-1 DO Tmp(Row,Col):=3; END; Cnt:= 0; END;
  IF INSTRING("s", MID(RLE, Ptr, 1)) <> 0 THEN // Sokoban
    FOR Col FROM Col TO Col+MAX(1, Cnt)-1 DO Tmp(Row,Col):=4; END; Cnt:= 0; END;
   END;
END;
RETURN Tmp;
END;
and the encoding for the first level
Code:
"$$$5b5w$5bw3bw$5bwc2bw$3b3w2bc2w$3bw2bcbcbw$b3wbwb2wbw3b7w$bw3bwb2wb5w2b2dw$bwbc​6bs6b2dw$b5wb3wbwb2w2b2dw$6bw5b9w$5b7w!"
The coding is :
$ : new line
! : End (optional)
b : Background (your 0)
w : Wall (your1)
c : Cube (your 3)
s : Sokoban (your 4)
and numeric is the repeat factor for next letter

Routine and level untested, but you get the idea

By the way, are you sure there is a Cube missing in level 1 ?
would be a nice idea to allow cursor keys instead of mouse.
Mouse have timeout that prevent quick moves. It is a pain.
(01-05-2014 11:01 AM)patrice Wrote: [ -> ]would be a nice idea to allow cursor keys instead of mouse.
Mouse have timeout that prevent quick moves. It is a pain.

Thanks Patrice!

I will analyze the compression routines, and provide an option to play with the keyboard or touch screen.
Revisiting the cube at level 1Wink
Yep....one cube was missing.

Fixed! (Beta 1.1 attached)

PS: Working in more levels/options

[Image: index.php?action=dlattach;topic=17833.0;...6641;image]
Here is a little rewrite of your code for Moves and Pushes in the 4 directions.
Code:
local DX, DY;
...
        IF xmouse<80 AND ymouse>60 AND ymouse<180 THEN DY:=0; DX:=-1; END;
        IF xmouse>240 AND ymouse>60 AND ymouse<180 THEN DY:=0; DX:=1; END;
        IF xmouse>80 AND xmouse<240 AND ymouse<60 THEN DY:=-1; DX:=0; END;
        IF xmouse>80 AND xmouse<240 AND ymouse>180 THEN DY:=1; DX:=0; END;

        CASE
          IF matriz [YYP+1+DY, XXP+1+DX] == 0 OR matriz [YYP+1+DY, XXP+1+DX] == 3 THEN
            IF matriz [YYP+1,XXP+1] == 0 THEN BLIT_P(G5,XXP*16,YYP*16); END;
            IF matriz [YYP+1,XXP+1] == 3 THEN BLIT_P(G3,XXP*16,YYP*16); END;
            YYP := YYP+DY; XXP := XXP+DX;
            BLIT_P(G4,XXP*16,YYP*16);
            MOVI := MOVI + 1;
          END; //-----------------------------------
          IF ((matriz [YYP+1+DY,XXP+1+DX]==2) OR (matriz [YYP+1+DY,XXP+1+DX]==5)) AND ((matriz [YYP+1+2*DY,XXP+1+2*DX]==0) OR (matriz [YYP+1+2*DY,XXP+1+2*DX]==3)) THEN
            IF matriz [YYP+1,XXP+1] == 0 THEN BLIT_P(G5,XXP*16,YYP*16); END;
            IF matriz [YYP+1,XXP+1] == 3 THEN BLIT_P(G3,XXP*16,YYP*16); END;
            YYP := YYP+DY; XXP := XXP+DX;
            BLIT_P(G4,XXP*16,YYP*16);
            BLIT_P(G2,(XXP+DX)*16,(YYP+DY)*16);
            IF (matriz [YYP+1,XXP+1]==2) THEN matriz [YYP+1,XXP+1] := 0; ELSE matriz [YYP+1,XXP+1] := 3; END;
            IF (matriz [YYP+1+DY,XXP+1+DX]==0) THEN matriz [YYP+1+DY,XXP+1+DX] := 2; ELSE matriz [YYP+1+DY,XXP+1+DX] := 5; END;
            MOVI := MOVI + 1;
            PUSH := PUSH + 1;
          END; //-----------------------------------
        END;
Since Moves and Pushes are the same in each directions, this code is doing the trick without duplicating the code. It save about 20K in source code.
(01-05-2014 03:29 PM)patrice Wrote: [ -> ]Here is a little rewrite of your code for Moves and Pushes in the 4 directions.

WOW!!! Thanks!
Versión Beta 1.03 ready.

* 40 levels
* Help screen
* Abort game
* Exit screen
* Etc.

Download Link: Sokoban for HP Prime (Beta 1.03) (some problems fixed, Beta 1.031)

Demo video:




Is the last release for 15 or 20 days (vacation time!)


PS: The "control with keys" opción don't work. When I return from my vacation will finish characteristic of this program, adding 60 more levels, and change in name to "version 1.0" Wink
That's one of my favorite games, it makes you think a lot, thank you for sharing your game with us Ariel. can't wait to get my hands dirty with version 1.0![/size][/size]
I love Sokoban and it was a very good idea to port it on HPP and nice implementation.
Thanks.
Bug report.
You need to add a test for when you hit a wall.
Because if the wall is on first/last row/col, you can't test for pushing because second cell is outside of matrix.

go to Board 4 7 and hit the wall on top
(01-14-2014 11:25 AM)patrice Wrote: [ -> ]Bug report.
You need to add a test for when you hit a wall.
Because if the wall is on first/last row/col, you can't test for pushing because second cell is outside of matrix.

go to Board 4 7 and hit the wall on top

Thanks!!! Checking....
Solved. Thanks a lot! Wink

Working in final version 1.0. Release date: Feb/2014, after vacation time Wink
Another problem.

When the program is running, the calc never slow down while waiting for an event (key or tap)

Something should be changed in the WAIT function. a WAIT(0) may do the trick
Board 1-2 is impossible
Fixed! Thanks a lot Wink

PS: Attach the original level, from Sinclair ZX Spectrum Sokoban:

[Image: attachment.php?aid=171]
Hi Ariel,
Have a look at the library entry "1 Utility for Games", you should be interested.
Pages: 1 2
Reference URL's