How to win in my game.

Hello.
How do I make that the player win in my game.
Its about destroying 6 blocks without 2 blocks gotta stay in pieces.
So at end there will only be the 2 blocks left on ground.

Anyone know how to do this? [import]uid: 134147 topic_id: 24532 reply_id: 324532[/import]

To be honest your description did not make perfect sense but conceptually you want to store all of your blocks in a display group or table. When the blocks get destroyed they are removed from the group. Every time a block is removed you check the number of items in your table or group. If less then 2 and both left on ground you call a function to initiate your victory.

Theres many ways you can do this, will have to see the code to be specific. Hopefully that helps. [import]uid: 118379 topic_id: 24532 reply_id: 99327[/import]

It’s like this.

[lua]local background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0

local ground = display.newImage( “ground.png” )
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 530
ground.name = “ground”

physics.addBody( ground, “static”, { friction=1.0, density=1.0, bounce=0 } )

local statue = display.newImageRect( “statue.png”, 74, 104 )
statue.x, statue.y = 160, 300
physics.addBody( statue, { density=1.0, friction=0.3, bounce=0.3 } )

function statue:collision(event)
print(“here”)
self.alive = false
if(event.phase == “began”)then
if(event.other.name == “ground”)then
print(“Game Over”)
event.other:setFillColor(255,0,0)
EndGame()
end
end
end
statue:addEventListener(“collision”, statue)

local crate = display.newImageRect( “cement.png”, 220, 40 )
crate.x, crate.y = 160, 380
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

local crate = display.newImageRect( “wood.png”, 50, 60 )
crate.x, crate.y = 60, 430
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

function crate:touch(event)
print(“Destroy”)
if (event.phase == “began”) then
timer.performWithDelay(1, function()
self:removeEventListener(“touch”,self)
self:removeSelf()
end)
end
end
crate:addEventListener(“touch”, crate)

local crate = display.newImageRect( “wood.png”, 50, 60 )
crate.x, crate.y = 260, 430
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

function crate:touch(event)
print(“Destroy”)
if (event.phase == “began”) then
timer.performWithDelay(1, function()
self:removeEventListener(“touch”,self)
self:removeSelf()
end)
end
end
crate:addEventListener(“touch”, crate)
– all display objects must be inserted into group
group:insert( background )
group:insert( ground)
group:insert( crate)
end[/lua] [import]uid: 134147 topic_id: 24532 reply_id: 99341[/import]

Any ideas? :s [import]uid: 134147 topic_id: 24532 reply_id: 99397[/import]

Still not sure what its is you want to happen for the victory please explain again and ill try and help best I can. [import]uid: 118379 topic_id: 24532 reply_id: 99474[/import]

The 2 destroyable wood pieces needs to get destroyed and the Statue has to be untouched on the cement piece. Otherwise if it would touch the ground it would be game over.

So I want to make the win by.

Destroying all the wood pieces. Then count down from 3,2,1 Victory, In case the statue get affected by the gravity. The game is a copy of Tiki Totems. Search it up and you will understand what I’m looking for.

Thanks [import]uid: 134147 topic_id: 24532 reply_id: 99498[/import]

Ive put this together its untested but it should work, I think. You have the right idea but you need to create a system for creating your levels using objects which can be reused. If you can get the level creation working well then the rest of the game will be simple.
Hope it makes sense. let me know how you get on and ill try to help some more.

[code]



– main.lua


– Your code here
local background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0

local ground = display.newImage( “ground.png” )
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 530
ground.name = “ground”

physics.addBody( ground, “static”, { friction=1.0, density=1.0, bounce=0 } )

local statue = display.newImageRect( “statue.png”, 74, 104 )
statue.x, statue.y = 160, 300
physics.addBody( statue, { density=1.0, friction=0.3, bounce=0.3 } )

function statue:collision(event)
print(“here”)
self.alive = false
if(event.phase == “began”)then
if(event.other.name == “ground”)then
print(“Game Over”)
event.other:setFillColor(255,0,0)
EndGame()
end
end
end

statue:addEventListener(“collision”, statue)

– create a table to make each type of crate objects

local woodcrateProperties = {}
woodcrateProperties.id = “destroyable”
woodcrateProperties.height = 40
woodcrateProperties.width = 220
woodcrateProperties.image = “cement.png”
woodcrateProperties.bounce = 0.3

–add more as you require

local cementcrateProperties = {}
cementcrateProperties.id = “indestructible”
cementcrateProperties.height = 60
cementcrateProperties.width = 50
cementcrateProperties.image = “wood.png”
cementcrateProperties.bounce = 0.3

local crateObjects = {woodcrateProperties,cementcrateProperties} --1,2

– this use of table better for larger amount of data for big levels etc can do same as above if you prefer
local levelConfig = {}
levelConfig[1] = {1,2,1} – crateObject
levelConfig[2] = {260,160,60} – Crate x
levelConfig[3] = {430,380,430} – Crate y

local function createCrate(param)

local crate = display.newImageRect( param.image, param.width, param.height )
physics.addBody( crate, { density=1.0, friction=0.3, bounce=param.height } )

return crate
end

local woodenNumber = 0
–check number of crates in levelconfig index 1, which is 3 . cycle through, use “i”
for i = 1, #levelConfig[1], 1 do

local param = crateObjects[levelConfig[1][i]] – pick corresponding object

local crate = createCrate(param)
crate.x = levelConfig[2][i]
crate.y = levelConfig[3][i]

crate:addEventListener(“touch”, crate)
group:insert(crate) – insert into group

if crate.id == “destroyable” then
woodenNumber = woodenNumber + 1 – count how many wooden
end

end

local winWhen = 0 – set how many need to be left to win
function checkRemainingCrates()

woodenNumber = woodenNumber - 1

if woodenNumber == winWhen then

print(“startCountdown()”) – cool your countdown

end

end

function crate:touch(event)

if event.id == “destroyable” then
print(“Destroy”)
if (event.phase == “began”) then
timer.performWithDelay(1, function()
self:removeEventListener(“touch”,self)
self:removeSelf()

checkRemainingCrates()

end)
end
end
end

– all display objects must be inserted into group
group:insert( background )
group:insert( ground)

end
[/code] [import]uid: 118379 topic_id: 24532 reply_id: 99705[/import]

I tried pasting this, did not work at all :s
My statue randomly just flew up in the air at hyperspeed.

Mabye I can e-mail you the files and you can take a look at all in its place, what I have & is missing?

Thanks for taking time and helping me! [import]uid: 134147 topic_id: 24532 reply_id: 99792[/import]

stu@beloudest.com. :wink: [import]uid: 118379 topic_id: 24532 reply_id: 99861[/import]

I have emailed you now :smiley: [import]uid: 134147 topic_id: 24532 reply_id: 100160[/import]