Skip to content

Commit

Permalink
Merge branch 'improves' of github.com:dblaichinger/LastPlant into imp…
Browse files Browse the repository at this point in the history
…roves
  • Loading branch information
Daniel Blaichinger committed Jan 25, 2011
2 parents 64794cd + 0ab0f29 commit e308d6c
Show file tree
Hide file tree
Showing 85 changed files with 3,961 additions and 159 deletions.
10 changes: 3 additions & 7 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,36 @@
<li class="left"><%= link_to "Home", current_user %></li>
<% end %>
<li class="slash">/</li>
<% if(request.fullpath == '/protect') %>
<li><%= link_to "Protect", protect_path, :class => 'highlight_link' %></li>
<% else %>
<li><%= link_to "Protect", protect_path %></li>
<% end %>
<li class="slash">/</li>
<% if(request.fullpath == '/destroy') %>
<li><%= link_to "Destroy", destroy_path,:class => 'highlight_link' %></li>
<% else %>
<li><%= link_to "Destroy", destroy_path %></li>
<% end %>
<li class="slash">/</li>
<% if(request.fullpath == '/users') %>
<li><%= link_to "Users", users_path, :class => 'highlight_link' %></li>
<% else %>
<li><%= link_to "Users", users_path %></li>
<% end %>
<li class="slash">/</li>
<% if(request.fullpath == '/users/'+ current_user[:id].to_s + '/edit') %>
<li><%= link_to "Settings", edit_user_path(current_user), :class => 'highlight_link' %></li>
<% else %>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<% end %>
<li class="abstand"><%= link_to "Logout", signout_path, :method => :delete %></li>

<li class="right"><%= link_to "Logout", signout_path, :method => :delete %></li>
<% if(request.fullpath =='/imprint') %>
<li><%= link_to "Imprint", imprint_path, :class => 'highlight_link'%></li>
<%else %>
<li><%= link_to "Imprint", imprint_path %></li>
<li class="right"><%= link_to "Imprint", imprint_path %></li>
<% end %>

</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ Engine.initObject("MouseInputComponent", "InputComponent", function() {
});
});

ctx.addEvent(null, "mousedown", function(evt) {
ctx.addEvent(LastPlant.renderContext, "mousedown", function(evt) {
var mouseInfo = Engine.getDefaultContext().MouseInputComponent_mouseInfo;
mouseInfo.button = evt.which;
mouseInfo.downPosition.set(evt.pageX, evt.pageY);
evt.preventDefault();
//evt.preventDefault();
});

ctx.addEvent(null, "mouseup", function(evt) {
Expand Down
Binary file added public/javascripts/renderengine/css/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions public/javascripts/renderengine/css/engine.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

body {
overflow: hidden;
margin: 0;
font: 10pt Arial;
}

div.metrics {
position: fixed;
top: 10px;
width: 200px;
right: 10px;
border: 1px solid black;
background: white;
padding: 2px;
font: 10px Arial, Helvetica;
z-index: 10000;
}

div.metrics .items {
clear: both;
position: relative;
width: 200px;
background: ghostwhite;
}

div.metric-button {
background-color: silver;
width: 15px;
height: 15px;
border: 1px outset white;
float: left;
margin-right: 3px;
}

div.metric-button.close,
div.metric-button.minimize,
div.metric-button.maximize {
float: right;
}

.run {
background: url('$<enginePath>/css/run.png') no-repeat;
}

.pause {
background: url('$<enginePath>/css/pause.png') no-repeat;
}

.shutdown {
background: url('$<enginePath>/css/shutdown.png') no-repeat;
}

.minimize {
background: url('$<enginePath>/css/minimize.png') no-repeat;
}

.maximize {
background: url('$<enginePath>/css/maximize.png') no-repeat;
}

.close {
background: url('$<enginePath>/css/close.png') no-repeat;
}

canvas.engine-profile {
position: fixed;
bottom: 10px;
width: 150px;
height: 100px;
left: 10px;
border: 1px solid white;
background: black;
z-index: 10000;
}

Binary file added public/javascripts/renderengine/css/maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/javascripts/renderengine/css/minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/javascripts/renderengine/css/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/javascripts/renderengine/css/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/javascripts/renderengine/css/shutdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ Engine.initObject("Background", "Object2D", function() {
this.setPosition(Point2D.create(0, 0));
},

setBGtoGameOver: function() {
this.getComponent("draw").setSprite(LastPlant.spriteLoader.getSprite("Background", "BackgroundGameOver"));
},
}, /** @scope Background.prototype */{ // Static
/**
* Get the class name of this object
* @return {String} The string <tt>Background</tt>
*/
getClassName: function() {
return "Background";
}
}

});

Expand Down
81 changes: 74 additions & 7 deletions public/javascripts/renderengine/lastplantgame/buildergame/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Engine.initObject("Block", "LPObject", function() {
var Block = LPObject.extend(/** @scope Block.prototype */{

boxSize: null,
isClicked: null,
wasOverLeftBorder: null,
rotateDirection: null,

/**
* @private
Expand All @@ -51,6 +54,9 @@ Engine.initObject("Block", "LPObject", function() {
this.base("Block-square", "Block-square", "Block-squareOver");

this.isPlaced=false;
this.isClicked=false;
this.wasOverLeftBorder=false;
this.rotateDirection=0;
},

/**
Expand All @@ -71,15 +77,74 @@ Engine.initObject("Block", "LPObject", function() {

// Set the friction, bounciness and density of the Block
// Mass depends on objects size
this.getComponent(componentName).setFriction(1);
this.getComponent(componentName).setRestitution(-1);
this.getComponent(componentName).setDensity(10);
this.getComponent(componentName).setFriction(0.7);
this.getComponent(componentName).setRestitution(0);

if(this.LPOType=="Block-long")
this.getComponent(componentName).setDensity(20);
else if(this.LPOType=="Block-square")
this.getComponent(componentName).setDensity(10);
},

clicked: function(p) {
//called every frame
update: function(renderContext, time){
renderContext.pushTransform();
this.base(renderContext, time);
renderContext.popTransform()

if(this.wasOverLeftBorder==false)
if(this.getPosition().get().x > 162)
this.wasOverLeftBorder=true;

if(this.isClicked==true){
var cursorPosition = LastPlant.getPlayer().getPosition();
var newBlockPos= cursorPosition;
if(cursorPosition.get().x > LastPlant.fieldWidth-140)
newBlockPos.setX(LastPlant.fieldWidth-140);
if(this.wasOverLeftBorder==true){
if(cursorPosition.get().x < 162)
newBlockPos.setX(162);
}else{
if(cursorPosition.get().x < 5){
newBlockPos.setX(5);
}
}

if(cursorPosition.get().y < 5)
newBlockPos.setY(5);
if(cursorPosition.get().y > LastPlant.fieldHeight-5)
newBlockPos.setY(LastPlant.fieldHeight);

//this.startsim();
this.setPosition(newBlockPos);
//this.stopsim();
}
if(this.rotateDirection==1)
this.rotateCW();
else if(this.rotateDirection==2)
this.rotateCCW();

},
setRotateDirection: function(direction) {
this.rotateDirection=direction;
},

rotateCW: function(p) {
this.getComponent("physics").setRotation( this.getRot()*0.017453292519943+0.034906585039887 );
this.startsim();
this.stopsim();
},
rotateCCW: function(p) {
this.getComponent("physics").setRotation( this.getRot()*0.017453292519943-0.034906585039887 );
this.startsim();
this.stopsim();
},

clicked: function(cursorPosition) {
if(this.isPlaced==false){
this.stopsim();
this.setPosition(p);
this.isClicked=true;
// this.startsim();
// this.setPosition(cursorPosition);
// this.stopsim();
}

},
Expand All @@ -90,6 +155,7 @@ Engine.initObject("Block", "LPObject", function() {
released: function(p) {
if(this.isPlaced==false){
this.isPlaced=true;
this.isClicked=false;
this.remove(this.Collider);
this.setSprite(0);
LastPlant.createLPObject(this);
Expand All @@ -113,6 +179,7 @@ Engine.initObject("Block", "LPObject", function() {
}
},


}, /** @scope Block.prototype */{ // Static

/**
Expand Down
64 changes: 57 additions & 7 deletions public/javascripts/renderengine/lastplantgame/buildergame/Plant.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Engine.initObject("Plant", "LPObject", function() {
*/
var Plant = LPObject.extend(/** @scope Plant.prototype */{

boxSize: null,
boxSize: null,
isClicked: null,
wasOverLeftBorder: null,
canBeSaved: true,

/**
Expand All @@ -48,6 +50,9 @@ Engine.initObject("Plant", "LPObject", function() {
this.base("Plant", "Plant", "PlantOver");
this.isPlaced=false;
this.LPOType="Plant";
this.canBeSaved=true;
this.isClicked=false;
this.wasOverLeftBorder=false;
},

/**
Expand All @@ -74,7 +79,38 @@ Engine.initObject("Plant", "LPObject", function() {
renderContext.pushTransform();
this.base(renderContext, time);
renderContext.popTransform();

if(this.wasOverLeftBorder==false)
if(this.getPosition().get().x > 162)
this.wasOverLeftBorder=true;
// Don't let Plant out of the Canvas
if(this.isClicked==true){
var cursorPosition = LastPlant.getPlayer().getPosition();
var newBlockPos= cursorPosition;
if(cursorPosition.get().x > LastPlant.fieldWidth-140)
newBlockPos.setX(LastPlant.fieldWidth-140);
if(this.wasOverLeftBorder==true){
if(cursorPosition.get().x < 162)
newBlockPos.setX(162);
}else{
if(cursorPosition.get().x < 5){
newBlockPos.setX(5);
}
}

if(cursorPosition.get().y < 5)
newBlockPos.setY(5);
if(cursorPosition.get().y > LastPlant.fieldHeight-5)
newBlockPos.setY(LastPlant.fieldHeight);

//this.startsim();
this.setPosition(newBlockPos);
//this.stopsim();
}
if(this.rotateDirection==1)
this.rotateCW();
else if(this.rotateDirection==2)
this.rotateCCW();

if(this.isPlaced==true && this.getComponent("physics").isSleeping()==true && this.canBeSaved==true){
this.canBeSaved=false;
Timeout.create("SaveTimer", 1000, function() {
Expand All @@ -86,9 +122,15 @@ Engine.initObject("Plant", "LPObject", function() {

clicked: function(p) {
if(this.isPlaced==false){
this.isClicked=true;
// this.startsim();
// this.setPosition(cursorPosition);
// this.stopsim();
}
/*if(this.isPlaced==false){
this.stopsim();
this.setPosition(p);
}
}*/
},

/**
Expand All @@ -97,17 +139,20 @@ Engine.initObject("Plant", "LPObject", function() {
released: function(p) {
if(this.isPlaced==false){
this.isPlaced=true;
this.isClicked=false;
this.remove(this.Collider);
this.setSprite(0);
this.startsim();
LastPlant.showPlantWasSetText();
// Backup timer if the safe function isnt called via update
Timeout.create("SaveTimer", 10000, function() {
if(this.canBeSaved==true){
/*if(this.canBeSaved==true){
this.canBeSaved=false;
Timeout.create("BackupSaveTimer", 10000, function() {
console.log("inside BackupSaveTimer");
LastPlant.gameOver();
LastPlant.saveConstruct();
}
});
});
}*/

}
},
Expand All @@ -128,6 +173,11 @@ Engine.initObject("Plant", "LPObject", function() {
return ColliderComponent.CONTINUE;
}
},
getWorldBox: function() {
var pos=this.getComponent("physics").getPosition();
var bBox = Rectangle2D.create(pos.x,pos.y,21,66);
return bBox.offset(-bBox.getHalfWidth(), -bBox.getHalfHeight());;
},

}, /** @scope Plant.prototype */{ // Static

Expand Down
Loading

0 comments on commit e308d6c

Please sign in to comment.