Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #28629 > unrolled thread

Sokoban on Android

Started byJulian Fondren <julian.fondren@gmail.com>
First post2014-02-20 15:21 -0800
Last post2014-03-12 19:50 +0100
Articles 5 — 3 participants

Back to article view | Back to comp.lang.forth


Contents

  Sokoban on Android Julian Fondren <julian.fondren@gmail.com> - 2014-02-20 15:21 -0800
    Re: Sokoban on Android Bernd Paysan <bernd.paysan@gmx.de> - 2014-02-21 20:51 +0100
      Re: Sokoban on Android Julian Fondren <julian.fondren@gmail.com> - 2014-02-22 20:55 -0800
        Re: Sokoban on Android Julian Fondren <ayrnieu@gmail.com> - 2014-03-12 09:24 -0700
          Re: Sokoban on Android Bernd Paysan <bernd.paysan@gmx.de> - 2014-03-12 19:50 +0100

#28629 — Sokoban on Android

FromJulian Fondren <julian.fondren@gmail.com>
Date2014-02-20 15:21 -0800
SubjectSokoban on Android
Message-ID<5c9c1e95-1ab4-4a0c-bb57-f37cf03777c8@googlegroups.com>
Hello clf,

The following code, loaded after gl-terminal under gforth on
Android, will start a game of Sokoban that responds to touch
events.  So you can put this in a file touch-sokoban.fs in gforth/home/
on your SD card (real or not), then start gforth like normal, then
REQUIRE touch-sokoban.fs  to begin.

To move in a direction, touch that portion of the screen.  i.e.,
the right side to move right; the upper side to move up.

The sokoban.fs accompanying gforth is used for this, and is
actually completely unmodified.  It runs normally, waiting for
keyboard input, while touch events fire off movements and cause the
screen to be redrawn.

The last bit with SCREEN-OPS is there to disable gl-terminal's
scrolling behavior, which interferes with play.


-- Julian


require sokoban.fs

also android
: height ( -- u )
  app window @ ANativeWindow_getHeight ;
: width ( -- u )
  app window @ ANativeWindow_getWidth ;
previous

: vertical? ( x y -- f )
  height 2/ - abs swap width 2/ - abs > ;
: touch-move ( x y -- )
  2dup vertical? if
    nip height 2/ > if soko-down else soko-up then
  else
    drop width 2/ > if soko-right else soko-left then
  then .maze ;

also android
: soko-touch defers android-touch
  *input action @ AMOTION_EVENT_ACTION_DOWN <> ?exit
  *input x0 @ *input y0 @ touch-move ;
' soko-touch is android-touch

:noname level# @ 0> ?exit screen-sync ; is screen-ops
previous

sokoban

[toc] | [next] | [standalone]


#28669

FromBernd Paysan <bernd.paysan@gmx.de>
Date2014-02-21 20:51 +0100
Message-ID<le8ane$fi$2@online.de>
In reply to#28629
Julian Fondren wrote:

> Hello clf,
> 
> The following code, loaded after gl-terminal under gforth on
> Android, will start a game of Sokoban that responds to touch
> events.  So you can put this in a file touch-sokoban.fs in gforth/home/
> on your SD card (real or not), then start gforth like normal, then
> REQUIRE touch-sokoban.fs  to begin.
> 
> To move in a direction, touch that portion of the screen.  i.e.,
> the right side to move right; the upper side to move up.
> 
> The sokoban.fs accompanying gforth is used for this, and is
> actually completely unmodified.  It runs normally, waiting for
> keyboard input, while touch events fire off movements and cause the
> screen to be redrawn.
> 
> The last bit with SCREEN-OPS is there to disable gl-terminal's
> scrolling behavior, which interferes with play.

Great idea.  Any plans to do the same on Tetris?

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#28702

FromJulian Fondren <julian.fondren@gmail.com>
Date2014-02-22 20:55 -0800
Message-ID<46196c24-58ca-4fc1-9978-3e3fe994b6e7@googlegroups.com>
In reply to#28669
On Friday, February 21, 2014 1:51:10 PM UTC-6, Bernd Paysan wrote:
> Great idea.  Any plans to do the same on Tetris?
> 

Yeah, I should get around to that tomorrow.  I've two versions in
mind:

1. One where edge-touches (e.g., 1/8th from 0, 1/8 from WIDTH)
move the tetramino in the given direction and center-touches
rotate it;

2. Another where you swipe across the screen to move the tetramino
and tap it to rotate it.  Or drag across the screen to
continuously move it and tap with a second finger to rotate it.

Although... actually, the exact same interface this Sokoban
example uses would suffice for Tetris, with 'up' as the command to
rotate.

Hopefully timing isn't an issue.


-- Julian

[toc] | [prev] | [next] | [standalone]


#29029

FromJulian Fondren <ayrnieu@gmail.com>
Date2014-03-12 09:24 -0700
Message-ID<9a0adadb-8b0a-4d45-894d-0d97138f363a@googlegroups.com>
In reply to#28702
On Saturday, February 22, 2014 10:55:08 PM UTC-6, Julian Fondren wrote:
> On Friday, February 21, 2014 1:51:10 PM UTC-6, Bernd Paysan wrote:
> > Great idea.  Any plans to do the same on Tetris?
> 
> Yeah, I should get around to that tomorrow.

Or after I finish every published book in the Lost Fleet series.
Whichever comes last :-)


This basically works:

-----
also android  : ms  screen-sync ms ;  previous
require tt.fs
also tetris

also android
: height ( -- u )
  app window @ ANativeWindow_getHeight ;
: width ( -- u )
  app window @ ANativeWindow_getWidth ;
previous

: vertical? ( x y -- f )
  height 2/ - abs swap width 2/ - abs > ;
: touch-move ( x y -- )
  2dup vertical? if
    nip height 2/ > if drop-brick else rotate-brick then
  else
    drop width 2/ > if 0 1 move-brick else 0 -1 move-brick then
  then ;

also android
: tt-touch defers android-touch
  *input action @ AMOTION_EVENT_ACTION_DOWN <> ?exit
  *input x0 @ *input y0 @ touch-move ;
' tt-touch is android-touch

:noname level# @ 0> ?exit screen-sync ; is screen-ops
previous

initialize draw-bottom play-game
-----

The two points of interest are:

1. injecting SCREEN-SYNC into MS
(Try removing that to see just how bad the mess is.)

2. using factors of TT instead of the word itself,
to avoid having to press a key just to start the
game.

Otherwise, it's about the same as the sokoban code above.


-- Julian

[toc] | [prev] | [next] | [standalone]


#29032

FromBernd Paysan <bernd.paysan@gmx.de>
Date2014-03-12 19:50 +0100
Message-ID<lfqa9u$et2$1@online.de>
In reply to#29029
Julian Fondren wrote:
> The two points of interest are:
> 
> 1. injecting SCREEN-SYNC into MS
> (Try removing that to see just how bad the mess is.)

I actually thing about moving SCREEN-SYNC into another task.  The way it 
works now, any long-running task gets an update only when using KEY.  That's 
not right.

> 2. using factors of TT instead of the word itself,
> to avoid having to press a key just to start the
> game.

The next project then is "flappy bird for terminal" ;-).

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web