2013/06/23

SAMPLE:simulate the physical behavior of the spring.

It is the program to simulate the physical behavior of the spring.
// http://d.hatena.ne.jp/x68000forever/20101123/1290520018 より
// 画面初期化 / screen initialize
apage(0)
wipe()
vpriority(TPAGE,SPAGE,GPAGE0,GPAGE1,GPAGE2,GPAGE3)
vpage(B_TPAGE+B_SPAGE+B_GPAGE0)
gborder(1,CTHYELLOW)
int by=0
switch deviceType()
 case DEVICE_IPODTOUCH: // iPod touch
 case DEVICE_IPHONE: // iPhone
 case DEVIDE_IPHONE_SIMURATOR
  width(40)
  by=32
endswitch
//
int c1,c2,t
float l1,l2,l3,k,m
float a,b,c,w1,w2,w3,xx1,xx2,xx3,x1,x2,x3,r2=1.4142135623731#
//
print localizedString("変位1=","Displacement1=");:input l1
print localizedString("変位2=","Displacement2=");:input l2
print localizedString("変位3=","Displacement2=");:input l3
print localizedString("バネ定数=","Rate of spring=");:input k
repeat
 print localizedString("質量(>0)=","Mass(>0)=");:input m
until m>0
//
w1=pow((2-r2)*k/m,0.5#)
w2=pow(2*k/m,0.5#)
w3=pow((2+r2)*k/m,0.5#)
a=(l1+r2*l2+l3)/4
b=(l1-l3)/2
c=(l1-r2*l2+l3)/4
//
c1=x68Color2iOSColor(61376):// hsv(30,31,31))
c2=x68Color2iOSColor(55358):// hsv(100,31,31))
gColor(c2)
line(  0,288+by,511,288+by)
gColor(c1)
line(130,285+by,130,291+by)
line(255,285+by,255,291+by)
line(380,285+by,380,291+by)
sp_clr()
sp_disp(0)
sprite_pattern():sprite_pallet()
sp_disp(1)
//
repeat
 x1=a*cos(w1*t)+b*cos(w2*t)+c*cos(w3*t)
 x2=r2*a*cos(w1*t)-r2*c*cos(w3*t)
 x3=a*cos(w1*t)-b*cos(w2*t)+c*cos(w3*t)
 locate(0,5):print "t=";t
 locate(0,6):print "x1=";x1,"x2=";x2,"x3=";x3
 xx1=130+x1:xx2=255+x2:xx3=380+x3
 locate(0,7):print "xx1=";xx1,"xx2=";xx2,"xx3=";xx3
 sp_halt(YES)
 sp_move( 0,xx1-16,256+by, 0)
 sp_move( 1,xx1   ,256+by, 1)
 sp_move( 2,xx1   ,272+by, 2)
 sp_move( 3,xx1-16,272+by, 3)
 sp_move( 4,xx2-16,256+by, 4)
 sp_move( 5,xx2   ,256+by, 5)
 sp_move( 6,xx2   ,272+by, 6)
 sp_move( 7,xx2-16,272+by, 7)
 sp_move( 8,xx3-16,256+by, 8)
 sp_move( 9,xx3   ,256+by, 9)
 sp_move(10,xx3   ,272+by,10)
 sp_move(11,xx3-16,272+by,11)
 sp_halt(NO)
 if t=0 then wait(1)
 t=t+1
 wait(0.1)
until t>1000
end
//
func sprite_pattern()
 int i,j
 dim char sp1(255),sp2(255),sp3(255),sp4(255)
 sp1={
  0,0,0,0,0,0,0,0,0,0,4,4,4,4,5,5,
  0,0,0,0,0,0,0,0,4,5,5,5,5,5,6,6,
  0,0,0,0,0,0,0,4,5,6,6,6,6,6,6,6,
  0,0,0,0,0,4,5,6,6,6,6,7,7,7,7,7,
  0,0,0,0,4,5,6,6,7,7,7,7,8,8,8,8,
  0,0,0,4,5,6,7,7,7,8,8,8,8,8,9,9,
  0,0,4,4,6,6,7,8,8,8,8,9,9,9,9,10,
  0,0,4,5,6,7,8,8,9,9,9,9,10,10,10,10,
  0,4,4,6,6,7,8,9,9,10,10,10,10,11,11,11,
  0,4,5,6,7,8,8,9,10,10,11,11,11,11,12,12,
  4,5,6,6,7,8,9,9,10,11,11,12,12,12,12,13,
  4,5,6,7,7,8,9,10,10,11,12,12,13,13,13,13,
  4,5,6,7,8,8,9,10,10,11,12,13,13,14,14,14,
  4,5,6,7,8,8,9,10,11,11,12,13,14,14,15,15,
  4,6,6,7,8,9,9,10,11,12,12,13,14,15,15,15,
  5,6,6,7,8,9,10,10,11,12,13,13,14,15,15,15
 }
 sp4={
  5,6,6,7,8,9,10,10,11,12,13,13,14,15,15,15,
  4,6,6,7,8,9,9,10,11,12,12,13,14,15,15,15,
  4,5,6,7,8,8,9,10,11,11,12,13,14,14,15,15,
  4,5,6,7,8,8,9,10,10,11,12,13,13,14,14,14,
  4,5,6,7,7,8,9,10,10,11,12,12,13,13,13,13,
  4,5,6,6,7,8,9,9,10,11,11,12,12,12,12,13,
  0,4,5,6,7,8,8,9,10,10,11,11,11,11,12,12,
  0,4,4,6,6,7,8,9,9,10,10,10,10,11,11,11,
  0,0,4,5,6,7,8,8,9,9,9,9,10,10,10,10,
  0,0,4,4,6,6,7,8,8,8,8,9,9,9,9,10,
  0,0,0,4,5,6,7,7,7,8,8,8,8,8,9,9,
  0,0,0,0,4,5,6,6,7,7,7,7,8,8,8,8,
  0,0,0,0,0,4,5,6,6,6,6,7,7,7,7,7,
  0,0,0,0,0,0,0,4,5,6,6,6,6,6,6,6,
  0,0,0,0,0,0,0,0,4,5,5,5,5,5,6,6,
  0,0,0,0,0,0,0,0,0,0,4,4,4,4,5,5
 }
 for i=0 to 255
  sp3(i)=sp1(255-i)
  sp2(i)=sp4(255-i)
 next
 sp_def(0 ,sp1)
 sp_def(1 ,sp2)
 sp_def(2 ,sp3)
 sp_def(3 ,sp4)
 sp_def(4 ,sp1)
 sp_def(5 ,sp2)
 sp_def(6 ,sp3)
 sp_def(7 ,sp4)
 sp_def(8 ,sp1)
 sp_def(9 ,sp2)
 sp_def(10,sp3)
 sp_def(11,sp4)
endfunc
//
func sp_color2(pal;int,colX68;int,pb;int)
// X68の色コードでスプライトの色を設定する / set sprite color by X68 color
 sp_color(pal,x68Color2iOSColor(colX68),pb)
endfunc
//
func sprite_pallet()
 sp_color(  0,    0,1)://sp_color2( 0,    1,1)
 sp_color2( 1, 4229,1)
 sp_color2( 2, 8457,1)
 sp_color2( 3,12685,1)
 sp_color2( 4,19027,1)
 sp_color2( 5,23255,1)
 sp_color2( 6,27483,1)
 sp_color2( 7,31711,1)
 sp_color2( 8,35939,1)
 sp_color2( 9,40167,1)
 sp_color2(10,44395,1)
 sp_color2(11,48623,1)
 sp_color2(12,52851,1)
 sp_color2(13,57079,1)
 sp_color2(14,61307,1)
 sp_color2(15,65535,1)
endfunc

func str localizedString(js;str,es;str)
 if isLocalizeJapan() then return(js)
 return (es)
endfunc

Zip archive file: XBetc.zip

2013/06/18

SAMPLE : Sinshu

It is a game like you have seen somewhere.

I do not write the manual
You are only going to take the same pattern tiles.

For iPad only
Portrait/Landscape both support

There is a corner-cutting in the calculation process from the touch position to identify the tile.
Therefore, if you do not touch near the middle of the tile, you will choose wrong tile.
(CheckPoint ()).

There is no score and undo.
Please improve by all means.

Also this is the iconic sample which indicate indicates that X-BASIC for iOS's sprite is just fit to this level.

Porting from Oh!X 1988/6.
It is all rights reserved.
Zip file :XBsinshu.zip

July-16/2013
Update for V2.3's X-BASIC.

2013/06/16

SAMPLE : PITMAN


PITMAN ; X-BASIC for iOS



Introduction


This game is for iPad Portrait screen only because of screen size.

How to play


The goal of this game is get all gold in the map by manipulate the PITMAN.
Here are characters and its feature.
Ladder PITMAN can move to up/down/left/right.
  Gold Can get left or right side only.
If under goes blank, gold will fall.
  Soil Can dig from left or right side.
If you dig, it becomes blank and it does not return to the original.
  Rock Can push from left or right side.
It falls as same as gold.
  Wall Can't move and push. And don't fall.
  PITMAN Hero of this game.
You fall when below is space. You can jump when upside is space.
(There is some maps using this jump.)

Operation in play mode



Operate by touch key and function keys as shown in the figure below:

Move PITMAN
 
[Giveup] Retry this map by reducing one PITMAN.
Please press when you are trapped.
[Edit] Enter the edit mode (see below).
[Next] Go to next map by reducing one PITMAN.
You can not go when the one PITMAN remaining.
[Prev] Go to previous map (PITMAN does not decrement).
[Exit] Exit the game.

Operation in edit mode



The edit mode is the mode that edit map data.
Operate by touch key and function keys as shown in the figure below:

Move cursor

[Flag] Erase clear flags.
[Exchange] Exchange this map and selected map.
[Erase] Clear this map.
[Save] Save map data and clear flags. You can set 0 to 3 maps.
[Load] Load map data and clear flags.
[Select] Select map
[Next] Go to next map
[Prev] Go to previous map
[Restore] Discard the edited contents and restore this map data.
[Play] Play from this map.
The following, select the data to be placed in the map.
[Space]
[Ladder]
[Gold]
[Soil]
[Rock]
[Wall]
[PITMAN]
Don't put two or more PITMAN in a map.
It also does not check the map data of whether no problem. You can also make the map data that can not be solved absolutely. Please be careful.

Operation in selection mode


If you push [Select] or [Exchange] in edit mode, you can select a map from list.

Operate by touch key and function keys as shown in the figure below.
Or you can select map directly with touching of map.

Move cursor

[Determine]Determine map
[+10] Display next 10 maps.
[-10] Display previous 10 maps.
[ESC] Escape from selection.

Such as convention


  1. Reproduction is prohibited.
  2. Any problem was caused by using this program, I do not care.
  3. This sample has been not-high dare perfection. Please improve in everyone by all means. For example it will be full touch operation. If you done, please send me.
  4. Please send me your impressions.
Porting from Oh!MZ 1985/11(PIT-MAN2000)
Original Oh!MZ 1985/8

Zip File :XBpit.zip

Bug information:
2013/06/22
Edited map and clear information file was not written correctly.
I am up a modified version, but only rewrite fopen(~, "w") to "c".