Friday, August 28, 2009
Life Get's in the way ...
Wednesday, February 25, 2009
New Logo using JavaScript and Canvas
Been working on a new logo for my nemesisstar.com website. Well not changing the logo really, just adding a bit of flair to it without using flash. If you want to take a look at it you can find it here. Again, don't bother trying to look at it using IE, as the internet explorer browser does not yet support canvas, and no official work that i know of that IE8 will support it either.
Break down of how the script is working ...
Ok, for speed reasons I'm using 3 canvas's, not just one. All the base objects are wrapped in a div tag, the first 'img' tag inside the div will be used for those browsers that do not support the canvas object. For non-game stuff I have not reason not to provide some sort of backwards-compatibility support ... at very least so the search engines can still browse the site. the very last. I will throw everything into a nice style sheet and make it pretty a bit later.
Setup of the cavas objects ...
Because I'm fitting the canvas objects to the screen width and height i need to adjust these values so that they are transformed to their appropriate 000px values. Otherwise, on some browsers at least, everything will have to pass through the scale routines and for some reason things really start to slow down.
Any graphics you use need to be preloaded, or if you are loading them as you need them in your script you need to verify that they are actually loaded before you use them ...
The animation script ...
The ctxBG is the middle layer which is holding the static logo. It is not moving at all in this portion of the script so their is no reason to keep redrawing it. Plus by sandwiching it between the three layers we can simulate the 3d effect.
angCos[curAng] and angSin[curAng] ...
Very simple simple if you have worked on any sort of 3d application. It takes more time to access Math.sin than it does an array. So we pre-calculate any sin or cos value that we might need and put them into these two arrays. As for the rest of the formula it is a very simple circle drawing routine from basic math class ...
The fbuff variable simply stands for "flip buffer" which tells the screen whether to draw to the foreground or the background based on the 'y' (vertical) value. After that we do the actual drawing ...
The canvas.save() and canvas.restore() do exactly like the sound, they save the current state of the canvas, allow us to do our manipulations, then restore it. canvas.translate(x,y) moves the origin point so that when we call the canvas.rotate(radian) function it rotates around the correct point and not the top of the screen (0,0). canvas.drawImage(img,x,y) does exactly like it sounds ... draw's the little spike to the screen .. finally.
Above all that in the code is this piece which simply adjusts the vertcale scale value and re-centers the origin. The coupled with the buffer flipping is what gives us our pseudo-3d look without having to bother with full 3d code which is slow at best with the current canvas object. Full 3d support is to be added to the canvas object later, but they will have to get past the arguments about the standards first. Myself if i wanted to add full 3D i would just use Unity 3D even though I don't like plug-ins.
Speed of the canvas rendering ...
I've done everything that I've been able to think of to make this run as fast as possible and have a great more that I do wish to add. So far Chrome seems to run it the fastest for me by far and the few people I've had test it have said that a higher end video card does help in the rendering speed. The only thing I don't like is with the black on white it seems a bit shaky in the rendering. I could probably add in 2 more buffers and then flip the visibility after they are rendered to remove that but I'm not positive how that will work out.
Future additions ...
- Add interactivity so the user can play with the logo
* double-click top and it will spin top-to-bottom
* double-click side and it will spin left-to-right
* drag the spikes to increase or decrease the spinning speed.
* be able to click and select a spike
* add a highlight-glow to currently selected spike/icon - Add icons to the spikes
- Make the center image change according to the icon clicked on.
- See if i can get more speed by removing the canvas.scale() and converting the spikes to vector drawings instead of images.
- Convert the entire script into an animation object/class.
Will be using this same type of animation in the nemesis-star game so that i can add space-station and such around planets. When being used on a smaller scale like that the animation speed should drastically increase.
Tuesday, February 17, 2009
Another jobless day
Anyways, did a bit more work last night on the canvas engine. Seems like Firebug has changed since I've lasted worked with the profile in the console. It no longer lists all the functions that are called like the old version. The old version would even list what classes were accessed, how often, and how much time it took. But alas I will have to just make due with it, just seems like their development progress took a step back. I have the mini map scrolling properly across the mm buffer, just need to get it updating the main map area fluidly.
if (notDrawing){drawDetails(obj, x, y, tx, ty)}
Ok, time to start wandering around Raleigh dropping off resumes to the local web business's. I was told by a recruiter that this looks desperate ... but then again he drives a Ferrari so I'm pretty sure that he hasn't tried to find a job in quite some time, especially in this economy.
Friday, February 13, 2009
Lychgate Roadmap
Lychgate - the JavaScript Game Engine
This is a portion of a Google document that I have created to assist me in my programming activities. I believe the first full game I will design this engine for will be for my Nemesis Star game. By doing this it will include support for ground, air and space activities across multiple planets. Nemesis Star however encompasses both RTS and RPG elements which should make the design of the basic engine a bit trickier but overall I think it would be a better final product for it.
I will be revising this as I go and put forth a more detailed road-map to a full fledged game, but at the current moment getting these few things done would allow me to open up some closed alpha testing and tweak the game till it works properly. I do have a list started for requests from people to be part of the closed alpha, but if you wish to participate you must make this request before it begins.
A few requirements I have laid down for myself ...
Classes
- Classes will be broken into groups based on what they do.
- These groups should work as independantly from each other as possible.
- Allow dynamic loading and unloading of these classes and scripts.
- Each group type will have basic get/put elements that are required for interaction with that group.
(this all allows multiple types of the same group.) - Cannot load more than one group type at the same time.
- Graphic animation strips should be small, 1 animation type/direction per file. This means multiple files however it does give a big speed processing. I've tested this quite a bit and the larger the file the more the slowdown when clipping from it.
- The graphics library must support dynamic buffering. This would be the dynamic creating/deletion of canvas objects where needed. Back-buffering is a very old trick but it does very much apply when using the canvas tag to render scenes and animations. By pre-rendering certain things you get a great improvement in performance.
- Dynamic loading and unloading of graphics. The map object will be designed to support a nearly infinite amount of different tile terrains. Because the base graphics are loaded into via smaller files the map engine itself can select what terrain tiles that it wishes to load. This allows the coder to put just what they want into the map from any terrain library that they wish.
- A simple web-based graphics editor. Not really so much for creating graphics as for clipping, arranging animations and such. Can make the graphics editor more complicated later.
- Web-based map editor. Their is none, map edits would be made by the GM/Owner in real time in the game world itself. Why create two version of the same thing.
The to do list ...
A Super-Basic RPG
Basic Client Side Graphics Development
Create the Draw Class
This class is responsible for all the drawing
Create the Sprite Class
This is an extension of the ‘Draw’ class as it gives it the ability to use tiny buffers to perform animations and movement.
Create the Timer Class
This is what controls the Sprite Class and Draw class in order to insure that everything runs at the same speed across all supported types of computer systems.
Map-Drawing Layers
Ground Layer
Object Layer
Mini-map
Character Map
Create the Panel Class, this utilizes the Draw class to display the panel information. But all the information itself is contained within this class. The “Overall Display” is a series of Panels so that they are more easily moved and migrated as required.
Primary Information Panel
Overall Generic Display Setup
Basic Server Side Database
Tables
MOB
Map
Player
NPC
Scripts
Encapsulation
Write DB Access scripts, ultimately should support SQL and postGreSQL, (access support would be useless to include, so don’t!)
Methods … (Check W3C? or another Open Source Solution first?)
Open
Get
Set
Properties
Basic Server Side Data Server
Basic AJAX setup, XML
Challenge-Pass.( Insure login through every connection via Sessions and Privacy Protection.)
XML Packages …
Note: Packages should ultimately be scriptable though an Admin section. The packages will be XML Templates with pre-programmed variables and scripting methods. This is done to ease later programming and increase the overall flexibility of the server.
MAP Package
Player Package
MOB Package
NPC Package
Script Package
Graphics Package
Navigating the Map
Now we add the ability to move around. Phase 1.1 is where we test our ability to draw the map. This is in all encapsulated in a draw class.
Create the MOB class, “Mobile Object”
Create the Player Class
Add ability for the player to move
Add animations
Create the NPC Class
This first instance is super generic and only displays the NPC as a static object. We give it the ability to move later in Phase 1.06.
Create the Collision Class
An extension of the Map Class but does no drawing.
Prevents the player from moving into certain area’s
Controls trigger areas
Create the Script Class
The script class load/unload scripts
Is what the Collision class activates, specifically triggers.
Our first battle
Loading from remote server
Battle-map
Players
The first battle this will be a single player
Enemies
Initial Monster will be the standard ole Green Slime. After that it will be a combination of slimes and/or goblins.
NPC’s
The NPC will be the second part to this phase, buy a mercenary from the shop and it will participate in the battle with you.
Initial Drawing Setup
Map
Mini-Map
Battle Panel Overlay
Pre-load and Pre-draw Common Animations for speed
Initiative Phase
Determine type of battle (turn-based or real-time)
Set Initial Initiative Matrix
Battle Sequence
Using Initiative Matrix begin the battle
When in turn-based mode everyone goes one-at a time.
When in real-time mode everyone goes at the same time.
Keep repeating until one team is victorious
Ending Sequence
Give out items and experience to winners if the player is victorious.
Cleanup
Close and destroy all object and classes created in this battle. Each object is stored in an object array called ‘trashcan’ when it is created.
Draw player onto map
Interacting with NPC’s
Simple NPC Shop
The NPC should already be drawn by this time.
Setup NPC animations
Setup shop window
Setup shop XML Package. Refer to 1.3.3.a for details on this
Retrieve Data Package from server for specific NPC
Monday, February 9, 2009
Lychgate: a JavaScript MMORPG game
Canvas HTML Tag:Specification: HTML5Standardized by: WHATWG.orgInitially released by Apple the canvas html element is now supported by FireFox, Opera, Chrome and Safari natively. In short, canvas allows you to draw anything you wish straight to the web-page. No plugins required so you are only limited by your imagination as far as what it can do. The only draw back is lack of support from Microsoft in IE, though there is a very clunky JavaScript version available it will not run the more complicated things that i develop here ... which is of course games.
