Jump to content
Opry99er

"Forth" game development

Recommended Posts

Here's the source for one of the demo's.

 

This probably looks scary, but it isn't. If I can do it, *anyone* can, seriously!

 

Please ask if there's anything you don't understand.

 

By the way: DCHAR is the equivalent of CHAR in TI BASIC. (CHAR means something else in Forth ;) )

 

( ** StarField Sprite Demo ** )

VARIABLE RND HERE RND ! ( seed )
VARIABLE StringSpace
82 CHARS ALLOT 		( create a string buffer )
StringSpace 84 32 FILL 	( initialise it to ASCII 32 )
S" The Power Of Forth!" ( addr len )
StringSpace 		( addr len addr )
SWAP 			( addr addr len )
CMOVE> 			( move string into buffer )

0 VALUE FlipFlop

( ascii codes for small, medium, and big stars )
64 CONSTANT Sml* 
65 CONSTANT Med* 
66 CONSTANT Big*

( keyboard codes )
CHAR E CONSTANT KeyE
CHAR S CONSTANT KeyS
CHAR D CONSTANT KeyD
CHAR X CONSTANT KeyX

( define colours )
15 CONSTANT White

( set up user defined graphics for the 3 star sizes )
: UDG 8000$    0  0 0 4 Sml* DCHAR ( define small star )
     40E0$ 4000$ 0 0 4 Med* DCHAR ( define medium star )
     70F8$ F870$ 0 0 4 Big* DCHAR ( define large star ) ;

: RANDOM ( limit -- rnd ) 
 RND @ 31421 * 6927 + DUP RND ! ABS SWAP MOD ;

( generate a random Y coordinate )
: RndY 180 RANDOM ;

( generate a random X coordinate )
: RndX 256 RANDOM ;

( set up our sprites. 10 small, 10 medium, 10 large )
: 10Small 10 FOR I       RndY RndX Sml* White SPRITE NEXT ;
: 10Med   10 FOR I 10 +  RndY RndX Med* White SPRITE NEXT ;
: 10Big   10 FOR I 20 +  RndY RndX Big* White SPRITE NEXT ;

( these routines set up the sprite movement list for each direction )
: GoLeft  10 FOR I       0 -1 SMLIST NEXT 
         10 FOR I 10 +  0 -2 SMLIST NEXT 
  10 FOR I 20 +  0 -3 SMLIST NEXT ;

: GoRight 10 FOR I       0  1 SMLIST NEXT 
         10 FOR I 10 +  0  2 SMLIST NEXT 
  10 FOR I 20 +  0  3 SMLIST NEXT ;

: GoUp    10 FOR I      -1  0 SMLIST NEXT 
         10 FOR I 10 + -2  0 SMLIST NEXT 
  10 FOR I 20 + -3  0 SMLIST NEXT ;

: GoDown  10 FOR I       1  0 SMLIST NEXT 
         10 FOR I 10 +  2  0 SMLIST NEXT 
  10 FOR I 20 +  3  0 SMLIST NEXT ;

: Delay 100 FOR NEXT ;

: DoFlipFlop FlipFlop NOT DUP TO FlipFlop ;

: ScanKeys 
  KEY? CASE 
       KeyE OF GoUp    ENDOF 
KeyS OF GoLeft  ENDOF
KeyD OF GoRight ENDOF
KeyX OF GoDown  ENDOF
  ENDCASE
  BREAK?
;

: Scroll 
  DoFlipFlop IF 
   [ StringSpace 83 + LITERAL ] [email protected]
   [ StringSpace LITERAL StringSpace 1+ LITERAL ] 83 CMOVE>
   [ StringSpace LITERAL ] C!
   0  0 GOTOXY [ StringSpace 32 + LITERAL ] 31 TYPE
   0 23 GOTOXY [ StringSpace 32 + LITERAL ] 31 TYPE
   ScanKeys
  THEN
;

: Setup 
  1 GMODE  0 SCREEN  UDG  10Small 10Med 10Big GoRight ;

: GO Setup BEGIN 0 30 SPRMOV Scroll Delay AGAIN ;
GO

Edited by Willsy

Share this post


Link to post
Share on other sites

btw - if you could eventually get interrupt driven sprites to work, or provide some mechanism to sync to the refresh rate, that'd be awesome. Wouldn't want our games to behave all crazy depending on the amount of work done in the game loop....

 

:)

Share this post


Link to post
Share on other sites

btw - if you could eventually get interrupt driven sprites to work, or provide some mechanism to sync to the refresh rate, that'd be awesome. Wouldn't want our games to behave all crazy depending on the amount of work done in the game loop....

 

:)

 

Ok, I'll add it to the 'to do' list!

 

Mark

Share this post


Link to post
Share on other sites

Ok, I'll add it to the 'to do' list!

 

Wow. If it's that easy to get you to do work, I'll humbly request that you make it write the game itself.

Share this post


Link to post
Share on other sites

Yea-- I want speech to text capabilities... All that typing stuff is overrated. Speech to text--- I can program while I'm driving all over this country.

Share this post


Link to post
Share on other sites

Ok, I'll add it to the 'to do' list!

 

Wow. If it's that easy to get you to do work, I'll humbly request that you make it write the game itself.

 

This feature is already included. Just type DOGAME.

 

Takes a VERY long time to run though ;)

Share this post


Link to post
Share on other sites

So THATS the word!!! I was trying "WRITEMYGAMEBITCH" and it kept kicking out a question mark

Share this post


Link to post
Share on other sites

Got my book. It looks to be written C-Bible style, which is a complement. Hopefully I'll get to the actual reading soon.

 

-H

Share this post


Link to post
Share on other sites

I have received my big blue Forth book in the mail as well. To this point, I have done my reading online and worked with Wycove Forth on Classic99. Happy happy joy joy!!! Come on Willsy... OUT WITH TURBOFORTH!!!!

Share this post


Link to post
Share on other sites

Yeah gave it a good read last night. Think I made it through 3 or 4 chapters. I'm hoping that we don't have to deal with the file system limitations described in the book. Icky!

 

-H

 

I have received my big blue Forth book in the mail as well. To this point, I have done my reading online and worked with Wycove Forth on Classic99. Happy happy joy joy!!! Come on Willsy... OUT WITH TURBOFORTH!!!!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...