Barf up a mini-"framework" to get started
This is kinda junky and only really useful for this game lol
This commit is contained in:
parent
c0385dbe96
commit
73514e1eaf
13 changed files with 402 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
/index.html
|
||||
/tmpfile
|
||||
/tmpfile
|
||||
/assets/sprites.json
|
||||
/assets/sprites.png
|
226
assets/sprites.tps
Normal file
226
assets/sprites.tps
Normal file
|
@ -0,0 +1,226 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<data version="1.0">
|
||||
<struct type="Settings">
|
||||
<key>fileFormatVersion</key>
|
||||
<int>4</int>
|
||||
<key>texturePackerVersion</key>
|
||||
<string>4.2.1</string>
|
||||
<key>fileName</key>
|
||||
<string>M:/adventurejam2016/assets/sprites.tps</string>
|
||||
<key>autoSDSettings</key>
|
||||
<array>
|
||||
<struct type="AutoSDSettings">
|
||||
<key>scale</key>
|
||||
<double>1</double>
|
||||
<key>extension</key>
|
||||
<string></string>
|
||||
<key>spriteFilter</key>
|
||||
<string></string>
|
||||
<key>acceptFractionalValues</key>
|
||||
<false/>
|
||||
<key>maxTextureSize</key>
|
||||
<QSize>
|
||||
<key>width</key>
|
||||
<int>-1</int>
|
||||
<key>height</key>
|
||||
<int>-1</int>
|
||||
</QSize>
|
||||
</struct>
|
||||
</array>
|
||||
<key>allowRotation</key>
|
||||
<true/>
|
||||
<key>shapeDebug</key>
|
||||
<false/>
|
||||
<key>dpi</key>
|
||||
<uint>72</uint>
|
||||
<key>dataFormat</key>
|
||||
<string>json</string>
|
||||
<key>textureFileName</key>
|
||||
<filename></filename>
|
||||
<key>flipPVR</key>
|
||||
<false/>
|
||||
<key>pvrCompressionQuality</key>
|
||||
<enum type="SettingsBase::PvrCompressionQuality">PVR_QUALITY_NORMAL</enum>
|
||||
<key>atfCompressData</key>
|
||||
<false/>
|
||||
<key>mipMapMinSize</key>
|
||||
<uint>32768</uint>
|
||||
<key>etc1CompressionQuality</key>
|
||||
<enum type="SettingsBase::Etc1CompressionQuality">ETC1_QUALITY_LOW_PERCEPTUAL</enum>
|
||||
<key>dxtCompressionMode</key>
|
||||
<enum type="SettingsBase::DxtCompressionMode">DXT_PERCEPTUAL</enum>
|
||||
<key>jxrColorFormat</key>
|
||||
<enum type="SettingsBase::JpegXrColorMode">JXR_YUV444</enum>
|
||||
<key>jxrTrimFlexBits</key>
|
||||
<uint>0</uint>
|
||||
<key>jxrCompressionLevel</key>
|
||||
<uint>0</uint>
|
||||
<key>ditherType</key>
|
||||
<enum type="SettingsBase::DitherType">NearestNeighbour</enum>
|
||||
<key>backgroundColor</key>
|
||||
<uint>0</uint>
|
||||
<key>libGdx</key>
|
||||
<struct type="LibGDX">
|
||||
<key>filtering</key>
|
||||
<struct type="LibGDXFiltering">
|
||||
<key>x</key>
|
||||
<enum type="LibGDXFiltering::Filtering">Linear</enum>
|
||||
<key>y</key>
|
||||
<enum type="LibGDXFiltering::Filtering">Linear</enum>
|
||||
</struct>
|
||||
</struct>
|
||||
<key>shapePadding</key>
|
||||
<uint>2</uint>
|
||||
<key>jpgQuality</key>
|
||||
<uint>80</uint>
|
||||
<key>pngOptimizationLevel</key>
|
||||
<uint>0</uint>
|
||||
<key>webpQualityLevel</key>
|
||||
<uint>101</uint>
|
||||
<key>textureSubPath</key>
|
||||
<string></string>
|
||||
<key>textureFormat</key>
|
||||
<enum type="SettingsBase::TextureFormat">png</enum>
|
||||
<key>borderPadding</key>
|
||||
<uint>0</uint>
|
||||
<key>maxTextureSize</key>
|
||||
<QSize>
|
||||
<key>width</key>
|
||||
<int>2048</int>
|
||||
<key>height</key>
|
||||
<int>2048</int>
|
||||
</QSize>
|
||||
<key>fixedTextureSize</key>
|
||||
<QSize>
|
||||
<key>width</key>
|
||||
<int>-1</int>
|
||||
<key>height</key>
|
||||
<int>-1</int>
|
||||
</QSize>
|
||||
<key>algorithmSettings</key>
|
||||
<struct type="AlgorithmSettings">
|
||||
<key>algorithm</key>
|
||||
<enum type="AlgorithmSettings::AlgorithmId">Basic</enum>
|
||||
<key>freeSizeMode</key>
|
||||
<enum type="AlgorithmSettings::AlgorithmFreeSizeMode">Best</enum>
|
||||
<key>sizeConstraints</key>
|
||||
<enum type="AlgorithmSettings::SizeConstraints">AnySize</enum>
|
||||
<key>forceSquared</key>
|
||||
<false/>
|
||||
<key>maxRects</key>
|
||||
<struct type="AlgorithmMaxRectsSettings">
|
||||
<key>heuristic</key>
|
||||
<enum type="AlgorithmMaxRectsSettings::Heuristic">Best</enum>
|
||||
</struct>
|
||||
<key>basic</key>
|
||||
<struct type="AlgorithmBasicSettings">
|
||||
<key>sortBy</key>
|
||||
<enum type="AlgorithmBasicSettings::SortBy">Best</enum>
|
||||
<key>order</key>
|
||||
<enum type="AlgorithmBasicSettings::Order">Ascending</enum>
|
||||
</struct>
|
||||
</struct>
|
||||
<key>andEngine</key>
|
||||
<struct type="AndEngine">
|
||||
<key>minFilter</key>
|
||||
<enum type="AndEngine::MinFilter">Linear</enum>
|
||||
<key>packageName</key>
|
||||
<string>Texture</string>
|
||||
<key>wrap</key>
|
||||
<struct type="AndEngineWrap">
|
||||
<key>s</key>
|
||||
<enum type="AndEngineWrap::Wrap">Clamp</enum>
|
||||
<key>t</key>
|
||||
<enum type="AndEngineWrap::Wrap">Clamp</enum>
|
||||
</struct>
|
||||
<key>magFilter</key>
|
||||
<enum type="AndEngine::MagFilter">MagLinear</enum>
|
||||
</struct>
|
||||
<key>dataFileNames</key>
|
||||
<map type="GFileNameMap">
|
||||
<key>data</key>
|
||||
<struct type="DataFile">
|
||||
<key>name</key>
|
||||
<filename>sprites.json</filename>
|
||||
</struct>
|
||||
</map>
|
||||
<key>multiPack</key>
|
||||
<false/>
|
||||
<key>forceIdenticalLayout</key>
|
||||
<false/>
|
||||
<key>outputFormat</key>
|
||||
<enum type="SettingsBase::OutputFormat">RGBA8888</enum>
|
||||
<key>alphaHandling</key>
|
||||
<enum type="SettingsBase::AlphaHandling">ClearTransparentPixels</enum>
|
||||
<key>contentProtection</key>
|
||||
<struct type="ContentProtection">
|
||||
<key>key</key>
|
||||
<string></string>
|
||||
</struct>
|
||||
<key>autoAliasEnabled</key>
|
||||
<false/>
|
||||
<key>trimSpriteNames</key>
|
||||
<true/>
|
||||
<key>prependSmartFolderName</key>
|
||||
<false/>
|
||||
<key>globalSpriteSettings</key>
|
||||
<struct type="SpriteSettings">
|
||||
<key>scale</key>
|
||||
<double>1</double>
|
||||
<key>scaleMode</key>
|
||||
<enum type="ScaleMode">Smooth</enum>
|
||||
<key>extrude</key>
|
||||
<uint>0</uint>
|
||||
<key>trimThreshold</key>
|
||||
<uint>1</uint>
|
||||
<key>trimMargin</key>
|
||||
<uint>1</uint>
|
||||
<key>trimMode</key>
|
||||
<enum type="SpriteSettings::TrimMode">None</enum>
|
||||
<key>tracerTolerance</key>
|
||||
<int>200</int>
|
||||
<key>heuristicMask</key>
|
||||
<false/>
|
||||
<key>defaultPivotPoint</key>
|
||||
<point_f>0.5,0.5</point_f>
|
||||
<key>writePivotPoints</key>
|
||||
<false/>
|
||||
</struct>
|
||||
<key>individualSpriteSettings</key>
|
||||
<map type="IndividualSpriteSettingsMap">
|
||||
<key type="filename">sprites/dolphin1.png</key>
|
||||
<key type="filename">sprites/dolphin2.png</key>
|
||||
<key type="filename">sprites/dolphin3.png</key>
|
||||
<key type="filename">sprites/dolphin4.png</key>
|
||||
<key type="filename">sprites/dolphin5.png</key>
|
||||
<struct type="IndividualSpriteSettings">
|
||||
<key>pivotPoint</key>
|
||||
<point_f>0.5,0.5</point_f>
|
||||
</struct>
|
||||
</map>
|
||||
<key>fileList</key>
|
||||
<array>
|
||||
<filename>sprites</filename>
|
||||
</array>
|
||||
<key>ignoreFileList</key>
|
||||
<array/>
|
||||
<key>replaceList</key>
|
||||
<array/>
|
||||
<key>ignoredWarnings</key>
|
||||
<array/>
|
||||
<key>commonDivisorX</key>
|
||||
<uint>1</uint>
|
||||
<key>commonDivisorY</key>
|
||||
<uint>1</uint>
|
||||
<key>packNormalMaps</key>
|
||||
<false/>
|
||||
<key>autodetectNormalMaps</key>
|
||||
<true/>
|
||||
<key>normalMapFilter</key>
|
||||
<string></string>
|
||||
<key>normalMapSuffix</key>
|
||||
<string></string>
|
||||
<key>normalMapSheetFileName</key>
|
||||
<filename></filename>
|
||||
</struct>
|
||||
</data>
|
BIN
assets/sprites/dolphin.xcf
Normal file
BIN
assets/sprites/dolphin.xcf
Normal file
Binary file not shown.
BIN
assets/sprites/dolphin1.png
Normal file
BIN
assets/sprites/dolphin1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 514 B |
BIN
assets/sprites/dolphin2.png
Normal file
BIN
assets/sprites/dolphin2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 503 B |
BIN
assets/sprites/dolphin3.png
Normal file
BIN
assets/sprites/dolphin3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 491 B |
BIN
assets/sprites/dolphin4.png
Normal file
BIN
assets/sprites/dolphin4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 503 B |
BIN
assets/sprites/dolphin5.png
Normal file
BIN
assets/sprites/dolphin5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 500 B |
5
init.js
Normal file
5
init.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Game.init(function() {
|
||||
Game.setScene(Level());
|
||||
});
|
||||
});
|
43
level/Level.js
Normal file
43
level/Level.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
Level = function() {
|
||||
var level = Scene();
|
||||
|
||||
// A set of 512x512 blocks that objects are contained in.
|
||||
// Blocks two grid spaces away (in a square, corners excluded) from the camera
|
||||
// are thunk and rendered in a frame.
|
||||
var objectGrid = {};
|
||||
|
||||
function getGridIndex(x, y) {
|
||||
return Math.floor(x/512) + Math.floor(y/512)*512;
|
||||
// If a map is bigger than 200k pixels one way then you have other problems.
|
||||
}
|
||||
|
||||
var sprite;
|
||||
level.init = function() {
|
||||
sprite = Renderer.animation([
|
||||
"dolphin3",
|
||||
"dolphin2",
|
||||
"dolphin1",
|
||||
"dolphin2",
|
||||
"dolphin3",
|
||||
"dolphin4",
|
||||
"dolphin5",
|
||||
"dolphin4"
|
||||
]).speed(20);
|
||||
sprite.position.set(200,200);
|
||||
level.addSprite(sprite);
|
||||
}
|
||||
|
||||
level.think = function() {
|
||||
sprite.x = Math.cos(level.ticCount/40)*100+250;
|
||||
}
|
||||
|
||||
level.show = function(frames) {
|
||||
|
||||
}
|
||||
|
||||
level.end = function() {
|
||||
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
55
main/Game.js
Normal file
55
main/Game.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
Game = (function() {
|
||||
var Game = {};
|
||||
|
||||
var currentScene, incomingScene;
|
||||
|
||||
Game.init = function(callback) {
|
||||
Renderer.init(initScene);
|
||||
|
||||
function initScene() {
|
||||
// Run callback to set the inital scene.
|
||||
callback();
|
||||
currentScene = incomingScene;
|
||||
currentScene.init();
|
||||
|
||||
gameLoop();
|
||||
}
|
||||
}
|
||||
|
||||
Game.setScene = function(scene) {
|
||||
incomingScene = scene;
|
||||
}
|
||||
|
||||
var frameskipMonitor = 0;
|
||||
|
||||
function gameLoop() {
|
||||
requestAnimationFrame(gameLoop);
|
||||
|
||||
flipScenes();
|
||||
currentScene.ticCount++;
|
||||
currentScene.think();
|
||||
render();
|
||||
}
|
||||
|
||||
function flipScenes() {
|
||||
if (currentScene != incomingScene) {
|
||||
currentScene.end();
|
||||
incomingScene.init();
|
||||
currentScene = incomingScene;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
frameskipMonitor++;
|
||||
if (frameskipMonitor >= Renderer.frameskip) {
|
||||
frameskipMonitor = 0;
|
||||
|
||||
currentScene.render(Renderer.frameskip);
|
||||
Renderer.show(currentScene.stage);
|
||||
} else {
|
||||
Renderer.skip();
|
||||
}
|
||||
}
|
||||
|
||||
return Game;
|
||||
})();
|
42
main/Renderer.js
Normal file
42
main/Renderer.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
Renderer = (function() {
|
||||
var Renderer = {};
|
||||
|
||||
var renderer;
|
||||
|
||||
Renderer.init = function(next) {
|
||||
renderer = PIXI.autoDetectRenderer(500, 280, {
|
||||
antialias: false,
|
||||
transparent: false,
|
||||
resolution: 1
|
||||
});
|
||||
|
||||
document.body.appendChild(renderer.view);
|
||||
|
||||
PIXI.loader.add("assets/sprites.json").load(next);
|
||||
}
|
||||
|
||||
Renderer.sprite = function(name) {
|
||||
return new PIXI.Sprite(PIXI.utils.TextureCache[name]);
|
||||
}
|
||||
|
||||
Renderer.animation = function(sprites) {
|
||||
var anim = PIXI.extras.MovieClip.fromFrames(sprites);
|
||||
anim.play();
|
||||
anim.speed = function(speed) {
|
||||
anim.animationSpeed = speed/60;
|
||||
return anim;
|
||||
}
|
||||
return anim;
|
||||
}
|
||||
|
||||
Renderer.show = function(stage) {
|
||||
renderer.render(stage);
|
||||
}
|
||||
|
||||
Renderer.skip = function() {
|
||||
}
|
||||
|
||||
Renderer.frameskip = 1;
|
||||
|
||||
return Renderer;
|
||||
})();
|
28
main/Scene.js
Normal file
28
main/Scene.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
Scene = function() {
|
||||
var scene = {};
|
||||
|
||||
scene.stage = new PIXI.ParticleContainer(512, {
|
||||
position: true,
|
||||
rotation: true,
|
||||
scale: true,
|
||||
alpha: true,
|
||||
uvs: true
|
||||
});
|
||||
|
||||
scene.ticCount = 0; // How many frames has this scene run?
|
||||
|
||||
// Base functions that a scene should overwrite.
|
||||
scene.init = function() {} // Run when the scene is switched to.
|
||||
scene.think = function() {} // Run once per thinker frame.
|
||||
scene.render = function(frames) {} // Run once per render frame before refresh and etc, for sprite positioning.
|
||||
scene.end = function() {} // Run when the scene is switched away from.
|
||||
|
||||
// Useful functions.
|
||||
|
||||
// Add a sprite or animation to this scene's stage.
|
||||
scene.addSprite = function(sprite) {
|
||||
scene.stage.addChild(sprite);
|
||||
}
|
||||
|
||||
return scene;
|
||||
}
|
Loading…
Add table
Reference in a new issue