Skip to content
Browse files

initial import

  • Loading branch information...
0 parents commit c14255b4666aa394b2f94fca85f697c894be8375 @gotosleep committed Apr 21, 2012
3 .gitignore
@@ -0,0 +1,3 @@
+_site
+.DS_Store
+.idea
42 _config.yml
@@ -0,0 +1,42 @@
+safe: false
+auto: true
+server: false
+server_port: 4000
+baseurl: /
+url: http://localhost:4000
+
+source: .
+destination: ./_site
+plugins: ./_plugins
+
+future: true
+lsi: false
+pygments: false
+markdown: maruku
+permalink: date
+
+maruku:
+ use_tex: false
+ use_divs: false
+ png_engine: blahtex
+ png_dir: images/latex
+ png_url: /images/latex
+
+rdiscount:
+ extensions: []
+
+kramdown:
+ auto_ids: true,
+ footnote_nr: 1
+ entity_output: as_char
+ toc_levels: 1..6
+ use_coderay: false
+
+ coderay:
+ coderay_wrap: div
+ coderay_line_numbers: inline
+ coderay_line_numbers_start: 1
+ coderay_tab_width: 4
+ coderay_bold_every: 10
+ coderay_css: style
+
31 _layouts/default.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>iojess - Jesse Andersen</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+ <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
+ <link href="css/main.css" rel="stylesheet" type="text/css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="js/crafty.js"></script>
+ <script src="js/ludum.js"></script>
+
+ <script type="text/javascript">
+
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-30678650-1']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+
+ </script>
+</head>
+<body>
+ <div id="content">
+ {{ content }}
+ </div>
+</body>
+</html>
BIN artwork/building.pxm
Binary file not shown.
BIN artwork/ground.pxm
Binary file not shown.
BIN artwork/robot_base.pxm
Binary file not shown.
78 css/main.css
@@ -0,0 +1,78 @@
+/* Global */
+
+html {
+ height: 100%;
+}
+
+body, p, span, div, h1, h2 {
+ font-family: 'Open Sans', sans-serif;
+ color: black;
+}
+
+body {
+ text-align: center;
+ background: url(../images/furley_bg.png);
+ padding: 0;
+ margin: 0;
+}
+
+h2 {
+ color: rgba(0, 0, 0, 0.75);
+ font-size: 32px;
+ margin: 0;
+}
+
+a, a:visited {
+ text-decoration: none;
+ color: blue;
+}
+
+.shadow {
+ -moz-box-shadow: 0px 0px 20px 0 #ccc;
+ -webkit-box-shadow: 0px 0px 20px 0 #ccc;
+ box-shadow: 0px 0px 20px 0 #ccc;
+}
+
+.woolBorder {
+ background: url(../images/light_wool.png);
+ border: 1px solid #ccc;
+ padding: 10px;
+}
+
+/* header */
+
+#header {
+ z-index: 1000;
+ position: absolute;
+ width: 100%;
+ height: 80px;
+ border-bottom: 1px solid #ccc;
+}
+
+#header h1 {
+ color: rgba(0, 0, 0, 0.75);
+ margin: 0;
+ padding: 20px 0;
+}
+
+/* footer */
+
+#footer {
+ position: absolute;
+ padding: 20px 0;
+ bottom: 0;
+ margin: 0;
+ width: 100%;
+ height: 20px;
+ border-top: 1px solid #ccc;
+}
+
+/* content */
+
+div#content {
+ padding: 50px;
+}
+
+div#cr-stage {
+ display: inline-block;
+}
BIN images/building.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/furley_bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/furley_bg_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/furley_bg_med.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/gray_sand.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/groovepaper.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/ground.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/iojess.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/jesse.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/light_wool.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/robot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN images/sprites.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 index.html
@@ -0,0 +1,7 @@
+---
+layout: default
+---
+<script type="text/javascript">
+</script>
+
+<div id="#cr-stage"></div>
8,976 js/crafty.js
8,976 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
403 js/example.js
@@ -0,0 +1,403 @@
+$(document).ready(function () {
+ //start crafty
+ Crafty.init(400, 336);
+ //Crafty.canvas.init();
+
+ // ------- SPRITES ------------
+
+ //turn the sprite map into usable components
+ Crafty.sprite(16, "images/sprites.png", {
+ grass1:[0, 0],
+ grass2:[1, 0],
+ grass3:[2, 0],
+ grass4:[3, 0],
+ flower:[0, 1],
+ bush1:[0, 2],
+ bush2:[1, 2],
+ player:[0, 3],
+ enemy:[0, 3],
+ banana:[4, 0],
+ empty:[4, 0]
+ });
+
+ //method to generate the map
+ function generateWorld() {
+ //loop through all tiles
+ for (var i = 0; i < 25; i++) {
+ for (var j = 0; j < 21; j++) {
+
+ //place grass on all tiles
+ grassType = Crafty.math.randomInt(1, 4);
+ Crafty.e("2D, DOM, grass" + grassType)
+ .attr({ x:i * 16, y:j * 16, z:1 });
+ //grid of bushes
+ if ((i % 2 === 0) && (j % 2 === 0)) {
+ Crafty.e("2D, DOM, solid, bush1")
+ .attr({x:i * 16, y:j * 16, z:2000})
+ }
+
+ //create a fence of bushes
+ if (i === 0 || i === 24 || j === 0 || j === 20)
+ Crafty.e("2D, DOM, solid, bush" + Crafty.math.randomInt(1, 2))
+ .attr({ x:i * 16, y:j * 16, z:2 });
+
+ //generate some nice flowers within the boundaries of the outer bushes
+ if (i > 0 && i < 24 && j > 0 && j < 20
+ && Crafty.math.randomInt(0, 50) > 30
+ && !(i === 1 && j >= 16)
+ && !(i === 23 && j <= 4)) {
+ var f = Crafty.e("2D, DOM, flower, Collision, solid, SpriteAnimation, explodable")
+ .attr({ x:i * 16, y:j * 16, z:1000 })
+ .animate("wind", 0, 1, 3)
+ .animate('wind', 80, -1)
+ .bind('explode', function () {
+ this.destroy();
+ })
+ .collision();
+ if (f.hit('solid')) {
+ f.destroy();
+ }
+ }
+ }
+ }
+ }
+
+ Crafty.c('BombDropper', {
+ _dropped:0,
+ maxBombs:2,
+ _key:Crafty.keys.SPACE,
+
+ init:function () {
+ var dropper = this;
+ this.requires('Grid')
+
+ //Create the bomb
+ .bind('KeyDown', function (e) {
+ if (e.key !== this._key) {
+ return;
+ }
+
+ if (this._dropped < this.maxBombs) {
+ Crafty.e('BananaBomb')
+ .attr({z:100})
+ .col(this.col())
+ .row(this.row())
+ .BananaBomb()
+ .bind('explode', function () {
+ dropper._dropped--;
+ });
+
+ this._dropped++;
+ }
+ });
+ },
+ bombDropper:function (key) {
+ this._key = key;
+ return this;
+ }
+ });
+
+ Crafty.c('BananaBomb', {
+
+ init:function () {
+ this.requires("2D, DOM, SpriteAnimation, Grid, banana, explodable, Delay")
+ .animate('explode', 4, 0, 5)
+ .animate('explode', 50, -1)
+ .delay(function () {
+ this.trigger("explode");
+ }, 4000);
+ this.bind('explode', function () {
+ this.destroy();
+
+ //Create fire from the explosion
+ for (var i = this.col() - 2; i < this.col() + 3; i++)
+ Crafty.e("BananaFire").attr({ z:9000 }).col(i).row(this.row())
+ for (var i = this.row() - 2; i < this.row() + 3; i++)
+ Crafty.e("BananaFire").attr({ z:9000 }).col(this.col()).row(i)
+ });
+ },
+
+ BananaBomb:function () {
+ //Create shadow fire to help the AI
+ for (var i = this.col() - 2; i < this.col() + 3; i++)
+ Crafty.e("ShadowBananaFire").attr({ z:9000 }).col(i).row(this.row())
+ for (var i = this.row() - 2; i < this.row() + 3; i++)
+ Crafty.e("ShadowBananaFire").attr({ z:9000 }).col(this.col()).row(i)
+ return this;
+ }
+ });
+
+ Crafty.c('BananaFire', {
+
+ init:function () {
+ this.requires("2D, DOM, SpriteAnimation, banana, Grid, Collision, fire, Delay")
+ .animate('fire', 4, 0, 5)
+ .animate('fire', 10, -1)
+ .collision()
+ .onHit('explodable', function (o) {
+ for (var i = 0; i < o.length; i++) {
+ o[i].obj.trigger("explode");
+ }
+ })
+ .delay(function () {
+ this.destroy();
+ }, 2000);
+ }
+ });
+
+ // Helps the AI avoid unsafe tiles. Created when a bomb is dropped and removed after fire is gone
+ Crafty.c('ShadowBananaFire', {
+
+ init:function () {
+ this.requires("2D, Grid, empty, Collision, ShadowFire, Delay")
+ .collision()
+ .delay(function () {
+ this.destroy();
+ }, 6100);
+ }
+ });
+
+ Crafty.c('Grid', {
+ _cellSize:16,
+ Grid:function (cellSize) {
+ if (cellSize) this._cellSize = cellSize;
+ return this;
+ },
+ col:function (col) {
+ if (arguments.length === 1) {
+ this.x = this._cellSize * col;
+ return this;
+ } else {
+ return Math.round(this.x / this._cellSize);
+ }
+ },
+ row:function (row) {
+ if (arguments.length === 1) {
+ this.y = this._cellSize * row;
+ return this;
+ } else {
+ return Math.round(this.y / this._cellSize);
+ }
+ },
+ snap:function () {
+ this.x = Math.round(this.x / this._cellSize) * this._cellSize;
+ this.y = Math.round(this.y / this._cellSize) * this._cellSize;
+ }
+ });
+
+ Crafty.c('AIControls', {
+ _move:'down',
+ _directions:{0:'left', 1:'right', 2:'up', 3:'down'},
+ _speed:3,
+ _inShadow:false,
+
+ AIControls:function (speed) {
+ if (speed) this._speed = speed;
+
+ //functions to determine if there is a free path in some direction
+ var AIScope = this;
+ var pathTester = Crafty.e('2D, empty, Collision').attr({z:30000}).collision();
+ var PathTest = {
+ left:function () {
+ pathTester.attr({x:AIScope.x - AIScope._speed, y:AIScope.y});
+ return !(pathTester.hit('solid') || (!AIScope._inShadow && pathTester.hit('ShadowBananaFire')));
+ },
+ right:function () {
+ pathTester.attr({x:AIScope.x + AIScope._speed, y:AIScope.y});
+ return !(pathTester.hit('solid') || (!AIScope._inShadow && pathTester.hit('ShadowBananaFire')));
+ },
+ up:function () {
+ pathTester.attr({x:AIScope.x, y:AIScope.y - AIScope._speed});
+ return !(pathTester.hit('solid') || (!AIScope._inShadow && pathTester.hit('ShadowBananaFire')));
+ },
+ down:function () {
+ pathTester.attr({x:AIScope.x, y:AIScope.y + AIScope._speed});
+ return !(pathTester.hit('solid') || (!AIScope._inShadow && pathTester.hit('ShadowBananaFire')));
+ },
+ none:function () {
+ return false;
+ }
+ };
+
+ function bombWillHit() {
+ pathTester.attr({x:AIScope.x - 1, y:AIScope.y});
+ if (pathTester.hit('flower')) {
+ return true;
+ }
+ pathTester.attr({x:AIScope.x + 1, y:AIScope.y});
+ if (pathTester.hit('flower')) {
+ return true;
+ }
+ pathTester.attr({x:AIScope.x, y:AIScope.y - 1});
+ if (pathTester.hit('flower')) {
+ return true;
+ }
+ pathTester.attr({x:AIScope.x, y:AIScope.y + 1});
+ if (pathTester.hit('flower')) {
+ return true;
+ }
+ return false;
+ }
+
+ this.bind('enterframe', function () {
+ var nextDirection = '';
+ if (PathTest[this._move]()) {
+ nextDirection = this._move;
+
+ //when we are at a crossroad interesting things can happen
+ if (this.x % 16 < this._speed && this.y % 16 < this._speed) {
+ //change direction
+ if (Crafty.randRange(0, 2) === 0) {
+ if (nextDirection === 'down' || nextDirection === 'up') {
+ if (PathTest.left()) {
+ nextDirection = 'left'
+ }
+ else if (PathTest.right()) {
+ nextDirection = 'right'
+ }
+ } else {
+ if (PathTest.up()) {
+ nextDirection = 'up'
+ }
+ else if (PathTest.down()) {
+ nextDirection = 'down'
+ }
+ }
+ }
+ if (bombWillHit() &&
+ !this._inShadow) {
+ this.trigger('Dropped');
+ }
+ }
+ } else {
+ this.snap();
+ nextDirection = this._directions[Crafty.randRange(0, 3)];
+ if (nextDirection === this._move) {
+ nextDirection = "none"; //we need to think
+ }
+
+ }
+ this._move = nextDirection;
+
+ if (PathTest[this._move]()) {
+ if (this._move == "right") this.x += this._speed;
+ else if (this._move == "left") this.x -= this._speed;
+ else if (this._move == "up") this.y -= this._speed;
+ else if (this._move == "down") this.y += this._speed;
+ }
+ })
+ .onHit("ShadowBananaFire", function () {
+ this._inShadow = true;
+ }, function () {
+ this._inShadow = false;
+ });
+
+ return this;
+ }
+ });
+
+ Crafty.c('Ape', {
+ Ape:function () {
+ //setup animations
+ this.requires("SpriteAnimation, Collision")
+ .animate("walk_left", 6, 3, 8)
+ .animate("walk_right", 9, 3, 11)
+ .animate("walk_up", 3, 3, 5)
+ .animate("walk_down", 0, 3, 2)
+ //change direction when a direction change event is received
+ .bind("NewDirection",
+ function (direction) {
+ if (direction.x < 0) {
+ if (!this.isPlaying("walk_left"))
+ this.stop().animate("walk_left", 10, -1);
+ }
+ if (direction.x > 0) {
+ if (!this.isPlaying("walk_right"))
+ this.stop().animate("walk_right", 10, -1);
+ }
+ if (direction.y < 0) {
+ if (!this.isPlaying("walk_up"))
+ this.stop().animate("walk_up", 10, -1);
+ }
+ if (direction.y > 0) {
+ if (!this.isPlaying("walk_down"))
+ this.stop().animate("walk_down", 10, -1);
+ }
+ if (!direction.x && !direction.y) {
+ this.stop();
+ }
+ })
+ // A rudimentary way to prevent the user from passing solid areas
+ .bind('Moved',
+ function (from) {
+ if (this.hit('solid')) {
+ this.attr({x:from.x, y:from.y});
+ }
+ }).onHit("fire", function () {
+ this.destroy();
+ });
+ return this;
+ }
+ });
+
+ Crafty.c("RightControls", {
+ init:function () {
+ this.requires('Multiway');
+ },
+
+ rightControls:function (speed) {
+ this.multiway(speed, {UP_ARROW:-90, DOWN_ARROW:90, RIGHT_ARROW:0, LEFT_ARROW:180})
+ return this;
+ }
+
+ });
+
+ Crafty.c("LeftControls", {
+ init:function () {
+ this.requires('Multiway');
+ },
+
+ leftControls:function (speed) {
+ this.multiway(speed, {W:-90, S:90, D:0, A:180})
+ return this;
+ }
+
+ });
+
+ //SCENES
+
+ //the loading screen that will display while our assets load
+ Crafty.scene("loading", function () {
+ //load takes an array of assets and a callback when complete
+ Crafty.load(["images/sprites.png"], function () {
+ Crafty.scene("main"); //when everything is loaded, run the main scene
+ });
+
+ //black background with some loading text
+ Crafty.background("#000");
+ Crafty.e("2D, DOM, Text").attr({ w:100, h:20, x:150, y:120 })
+ .text("Loading")
+ .css({ "text-align":"center", "color":"white" });
+ });
+
+ Crafty.scene("main", function () {
+ generateWorld();
+
+ //create our player entity with some premade components
+ var player1 = Crafty.e("2D, DOM, Ape, player, LeftControls, BombDropper")
+ .attr({ x:16, y:304, z:1 })
+ .leftControls(1)
+ .Ape();
+
+ var player2 = Crafty.e("2D, DOM, Ape, player, RightControls, SpriteAnimation, Collision, BombDropper, Grid")
+ .attr({ x:368, y:16, z:1 })
+ .rightControls(1)
+ .bombDropper(Crafty.keys.ENTER)
+ .Ape();
+
+ });
+
+
+ //automatically play the loading scene
+ Crafty.scene("loading");
+});
170 js/ludum.js
@@ -0,0 +1,170 @@
+/**
+ * Created with JetBrains RubyMine.
+ * User: gotosleep
+ * Date: 4/21/12
+ * Time: 11:10 AM
+ * To change this template use File | Settings | File Templates.
+ */
+
+$(document).ready(function () {
+ //start crafty
+
+ var config = {
+ width:600,
+ height:400,
+ maxRight:300,
+ maxLeft:50
+ }
+
+ Crafty.init(config.width, config.height);
+
+ //turn the sprite map into usable components
+ Crafty.sprite(128, "images/robot.png", {
+ robot:[0, 0]
+ });
+
+ Crafty.sprite(16, "images/ground.png", {
+ grass1:[0, 0],
+ grass2:[1, 0],
+ dirt1:[2, 0],
+ dirt2:[3, 0]
+ });
+
+ Crafty.sprite(32, "images/building.png", {
+ building1L:[0, 0],
+ building1R:[1, 0],
+ building1TL:[2, 0],
+ building1TR:[3, 0],
+ building1T:[4, 0],
+ building1C:[5, 0]
+ });
+
+ Crafty.c('Attached', {
+ init:function () {
+ this.bind('WorldMoved', function (movement) {
+ this.attr({x:this.x - movement.x});
+ if (this.x + this.w <= 0) {
+ this.destroy();
+ }
+ });
+ }
+ });
+
+ Crafty.c('Generator', {
+ groundProgress:0,
+ buildingProgress:0,
+ init:function () {
+ this.bind('WorldMoved', function (movement) {
+ this.groundProgress -= movement.x;
+ this.buildingProgress -= movement.x;
+ this.ground(config.width);
+ this.building1();
+ });
+ },
+ ground:function (x) {
+ while (this.groundProgress < x) {
+ var type = Crafty.math.randomInt(1, 2) % 2 == 0 ? "grass" : "dirt";
+ type += Crafty.math.randomInt(1, 2);
+ Crafty.e("2D, DOM, solid, Attached, " + type)
+ .attr({ 'x':this.groundProgress, y:config.height - 16, z:1 });
+ this.groundProgress += 16;
+ }
+ },
+ building1Height: 32,
+ building1:function () {
+
+ if (this.buildingProgress < config.width) {
+ var width = Crafty.math.randomInt(2, 6);
+ if (Crafty.math.randomInt(1, 4) % 4 == 0) {
+ var height = Crafty.math.randomInt(2, 6);
+ var placement = config.height - 16 - (this.building1Height * height);
+ var z = Crafty.math.randomInt(1, 2);
+
+ for (var x = 0; x < width; ++x) {
+ for (var y = 0; y < height; ++y) {
+ var type;
+ if (x === 0) {
+ type = y === 0 ? "building1TL" : "building1L";
+ } else if (x === width - 1) {
+ type = y === 0 ? "building1TR" : "building1R";
+ } else {
+ type = y === 0 ? "building1T" : "building1C";
+ }
+
+ Crafty.e("2D, DOM, Attached, " + type)
+ .attr({ 'x':config.width + (x * this.building1Height), y:placement + (this.building1Height * y), 'z': z});
+ }
+ }
+ }
+ this.buildingProgress = config.width + (width * this.building1Height) + 16;
+ }
+ }
+ });
+
+ Crafty.c('Ape', {
+ Ape:function () {
+ // A rudimentary way to prevent the user from passing solid areas
+ this.bind('Moved',
+ function (from) {
+ if (this.hit('solid')) {
+ this.attr({x:from.x, y:from.y});
+ } else if (this.x > config.maxRight) {
+ Crafty.trigger("WorldMoved", {'x':this.x - from.x, 'y':this.y - from.y});
+ this.attr({x:config.maxRight});
+ } else if (this.x < config.maxLeft) {
+ this.attr({x:config.maxLeft});
+ }
+
+ }).onHit("fire", function () {
+ this.destroy();
+ });
+ return this;
+ }
+ });
+
+
+ Crafty.c("RightControls", {
+ init:function () {
+ this.requires('Multiway');
+ },
+
+ rightControls:function (speed) {
+ this.multiway(speed, {UP_ARROW:-90, DOWN_ARROW:90, RIGHT_ARROW:0, LEFT_ARROW:180})
+ return this;
+ }
+
+ });
+
+ //SCENES
+
+ //the loading screen that will display while our assets load
+ Crafty.scene("loading", function () {
+ //load takes an array of assets and a callback when complete
+ Crafty.load(["images/robot.png", "images/ground.png", "images/building.png"], function () {
+ Crafty.scene("main"); //when everything is loaded, run the main scene
+ });
+
+ //black background with some loading text
+ Crafty.background("#000");
+ Crafty.e("2D, DOM, Text").attr({ w:100, h:20, x:150, y:120 })
+ .text("Loading")
+ .css({ "text-align":"center", "color":"white" });
+ });
+
+ Crafty.scene("main", function () {
+
+ var Generator = Crafty.e("Generator");
+ Generator.ground(config.width);
+ Crafty.background("#FFF");
+
+ var player = Crafty.e("2D, DOM, Ape, robot, RightControls, SpriteAnimation, Collision, BombDropper, Grid")
+ .attr({ x:150, y:150, z:2 })
+ .rightControls(4)
+ .Ape();
+
+ });
+
+ //automatically play the loading scene
+ Crafty.scene("loading");
+
+});

0 comments on commit c14255b

Please sign in to comment.
Something went wrong with that request. Please try again.