Skip to content

Commit

Permalink
Merge pull request AtomicGameEngine#22 from rsredsq/RED-SPACEGAME-DPAD
Browse files Browse the repository at this point in the history
Added DPad in the SpaceGame
  • Loading branch information
JoshEngebretson committed Sep 30, 2015
2 parents 8253b5b + a23cf31 commit 15b8f86
Show file tree
Hide file tree
Showing 29 changed files with 265 additions and 25 deletions.
18 changes: 13 additions & 5 deletions PhysicsPlatformer/Resources/Modules/DPad.js
Expand Up @@ -3,13 +3,14 @@ function DPad() {
var width = Atomic.graphics.width;
var height = Atomic.graphics.height;
//create a new view for ours dpad
this.view = new Atomic.UIView();
//horizontal buttons sizeX, sizeY
var horizButtonsSize = [75, 61];
var verticButtonsSize = [61, 75];
//init function should be called adding vertical/horizontal buttons
//it's like we are commiting ours buttons
this.init = function() {
this.init = function(view) {
if (view) this.view = view;
else this.view = new Atomic.UIView();
//if touch buttons skin is not loaded
if(!DPad.skinLoaded) {
//load skin
Expand All @@ -19,6 +20,12 @@ function DPad() {
//create a dpad layout
this.dpad = new Atomic.UILayout();
this.dpad.rect = this.view.rect;
if(this.leftLayout)
this.leftLayout.rect = this.dpad.rect;
if(this.rightLayout)
this.rightLayout.rect = this.dpad.rect;
if(this.upDownLayout)
this.upDownLayout.rect = this.dpad.rect;
//sets dpad position
this.dpad.setPosition(-width/3, height/4);
//move buttons a bit closer to each other
Expand Down Expand Up @@ -48,15 +55,13 @@ function DPad() {
if(!this.layoutParamsLeftRight) this.initLeftRightLayoutParams();
//new layout for left button
this.leftLayout = new Atomic.UILayout();
this.leftLayout.rect = this.view.rect;
//create a left button
this.leftButton = new Atomic.UIButton();
this.leftButton.skinBg = "TouchButtonLeft";
this.leftButton.layoutParams = this.layoutParamsLeftRight;
this.leftLayout.addChild(this.leftButton);
//new layout for right button
this.rightLayout = new Atomic.UILayout();
this.rightLayout.rect = this.view.rect;
//create a right button
this.rightButton = new Atomic.UIButton();
this.rightButton.skinBg = "TouchButtonRight";
Expand All @@ -81,7 +86,6 @@ function DPad() {
if(!this.layoutParamsUpDown) this.initUpDownLayoutParams();
//create a new layout for up and down buttons
this.upDownLayout = new Atomic.UILayout();
this.upDownLayout.rect = this.view.rect;
this.upDownLayout.axis = Atomic.UI_AXIS_Y;
this.upDownLayout.spacing = 50;
//create an up buttons
Expand Down Expand Up @@ -153,6 +157,10 @@ function DPad() {
this.setPosition = function(x, y) {
this.view.setPosition(x, y);
}

this.remove = function() {
this.view.removeChild(this.dpad);
}
}

module.exports = DPad;
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/AI.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/AI.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "bd8cbe4bba850f8cf9af5a58df303008",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/Bullet.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/Bullet.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "078f1732d962b6672d6c478e48e93417",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/CapitalShip.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/CapitalShip.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "54caa665294949b3ad81810940577a9d",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/Enemy.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/Enemy.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "ac09ff19e260ab183bdccbbc00d65a4a",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/Explosion.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/Explosion.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "411d541f2b2f8f1976415cdeb827842e",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/HUD.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/HUD.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "632be57d8a025039d817b061aeb52119",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 2 additions & 0 deletions SpaceGame/Resources/Components/Player.js
@@ -1,3 +1,5 @@
'atomic component';

exports.component = function(self) {

var game = Atomic.game;
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/Player.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "96394b4b186f01cfcffea56473a9f485",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/SpaceBackground.js
@@ -1,4 +1,4 @@

'atomic component';

exports.component = function(self) {

Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/SpaceBackground.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "dbf1079dee807143996ec05b4fb782ca",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
53 changes: 52 additions & 1 deletion SpaceGame/Resources/Components/SpaceGame.js
@@ -1,3 +1,5 @@
'atomic component';

var UI = require("UI/ui");
var options = require("UI/options")

Expand Down Expand Up @@ -113,7 +115,13 @@ exports.component = function(self) {
}

self.cleanup = function() {

//if its a mobile
if(Atomic.platform == "Android" || Atomic.platform == "iOS") {
//remove dpad
Atomic.game.dpad.remove();
//remove fireButton
Atomic.game.uiView.removeChild(self.fireButton);
}
game.renderer.setViewport(1, null);

self.hud.cleanup();
Expand Down Expand Up @@ -194,6 +202,49 @@ exports.component = function(self) {

var hudnode = self.myscene.createChild();
self.hud = hudnode.createJSComponent("Components/HUD.js");
//if its a mobile
if(Atomic.platform == "Android" || Atomic.platform == "iOS") {
//require ours dpad module
var DPad = require("DPad");
//create dpad
var dpad = new DPad();
//add only horizontal buttons
dpad.addHorizontal();
//init with existing ui
dpad.init(Atomic.game.uiView);
//set X spacing
dpad.setSpacingX(50);

Atomic.game.dpad = dpad;

//create a jump button
self.fireButton = new Atomic.UIButton();
//unset its skin, because we will use UIImageWidget
self.fireButton.skinBg = "";
//create ours fire button image
var fireButtonImage = new Atomic.UIImageWidget();
//load image
fireButtonImage.setImage("UI/fireButton.png");
//resize ours image by 2.2x
var fireButtonWidth = fireButtonImage.imageWidth*2.2;
var fireButtonHeight = fireButtonImage.imageHeight*2.2;
//calculate position
var posX = Atomic.graphics.width - Atomic.graphics.width/8-fireButtonWidth/2;
var posY = Atomic.graphics.height - Atomic.graphics.height/4-fireButtonHeight/2;

//sets fireButton rect, specify position and end position
self.fireButton.rect = [posX, posY, posX+fireButtonWidth, posY+fireButtonHeight];
//sets fireButtonImage rect, we specify there only end position
fireButtonImage.rect = [0, 0, fireButtonWidth, fireButtonHeight];
//adds image to fireButton
self.fireButton.addChild(fireButtonImage);
//adds fireButton to the dpad view
dpad.view.addChild(self.fireButton);
//sets fireButton capturing to false, because we wanna make it multitouchable
self.fireButton.setCapturing(false);
//binds fireButton to KEY_SPACE
Atomic.input.bindButton(self.fireButton, Atomic.KEY_SPACE);
}

spawnPlayer();
spawnEnemies();
Expand Down
2 changes: 1 addition & 1 deletion SpaceGame/Resources/Components/SpaceGame.js.asset
Expand Up @@ -2,6 +2,6 @@
"version": 1,
"guid": "ecd3b3a804041f3427e4542ff71208c6",
"JavascriptImporter": {
"IsComponentFile": false
"IsComponentFile": true
}
}
1 change: 0 additions & 1 deletion SpaceGame/Resources/Components/TouchInput.js

This file was deleted.

7 changes: 0 additions & 7 deletions SpaceGame/Resources/Components/TouchInput.js.asset

This file was deleted.

0 comments on commit 15b8f86

Please sign in to comment.