Jayenkai's Framework - October 2013

Monkey Archive Forums/Monkey Projects/Jayenkai's Framework - October 2013

ElectricBoogaloo(Posted 2013) [#1]
Link
Most Recent Version (as of 20th October 2012)
From here you can read through blog posts about the previous versions, and download as required.

-=-=-

WARNING
Jayenkai's Monkey Framework consists of Jayenkai's 1980's Influenced Coding Style, and should not be used without taking proper precautions.
Do not attempt to train yourself coding techniques using the methodology contained within.
Do not attempt to pretend to learn anything useful from the functions included.
Do not complain about the fact that 95% of the code is all crammed into one great big gigantic .monkey file.
Do not read code whilst driving.

General
Writing games at a rate of AGameAWeek needs something a little more substantial than a simple "Here's a tilemap engine".
In truth, I've barely ever used a tilemap engine. I can do that on the fly. It's not exactly difficult to line up some pictures and scroll them around. I learned to do that on an Amstrad, so being able to do it on a modern PC using a fancy language like Monkey is a doddle.
Instead, I need the annoying bits.
My "Framework" does all those horribly annoying things that I typically don't enjoy doing.

-=-=-

Contents

Menu/Ingame/Menu
The framework draws a simple looking titlescreen made up of 2 images. Replace the images, get a different looking but similar titlescreen. It's a fairly simple task.
The menu handles Easy/Normal/Hard mode select, displays a highscore table, and even lets you turn sfx off and on.
The engine then handles the switch to Ingame, handles a Pause button along with Pause Menu and Quit, and in your game code you simply flag up EndofGame=1 and it exits nicely, then swiftly fades back to the menu again.

Very simple stuff, easy to work with, job done.

Scores
Update the Score= variable, and the engine handles the rest. Highscores are updated, LastScores get recorded, it all kinda does things itself.

Credit Testcard
Tap the AGameAWeek Logo to pop up the Credits screen. It's simplistic, but works well enough.

PlayKey()
PlayKey(0) is Up
PlayKey(8) is Down
PlayKey(3) is Left
PlayKey(5) is Right (For those keeping track, these are taken from the 200,203,205,208 cursorkey scancodes that Blitz used to use)
PlayKey(10 to 13) are four main fire buttons.
PlayKey(14 and 15) are Triggers
PlayKey(99) is Start/Quit/Whatever.

PlayKey works for the following.
1. Cursor keys and ZXCVBN
2. WASD and JKLIUO
3. Spacebar, Shift, Control, Enter and other expected keys.
4. Escape!
5. The majority of USB gamedevices, assuming they're vaguely standardised.
6. If you set "OnScreenControls=1", then the onscreen dpad and buttons are reflected in PlayKey()
7. iCade. If you toggle the iCade icon on the menu, and have an iCade compatible device hooked up, that works here, too.
8. Android Gamepads. Those work.
9. OUYA. Works on OUYA.

I've also recently added StickX, StickY and Trigger, to fit the OUYA.

Resolutions

LoadImg() and DrawImg() replace your normal commands, and perform two tasks.
First up, LoadImg loads a different asset depending on the general resolution of the screen. ("a.png" for <640, "a-hd.png" for >640 and "a-hd2.png" for >1280)
DrawImg, Rect, Oval and Line all then scale from your given original resolution, up to whatever the user's current resolution and aspect ratio is.

You can setup a virtual resolution near the top of the code. Set your own rawscrw and rawscrh, and that'll be your target, then draw within 0,0 to jscrw,jscrh, and everything you draw will be visible on the screen.

Bitmap Fonts
It's barely complex at all, but it does the job. Barebones, but functional.

-=-=-

Further Reading
The blog posts contain plenty more information about the ins and outs of the framework.

Not Included
. Sprites Engine - just draw things.
. Tilemap Engine - just draw things.
. Particle Engine - just draw things.
. Batteries

Targets
This framework has been tested on, and proved to work with the following targets.

1. HTML5
2. GLFW
3. Android
4. Android OUYA
5. iOS

Theoretically it should also work on other targets, but might require tweaking, especially around the PlayKey area.

-=-=-

Usage

I wouldn't have put it online if I wanted to guard it.
Grab, Use, and Credit me if you're nice.

But...
WARNING PART TWO
It's not really meant for public consumption, and is very much coded specifically for myself, and my AGameAWeek coding style. Any complications should be easy to deal with, any complaints should be fixable yourself. If you want to rant about my insane use of Globals, Arrays, and the terrible way it's all in one giant file, then strip it all out, fix it all up, upload a new version, and then go "I KAN HAS DUN MAIKED IT BETERERER".
I didn't write this with "awesome-code-style" in mind. I wrote it with "AGameAWeek" in mind.

Fast and furious isn't always pretty.
Don't whinge about the results.

As of October 2013
5 games on the iOS AppStore use this framework.
17 games on the GooglePlay Android store use this framework.
2 games on the OUYA marketplace use this framework.
and all of these games use this framework.

It's not clean, it's not pretty, but it gets the job done.

-=-=-

Link
Most Recent Version (as of 20th October 2012)
From here you can read through blog posts about the previous versions, and download as required.


Shinkiro1(Posted 2013) [#2]
Oh my god, that's horrible ^^

Just kidding, if you can pull out a game a week with this you have to do something right :)


Neuro(Posted 2013) [#3]
Lol, looks interesting. Will have to check it out :).