SmileBASIC

プログラムリスト

SYS/GAME3JUMP

トップメニュー「SmileBASICでプログラムを作る」から、LOAD"SYS/GAME3JUMP"でプログラムが読み込まれます。キーボードの「EDIT」キーを押すと、このプログラムが自由に編集できます。


'
' GAME3JUMP 
' JUMP KUN  
'

GOSUB @INIT

WHILE 1

 GOSUB @INIT2

 '---MAIN LOOP
 WHILE 1
  GOSUB @MSGCTR
  GOSUB @BGSCR
  GOSUB @MYCTR
  GOSUB @TEKICTR
  VSYNC 1
  IF OVR THEN BREAK
 WEND

 GOSUB @GOVER

WEND

'---INIT
@INIT
XSCREEN 0
DISPLAY 0
GPRIO 1024
VISIBLE 1,1,1,1
GCLS
CLS

GRW=400
GRH=240
NONE=999

BGW=25*8 'BG WIDTH
BGH=15   'BG HEIGHT
SCL=2  'SCALE
SZ=FLOOR(16*SCL)    'CHARA SIZE
SZH=(SZ/2)-2

DIM MAP[BGW,BGH]
DIM HX[4]
DIM HY[4]

HX[0]= 0:HY[0]= 1  '
HX[1]= 0:HY[1]=-1  '
HX[2]= 1:HY[2]= 0  '
HX[3]=-1:HY[3]= 0  '

CMAX=10
LVLLOOP=7

DIM BGTBL[10,4]
DIM ANINUM[CMAX]
DIM ANIMAX[CMAX]
DIM HITPRG$[CMAX]

RESTORE @ANIDATA
FOR I=0 TO CMAX-1
 READ ANINUM[I]
 READ ANIMAX[I]
 READ HITPRG$[I]
NEXT

@ANIDATA
DATA 1024,3,"@SETOVR"  '0:(TYPE A)GHOST
DATA  230,4,"@GETCOIN" '1:(TYPE B)COIN
DATA  944,3,"@SETOVR"  '2:(TYPE C)ROBOT
DATA  924,3,"@SETOVR"  '3:(TYPE D)INO
DATA 1248,1,"@SETOVR"  '4:(TYPE E)TOGE
DATA 1346,2,"@SETOVR"  '5:(TYPE F)FIRE BALL
DATA  242,1,"@RIDEBS"  '6:(TYPE G)BASE 
DATA  242,1,"@RIDEBS"  '7:(TYPE H)BASE 
DATA    0,1,""  '8:(TYPE I) 
DATA    0,1,""  '9:(TYPE J) 

DIM JMPTBL$[CMAX]
FOR I=0 TO CMAX-1
 JMPTBL$[I]="@ARG"+STR$(I)
NEXT


AN=0   'SPRITE NO.
DN=1   'テキ SPRITE NO.
DMAX=10

AA=0  'ANIME COUNTER


'---GRP
FOR Y=0 TO GRH STEP 16
 C=(Y/16) MOD 2
 FOR X=0 TO GRW STEP 16
  C=C XOR 1
  GFILL X,Y,X+15,Y+15,RGB(0,0,C*64+64)
 NEXT
NEXT
RETURN


'---TITLE
@INIT2
CLS
COLOR 15
BGMSTOP

BGCLR
SPCLR
'
LOGOSP=255:SPSET LOGOSP,4095:SPHIDE LOGOSP
'
ACH=496+2048
SPSET AN,ACH
X=200
Y=150
SPANIM AN,"I",8,ACH,8,ACH+1,8,ACH+2,8,ACH+3,0
SPANIM AN,"XY",90,X,Y,-20,X,Y-48,-20,X,Y,0
SPSCALE AN,4,4

BEEP 12

@TITLEDAT
DATA "            "
DATA "              "
DATA "             "
DATA "         KUN"
DATA ""

RESTORE @TITLEDAT
FOR Y=5 TO 99
 READ A$
 IF A$=="" THEN BREAK
 GOSUB @PRTSUB
NEXT

'
SPOFS LOGOSP,200,172,-201:SPSHOW LOGOSP

'---

DEBUG=0
LVL=1
WHILE 1

 GOSUB @HITANY
 IF BTN AND &HFF0 THEN BREAK

 IF BTN AND 1 THEN LVL=LVL-1
 IF BTN AND 2 THEN LVL=LVL+1
 IF BTN AND (4+8) THEN DEBUG=DEBUG XOR 1
 IF LVL<1 THEN LVL=1
 BEEP 2
 A$="[]STAGE "+STR$(LVL)
 Y=24
 GOSUB @PRTSUB

 A$="[]"
 IF DEBUG THEN
  A$=A$+"DEBUG  MODE"
 ELSE
  A$=A$+"NORMAL MODE"
 ENDIF
 Y=25
 GOSUB @PRTSUB
WEND

SCORE=0
OVR=0   'GAMEOVER
GOAL=0  'GOAL

BXMAX=(BGW*16)-400-1

'---MAP
GOSUB @READMAP
'
SPANIM LOGOSP,"XY",-15,336,40
'
RETURN

'---MESSAGE
@MSGCTR
Y=14
IF MSG$!="" THEN
 A$=MSG$
 GOSUB @PRTSUB
 MSGCNT=100
 MSG$=""
ENDIF

IF MSGCNT THEN
 MSGCNT=MSGCNT-1
 IF MSGCNT<=0 THEN
  A$=" "*20
  GOSUB @PRTSUB
 ENDIF
ENDIF

IF MAINCNT MOD 60 THEN RETURN
IF TIMER>0 THEN DEC TIMER

GOSUB @PUTSCORE

IF (TIMER<=0) AND (GOAL==0) THEN OVR=1
RETURN
'---SCORE
@PUTSCORE
A$="SCORE:"+FORMAT$("%06D",SCORE)
A$=A$+"  TIME:"+FORMAT$("%03D",TIMER)
Y=1
GOSUB @PRTSUB
RETURN

'---GAME OVER
@GOVER
BGMPLAY 4
A$="G A M E  O V E R"
Y=11
GOSUB @PRTSUB

A$=" "*30
Y=28
GOSUB @PRTSUB

ACH=468+2048
SPCHR AN,ACH
AY1=-2
WHILE AY<GRH+32
 AY=AY+AY1
 AY1=AY1+0.05
 SPOFS AN,AX,AY
 VSYNC 1
WEND

GOSUB @HITANY
RETURN
'---PLAYER
@MYCTR
IF GOAL THEN
 IF TIMER>0 THEN
  DEC TIMER
  INC SCORE,10
  GOSUB @PUTSCORE
 ELSE
  GOAL=GOAL+1
  IF GOAL>4*60 THEN
   LVL=LVL+1
   GOSUB @READMAP
  ENDIF
 ENDIF
ENDIF

FOR I=0 TO 3
 FOR J=-SZH TO SZH STEP SZH
  X=AX+(HX[I]*(SZH+2))+(HY[I]*J)
  Y=AY+(HY[I]*(SZH+2))+(HX[I]*J)-SZH
  GOSUB @BGCHK
  IF CH>32 THEN
   AX=AX-HX[I]
   AY=AY-HY[I]
   IF I<=1 THEN AY1=0
   IF I>=2 THEN AX1=0
  ENDIF
 NEXT
NEXT
GOSUB @BTNCTR
AY=AY+AY1
AX=AX+AX1
IF AX<SZH THEN AX=SZH

SPOFS AN,AX,AY,AZ
IF AY>GRH THEN OVR=1  'GAMEOVER

IF BT AND 8 THEN SPCHR AN,ACH+FLOOR(AA)
IF BT AND 4 THEN SPCHR AN,ACH+FLOOR(AA)+8

RETURN
'---BUTTON CONTROL
@BTNCTR
'PRINT "JUMP";JUMP

BT=STKANDBTN()
X=AX:Y=AY:GOSUB @JMNCHK
IF HIT>32 THEN @BTNCTR2

SPN=SPHITSP(AN)
IF SPN!=-1 THEN
 IF SPVAR(SPN,0)>=6 THEN
 SPOFS SPN OUT X,Y
 IF AY<=((Y-SZ)+4) THEN @BTNCTR2
 ENDIF
ENDIF

'---IN THE SKY
G=0.25
IF BT AND 16 THEN G=0.125
AY1=AY1+G
IF BT AND 4 THEN AX1=AX1-0.025
IF BT AND 8 THEN AX1=AX1+0.025
RETURN
'---ON THE GROUND
@BTNCTR2
AY1=0
AX1=AX1-(0.05*SGN(AX1))

IF BT AND 4 THEN AX1=AX1-0.1
IF BT AND 8 THEN AX1=AX1+0.1
IF ABS(AX1)<0.05 THEN AX1=0
IF ABS(AX1)>2 THEN AX1=SGN(AX1)*2

IF BT AND 4+8 THEN
 AA=AA+0.3  'ANIME
 IF AA>=4 THEN AA=AA-4
ENDIF

IF JUMP THEN
 IF (BT AND 16)==0 THEN JUMP=0
ELSE
 IF (BT AND 16) THEN
  AY1=-4.5
  BEEP 8,-500
  JUMP=1
 ENDIF
ENDIF
RETURN

'---JIMEN CHECK
@JMNCHK
Y=Y+3
X=X-SZH:GOSUB @BGCHK
HIT=CH
X=X+SZH:GOSUB @BGCHK
HIT=HIT OR CH
RETURN

'---BG CHECK
@BGCHK
TX=FLOOR((X+BX)/16)
TY=FLOOR(Y/16)
IF TX<0 THEN TX=0
IF TY<0 THEN TY=0
IF TX>=BGW THEN TX=BGW-1
IF TY>=BGH THEN TY=BGH-1

CH=BGGET(LAY,TX,TY)

RETURN
'---BG SCROLL
@BGSCR
IF GOAL THEN
 IF AX>GRW-24 THEN AX=GRW-24
 RETURN
ENDIF

WHILE 1
 IF AX<GRW/2 THEN BREAK
 AX=AX-1

 'SLIDE ENEMY
 FOR I=DN TO (DN+DMAX-1)
  SPOFS I OUT X,Y,Z
  IF Y==NONE THEN CONTINUE
  X=X-1
  SPOFS I,X,Y
 NEXT

 IF (BX MOD 16)==0 THEN
 FOR Y=0 TO BGH-1
  X=(BX+400)/16
  IF X>=BXMAX THEN BREAK
  C=MAP[X,Y]-ASC("A")
  IF (C>=0) AND (C<CMAX) THEN
   NX=400+16
   NY=Y*16+32
   NZ=-63
   NC=C
   GOSUB @TEKIBORN
  ENDIF
'PRINT "MAP";MAP[X,Y]
 NEXT
 ENDIF

 BX=BX+1
 IF BX>BXMAX THEN
  BX=BXMAX
  IF GOAL==0 THEN
   BGMPLAY 5
   MSG$="G O A L!!"
   GOAL=1
  ENDIF
 ENDIF

 BGOFS LAY,BX,BY

 BGOFS 0,BX,BY
 BGOFS 1,BX,BY
 BGOFS 3,BX,BY

WEND
RETURN

'---TEKI
@TEKICTR
FOR I=DN TO (DN+DMAX-1)
 SPOFS I OUT VX,VY
 IF VY==NONE THEN CONTINUE
 TN =SPVAR(I,0)  'TYPE NO.
 TIM=SPVAR(I,1)  'TIME
 X1 =SPVAR(I,2)  'X1
 Y1 =SPVAR(I,3)  'Y1
 TMP=SPVAR(I,4)  'TEMP

 GOSUB JMPTBL$[TN]

 IF (VX<-32) OR (VX>GRW+128) OR (VY>GRH+48) THEN
  VY=NONE
 ENDIF
 SPOFS I,VX,VY

 ANI=FLOOR(TIM/8) MOD ANIMAX[TN]
 SPCHR I,ANINUM[TN]+ANI+2048

 TIM=TIM+1
 SPVAR I,1,TIM
 SPVAR I,2,X1
 SPVAR I,3,Y1
 SPVAR I,4,TMP

'CHECK HIT
 IF SPHITSP(I)==AN THEN
  GOSUB HITPRG$[TN]
 ENDIF
NEXT
RETURN
'---
@RIDEBS
SXA=SGN(AX-VX)
SYA=SGN(AY-VY)
DXA=ABS(AX-VX)
DYA=ABS(AY-VY)

IF AY<=((VY-SZ)+4) THEN
 AX=AX+X1
ENDIF

IF DYA>DXA THEN
 IF DYA<=(SZ-2) THEN
  AY=AY+((SZ-2)-DYA)*SYA
 ENDIF
ELSE
 IF DXA<=(SZ-2) THEN
  AX=AX+((SZ-2)-DXA)*SXA
  AX1=0
 ENDIF
ENDIF
RETURN
'----
@GETCOIN
VY=NONE
SPOFS I,VX,VY
BEEP 7
SCORE=SCORE+100
RETURN
'----
@SETOVR
IF DEBUG THEN RETURN
OVR=1
RETURN

'---
'0:(TYPE A)GHOST
@ARG0
 IF TIM==0 THEN
  X1=-1
 ENDIF
 X=VX+X1*SZH:Y=VY-SZH
 GOSUB @BGCHK
 IF CH>32 THEN X1=-X1

 X=VX:Y=VY
 GOSUB @BGCHK
 IF CH>32 THEN Y1=-4

 Y1=Y1+0.1
 VX=VX+X1
 VY=VY+Y1
RETURN
'---
'1:(TYPE B)COIN
@ARG1
RETURN
'---
'2:(TYPE C)ROBOT
@ARG2
IF TMP==0 THEN
 IF RND(20)==0 THEN X1=-1:TMP=64
ELSE
 TMP=TMP-1
 IF TMP==0 THEN X1=0
ENDIF

X=VX+SZH*X1
Y=VY-SZH
GOSUB @BGCHK
IF CH>32 THEN X1=-X1

X=VX
Y=VY+3
GOSUB @BGCHK
IF CH<=32 THEN Y1=Y1+0.1

VX=VX+X1
VY=VY+Y1

X=VX
Y=VY+2
GOSUB @BGCHK
IF CH>32 THEN Y1=0:VY=VY-1

RETURN
'---
'3:(TYPE D)INO
@ARG3
IF X1==0 THEN
 IF ABS(AX-VX)<128 THEN X1=-0.3
ELSE
 X1=X1-0.03
ENDIF

X=VX
Y=VY+3
GOSUB @BGCHK
IF CH<=32 THEN Y1=Y1+0.1

VX=VX+X1
VY=VY+Y1

X=VX
Y=VY+2
GOSUB @BGCHK
IF CH>32 THEN Y1=0:VY=VY-1

RETURN
'---
'4:(TYPE E)TOGE
@ARG4
IF Y1==0 THEN
 IF ABS(AX-VX)<48 THEN Y1=1
 TMP=VY
ELSE
 IF Y1<0 THEN
  IF TMP>=VY THEN Y1=0
 ELSE
  X=VX
  Y=VY+2
  GOSUB @BGCHK
  IF CH<=32 THEN
   Y1=Y1+0.1
  ELSE
   Y1=-1
  ENDIF
 ENDIF
 VY=VY+Y1
ENDIF
RETURN
'---
'5:(TYPE F)FIRE BALL
@ARG5
IF Y1>=0 THEN
 IF VY>=GRH+32 THEN
  IF RND(60)==0 THEN Y1=-5
  RETURN
 ENDIF
ENDIF
VY=VY+Y1
Y1=Y1+0.1

RETURN
'---
'6:(TYPE G)BASE
@ARG6
IF X1==0 THEN X1=-1
GOSUB @ARGSLIDE
RETURN
'---
'7:(TYPE H)BASE
@ARG7
IF X1==0 THEN X1=1
GOSUB @ARGSLIDE
RETURN
'---
@ARGSLIDE
IF TMP==0 THEN X1=-X1
TMP=(TMP+1) MOD 96
VX=VX+X1
'IF SPHITSP(I)==AN THEN
' IF AY<VY THEN
'  AX=AX+X1
' ENDIF
'ENDIF
RETURN

'---
'8:(TYPE I)
@ARG8
RETURN
'---
'9:(TYPE J)
@ARG9
RETURN


'---TEKI BORN
@TEKIBORN
'PRINT "BORN"
FOR I=DN TO (DN+DMAX-1)
 SPOFS I OUT VX,VY,VZ
'PRINT "SPOF";VX,VY
 IF VY!=NONE THEN CONTINUE
'PRINT "SP";I,NX,NY
 SPCHR I,ANINUM[NC]+2048
 SPOFS I,NX,NY,NZ
 SPDEF ANINUM[NC] OUT U,V,W,H
 SPCOL I,-W/2,-H/2,W,H,TRUE

 SPVAR I,0,NC  'CHARA TYPE NO.
 SPVAR I,1,0   'TIME
 SPVAR I,2,0   'X1
 SPVAR I,3,0   'Y1
 SPVAR I,4,0   'TEMP
 BREAK

NEXT
RETURN


'---PRINT SUB
@PRTSUB
LOCATE 25-LEN(A$)/2,Y,-200
PRINT A$
RETURN

'---HIT ANY BUTTON
@HITANY
A$="HIT ANY BUTTON"
Y=27
GOSUB @PRTSUB
VSYNC 20
WHILE 1
 IF STKANDBTN()==0 THEN BREAK
WEND
WHILE 1
 BTN=STKANDBTN()
 IF BTN THEN BREAK
WEND

RETURN
'--- LOAD BG DATA
@READMAP

BX=0:BY=0:BZ=0
BGL=4  'BG LAYER MAX
LAY=2

LOADSUB "DAT:SYS/GAME3"

BGOFS 3,BX,BY,-200
BGOFS 2,BX,BY,-62
BGOFS 1,BX,BY,128
BGOFS 0,BX,BY,768

FOR Y=0 TO BGH-1
 FOR X=0 TO BGW-1
  MAP[X,Y]=0
 NEXT
NEXT

FOR Y=0 TO BGH-1
 FOR X=0 TO BGW-1
  C=BGGET(LAY,X,Y)
  IF C>=ASC("A") AND C<=ASC("Z") THEN
   MAP[X,Y]=C
   BGPUT LAY,X,Y,0
  ENDIF
  IF C==32 THEN
   BGPUT LAY,X,Y,0
  ENDIF
 NEXT
NEXT

SPDEF 0 OUT U,V,W,H
AX=GRW*1/4:AY=100:AZ=-64
AX1=0
AY1=0
SPSCALE AN,SCL,SCL
SPCOL AN,-W/2,-H/2,W,H,TRUE

X=NONE
Y=NONE
Z=0

FOR I=DN TO (DN+DMAX-1)
 C=6
 SPSET I,C
 SPSCALE I,SCL,SCL
 SPOFS I,X,Y,Z
NEXT

MSGCNT=0
MSG$="S T A G E  "+STR$(LVL)
BGMPLAY 3

GOAL=0
CLS
A$="[ ]MOVE  [A]JUMP"
Y=28
GOSUB @PRTSUB

TIMER=300
RETURN

'---
DEF LOADSUB N$
 ID=(ASC("M")<<24)
 ID=(ASC("A")<<16) OR ID
 ID=(ASC("P")<<8)  OR ID
 ID=(ASC(":"))     OR ID
 H_ID=0:H_VR=1:H_R2=2:H_LY=3
 H_DW=4:H_DH=5:H_MX=6:H_MY=7

 ATRMAX=32*32
 DIM ATR%[ATRMAX]
 HEADMAX=8
 MAPMAX=16383

' IF CHKFILE(N$)==FALSE THEN RETURN

 ATRSIZE=ATRMAX DIV 4
 WMAX=HEADMAX+ATRSIZE+(MAPMAX*4)
 DIM W%[WMAX]

 '---
 LOAD N$,W%,FALSE 'LOAD DIALOG OFF

 '--- HEADER
 IF W%[H_ID]!=ID THEN
  PRINT "ERROR< BAD ID >"
  RETURN
 ENDIF
 BGL=W%[H_LY]
 DW=W%[H_DW]:DH=W%[H_DH]
 MX=W%[H_MX]:MY=W%[H_MY]

 BGW=DW*MX:BGH=DH*MY:MAX=BGW*BGH
 IF MAX>16383 THEN
  PRINT "BG CHIP OVER:";MAX
  RETURN
 ENDIF
 IF BGL<1 OR BGL>4 THEN RETURN
 '---
 DISPLAY 0
 FOR L=0 TO BGL-1
'  BGCLR L
  BGSCREEN L,BGW,BGH
  BGOFS L,0,0,0
  BGSCALE L,1,1
  BGSHOW L
 NEXT
 
 '--- ATR[]
 TOP=HEADMAX
 FOR I=0 TO ATRMAX-1 STEP 4
  ATR%[I+0]=W%[TOP] AND &HFF
  ATR%[I+1]=(W%[TOP]>>8) AND &HFF
  ATR%[I+2]=(W%[TOP]>>16) AND &HFF
  ATR%[I+3]=(W%[TOP]>>24) AND &HFF
  TOP=TOP+1
 NEXT
 
 '--- TMP0[]-TMP3[]
' DISPLAY 0
 BGCLR
 DIM TMP%[BGH*BGW]
 FOR I=0 TO BGL-1
  FOR Y=0 TO BGH-1
   FOR X=0 TO BGW-1 STEP 2
    O=X+Y*BGW
    TMP%[O+0]=W%[TOP] AND &HFFFF
    TMP%[O+1]=(W%[TOP]>>16) AND &HFFFF
    TOP=TOP+1
   NEXT
  NEXT
  BGLOAD I,TMP%
 NEXT

END
'---
DEF STKANDBTN()
 SLV=0.2  'THRESHOLD
 BTN=BUTTON()
 STICK OUT SX,SY
 IF (SY>SLV)  THEN BTN=BTN OR 1
 IF (SY<-SLV) THEN BTN=BTN OR 2
 IF (SX<-SLV) THEN BTN=BTN OR 4
 IF (SX>SLV)  THEN BTN=BTN OR 8
 RETURN BTN
END
'----
'
'
'

ページトップへ