'Space Dodger Eps 1: "Attack of the Giant Killer Space Hamsters!"
'UniKorn ProDucKions 2020
'Demo release
'ToDo list:
'Adds:
'-Title Screen
'-Main Menu
'-High Score list
'-Boss Fight
'-Better SFX
'-Cleaned up Death Animation screen
'-Game Over Screen
'-Power Up drops
'-Variable Hamster targets
DIM SHARED LED
(9) AS SpriteLocation
, ShipExplode
(16) AS SpriteLocation
DIM SHARED P
AS PlayerData
, G
AS Gamedata
, Stars
(150) AS stardata
, Shot
(10) AS SpriteLocation
'LED display sprite locations
DATA 0,28,10,28,20,28,30,28,40,28,50,28,60,28,70,28,80,28,90,28 'Ship Explostion sprite locations
DATA 0,160,107,221,0,0:
' 0 DATA 108,160,215,221,0,0:
' 1 DATA 216,160,323,221,0,0:
' 2 DATA 324,158,429,223,0,-2:
' 3 DATA 432,148,533,229,0,-12:
'4 DATA 0,252,107,349,0,-20:
' 5 DATA 108,242,209,357,0,-30:
'6 DATA 216,238,317,365,0,-34:
'7 DATA 324,230,425,369,0,-42:
'8 DATA 432,236,539,363,0,-36:
'9 DATA 0,380,107,517,0,-40:
' 10 DATA 108,370,213,533,0,-46:
'11 DATA 214,370,319,533,14,-46:
'12 DATA 320,370,425,533,20,-46:
'13 DATA 442,372,529,529,12,-46:
'14 DATA 552,418,625,483,16,-46:
'15 DATA 652,372,739,533,20,-46:
'16
FOR i%%
= 0 TO 9 'load LED display sprite locations READ LED
(i%%
).X
, LED
(i%%
).Y
READ ShipExplode
(i%%
).X
, ShipExplode
(i%%
).Y
, ShipExplode
(i%%
).Sx
, ShipExplode
(i%%
).Sy
, ShipExplode
(i%%
).Ox
, ShipExplode
(i%%
).Oy
Layer
(4) = _NEWIMAGE(640, 400, 32) 'temp bgplateLayer
(5) = _NEWIMAGE(640, 400, 32) 'Collision layer
MFI_Loader "SpaceDog.MFI"
CONST max
= 7, min
= 1, Stars
= 50, Maxshotsfired
= 3, MaxHamsters
= 10
P.Shield = 100
P.Score = 0
P.Lives = 3
G.CurrentShot = -1
G.PlayerDeath = 0
MakeNewStar i%
FOR i%%
= 0 TO MaxHamsters
MakeHamster i%%
ExitFlag%% = Controls
StarField
DisplayPlayer
IF G.CurrentShot
>= 0 THEN Process_Shots: Displayshots
Process_Hamsters: Make_Collision_Layer_Hamsters: DisplayHamsters
DisplayExtraLives
DisplayShieldLevel
DisplayScore
DisplayEngineFlame
ExplodePlayer
FOR i%%
= 0 TO MaxHamsters
MakeHamster i%%
P.Shield = 100
P.Lives = P.Lives - 1
IF P.Lives
= -1 THEN ExitFlag%%
= TRUE
G.PlayerDeath = FALSE
IF P.Lives
= 0 THEN ExitFlag%%
= TRUE
DisplayExtraLives
DisplayScore
STATIC SlowFlag%%
, CoastFlag%%
, KeyLocked%%
', BombLock%% Result%% = FALSE
IF G.CurrentShot
< Maxshotsfired
THEN G.CurrentShot = G.CurrentShot + 1
Makeshot G.CurrentShot
KeyLocked%% = TRUE
KeyLocked%% = FALSE
'20480
IF _KEYDOWN(20480) THEN P.SpeedY
= P.SpeedY
+ .25: CoastFlag%%
= FALSE
IF P.SpeedY
>= 5 THEN P.SpeedY
= 5
IF P.SpeedX
< .5 THEN P.SpeedX
= .5 IF P.SpeedX
> max
THEN P.SpeedX
= max
IF _KEYDOWN(18432) THEN P.SpeedY
= P.SpeedY
- .25: CoastFlag%%
= FALSE
IF P.SpeedY
<= -5 THEN P.SpeedY
= -5
P.SpeedX
= P.SpeedX
- .05:
IF P.SpeedX
< min
THEN P.SpeedX
= min: SlowFlag%%
= TRUE
IF NOT CoastFlag%%
THEN 'allow coast up and down P.SpeedY = P.SpeedY - .05
IF P.SpeedY
<= .2 THEN CoastFlag%%
= TRUE: P.SpeedY
= 0 P.SpeedY = P.SpeedY + .05
IF P.SpeedY
>= -.2 THEN CoastFlag%%
= TRUE: P.SpeedY
= 0
Controls = Result%%
'((x-h)/a)^2 + ((y-k)/b)^2 <= 1
'H,K -center x,y
'x,y -hamster point to check
'a,b Radius X, radius Y
Result%% = 0
hit%% = 0
'hamster size 48x28, check 8 points
'hit%% = _RED32(POINT(H(id%%).X + 0, H(id%%).Y)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 0, H(id%%).Y + 7)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 0, H(id%%).Y + 14)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 10, H(id%%).Y + 21)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 10, H(id%%).Y + 28)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 48, H(id%%).Y)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 48, H(id%%).Y + 14)) 'check for hit box
'IF hit%% THEN hit%% = _RED32(POINT(H(id%%).X + 48, H(id%%).Y + 28)) 'check for hit box
' test~& = POINT(H(id%%).X + 0, H(id%%).Y)
' _PRINTSTRING (16, 16 + 16 * id%%), STR$(_RED32(test~&)), Layer(1)
' _PRINTSTRING (0, 220 + 16 * id%%), STR$(H(id%%).X + 0) + STR$(H(id%%).Y), Layer(1)
'IF hit%% = 1 THEN Result%% = hit%%
IF (((H
(id%%
).X
+ 24) - 113) / 53) ^ 2 + (((H
(id%%
).Y
+ 14) - 200) / 30) ^ 2 <= 1 THEN Result%%
= TRUE
Hamster_Collision = Result%%
Result%% = -1
hit%% = 0
'shot size 16x10, check 6 points
hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 16, Shot
(id%%
).Y
)) 'check for hit box IF hit%%
< 10 THEN hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 16, Shot
(id%%
).Y
+ 5)) 'check for hit box IF hit%%
< 10 THEN hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 16, Shot
(id%%
).Y
+ 10)) 'check for hit box IF hit%%
< 10 THEN hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 12, Shot
(id%%
).Y
)) 'check for hit box IF hit%%
< 10 THEN hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 12, Shot
(id%%
).Y
+ 5)) 'check for hit box IF hit%%
< 10 THEN hit%%
= _RED32(POINT(Shot
(id%%
).X
+ 12, Shot
(id%%
).Y
+ 10)) 'check for hit box IF hit%%
>= 10 THEN Result%%
= hit%%
- 10 'which hamster was hit?
Shot_Collision = Result%%
_PUTIMAGE (15 - P.SpeedX
, 190)-STEP(44 + P.SpeedX
, 21), Layer
(2), Layer
(1), (0, 104)-STEP(52, 21) _PUTIMAGE (15 - P.SpeedX
, 190)-STEP(44 + P.SpeedX
, 21), Layer
(2), Layer
(1), (54, 104)-STEP(52, 21) _PUTIMAGE (15 - P.SpeedX
, 190)-STEP(44 + P.SpeedX
, 21), Layer
(2), Layer
(1), (108, 104)-STEP(52, 21) _PUTIMAGE (15 - P.SpeedX
, 211)-STEP(44 + P.SpeedX
, -21), Layer
(2), Layer
(1), (0, 104)-STEP(52, 21) _PUTIMAGE (15 - P.SpeedX
, 211)-STEP(44 + P.SpeedX
, -21), Layer
(2), Layer
(1), (54, 104)-STEP(52, 21) _PUTIMAGE (15 - P.SpeedX
, 211)-STEP(44 + P.SpeedX
, -21), Layer
(2), Layer
(1), (108, 104)-STEP(52, 21)
SUB DisplayLED
(X%
, Y%
, D%
) _PUTIMAGE (X%
, Y%
)-STEP(7, 13), Layer
(2), Layer
(1), (LED
(D%
).X
, LED
(D%
).Y
)-STEP(7, 13)
_PUTIMAGE (60, 170), Layer
(2), Layer
(5), (124, 42)-STEP(106, 60) 'collision shadow
DisplayLED
444 - (LEN(Shld$
) * 10) + 10 * I%%
, 382, VAL(MID$(Shld$
, I%%
, 1))
DisplayLED
614 - (LEN(Score$
) * 10) + 10 * I%%
, 382, VAL(MID$(Score$
, I%%
, 1))
DisplayLED 348, 382, P.Lives
FOR i%%
= 0 TO G.CurrentShot
_PUTIMAGE (Shot
(i%%
).X
, Shot
(i%%
).Y
), Layer
(2), Layer
(1), (108, 68)-STEP(15, 9)
FOR i%%
= 0 TO MaxHamsters
IF NOT H
(i%%
).Ox
THEN 'check flag for hamster death _PUTIMAGE (H
(i%%
).X
, H
(i%%
).Y
), Layer
(2), Layer
(1), (0, 0)-STEP(47, 27) ELSE 'this hamster is dead _PUTIMAGE (H
(i%%
).X
, H
(i%%
).Y
), Layer
(2), Layer
(1), (0 + 48 * (H
(i%%
).Oy \
10), 0)-STEP(47, 27)
SUB Make_Collision_Layer_Hamsters
_DEST Layer
(5) 'collision check layer FOR i%%
= 0 TO MaxHamsters
'only draw collision box of live hamsters
_DEST Layer
(1) 'back to mix layer
_PUTIMAGE (50 + ShipExplode
(i%%
).Ox
+ i%%
* 10, 160 + ShipExplode
(i%%
).Oy
), Layer
(2), Layer
(1), (ShipExplode
(i%%
).X
, ShipExplode
(i%%
).Y
)-(ShipExplode
(i%%
).Sx
, ShipExplode
(i%%
).Sy
) _PUTIMAGE (50 + ShipExplode
(16).Ox
+ 160, 160 + ShipExplode
(16).Oy
+ i%
), Layer
(2), Layer
(0), (ShipExplode
(16).X
, ShipExplode
(16).Y
)-(ShipExplode
(16).Sx
, ShipExplode
(16).Sy
) P.SpeedX = 1: P.SpeedY = 0
FOR i%%
= 0 TO MaxHamsters
H(i%%).X = H(i%%).X - H(i%%).Sx - P.SpeedX 'move hamsters
H(i%%).Y = H(i%%).Y - P.SpeedY
IF Hamster_Collision
(i%%
) AND NOT H
(i%%
).Ox
THEN 'does hamster hit player? ' _DEST Layer(0)
MakeHamster (i%%) 'replace hamster
P.Shield = P.Shield - 10 'damage shields
IF P.Shield
= 0 THEN G.PlayerDeath
= TRUE
'does player's ship explode?
IF H
(i%%
).X
< -48 THEN MakeHamster
(i%%
) 'hamster off screen IF H
(i%%
).Y
< -64 THEN 'transport hamster to other side of screen, to prevent sneeky way to HIGH score. IF H
(i%%
).Ox
THEN 'do not continue exploding hamster off screen MakeHamster (i%%)
H(i%%).Y = 440
IF H
(i%%
).Y
> 464 THEN 'transport hamster to other side of screen, to prevent sneeky way to HIGH score. IF H
(i%%
).Ox
THEN 'do not continue exploding hamster off screen MakeHamster (i%%)
H(i%%).Y = -40
IF H
(i%%
).Ox
THEN 'has hamster been hit? IF H
(i%%
).Oy
= 120 THEN MakeHamster
(i%%
) H(i%%).Oy = H(i%%).Oy + 1
FOR i%%
= 0 TO G.CurrentShot
Shot(i%%).X = Shot(i%%).X + ShotSpeed + Shot(i%%).Sx
Shot(i%%).Y = Shot(i%%).Y - P.SpeedY / 2
IF Shot
(i%%
).X
> 635 THEN 'drop shot FOR j%%
= i%%
TO G.CurrentShot
+ 1 SWAP Shot
(j%%
), Shot
(j%%
+ 1) Shot(j%%).X = 0: Shot(j%%).Y = 0 'erase shot
Shot(j%%).Sx = 0: Shot(j%%).Sy = 0 'erase shot
G.CurrentShot = G.CurrentShot - 1 'reduce shot count
Check_hit%% = Shot_Collision(i%%)
IF Check_hit%%
>= 0 THEN 'hamster has been shot P.Score = P.Score + 25 * P.SpeedX
H(Check_hit%%).Ox = TRUE 'set hamster death animation
H(Check_hit%%).Sx = 0
H(Check_hit%%).Oy = 0
FOR j%%
= i%%
TO G.CurrentShot
+ 1 'drop shot SWAP Shot
(j%%
), Shot
(j%%
+ 1) Shot(j%%).X = 0: Shot(j%%).Y = 0 'erase shot
Shot(j%%).Sx = 0: Shot(j%%).Sy = 0 'erase shot
G.CurrentShot = G.CurrentShot - 1 'reduce shot count
FNR = Result%
Stars(ID%).x = FNR(639)
Stars(ID%).y = FNR(399)
Stars(ID%).colr = FNR(3) - 1
Stars
(ID%
).speed
= FNR
(INT(Stars
(ID%
).colr
) / 10)
Shot(ID%%).X = 145
Shot(ID%%).Y = 196
Shot(ID%%).Sx = P.SpeedX
Shot(ID%%).Sy = P.SpeedY
H(id%%).X = 640 + FNR(92)
H(id%%).Y = FNR(480) - 40
H(id%%).Sx = FNR(3) 'hamster self speed
H(id%%).Ox = FALSE 'been shot flag
H(id%%).Oy = FALSE 'been shot animation frame
_PUTIMAGE (Stars
(i%
).x
, Stars
(i%
).y
), Layer
(2), Layer
(1), (100 + 6 * Stars
(i%
).colr
, 28)-STEP(5, 5)
Stars(i%).x = Stars(i%).x - Stars(i%).speed - P.SpeedX - ((8 - (Stars(i%).colr * 2)) / 10)
IF P.SpeedY
THEN Stars
(i%
).y
= Stars
(i%
).y
+ P.SpeedY
MakeNewStar i%
Stars(i%).x = 639
MakeNewStar i%
Stars(i%).x = 2
MakeNewStar i%
Stars(i%).y = 399
MakeNewStar i%
Stars(i%).y = 2
GET #1, , c~%%
'retrieve number of files FOffset&(I~%%) = FOffset&(I~%%) + 1
'Layer(2) = _LOADIMAGE("SpaceDodgerSpriteSheet.bmp", 32)
'Layer(3) = _LOADIMAGE("BGPlate.bmp", 32)
'SFX(0) = _SNDOPEN("gunshot.ogg")
'SFX(1) = _SNDOPEN("impactquick.ogg")
'SFX(2) = _SNDOPEN("ouch.ogg")
'SFX(3) = _SNDOPEN("PdiesMSTR.ogg")
'SFX(4) = _SNDOPEN("sqeek.ogg")
'BGM(0) = _SNDOPEN("BGM_Alt_LO.ogg")
Layer(2) = LoadGFX(FOffset(2), Size(2))
Layer(3) = LoadGFX(FOffset(1), Size(1))
SFX(0) = LoadSFX(FOffset(7), Size(7))
SFX(1) = LoadSFX(FOffset(3), Size(3))
SFX(2) = LoadSFX(FOffset(6), Size(6))
SFX(3) = LoadSFX(FOffset(5), Size(5))
SFX(4) = LoadSFX(FOffset(4), Size(4))
BGM(0) = LoadSFX(FOffset(8), Size(8))
FUNCTION LoadFFX&
(Foff&
, Size&
, Fize%%
) LoadFFX&
= _LOADFONT("temp.dat", Fize%%
, "monospace")