Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pascalated ZX BASIC Demo #5 - Predator
#1
To run online, click here: RUN ONLINE



Code:
' PROGRAM Predator
' Demo for the Pascalated language
' Pascalated Sinclair BASIC (c) 1987 by ZarSoft
' Pascalated BASIC Converter (c) 2021 by Zarsoft
' Pascalated Boriel (c) 2023 by ZarSoft
' ZX BASIC Compiler (c) 2008 by Boriel

#include <input.bas>
#include <screen.bas>

'--- Pascalated Boriel ---
'#define CONST     CONST
#define VAR       DIM
#define INTEGER   LONG
#define REAL      FLOAT
#define CHAR      UBYTE
'#define STRING    STRING
#define BOOLEAN   LONG
#define TYPE      AS
#define REPEAT    DO
#define UNTIL     LOOP UNTIL
#define PROCEDURE SUB
#define PROGRAM   REM
CONST   TRUE      TYPE INTEGER = 1
CONST   FALSE     TYPE INTEGER = 0

' Variable Declarations
VAR Name$ TYPE STRING ' player's name
VAR HighScore TYPE INTEGER ' high HighScore
VAR Score TYPE INTEGER ' Score in this game
VAR UserLin TYPE INTEGER
VAR UserCol TYPE INTEGER
VAR UserLin0 TYPE INTEGER
VAR UserCol0 TYPE INTEGER
VAR PredatorLin TYPE INTEGER
VAR PredatorCol TYPE INTEGER
VAR PredatorLin0 TYPE INTEGER
VAR PredatorCol0 TYPE INTEGER
VAR GameOver TYPE BOOLEAN
VAR Walker$ TYPE STRING ' 2 frames walking
VAR frame TYPE INTEGER

PROCEDURE ShowScores
PRINT AT 22,0;"Score:";Score;TAB 13;"High score: ";HighScore;TAB 13;"by ";Name$;
END PROCEDURE

PROCEDURE InitEnemy
LET PredatorLin = 1+INT (RND*20): LET PredatorCol = 30
LET PredatorLin0 = PredatorLin: LET PredatorCol0 = PredatorCol
END PROCEDURE

PROCEDURE CaughtInTrap
VAR N TYPE INTEGER
PRINT AT PredatorLin0,PredatorCol0;INK 2;" ";
PRINT AT PredatorLin,PredatorCol;INK 3;"*";
LET Score=Score+50
ShowScores
FOR N=-30 TO 30 STEP 5: BEEP .02,ABS N: NEXT N
PRINT AT PredatorLin,PredatorCol;" ";
InitEnemy
END PROCEDURE

PROCEDURE InitArena
VAR N TYPE INTEGER
BORDER 4: PAPER 4: INK 1: CLS
POKE 23609,50
LET GameOver = FALSE
REM InitUser
LET UserLin = 1+INT (RND*20): LET UserCol=1
LET UserLin0 = UserLin: LET UserCol0 = UserCol
InitEnemy
LET Score=0
FOR N=0 TO 31: PRINT AT 0,N;PAPER 1;INK 5;"X";AT 21,N;"X": NEXT N
FOR N=0 TO 21: PRINT AT N,0;PAPER 1;INK 5;"X";AT N,31;"X": NEXT N
FOR N=1 TO 30: PRINT AT 2+INT (18*RND),2+INT (29*RND);"O": NEXT N
PRINT AT 0,11;PAPER 1;INK 7;"-PREDATOR-"
PRINT AT UserLin,UserCol;INK 2;Walker$(1);
PRINT AT PredatorLin,PredatorCol;INK 2;"\{vi}\C\{vn}"
END PROCEDURE

PROCEDURE TheEnd
VAR N TYPE INTEGER
PRINT INK 3;AT UserLin,UserCol;"#";OVER 1;CHR$ 8;"X"
FOR N=-30 TO 30 STEP 3: BEEP .02,ABS N: BEEP .03,N: NEXT N
IF HighScore<Score THEN
  LET HighScore=Score
  PRINT AT 22,0;"New high score";TAB 0;TAB 31;AT 23,0;"What's your name? ";
  Name$ = INPUT(15)
ENDIF
END PROCEDURE

PROCEDURE WaitForUser
PRINT AT 23,0;"     Pascalated BASIC demo";
BEEP .1,5: BEEP .1,10: BEEP .1,5: BEEP .1,0
REPEAT
  PAUSE 1
  LET k$=INKEY$
UNTIL k$ = ""
PAUSE 0
BEEP .1,5: BEEP .1,10: BEEP .1,0
PRINT AT 23,0;"                          ";
ShowScores
END PROCEDURE

PROCEDURE InitSprites
REM \A\B\C
REM \A
POKE USR "A"+0,BIN 00011000
POKE USR "A"+1,BIN 00010000
POKE USR "A"+2,BIN 00111000
POKE USR "A"+3,BIN 11010111
POKE USR "A"+4,BIN 00010000
POKE USR "A"+5,BIN 00101000
POKE USR "A"+6,BIN 01000100
POKE USR "A"+7,BIN 10000010
REM \B
POKE USR "B"+0,BIN 00011000
POKE USR "B"+1,BIN 00010000
POKE USR "B"+2,BIN 00111000
POKE USR "B"+3,BIN 01010100
POKE USR "B"+4,BIN 10010100
POKE USR "B"+5,BIN 00101000
POKE USR "B"+6,BIN 00101000
POKE USR "B"+7,BIN 01000100
REM \C
POKE USR "C"+0,BIN 11000011
POKE USR "C"+1,BIN 10000001
POKE USR "C"+2,BIN 00100100
POKE USR "C"+3,BIN 00000000
POKE USR "C"+4,BIN 01011010
POKE USR "C"+5,BIN 01111110
POKE USR "C"+6,BIN 01111110
POKE USR "C"+7,BIN 00000000
END PROCEDURE

PROCEDURE Game
REPEAT
  REM Process keys
  PAUSE 10
  LET k$ = INKEY$
  IF k$="5" OR k$="o" THEN IF UserCol>1 THEN BEEP .02,5*RND: LET UserCol=UserCol-1
  IF k$="6" OR k$="a" THEN IF UserLin<20 THEN BEEP .02,5*RND: LET UserLin=UserLin+1
  IF k$="7" OR k$="q" THEN IF UserLin>1 THEN BEEP .02,5*RND: LET UserLin=UserLin-1
  IF k$="8" OR k$="p" THEN IF UserCol<30 THEN BEEP .02,5*RND: LET UserCol=UserCol+1
  REM show user
  PRINT AT UserLin0,UserCol0;INK 5;".";
  PRINT AT UserLin,UserCol;INK 2;Walker$(frame);: LET frame = 3-frame
  LET UserLin0=UserLin: LET UserCol0=UserCol
  REM move predator
  IF ABS (PredatorLin-UserLin) > ABS (PredatorCol-UserCol) THEN LET PredatorLin = PredatorLin+SGN (UserLin-PredatorLin)
  IF ABS (PredatorLin-UserLin) <= ABS (PredatorCol-UserCol) THEN LET PredatorCol = PredatorCol+SGN (UserCol-PredatorCol)
  REM test trap
  IF SCREEN$ (PredatorLin,PredatorCol)="O" THEN CaughtInTrap
  REM show predator
  PRINT AT PredatorLin0,PredatorCol0;" ";
  PRINT AT PredatorLin,PredatorCol;INK 2;"\{vi}\C\{vn}";
  LET PredatorLin0=PredatorLin: LET PredatorCol0=PredatorCol
  BEEP .01,0
  REM test game status
  IF UserLin=PredatorLin THEN IF UserCol=PredatorCol THEN LET GameOver = TRUE
UNTIL GameOver
END PROCEDURE

PROCEDURE MainRoutine
REPEAT
  InitArena
  WaitForUser
  Game
  TheEnd
UNTIL FALSE
END PROCEDURE

PROCEDURE InitProgram
Name$ = "Username"
LET frame = 1
LET HighScore=0
InitSprites: LET Walker$=" \A\B"
END PROCEDURE

PROGRAM Predator
REM (c) 2022 Zarsoft
REM Hunter - Written by ZE OLIVEIRA, 1984
REM Pascalated version 2022, 2023
InitProgram
MainRoutine
' last 2 lines are going to be deleted
PRINT AT 23,0;
END PROGRAM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)