Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:37 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : xDragon Game Engine for CMM2

     Page 1 of 2    
Author Message
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 02:49pm 25 May 2021
Copy link to clipboard 
Print this post

Hi all,

Attached is the first release of my Game Engine for the CMM2.

Some screenshots:





Here is footage of an amazing display of dexterity by self, holding my cell phone and recording in one hand, and playing the game engine's demo game in the other:

https://youtu.be/qD5m2_azJWo

API and demo code are reasonably well documented. If there's any interest, I'd be happy to provide more documentation about the Game Engine and toolchain used.

See README below for more info. Any feedback is more than welcome.

Cheers,
Ruben/Epsilon.

xDragon Game Engine for CMM2
----------------------------
Author: Epsilon

Credits
-------
- Mark Claypool: Author of the original Dragonfly engine on which this engine is based.
A CMM2 port of the Dragonfly engine can be found here: https://github.com/epsilon537/df_cmm2
- Nautilus: The topics covered on the MAPSTER thread on TBS were a great source of inspiration:
Tiles, Palettes, Level Editors, Pixel Editors... The xDragon in its current form is essentially
DragonFly plus everything discussed in that thread.
- jirsoft: Some BMP decoding logic to establish BMP dimensions, taken from NC commander.
- Kauzz/itch.io: xDragon Demo Cave Tiles
- Ansimuz/itch.io: xDragon Demo parallax background graphics.
- Ansimux/itch.io: xDragon Demo Intro soundtrack.
- !!!alchemist2/modarchive.org: xDragon Demo in-game soundtrack.

Changelog
---------
0.1: Initial version

Description
-----------
xDragon is a 2D game engine in tune with the CMM2 feature set. The engine is geared towards
arcade style action games such as shooters, platformers, top-down racers etc.

Demo Game:
---------
To start the Demo mini-game, navigate to the DEMO/ directory and run "xd_demo.bas".
The demo game is maybe a bit sparse. The focus is on the tutorial aspect of the demo code.

It probably wouldn't be a bad idea to create a showcase demo as well. It would be cool if
people would add some bells and whistles and post the result on TBS.

Features:
--------
* GraphicsGale compatible frame (sprite) based animations.
* Tiled compatible Tile Engine.
* Tile Map based trigger events (Trigger Layer in Tile Map)
* Bounding Box based collision detection, between Objects and between Objects and tiles
* Collision Groups.
* Parallax background layer.
* Palette Management, effects such as fading, support for JASC palette file format exported
 from GraphicsGale.
* World/View representation
* Object Management
* Nunchuk support
* Event Dispatching (E.g. collisions, keyboard/nunchuk input events, user defined events...)
* Sound support
* HUD-type view objects (e.g. points, lives...)
* Text Entry objects (e.g. for entering high scores).

Tiled and GraphicsGale
----------------------
Tiled and GraphicsGale are key tools used to create game content.

Tiled is a free tile based level editor. It supports multiple layers. The xDragon engine currently
supports a tiling layer, a collision layer and an even trigger layer.
URL: https://www.mapeditor.org/

GraphicsGale is a free pixel editor with great support for creating frame based animations.
GraphicsGale exports spritesheets and metadata in .csv files that describe the animation
parameters (dimensions, position in spritesheet etc.)
URL: https://graphicsgale.com/us/

Sound support
-------------
The code includes a small SOUND.INC module intended for .WAVs, but by far the best way to
handle sound in games is the excellent PLAY MODFILE/MODSAMPLE MMBasic API.
The Game Engine has nothing to add here.

Vegipete did a great write-up on creating sounds with MODS using Audacity and OpenMPT:
http://www.thebackshed.com/forum/ViewTopic.php?TID=13412&PID=163703#163703

Audacity: https://www.audacityteam.org/
OpenMPT: https://openmpt.org/

Directory Layout:
----------------
* INC/ contains the game engine implementation
* TEST/ contain game engine test cases. The test code is messy but all test cases work.
 It's a good repository to check to see how certain parts of the API work.
* DEMO/ A demo mini-game used to demonstrate most of the features of the game engine.
* RESOURCES/ Resource files such as bitmaps and sounds.
* DOCS/ Documentation. Currently just some odds and ends. I can add actual documentation if
 there is any interest.
* CSUBS/ CSUBs and their source code.

To-Dos:
------
- Support animated tiles.
- Add nicer ViewObjects for HUD display.
- Add High Score to demo game as an illustration of the TextEntry object.
- Add support for path definitions created in Tiled Object Layer.
- Add support for small viewports surrounded by more elaborate HUD display.
- Add more info to OUT Event Object.
- Add support for diagonal scrolling (currently only horizontal and vertical).
- Improve log handling.
- Improve documentation.
- Reduce global variable count.
- Write a game.

Required CMM2 FW:
----------------
V5.07.00b30 or later.

GitHub:
------
https://github.com/epsilon537/xDragon_cmm2


xDragon.zip
Epsilon CMM2 projects
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 03:11pm 25 May 2021
Copy link to clipboard 
Print this post

Amazing      
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 03:23pm 25 May 2021
Copy link to clipboard 
Print this post

Excellent Ruben
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 03:58pm 25 May 2021
Copy link to clipboard 
Print this post

Wow!  

Steve
 
Nautilus
Newbie

Joined: 01/01/2021
Location: Germany
Posts: 16
Posted: 06:11pm 25 May 2021
Copy link to clipboard 
Print this post

wow - that is just impressive      
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 07:40pm 25 May 2021
Copy link to clipboard 
Print this post

  Nautilus said  wow - that is just impressive      


Thanks Nautilus. You helped more with this than you know.
I worked through an entire book on Game Engine Development, implemented it on PC, then on CMM2, but there were still a lot of loose ends, like 'how do you design level'? But with your Mapster engine post and all the pointers you gave, a lot of things fell into place.
Epsilon CMM2 projects
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 08:46pm 25 May 2021
Copy link to clipboard 
Print this post

Very good work!
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 543
Posted: 04:12pm 26 May 2021
Copy link to clipboard 
Print this post

Fantastic!
 
Nautilus
Newbie

Joined: 01/01/2021
Location: Germany
Posts: 16
Posted: 04:48pm 26 May 2021
Copy link to clipboard 
Print this post

  epsilon said  
Thanks Nautilus. You helped more with this than you know.


I am glad that I could contribute a few ideas.

The mapster engine is far behind your game engine, but the tile animation works. i'll upload a new demo this weekend. maybe it's interesting for you *look at your todo list*  

greetings, nautilus
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 09:01am 27 May 2021
Copy link to clipboard 
Print this post

  Quote  *look at your todo list*


I think I can guess Looking forward to it!
Epsilon CMM2 projects
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 11:24pm 27 May 2021
Copy link to clipboard 
Print this post

Fun! Well, changing things....like making it easier for an old geezer like myself to play...by making the ship not blow up by hitting the foreground layer and just now changing the bullets from one to two...firing at angles and seeing that there doesn't appear to be much impact (any...detectable) to smoothness.

In spite of my 'cheating'...does the game just go on and on until you die....I suppose I could look at the code... ...I still die all too soon!

While I'm not sure that I'd ever start a project from scratch...it's fun figure out how things work and to tinker and maybe someday....

Steve

PS. I use xedit (after changing ctrl-c to copy!   )

Steve
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 10:22am 28 May 2021
Copy link to clipboard 
Print this post

  yock1960 said  .like making it easier for an old geezer like myself to play...by making the ship not blow up by hitting the foreground layer and just now changing the bullets from one to two...firing at angles and seeing that there doesn't appear to be much impact (any...detectable) to smoothness.


That's great! Have fun, break things  

I made the controls acceleration-based to give the demo game some challenge, i.e. the ship accelerates in the direction of the controls.
If you just make the ship move at a constant speed in the direction of the controls, it becomes much easier, and more in line with the behavior you'd expect from a side-scrolling shooter.

The serial console will print out a message if the game loop time exceeds the deadline needed to maintain 75/2 fps. It's a soft deadline. If it gets exceeded just a bit and not too often, you might not notice.
My performance benchmark for this release was that there are no deadline misses in the game as-is. However, I just realized that I completely forgot to test at 400MHz, so people with 400MHz devices might still see hick-ups.


  yock1960 said  In spite of my 'cheating'...does the game just go on and on until you die....I suppose I could look at the code... ...I still die all too soon!


It just goes on, gradually faster and faster.

A real side-scrolling shooter game would have a level-map defined that's a few minutes wide horizontally, has some attack waves and power-ups sprinkled over it, and a boss fight at the end.
All that should be doable with the current game engine except that I don't have any support yet for scripted attack waves (swirly patterns etc). I think the best place to design attack waves is inside the Tiled level editor and to export that somehow. That'll be a key feature for a future release.
Epsilon CMM2 projects
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 99
Posted: 11:11am 28 May 2021
Copy link to clipboard 
Print this post

After starting the demo i get an error:
Error in ../INC/Anim.inc line 4: Invalid character: #

Do i have the wrong  CMM2 version (5.06.00)?
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 12:28pm 28 May 2021
Copy link to clipboard 
Print this post

  epsilon said  

The serial console will print out a message if the game loop time exceeds the deadline needed to maintain 75/2 fps. It's a soft deadline. If it gets exceeded just a bit and not too often, you might not notice.
My performance benchmark for this release was that there are no deadline misses in the game as-is. However, I just realized that I completely forgot to test at 400MHz, so people with 400MHz devices might still see hick-ups.



My twisted wires to overclock to 504mhz have come apart and I haven't reconnected them yet, so playing at 400 and all seems well.

I've had issues with serial console...mental block really...I need a good solid HOWTO on that, but it seems like playing with this will perhaps get me to overcome my...hesitancy.

I'm starting to read over the Dragonfly book. Aside from my aversion to C++, I think I can mostly follow the code, but it might be informative if you wrote something...in your spare time...regarding differences/compromises...in doing the port. It's certainly a learning experience as far as coding...style/paradigm...versus my 'seat of the pants' coding approach!

I will probably try to implement the Classic controller...since I prefer it, plus it offers more buttons for future...events!

Steve
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 12:57pm 28 May 2021
Copy link to clipboard 
Print this post

  PilotPirx said  After starting the demo i get an error:
Error in ../INC/Anim.inc line 4: Invalid character: #

Do i have the wrong  CMM2 version (5.06.00)?


Yes, you'll need the latest beta FW version, sorry.
The #COMMENT block feature you ran into is easy to work around, but the engine also uses other 5.07 features such as PAGE DISPLAY which are less trivial to avoid.
Epsilon CMM2 projects
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 01:34pm 28 May 2021
Copy link to clipboard 
Print this post

  yock1960 said  
I've had issues with serial console...mental block really...I need a good solid HOWTO on that, but it seems like playing with this will perhaps get me to overcome my...hesitancy.


I wrote a little to tool called rexec that allow the CMM2 to remotely execute commands on PC. I use it mostly to copy files back and forth, and CSUB compilation. However, it also acts as a serial console (display only). I leave it always on, which is very convenient, e.g. when text scrolls off your CMM2's screen, you can still get back to it on the console. And you can easily copy MMBasic snippets from the console to post here on TBS.

https://github.com/epsilon537/rexec_cmm2

  yock1960 said  
I'm starting to read over the Dragonfly book. Aside from my aversion to C++, I think I can mostly follow the code, but it might be informative if you wrote something...in your spare time...regarding differences/compromises...in doing the port. It's certainly a learning experience as far as coding...style/paradigm...versus my 'seat of the pants' coding approach!


That's really great! I will happily put together some documentation if someone will read it  
The paradigm shift from C++ to MMBasic was indeed an interesting puzzle, and even though MMBasic is not an Object Oriented language, there's still a lot of OO-ness in the MMBasic port of both the Dragonfly and the xDragon engines.
Although xDragon is a bit more fun to use in terms of graphics and tile engine, if you're working through the xDragon book, it'll be a bit easier to cross-check against the Dragonfly CMM2 code base. For that one I tried to stay as close to the book as I could:

https://github.com/epsilon537/df_cmm2
Epsilon CMM2 projects
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 01:25am 29 May 2021
Copy link to clipboard 
Print this post

Managed to implement the Wii Classic...partly, just the Zl and L buttons mapped. Which just now made me think that while this is fine, mapping more buttons to add capabilities...it seems like this should somehow be done in the individual 'game' code rather than changing the engine inputmanager.inc, but maybe you have thoughts on this...I'm certainly not that far down the rabbit hole!

An interesting piece of data...while debugging the Classic...before it was working correctly. With the ship hugging the lower edge of the screen (stuck   ) I got way further in the game...over 2000 points, to where the bullets wouldn't move very far from the ship and eventually, the ship got embedded in a chunk of foreground (cavern wall?) and the enemy ships stopped appearing...probably stuck off screen somewhere!  

Not that important...I'm not sure anyone could get this far during 'normal' play....but...amusing.

Oh, I fired up Teraterm and got the console going. That's really handy for debugging!!! No more print/text statements messing up your display!

Steve
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 04:19am 29 May 2021
Copy link to clipboard 
Print this post

I don't know if this can be useful for you, but here is my source code of the NES Classic Mini Controller used in the Mazes of Chaos:

'ROUTINES FOR CONTROLLERS: SNES / NES / CLASSIC MINI

'HOW TO USE
'if PEEK(VAR KCM$, 1)=48 Then ?"RIGHT"
'if PEEK(VAR KCM$, 2)=48 Then ?"DOWN"
'if PEEK(VAR KCM$, 3)=48 Then ?"LB"
'if PEEK(VAR KCM$, 4)=48 Then ?"SELECT"
'if PEEK(VAR KCM$, 5)=48 Then ?"HOME"
'if PEEK(VAR KCM$, 6)=48 Then ?"START"
'if PEEK(VAR KCM$, 7)=48 Then ?"RB"
'if PEEK(VAR KCM$, 8)=48 Then ?"ok"
'if PEEK(VAR KCM$, 9)=48 Then ?"ZL"
'if PEEK(VAR KCM$,10)=48 Then ?"B"
'if PEEK(VAR KCM$,11)=48 Then ?"Y"
'if PEEK(VAR KCM$,12)=48 Then ?"A"
'if PEEK(VAR KCM$,13)=48 Then ?"X"
'if PEEK(VAR KCM$,14)=48 Then ?"ZR"
'if PEEK(VAR KCM$,15)=48 Then ?"LEFT"
'if PEEK(VAR KCM$,16)=48 Then ?"UP"

DIM BUF(10)

' READ CLASSIC MINI CONTROLLER AND UPDATE KMC$ VARIABLE
SUB Classic_Mini_Read(CHAN)
 IF CHAN=3 THEN I2C3 READ &H52,0,8,BUF() ELSE I2C READ &H52,0,8,BUF()
 KCM$=RIGHT$("00000000"+BIN$(BUF(6)),8)+RIGHT$("00000000"+BIN$(BUF(7)),8)
 IF CHAN=3 THEN I2C3 WRITE &H52,0,1,&H00 ELSE I2C WRITE &H52,0,1,&H00
END SUB

' CLOSE THE CLASSIC MINI CONTROLLER I2C PROTOCOL
SUB Classic_Mini_Close(CHAN)
ON ERROR SKIP 1
IF CHAN=3 THEN I2C3 CLOSE ELSE I2C CLOSE
END SUB

' INIT THE CLASSIC MINI CONTROLLER I2C PROTOCOL
SUB Classic_Mini_Init(CHAN)
Local n
 
 ON ERROR SKIP 1
 CONTROLLER CLASSIC OPEN CHAN
 ON ERROR SKIP 1
 CONTROLLER CLASSIC CLOSE CHAN

 IF CHAN=3 THEN I2C3 OPEN 100,100 ELSE I2C OPEN 100,100

 'INIT CONTROLLER
 FOR n = 1 TO 10
  IF CHAN=3 THEN I2C3 WRITE &H52,0,2,&HF0,&H55 ELSE I2C WRITE &H52,0,2,&HF0,&H55
  PAUSE 2
  IF MM.I2C = 0 THEN EXIT FOR
 NEXT n

 IF CHAN=3 THEN
  I2C3 WRITE &H52,0,2,&H00,&HFB: PAUSE(10)
  I2C3 WRITE &H52,0,2,&HFE,&H03 'REQUEST DATA TYPE 3'
  'CONTROLLER TYPE
  I2C3 WRITE &H52,0,1,&HFA: PAUSE 10
  I2C3 READ &H52,0,6,BUF()
 ELSE
  I2C WRITE &H52,0,2,&H00,&HFB: PAUSE(10)
  I2C WRITE &H52,0,2,&HFE,&H03 'REQUEST DATA TYPE 3'
  'CONTROLLER TYPE
  I2C WRITE &H52,0,1,&HFA: PAUSE 10
  I2C READ &H52,0,6,BUF()
 ENDIF

 IF BUF(0)=1 AND BUF(1)=0 AND BUF(2)=164 AND BUF(3)=32 AND BUF(4)=3 AND BUF(5)=1 AND BUF(6)=0 THEN
  CtrlExist(1)=CHAN
 ELSE
  Classic_Mini_Close(CHAN)
 ENDIF

END SUB

Edited 2021-05-29 14:22 by MauroXavier
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 09:50am 29 May 2021
Copy link to clipboard 
Print this post

  MauroXavier said  I don't know if this can be useful for you, but here is my source code of the NES Classic Mini Controller used in the Mazes of Chaos:

'ROUTINES FOR CONTROLLERS: SNES / NES / CLASSIC MINI

'HOW TO USE
'if PEEK(VAR KCM$, 1)=48 Then ?"RIGHT"
'if PEEK(VAR KCM$, 2)=48 Then ?"DOWN"
'if PEEK(VAR KCM$, 3)=48 Then ?"LB"
'if PEEK(VAR KCM$, 4)=48 Then ?"SELECT"
'if PEEK(VAR KCM$, 5)=48 Then ?"HOME"
'if PEEK(VAR KCM$, 6)=48 Then ?"START"
'if PEEK(VAR KCM$, 7)=48 Then ?"RB"
'if PEEK(VAR KCM$, 8)=48 Then ?"ok"
'if PEEK(VAR KCM$, 9)=48 Then ?"ZL"
'if PEEK(VAR KCM$,10)=48 Then ?"B"
'if PEEK(VAR KCM$,11)=48 Then ?"Y"
'if PEEK(VAR KCM$,12)=48 Then ?"A"
'if PEEK(VAR KCM$,13)=48 Then ?"X"
'if PEEK(VAR KCM$,14)=48 Then ?"ZR"
'if PEEK(VAR KCM$,15)=48 Then ?"LEFT"
'if PEEK(VAR KCM$,16)=48 Then ?"UP"

DIM BUF(10)

' READ CLASSIC MINI CONTROLLER AND UPDATE KMC$ VARIABLE
SUB Classic_Mini_Read(CHAN)
 IF CHAN=3 THEN I2C3 READ &H52,0,8,BUF() ELSE I2C READ &H52,0,8,BUF()
 KCM$=RIGHT$("00000000"+BIN$(BUF(6)),8)+RIGHT$("00000000"+BIN$(BUF(7)),8)
 IF CHAN=3 THEN I2C3 WRITE &H52,0,1,&H00 ELSE I2C WRITE &H52,0,1,&H00
END SUB

' CLOSE THE CLASSIC MINI CONTROLLER I2C PROTOCOL
SUB Classic_Mini_Close(CHAN)
ON ERROR SKIP 1
IF CHAN=3 THEN I2C3 CLOSE ELSE I2C CLOSE
END SUB

' INIT THE CLASSIC MINI CONTROLLER I2C PROTOCOL
SUB Classic_Mini_Init(CHAN)
Local n
 
 ON ERROR SKIP 1
 CONTROLLER CLASSIC OPEN CHAN
 ON ERROR SKIP 1
 CONTROLLER CLASSIC CLOSE CHAN

 IF CHAN=3 THEN I2C3 OPEN 100,100 ELSE I2C OPEN 100,100

 'INIT CONTROLLER
 FOR n = 1 TO 10
  IF CHAN=3 THEN I2C3 WRITE &H52,0,2,&HF0,&H55 ELSE I2C WRITE &H52,0,2,&HF0,&H55
  PAUSE 2
  IF MM.I2C = 0 THEN EXIT FOR
 NEXT n

 IF CHAN=3 THEN
  I2C3 WRITE &H52,0,2,&H00,&HFB: PAUSE(10)
  I2C3 WRITE &H52,0,2,&HFE,&H03 'REQUEST DATA TYPE 3'
  'CONTROLLER TYPE
  I2C3 WRITE &H52,0,1,&HFA: PAUSE 10
  I2C3 READ &H52,0,6,BUF()
 ELSE
  I2C WRITE &H52,0,2,&H00,&HFB: PAUSE(10)
  I2C WRITE &H52,0,2,&HFE,&H03 'REQUEST DATA TYPE 3'
  'CONTROLLER TYPE
  I2C WRITE &H52,0,1,&HFA: PAUSE 10
  I2C READ &H52,0,6,BUF()
 ENDIF

 IF BUF(0)=1 AND BUF(1)=0 AND BUF(2)=164 AND BUF(3)=32 AND BUF(4)=3 AND BUF(5)=1 AND BUF(6)=0 THEN
  CtrlExist(1)=CHAN
 ELSE
  Classic_Mini_Close(CHAN)
 ENDIF

END SUB


Nobody...least of all me...could question your programming prowess...and I have no doubt that this code works. But it kind of reminds me of old C64 BASIC 2.O code versus say...BASIC 7 from the 128....where one uses peeks and pokes to hardware registers and the other has those 'shiny new' BASIC commands that do all that 'nasty' stuff under the hood!  

Your CMM heritage is showing.    Apart from 'if it ain't broke, don't fix it' is there a performance advantage to the old way of communicating versus the dedicated CLASSIC/NUNCHUK commands?

Steve
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 06:21pm 29 May 2021
Copy link to clipboard 
Print this post

It's simple, the dedicated commands in the current firmware can't work with all controllers types, it works only for a type of Classic controller, but the SNES and NES Mini have another type of initialization that is the same as the Classic Controller Pro, and even using the same protocol, the order of reading is different too.

These links show some information about it:
http://spinalcode.co.uk/2018/08/14/wii-classic-controller-protocol
https://wiibrew.org/wiki/Wiimote/Extension_Controllers

I developed this code because I have an NES Classic Mini Controller that is wireless, and had to create an implementation to use in the Mazes of Chaos. If matherp implement this in the firmware, for sure my code will not be necessary anymore.
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025