Skip to content

Commit

Permalink
Physics working again!
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrch committed Aug 5, 2014
1 parent 4c39611 commit a17e81b
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .c9/metadata/tab23
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"filter":false,"title":"index.html - Stopped","tooltip":"index.html - Stopped","undoManager":{"mark":0,"position":-1,"stack":[]},"output":{"id":"output752485","width":1328,"height":131,"scrollTop":3622,"config":{"runner":"Apache httpd (PHP, HTML)","command":"index.html","debug":true,"name":""}},"timestamp":1407190075808,"hash":"da39a3ee5e6b4b0d3255bfef95601890afd80709"}
{"filter":false,"title":"index.html - Stopped","tooltip":"index.html - Stopped","undoManager":{"mark":0,"position":-1,"stack":[]},"output":{"id":"output752485","width":0,"height":0,"scrollTop":8812,"config":{"runner":"Apache httpd (PHP, HTML)","command":"index.html","debug":true,"name":""}},"timestamp":1407190075808,"hash":"da39a3ee5e6b4b0d3255bfef95601890afd80709"}
2 changes: 1 addition & 1 deletion .c9/metadata/tab36
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"filter":false,"title":"Terminal","undoManager":{"mark":0,"position":-1,"stack":[]},"terminal":{"id":"cdrch@gbjam3-game_193","cwd":"","width":1328,"height":131,"scrollTop":580},"timestamp":1407224015723,"hash":"da39a3ee5e6b4b0d3255bfef95601890afd80709"}
{"filter":false,"title":"Terminal","undoManager":{"mark":0,"position":-1,"stack":[]},"terminal":{"id":"cdrch@gbjam3-game_193","cwd":"","width":1300,"height":131,"scrollTop":1780},"timestamp":1407224015723,"hash":"da39a3ee5e6b4b0d3255bfef95601890afd80709"}
2 changes: 1 addition & 1 deletion .c9/metadata/workspace/Game.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .c9/metadata/workspace/Preloader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .c9/metadata/workspace/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"filter":false,"title":"index.html","tooltip":"/index.html","undoManager":{"mark":-1,"position":-1,"stack":[]},"ace":{"folds":[],"scrolltop":0,"scrollleft":0,"selection":{"start":{"row":29,"column":26},"end":{"row":29,"column":26},"isBackwards":false},"options":{"guessTabSize":true,"useWrapMode":false,"wrapToView":true},"firstLineState":0},"timestamp":1407182950374,"hash":"c109121db869f605d3ef256ab0980fbee91c3753"}
{"filter":false,"title":"index.html","tooltip":"/index.html","undoManager":{"mark":-1,"position":-1,"stack":[]},"ace":{"folds":[],"scrolltop":0,"scrollleft":0,"selection":{"start":{"row":29,"column":26},"end":{"row":29,"column":26},"isBackwards":false},"options":{"guessTabSize":true,"useWrapMode":false,"wrapToView":true},"firstLineState":{"row":7,"state":"start","mode":"ace/mode/html"}},"timestamp":1407182950374,"hash":"c109121db869f605d3ef256ab0980fbee91c3753"}
182 changes: 108 additions & 74 deletions Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ BasicGame.Game = function (game) {

// Global Variables
var map;
var layer_back3;
var layer_back2;
var layer_back1;
var layer_mid;
var layer_fore1;
var layer_fore2;
var layer_fore3;

var player;
var collision_layer;
var foreground_layer;

var fG;

// var p;
var cursors;

// Global Statics
Expand All @@ -48,91 +45,128 @@ BasicGame.Game.prototype = {

this.sea = this.add.tileSprite(0, 0, 1024, 768, 'sea');

this.physics.startSystem(Phaser.Physics.ARCADE);
this.physics.startSystem(Phaser.Physics.ARCADE);

this.stage.backgroundColor = '#787878';

map = this.add.tilemap('layertest2');

map.addTilesetImage('gbjam3-game-tile-atlas-1', 'tile-atlas-1');

this.stage.backgroundColor = '#787878';
// setCollision, or setCollisionBetween for ranges of tiles
// map.setCollision(2);
// map.setCollision(3);
// map.setCollision(4);
// map.setCollisionBetween(0,255);
// map.setCollisionBetween(4, 11);
// map.setCollisionBetween(36, 40);
// map.setCollisionBetween(68, 71);

map = this.add.tilemap('level1');
map.setCollisionBetween(4, 11);
map.setCollisionBetween(36, 40);
map.setCollisionBetween(68, 71);
collision_layer = map.createLayer('Tile Layer 1');
this.player = this.add.sprite(16, 650, 'player');

// Un-comment this on to see the collision tiles
// collision_layer.debug = true;

collision_layer.resizeWorld();

map.addTilesetImage('gbjam3-game-tile-atlas-1', 'tile-atlas-1');

// setCollision, or setCollisionBetween for ranges of tiles
// map.setCollision(2);
// map.setCollision(3);
// map.setCollision(4);
map.setCollisionBetween(0,255);
map.setCollisionBetween(4, 11);
map.setCollisionBetween(36, 40);
map.setCollisionBetween(68, 71);

layer_back3 = map.createLayer('Background3');
layer_back2 = map.createLayer('Background2');
layer_back1 = map.createLayer('Background1');
layer_mid = map.createLayer('Middleground');
layer_fore1 = map.createLayer('Foreground1');
layer_fore2 = map.createLayer('Foreground2');
layer_fore3 = map.createLayer('Foreground3');

// layer_col = map.createLayer('Collision');

// layer_fore = map.createLayer('Foreground');

// Un-comment this on to see the collision tiles
layer_mid.debug = true;
this.game.physics.enable(this.player);

layer_mid.resizeWorld();
player = this.add.sprite(16, 650, 'player');
this.physics.enable(player);
this.physics.arcade.gravity.y = 250;
this.physics.arcade.gravity.y = 250;

this.player.body.bounce.y = 0.2;
this.player.body.linearDamping = 1;
this.player.body.collideWorldBounds = true;

this.camera.follow(this.player);

player.body.bounce.y = 0.2;
player.body.linearDamping = 1;
player.body.collideWorldBounds = true;
this.game.physics.enable(this.player);

this.camera.follow(player);
this.physics.arcade.gravity.y = 250;

this.player.body.bounce.y = 0.2;
this.player.body.linearDamping = 1;
this.player.body.collideWorldBounds = true;

cursors = this.input.keyboard.createCursorKeys();

this.foeGroup = this.add.group();



this.foeGroup.enableBody = true;
this.foeGroup.physicsBodyType = Phaser.Physics.ARCADE;

// The foreground tile laye
foreground_layer = map.createLayer('Tile Layer 2');

for (var i = 0; i < 16; i++)
{
// This creates a new Phaser.Sprite instance within the group
// It will be randomly placed within the world and use the 'baddie' image to display
var x = this.foeGroup.create(10 + i * 20, 560, 'player');
x.body.gravity.y = 200;
x.body.collideWorldBounds = true;
}

fG = this.foeGroup;

cursors = this.input.keyboard.createCursorKeys();

},

update: function () {

// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!

//this.sea.y += 2;
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
//this.sea.y += 2;

this.physics.arcade.collide(player, layer_mid);

player.body.velocity.x = 0;

if (cursors.up.isDown)
{
if (player.body.onFloor())
{
player.body.velocity.y = -200;
}
}

if (cursors.left.isDown)
{
player.body.velocity.x = -150;
}
else if (cursors.right.isDown)
{
player.body.velocity.x = 150;
}

//map.setTileIndexCallback(2, this.justChecking, this);


this.game.physics.arcade.collide(this.player, collision_layer);
this.game.physics.arcade.collide(this.foeGroup, collision_layer);
this.game.physics.arcade.collide(this.player, this.foeGroup);
this.game.physics.arcade.collide(this.foeGroup, this.foeGroup);

this.player.body.velocity.x = 0;

if (cursors.up.isDown)
{
if (this.player.body.onFloor())
{
this.player.body.velocity.y = -200;
}
}

if (cursors.left.isDown)
{
this.player.body.velocity.x = -150;
}
else if (cursors.right.isDown)
{
this.player.body.velocity.x = 150;
}

//map.setTileIndexCallback(2, this.quitGame, this);

},

CollisionD: function(obj1, obj2) {

alert('collision!');
this.state.start('MainMenu');

},

render: function () {

// Every loop we need to render the un-scaled game canvas to the displayed scaled canvas:
BasicGame.pixel.context.drawImage(this.game.canvas, 0, 0, this.game.width, this.game.height, 0, 0, BasicGame.pixel.width, BasicGame.pixel.height);
// this.debug.bodyInfo(p, 32, 120);
this.game.debug.body(this.player);
BasicGame.pixel.context.drawImage(this.game.canvas, 0, 0, this.game.width, this.game.height, 0, 0, BasicGame.pixel.width, BasicGame.pixel.height);

},

Expand Down
3 changes: 3 additions & 0 deletions Preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ BasicGame.Preloader.prototype = {
this.load.tilemap('testlevel1', 'assets/testingmap3.json', null, Phaser.Tilemap.TILED_JSON);
this.load.image('tiles1', 'assets/4-color-tileset.png');
this.load.image('player', 'assets/checkerplayer.png');
this.load.tilemap('layertest1', 'assets/layertest1.json', null, Phaser.Tilemap.TILED_JSON);
this.load.tilemap('layertest2', 'assets/layertest2.json', null, Phaser.Tilemap.TILED_JSON);
this.load.tilemap('layertest3', 'assets/layertest3.json', null, Phaser.Tilemap.TILED_JSON);

this.load.tilemap('level1', 'assets/level1.json', null, Phaser.Tilemap.TILED_JSON);
this.load.image('tile-atlas-1', 'assets/gbjam3-game-tile-atlas-1.png');
Expand Down

0 comments on commit a17e81b

Please sign in to comment.