Squaby Demo
import QtQuick 2.0
import Felgo 4.0
EntityBaseDraggable {
id: obstacle
property int column
property int row
entityType: "obstacle"
variationType: "teddy"
x: column*gridSize
y: row*gridSize
z: 1
width: sprite.width
height: sprite.height
colliderComponent: collider
colliderCategoriesWhileDragged: Box.Category4
colliderCollidesWithWhileDragged: Box.Category3
selectionMouseArea.width: sprite.width
selectionMouseArea.height: sprite.height
selectionMouseArea.x: -sprite.width/2
selectionMouseArea.y: -sprite.height/2
selectionMouseArea.enabled: !scene.itemEditor.visible && scene.state === "levelEditing" && variationType !== "closet" && variationType !== "bed" && variationType !== "closet-door1" && variationType !== "closet-door2"
opacityChangeItemWhileSelected: sprite
onEntityClicked: {
if(scene.state === "levelEditing") {
hud.entitySelected(obstacle);
}
}
property string spriteSource
Component.onCompleted: {
var type = variationType;
if(type==="bed") {
spriteSource = "bed.png";
obstacle.z = 1;
sprite.z = 1;
preventFromRemovalFromEntityManager = true
} else if (type==="closet"){
obstacle.z = 1;
sprite.z = 1;
spriteSource = "closet-main.png";
preventFromRemovalFromEntityManager = true
} else if (type==="closet-door1"){
spriteSource = "closet-door1.png";
preventFromRemovalFromEntityManager = true
} else if (type==="closet-door2"){
spriteSource = "closet-door2.png";
preventFromRemovalFromEntityManager = true
} else if (type==="choco"){
spriteSource = "choco-right.png";
} else if (type==="book"){
spriteSource = "book-left.png";
} else if (type==="pillow"){
spriteSource = "pillow.png";
} else if (type==="soccerball"){
spriteSource = "soccerball-left.png";
} else if (type==="teddy"){
spriteSource = "teddy.png";
} else if (type==="toyblocks"){
spriteSource = "toyblocks-left.png";
} else{
console.debug("WARNING: unknown obstacleType", type);
}
}
MultiResolutionImage {
id: sprite
z:obstacle.z
source: spriteSource !== "" ? Qt.resolvedUrl("../../assets/img/backgrounds/" + spriteSource) : spriteSource
translateToCenterAnchor: (variationType === "closet" || variationType === "closet-door1" || variationType === "closet-door2") ? false : true
}
BoxCollider {
id: collider
width: {
if (obstacle.variationType==="bed") {
return sprite.width;
} else if(obstacle.variationType==="closet") {
return 74;
} else
return 2*gridSize;
}
height: {
if (obstacle.variationType==="bed") {
return sprite.height;
} else if(obstacle.variationType==="closet") {
return 91;
} else
return 2*gridSize;
}
collisionTestingOnlyMode: true
x: obstacle.variationType==="closet" ? 0 : -width/2
y: obstacle.variationType==="closet" ? 0 : -height/2
categories: Box.Category3
collidesWith: Box.Category4
}