Propeller - An Example SGDK-Based Game Engine

Talk about development tools here

Moderator: BigEvilCorporation

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Propeller - An Example SGDK-Based Game Engine

Post by djcouchycouch » Fri Feb 08, 2013 3:22 am

Introducing Propeller, an example game engine for the Sega Genesis written with Stef's SGDK.

https://dl.dropboxusercontent.com/u/173 ... .1.0.3.zip
https://dl.dropbox.com/u/17303735/Propeller.1.0.2.zip
https://dl.dropbox.com/u/17303735/Propeller.1.0.1.zip
https://dl.dropbox.com/u/17303735/Propeller.1.0.0.zip

Some features:

- 8-way scrolling engine with "special tiles" the player can interact with like coins.
- object management system with per-object type collisions
- contains examples of effects, level structure, tile collisions, projectiles, enemy AI, player handling, animation, rotations and distance calculations
- python based tools to generate sin/cos and distance tables


The code is released as-is. It's free and you can do anything with it. It's meant to be used as a learning tool. I see questions about how to do things like scrolling, and I want to be able to give a concrete example instead of just talking about the theory.

As for the future, I don't foresee myself doing any major work on Propeller. I wish for people to take it and use it as a base to build new things.

I will, however, most definitely answer questions about how some parts work. The code isn't super clean or super clear in parts.

Propeller 1.0.0, Feb 13th, 2013
- Works with SGDK 0.92. Haven't tried the latest version yet.

Propeller 1.0.1, Feb 16th, 2013
- Fixed compilation issues with scrolling functions in SGDK 0.93b.

Propeller 1.0.2, Feb 16th, 2013
- Fixed corruption bug when scrolling.

Propeller 1.0.3 Nov 30th, 2014
- updated to SGDK 1.00

DJCC
Last edited by djcouchycouch on Sun Nov 30, 2014 9:02 pm, edited 7 times in total.

User avatar
powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Post by powerofrecall » Fri Feb 08, 2013 5:15 am

Nice work! This kind of thing is a boon to the community.

It's good to see this kind of thing come from all your own hard work and inquisitiveness. The questions you asked on this board, I also learned from. I think many people will learn from your code.

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Wed Feb 13, 2013 10:05 am

Which version of Stef's SGDK made an example?
On SGDK 0.9.3b gives out a errors in Game.c
Line 145, 146, 147, 148.

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Wed Feb 13, 2013 11:43 am

Mixail wrote:Which version of Stef's SGDK made an example?
On SGDK 0.9.3b gives out a errors in Game.c
Line 145, 146, 147, 148.
SGDK 0.92 should compile fine. I'll try the latest version this week and release a fix.

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Feb 16, 2013 3:35 pm

Fixed compilation issues with scrolling functions in SGDK 0.93b.

https://dl.dropbox.com/u/17303735/Propeller.1.0.1.zip

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Sat Feb 16, 2013 4:46 pm

djcouchycouch wrote:Fixed compilation issues with scrolling functions in SGDK 0.93b.

https://dl.dropbox.com/u/17303735/Propeller.1.0.1.zip
There is one problem. Your engine badly works at iron. As it badly works and at the emulator Fusion 3.51 . After movement down game hangs. Please, correct errors.

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Feb 16, 2013 6:00 pm

Mixail wrote:
djcouchycouch wrote:Fixed compilation issues with scrolling functions in SGDK 0.93b.

https://dl.dropbox.com/u/17303735/Propeller.1.0.1.zip
There is one problem. Your engine badly works at iron. As it badly works and at the emulator Fusion 3.51 . After movement down game hangs. Please, correct errors.
I've reproduced it on hardware. Will take a look. Seems related to object handling.

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Sat Feb 16, 2013 6:42 pm

djcouchycouch wrote:
Mixail wrote:
djcouchycouch wrote:Fixed compilation issues with scrolling functions in SGDK 0.93b.

https://dl.dropbox.com/u/17303735/Propeller.1.0.1.zip
There is one problem. Your engine badly works at iron. As it badly works and at the emulator Fusion 3.51 . After movement down game hangs. Please, correct errors.
I've reproduced it on hardware. Will take a look. Seems related to object handling.
I will wait for corrections, I hope it will succeed.

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Feb 16, 2013 8:01 pm

DrawForeground() in LevelManager.c is bad. Not doing DMA writes properly most likely. Affects Goplanes too.

Sigh. I hate that part of the code :)

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sun Feb 17, 2013 2:11 am

Found the issue. Version 1.0.2 here:

https://dl.dropbox.com/u/17303735/Propeller.1.0.2.zip

The problem:

The UpdateForeground() function in LevelManager.c, which sets up the rows and columns to be drawn by DMA, had a check to see if the plane actually scrolled before updating the background layer. It compared tilepositionX/Y with oldtilepositionX/Y. If there wasn't any scrolling, then the function would return and not do anything. But the DrawForeground() function that is called later in the frame, which does the DMA calls, would run no matter what. It would still do the DMA calls, with unset values, causing garbage data to stomp all over memory causing corrupted tiles. Fun stuff.

Goplanes never showed that problem, which is real strange. The garbage values it used must've stomped unused data. There was one time I ran on hardware where the whole screen blew up. That must've been a time where the garbage values weren't outside used data. It had only happened once.

I tried adding a quick fix to DrawForeground() of also checking to see if the screen actually scrolled before doing the DMA calls, but I'd get missing rows of tiles in Goplanes by flying at certain angles. Instead of investigating that, I just avoid the check all together in UpdateForeground() and compute everything every frame. Seems to have solved the problem.

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Sun Feb 17, 2013 9:24 am

djcouchycouch, good job!

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Tue Nov 19, 2013 11:57 am

djcouchycouch, please, you can make an example only with the skroll?

djcouchycouch
Very interested
Posts: 672
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Tue Nov 19, 2013 5:43 pm

Mixail wrote:djcouchycouch, please, you can make an example only with the skroll?
Hi,

I'm afraid I don't have the time to make you a tutorial-like example for the 8 way scrolling. Even if there was, you still need to wrap your head around the basic concepts. There's no way to abstract it so that you can just use it.

The best way is to experiment and start simple. Left-right scrolling of a long level, etc.

The basic idea is to update the plane at the edges of the screen.

Code: Select all

000000000000000000000000[111111]000000000000000000000000
000000000000000000000000[111111]000000000000000000000000
000000000000000000000000[111111]000000000000000000000000
000000000000000000000000[111111]000000000000000000000000
0 is the the level
1 is the area seen by the screen

When moving the screen left, you have to update the column of tiles at the left side of the screen. When moving right, update the column of tiles on the right.

That part is pretty straight forward. The tricky parts come when you start crossing plane boundaries. There will be a point where you can't simply draw the next column at the next logical position in memory because you'll start stomping memory.

Planes have a property where they wrap if you scroll too much. If you take a 64x64 map and scroll it horizontally by 65 tiles, you'll start seeing the first column of the map again.

If your level is 128 tiles wide and your plane is 64 tiles wide, when you're scrolling right and you want to draw the 65th tile column of your level, you have to draw it at the 0th column of the plane. Basically (column position % 64).

Code: Select all

|-------- plane width --------||----- plane width (wrapped)--|
|----------------------level width---------------------------|
000000000000000000000000000000[111111]000000000000000000000000
000000000000000000000000000000[111111]000000000000000000000000
000000000000000000000000000000[111111]000000000000000000000000
000000000000000000000000000000[111111]000000000000000000000000
Anyway, I can try to answer any questions you may have, but you'll have to do the legwork :)

Mixail
Very interested
Posts: 94
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Tue Nov 19, 2013 7:12 pm

I meant to make an example only scroll on the basis of Propeller. To delete unnecessary code from the program and to leave only scroll. Thanks.

User avatar
oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Fri Dec 13, 2013 12:58 pm

I agree with djcouchycouch.

He gave you usefull information to do your own scroll engine.
Nothing complicate, just as he told you when your level is longer than your plane.

With his explination, try to do a simple scrolling, you'll see, it's no sot hard.

If he modify his engine just to have a simple lateral scroll while you don't really know how it's working, it will be harder for you to do any change when you want.

You have really to understand how it's working to really appreciate the job ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest