_TITLE "B+ Flying Hero Mod of TempodiBasic Trap Mod of Terri Ritchie Simple Map Demo, 2018-08-21"
'*
'* Bitwise math demonstration
'*
'* Draws a simple map and allows player to move circle within map
'* rapresentation using a clockwise power of 2 for each segment first the 4 basilar
'* and then the 4 diagonal for optional directions
'* as picture power of 2 (2^n) result of 2^n
'* __ 0 1 N
'* / \ 7 4 128 16 NE NW
'* | | 3 1 8 2 E W
'* \ / 6 5 64 32 SE SW
'* -- 2 4 S
'* example of how the value of cell in the map changes using octagonal movement controls
'* a closed box squared wall scoring octagonal wall scoring
'* -- 1+2+4+8= 15 1+2+4+8+ 16+32+64+128=255
'* | |
'* --
'* a U box squared wall scoring octagonal wall scoring
'* 2+4+8= 14 2+4+8+ 32+64+128+16=
'* | | or 15 - 1 = 14 14 + oblique directions forbidden
'* --
'* a C box squared wall scoring octagonal wall scoring
'* -- 1+4+8= 13 1+4+8+ 64+128=205 moving NW W SW
'* | or 15-2 =13
'* --
'*
'* squared wall 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
'*
'--------------------------------
'- Variable Declaration Section -
'--------------------------------
'Window
'Map active arena
'special powers
'key codes
TYPE MAP
' set up map cell structure x
AS INTEGER ' upper left x coordinate of cell y
AS INTEGER ' upper left y coordinate of cell
'get ready
XOFF = (WW - MAPW * SQ) / 2 - SQ
YOFF = (WH - MAPH * SQ) / 2 - SQ
H.X = 1: H.Y = 1
RAT.X = 1: RAT.Y = 1
RAT.DX = 0: RAT.DY = 1 'moving right need these for heading calulations for drawing
DIM KH&
' player key presses DIM MagicKey
' Magic Key to across the walls
'----------------------------
'- Main Program Begins Here -
'----------------------------
DRAWMAP '
DO ' MAIN LOOP begins here PCOPY 1, 0 ' copy page 1 to current screen DrawHero MagicKey
'diagonal movements are managed here
IF (NOT MAP
(RAT.X
, RAT.Y
).walls
AND 64) OR MagicKey
THEN RAT.X
= RAT.X
- 1: RAT.Y
= RAT.Y
+ 1: RAT.DX
= -1: RAT.DY
= 1 IF (NOT MAP
(RAT.X
, RAT.Y
).walls
AND 128) OR MagicKey
THEN RAT.X
= RAT.X
- 1: RAT.Y
= RAT.Y
- 1: RAT.DX
= -1: RAT.DY
= -1
IF (NOT MAP
(RAT.X
, RAT.Y
).walls
AND 32) OR MagicKey
THEN RAT.X
= RAT.X
+ 1: RAT.Y
= RAT.Y
+ 1: RAT.DX
= 1: RAT.DY
= 1
IF (NOT MAP
(RAT.X
, RAT.Y
).walls
AND 16) OR MagicKey
THEN RAT.X
= RAT.X
+ 1: RAT.Y
= RAT.Y
- 1: RAT.DX
= 1: RAT.DY
= -1
'previous key's commands are managed here
_DISPLAY ' update the screen without flicker
'-----------------------------------
'- Function and Subroutine section -
'-----------------------------------
rx = RAT.X * SQ + .5 * SQ + XOFF
ry = RAT.Y * SQ + .5 * SQ + YOFF
rr = .2 * SQ
heading
= _ATAN2(RAT.DY
, RAT.DX
) noseX
= rx
+ 2 * rr
* COS(heading
) noseY
= ry
+ 2 * rr
* SIN(heading
) neckX
= rx
+ .75 * rr
* COS(heading
) neckY
= ry
+ .75 * rr
* SIN(heading
) tailX
= rx
+ 2 * rr
* COS(heading
+ _PI) tailY
= ry
+ 2 * rr
* SIN(heading
+ _PI) earLX
= rx
+ rr
* COS(heading
- _PI(1 / 12)) earLY
= ry
+ rr
* SIN(heading
- _PI(1 / 12)) earRX
= rx
+ rr
* COS(heading
+ _PI(1 / 12)) earRY
= ry
+ rr
* SIN(heading
+ _PI(1 / 12)) fcirc rx, ry, .65 * rr, rc&
fcirc neckX, neckY, rr * .3, rc&
ftri noseX, noseY, earLX, earLY, earRX, earRY, rc&
fcirc earLX, earLY, rr * .3, rc&
fcirc earRX, earRY, rr * .3, rc&
wX
= .5 * rr
* COS(heading
- _PI(11 / 18)) wY
= .5 * rr
* SIN(heading
- _PI(11 / 18)) LINE (noseX
+ wX
, noseY
+ wY
)-(noseX
- wX
, noseY
- wY
), rc&
wX
= .5 * rr
* COS(heading
- _PI(7 / 18)) wY
= .5 * rr
* SIN(heading
- _PI(7 / 18)) LINE (noseX
+ wX
, noseY
+ wY
)-(noseX
- wX
, noseY
- wY
), rc&
LINE (rx
, ry
)-(tailX
, tailY
), rc&
IF Status
AND (FLAP
MOD 60 > 10) THEN 'how about some wings? wingx
= rx
+ .25 * rr
* COS(heading
) wingy
= ry
+ .25 * rr
* SIN(heading
) pieSlice wingx
, wingy
, 4 * rr
, heading
+ _PI(.5) - _PI(1 / 24), heading
+ _PI(.5) + _PI(1 / 6), _RGB32(0, 255, 255) pieSlice wingx
, wingy
, 4 * rr
, heading
- _PI(.5) - _PI(1 / 6), heading
- _PI(.5) + _PI(1 / 24), _RGB32(0, 255, 255)
'*
'* draws a map based on the value of each map cell
'*
DIM x
, y
' x,y map coordinates
FOR y
= 1 TO MAPH
' cycle through map rows FOR x
= 1 TO MAPW
' cycle through map columns READ MAP
(x
, y
).walls
' read wall DATA MAP(x, y).x = x * SQ + XOFF ' compute upper left x coordinate of cell
MAP(x, y).y = y * SQ + YOFF ' compute upper left y coordinate of cell
IF MAP
(x
, y
).walls
AND 1 THEN ' is NORTH wall present? LINE (MAP
(x
, y
).x
, MAP
(x
, y
).y
)-STEP(SQ
- 1, 0), _RGB32(255, 255, 255) ' yes, draw it IF MAP
(x
, y
).walls
AND 2 THEN ' is EAST wall present? LINE (MAP
(x
, y
).x
+ SQ
- 1, MAP
(x
, y
).y
)-STEP(0, SQ
- 1), _RGB32(255, 255, 255) ' yes, draw it IF MAP
(x
, y
).walls
AND 4 THEN ' is SOUTH wall present? LINE (MAP
(x
, y
).x
, MAP
(x
, y
).y
+ SQ
- 1)-STEP(SQ
- 1, 0), _RGB32(255, 255, 255) ' yes, draw it IF MAP
(x
, y
).walls
AND 8 THEN ' is WEST wall present? LINE (MAP
(x
, y
).x
, MAP
(x
, y
).y
)-STEP(0, SQ
- 1), _RGB32(255, 255, 255) ' yes, draw it
PCOPY 0, 1 ' save a copy of the map
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), K
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), K
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), K
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), K
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), K
, BF
'use radians
'x, y origin, r = radius, c = color
'raStart is first angle clockwise from due East = 0 degrees
' arc will start drawing there and clockwise until raStop angle reached
arc x
, y
, r
, raStart
, _PI(2), c
arc x, y, r, 0, raStop, c
' modified to easier way suggested by Steve
'Why was the line method not good? I forgot.
al
= _PI * r
* r
* (raStop
- raStart
) / _PI(2)
'draw lines from origin to arc on sides
arc x, y, r, raStart, raStop, c
px
= x
+ r
* COS(raStart
): py
= y
+ r
* SIN(raStart
) px
= x
+ r
* COS(raStop
): py
= y
+ r
* SIN(raStop
)
'------------------------
'- Program DATA section -
'------------------------
'*
'* Map cell values
'*
'DATA 11,15,15,11,15,12,5,5,4,3,15,15,15,15,10,11,15,9,5,6,12,5,6,15,15
' a different map
' DATA 11,15,15,11,15,12,5,5,4,3,15,11,15,15,10,9,0,1,5,6,12,4,5,15,15
'conversion of the map above with square movement to octagonal movement
DATA 219,255,255,155,255,252,117,229,212,115,255,155,255,255,58,201,144,49,165,246,236,100,119,255,255 '* as picture power of 2 (2^n) result of 2^n
'* __ 0 1
'* / \ 7 4 128 16
'* | | 3 1 8 2
'* \ / 6 5 64 32
'* -- 2 4