I tried to "translate" this code from C to Basic-like language used in BEX, and to add it to my source (new code insertion is selected with a bold).
Code: Select all
Option TextStart, 0, 0
Option TextHeight, 30 ' Default is 26
Option TextWidth, 39 ' Default is 38
Cls
LoadTiles topTiles1,45,256
LoadTiles bottomTiles1,30,301
LoadTiles topTiles2,60,331
LoadTiles bottomTiles2,30,391
LoadTiles CellTiles,4,421
Palettes palette1,1,0,16
Palettes palette2,2,0,16
Palettes palette3,3,0,16
Palettes cells_pal,3,0,16
SetGfxPlane Scroll_B
For cell_y = 0 to 28
For cell_x= 0 to 10
Ink 3
DrawTiles Grid,421,(cell_x*2)+(cell_y%2)*2,cell_y,3,2
Next
Next
character1_top = AddSprite(3,3)
PropSprite character1_top,274,1
MoveSprite character1_top,272,224
character1_bottom = AddSprite(2,3)
PropSprite character1_bottom,313,1
MoveSprite character1_bottom,272,248
character2_top = AddSprite(4,3)
PropSprite character2_top,331,2
MoveSprite character2_top,240,248
character2_bottom = AddSprite(2,3)
PropSprite character2_bottom,391,2
MoveSprite character2_bottom,240,280
Body=0
ap=6
characters_turn=0
[b]halftile=12
delta_x=0
delta_y=0[/b]
On VBlank GoSub main
Enable Interrupt VBlank
End
main:
'Bit Hex Decimal Button
'0 &h001 1 Up
'1 &h002 2 Down
'2 &h004 4 Left
'3 &h008 8 Right
'4 &h010 16 B
'5 &h020 32 C
'6 &h040 64 A
'7 &h080 128 Start
'8 &h100 256 Z (6-Button)
'9 &h200 512 Y (6-Button)
'10 &h400 1024 X (6-Button)
'11 &h800 2048 Mode (6-Button)
'DeBug Info:
ink 0
locate 0,16: print "AP=";ap
locate 1,16: print "Now turns=";characters_turn
'End DeBug Info
c=j
j=JoyPad(0)
'Start
If j.7 And c.7=0 Then
GoSub Pause
EndIf
'Left
If j.2 And j.0=0 And j.1=0 Then
Body=2
Gosub LookingSideChanging
If SpritePosX(character1_top)>128 Then
If ap>1 then
WAITPADUP
ap-=2
[b]delta_x=-halftile[/b]
if characters_turn=0 then
[b]ShiftSprite character1_top,character_x,0
ShiftSprite character1_bottom,character_x,0[/b]
else
[b]ShiftSprite character2_top,character_x,0
ShiftSprite character2_bottom,character_x,0[/b]
endif
Gosub NewTurn
else
locate 26,1: print "Action points not enough!"
endif
EndIf
EndIf
'Right
If j.3 And j.0=0 And j.1=0 Then
Body=3
Gosub LookingSideChanging
If SpritePosX(character1_top)<424 Then
If ap>1 then
WAITPADUP
ap-=2
[b]delta_x=halftile[/b]
if characters_turn=0 then
[b]ShiftSprite character1_top,character_x,0
ShiftSprite character1_bottom,character_x,0[/b]
else
[b]ShiftSprite character2_top,character_x,0
ShiftSprite character2_bottom,character_x,0[/b]
endif
Gosub NewTurn
else
locate 26,1: print "Action points not enough!"
endif
EndIf
EndIf
'Up
If j.0 And j.2=0 And j.3=0 Then
Body=0
Gosub LookingSideChanging
If SpritePosY(character1_top)>128 Then
WAITPADUP
ap--
[b]delta_y=-halftile[/b]
if characters_turn=0 then
[b]ShiftSprite character1_top,0,character_y
ShiftSprite character1_bottom,0,character_y[/b]
else
[b]ShiftSprite character2_top,0,character_y
ShiftSprite character2_bottom,0,character_y[/b]
endif
Gosub NewTurn
EndIf
EndIf
'Down
If j.1 And j.2=0 And j.3=0 Then
Body=1
Gosub LookingSideChanging
If SpritePosY(character1_bottom)<336 Then
WAITPADUP
ap--
[b]delta_y=halftile[/b]
if characters_turn=0 then
[b]ShiftSprite character1_top,0,character_y
ShiftSprite character1_bottom,0,character_y[/b]
else
[b]ShiftSprite character2_top,0,character_y
ShiftSprite character2_bottom,0,character_y[/b]
endif
Gosub NewTurn
EndIf
EndIf
'Left+Up+
If j.2 And j.0=1 And j.1=0 Then
Body=4
Gosub LookingSideChanging
If SpritePosX(character1_top)>128 And SpritePosY(character1_top)>128 Then
WAITPADUP
ap--
if characters_turn=0 then
ShiftSprite character1_top,-12,-8
ShiftSprite character1_bottom,-12,-8
else
ShiftSprite character2_top,-12,-8
ShiftSprite character2_bottom,-12,-8
endif
Gosub NewTurn
EndIf
EndIf
'Right+Up
If j.3 And j.0 And j.1=0 Then
Body=5
Gosub LookingSideChanging
If SpritePosX(character1_top)<432 And SpritePosY(character1_top)>128 Then
WAITPADUP
ap--
if characters_turn=0 then
ShiftSprite character1_top,12,-8
ShiftSprite character1_bottom,12,-8
else
ShiftSprite character2_top,12,-8
ShiftSprite character2_bottom,12,-8
endif
Gosub NewTurn
EndIf
EndIf
'Right+Down
If j.0=0 And j.1 And j.3 Then
Body=7
Gosub LookingSideChanging
If SpritePosX(character1_top)<432 And SpritePosY(character1_bottom)<336 Then
WAITPADUP
ap--
if characters_turn=0 then
ShiftSprite character1_top,12,8
ShiftSprite character1_bottom,12,8
else
ShiftSprite character2_top,12,8
ShiftSprite character2_bottom,12,8
endif
Gosub NewTurn
EndIf
EndIf
'Left+Down
If j.1 And j.2 And j.3=0 Then
Body=6
Gosub LookingSideChanging
If SpritePosX(character1_top)>128 And SpritePosY(character1_bottom)<336 Then
WAITPADUP
ap--
if characters_turn=0 then
ShiftSprite character1_top,-12,8
ShiftSprite character1_bottom,-12,8
else
ShiftSprite character2_top,-12,8
ShiftSprite character2_bottom,-12,8
endif
Gosub NewTurn
EndIf
EndIf
[b]if characters_turn=0 then
x2=SpritePosX(character1_bottom)+delta_x
y2=SpritePosY(character1_bottom)+delta_y
else
x2=SpritePosX(character2_bottom)+delta_x
y2=SpritePosY(character2_bottom)+delta_y
endif
character_x=x2>>4 'Shifts right by 4 bits; effectivelly the same as x2 / 16, but faster
character_y=y2>>4 'Shifts right by 4 bits; effectivelly the same as y2 / 16, but faster[/b]
Return
NewTurn:
if ap<1 then
ap=6
characters_turn++
endif
if characters_turn>1 then characters_turn=0
return
LookingSideChanging:
if Body=0 then
if characters_turn=0 then
PropSprite character1_top,274,1
PropSprite character1_bottom,313,1
else
PropSprite character2_top,355,2
PropSprite character2_bottom,403,2
endif
endif
if Body=1 then
if characters_turn=0 then
PropSprite character1_top,265,1
PropSprite character1_bottom,307,1
else
PropSprite character2_top,343,2
PropSprite character2_bottom,397,2
endif
endif
if Body=2 then
if characters_turn=0 then
PropSprite character1_top,256,1
PropSprite character1_bottom,301,1
else
PropSprite character2_top,331,2
PropSprite character2_bottom,391,2
endif
endif
if Body=3 then
if characters_turn=0 then
PropSprite character1_top,256+hFlipTile(1),1
PropSprite character1_bottom,301+hFlipTile(1),1
else
PropSprite character2_top,331+hFlipTile(1),2
PropSprite character2_bottom,391+hFlipTile(1),2
endif
endif
if Body=4 then
if characters_turn=0 then
PropSprite character1_top,292,1
PropSprite character1_bottom,325,1
else
PropSprite character2_top,379,2
PropSprite character2_bottom,415,2
endif
endif
if Body=5 then
if characters_turn=0 then
PropSprite character1_top,292+hFlipTile(1),1
PropSprite character1_bottom,325+hFlipTile(1),1
else
PropSprite character2_top,379+hFlipTile(1),2
PropSprite character2_bottom,415+hFlipTile(1),2
endif
endif
if Body=6 then
if characters_turn=0 then
PropSprite character1_top,283,1
PropSprite character1_bottom,319,1
else
PropSprite character2_top,367,2
PropSprite character2_bottom,409,2
endif
endif
if Body=7 then
if characters_turn=0 then
PropSprite character1_top,283+hFlipTile(1),1
PropSprite character1_bottom,319+hFlipTile(1),1
else
PropSprite character2_top,367+hFlipTile(1),2
PropSprite character2_bottom,409+hFlipTile(1),2
endif
endif
return