samurai fruit add on

I am currently working on adding some things to the samurai fruit templete. I was able to have a floating sad face appear every time you slice a bad food item. I also was able to add three sad faces show up at the top of the screen. What I am having trouble with is just showing one face at a time with every slice of a bad food. Here is the line of code I am working with:

function threeStrikes()

for i=1, 3 do

local strike = display.newImageRect(“strike.png”, 65, 65)

junkGroup:insert(strike)

local offsetFraction = i+1/6

strike.x = 80 * offsetFraction
strike.y = 60

strike[i] = threeStrikes + 1

–strike.isVisible = false

end

end

function createbadEffect(junk)

local badEffect = display.newImage (“sadFace.png”)

badEffect.x = junk.x
badEffect.y = junk.y

threeStrikes()

junkGroup:insert(badEffect)

transition.to(badEffect, {time = 900, delay = 200, y=badEffect.y-100, alpha = 0, onComplete = function(event) badEffect:removeSelf() end})
end
any help would be GREAT!!

[import]uid: 51459 topic_id: 11732 reply_id: 311732[/import]

Hello Jake XD

It’s good your posting in the right section but when we post our code we use < lua > tags, so it doesn’t give people reading it a headache :wink:

When you say one face, you mean if two “bad” things are sliced close together you don’t want a second face showing up because the first one is still there, yes? Please clarify.

Peach [import]uid: 52491 topic_id: 11732 reply_id: 42872[/import]

Not sure how to tag… :confused: do I do something like this before [lua] and after I post code [/lua]

And I figured out the last issue I was having but of course I have a new issue. Its a bit of code to add so I wont add it until I know how to tag!.

Is it possible to have an explosion happen after 5 bad items have been sliced? [import]uid: 51459 topic_id: 11732 reply_id: 42880[/import]

Yes, that was Lua tags.

And yes - just create a variable, like badSliced = 0.

Put it up by one each time a bad item is sliced.

In your function for whatever happens when a bad item is sliced, add an if statement for if badSliced == 5 then --explosion here.

Make sense? [import]uid: 52491 topic_id: 11732 reply_id: 43014[/import]

I did something like that that… Here is my line of code Peachy

[lua]local hitCount = 0

function SadFaceCount()

hitCount = hitCount + 1
if hitCount <= 5 then
local strike = display.newImageRect(“strike.png”, 65, 65)
junkGroup:insert(strike)
local offsetFraction = hitCount + 1/6
strike.x = 80 * offsetFraction
strike.y = 60
else
local sadFaceEndFunction
sadFaceEndFunction = function(event) explode(junk, sadFaceEndFunction); end
junk:addEventListener(“touch”, sadFaceEndFunction)
end

end


function explode(junk, listener)

junk:removeEventListener(“touch”, listener)

– The junk should not move while exploding
junk.bodyType = “kinematic”
junk:setLinearVelocity(0, 0)
junk.angularVelocity = 0

– Shake the stage
local stage = display.getCurrentStage()

local moveRightFunction
local moveLeftFunction
local rightTrans
local leftTrans
local shakeTime = 50
local shakeRange = {min = 1, max = 25}

moveRightFunction = function(event) rightTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max), y = math.random(shakeRange.min, shakeRange.max), time = shakeTime, onComplete=moveLeftFunction}); end
moveLeftFunction = function(event) leftTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max) * -1, y = math.random(shakeRange.min,shakeRange.max) * -1, time = shakeTime, onComplete=moveRightFunction}); end

moveRightFunction()

local linesGroup = display.newGroup()

– Generate a bunch of lines to simulate an explosion
local drawLine = function(event)

local line = display.newLine(junk.x, junk.y, display.contentWidth * 2, display.contentHeight * 2)
line.rotation = math.random(1,360)
line.width = math.random(15, 25)
linesGroup:insert(line)
end
local lineTimer = timer.performWithDelay(100, drawLine, 0)

– Function that is called after the pre explosion
local exploded = function(event)

audio.play(explosion)
blankOutScreen(junk, linesGroup);
timer.cancel(lineTimer)
stage.x = 0
stage.y = 0
transition.cancel(leftTrans)
transition.cancel(rightTrans)

end

– Play the preExplosion sound first followed by the end explosion
audio.play(preExplosion, {onComplete = exploded})

timer.cancel(fruitTimer)
timer.cancel(junkTimer)

end

function blankOutScreen(junk, linesGroup)

local gameOver = displayGameOver()
gameOver.alpha = 0 – Will reveal the game over screen after the explosion

– Create an explosion animation
local circle = display.newCircle( junk.x, junk.y, 5 )
local circleGrowthTime = 300
local dissolveDuration = 1000

local dissolve = function(event) transition.to(circle, {alpha = 0, time = dissolveDuration, delay = 0, onComplete=function(event) gameOver.alpha = 1 end}); gameOver.alpha = 1 end

circle.alpha = 0
transition.to(circle, {time=circleGrowthTime, alpha = 1, width = display.contentWidth * 3, height = display.contentWidth * 3, onComplete = dissolve})

– Vibrate the phone
system.vibrate()

junk:removeSelf()
linesGroup:removeSelf()

end[/lua] [import]uid: 51459 topic_id: 11732 reply_id: 43022[/import]

I get this error when I get to the 5th piece of junk

Runtime error
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/203/main.lua:571: attempt to index global ‘junk’ (a nil value)
stack traceback:
[C]: ?
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/203/main.lua:571: in function ‘SadFaceCount’
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/203/main.lua:666: in function ‘createbadEffect’
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/203/main.lua:456: in function ‘chopJunk’
…ZS-a189GNQo1k+++TI/-Tmp-/TemporaryItems/203/main.lua:354: in function <…zs-a189gnqo1k>
?: in function <?:214>
Runtime error [import]uid: 51459 topic_id: 11732 reply_id: 43023[/import] </…zs-a189gnqo1k>

As I can’t see line 571 I’m not sure what to tell you; I can’t imagine the code :wink: [import]uid: 52491 topic_id: 11732 reply_id: 43204[/import]

The error I am getting is with in this function [lua]function explode(junk, listener)

junk:removeEventListener(“touch”, listener)

– The junk should not move while exploding
junk.bodyType = “kinematic”
junk:setLinearVelocity(0, 0)
junk.angularVelocity = 0

– Shake the stage
local stage = display.getCurrentStage()

local moveRightFunction
local moveLeftFunction
local rightTrans
local leftTrans
local shakeTime = 50
local shakeRange = {min = 1, max = 25}

moveRightFunction = function(event) rightTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max), y = math.random(shakeRange.min, shakeRange.max), time = shakeTime, onComplete=moveLeftFunction}); end
moveLeftFunction = function(event) leftTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max) * -1, y = math.random(shakeRange.min,shakeRange.max) * -1, time = shakeTime, onComplete=moveRightFunction}); end

moveRightFunction()

local linesGroup = display.newGroup()

– Generate a bunch of lines to simulate an explosion
local drawLine = function(event)

local line = display.newLine(junk.x, junk.y, display.contentWidth * 2, display.contentHeight * 2)
line.rotation = math.random(1,360)
line.width = math.random(15, 25)
linesGroup:insert(line)
end
local lineTimer = timer.performWithDelay(100, drawLine, 0)

– Function that is called after the pre explosion
local exploded = function(event)

audio.play(explosion)
blankOutScreen(junk, linesGroup);
timer.cancel(lineTimer)
stage.x = 0
stage.y = 0
transition.cancel(leftTrans)
transition.cancel(rightTrans)

end

– Play the preExplosion sound first followed by the end explosion
audio.play(preExplosion, {onComplete = exploded})

timer.cancel(fruitTimer)
timer.cancel(junkTimer)

end[/lua]
I didn’t want to paste the whole code because it would be just to long. The problem that I am having has something to do with the word junk. Now in the open source code that I am referring to the explosion is connected to the bomb. I don’t have a bomb I have junk. Someone I know told me to do this: at the high level you just need to add your game over screen to the director and switch to it once the hitCount turns to six. I don’t know how to write this in the code PEACH! [import]uid: 51459 topic_id: 11732 reply_id: 43255[/import]

You need to make it clear which line your error is on, whether pasting all your code or not - just tell me specifically which line.

As to “junk”, if it seems to be an issue with that word, try changing it to “xjunk” or something. It could be a reserved word. (I don’t know whether or not it is, I’m guessing. I had a similar problem using “break”.)

To add a count you’d have a variable and do +1 to it every time you sliced a bad item - add it to the slicing function - if item == “bad” (or whatever) then myVariable + 1 end

Make sense? XD

Peach [import]uid: 52491 topic_id: 11732 reply_id: 43390[/import]

Hey PEACH!!

I figured out that the code was way to messy. I have to do a massive clean up!! So no worries…
Thanks for all your help though…

On another note I will be done with my first game a week from today! How can I get that image that says developed with corona sdk?

Hope you are doing well!! [import]uid: 51459 topic_id: 11732 reply_id: 43406[/import]

When you submit it to the showcase you’ll end up on a page with those buttons in different sizes :slight_smile: [import]uid: 52491 topic_id: 11732 reply_id: 43534[/import]

how to add score ?

[import]uid: 13061 topic_id: 11732 reply_id: 43753[/import]

If you don’t know how to add a score there are various tutorials out there, including a video one I did on http://Techority.com and some examples in the code exchange.

Peach [import]uid: 52491 topic_id: 11732 reply_id: 43765[/import]

Here is my line of code Peachy

“Peachy”, hmmmm, interesting [import]uid: 3826 topic_id: 11732 reply_id: 44498[/import]

Peach , I know how to add score,

but the problem , I did that , but when I added it in the game page, I got trouble like :

all number will be mix together , for example ,

starting with Zero, then 1 , number one will added above the zero ,

how do delete the zero , then add number one,

I got trouble w that, would u please clarify that , thx all [import]uid: 13061 topic_id: 11732 reply_id: 44539[/import]

Jayantv, I don’t share your interest. Get out :stuck_out_tongue:

eng.tareqali, you need to update the score, not keep adding new ones.

If you called your score text ScoreText and your score score, then you’d do this when you earned points;

[lua]ScoreText.text = score[/lua]

Make sense?

Peach(y) :slight_smile: [import]uid: 52491 topic_id: 11732 reply_id: 44556[/import]

???

Seems that you did not or do not read the comments carefully…

>>>>>>
Posted on Wed, 2011-06-29 23:23
#4
jakescarano
User offline. Last seen 1 day 22 hours ago. Offline
Joined: 9 Apr 2011

I did something like that that… Here is my line of code Peachy
>>>>>>

[import]uid: 3826 topic_id: 11732 reply_id: 44560[/import]

I assumed from your post;

“Here is my line of code Peachy
“Peachy”, hmmmm, interesting”

That you were saying the fact he called me “Peachy” was interesting. Was I mistaken? [import]uid: 52491 topic_id: 11732 reply_id: 44569[/import]

I was stating that you would not like being called Peachy, so it is interesting that someone asking for help starts to get too comfortable, however it just went the other way, so it is still *interesting*

?:slight_smile: [import]uid: 3826 topic_id: 11732 reply_id: 44573[/import]

I see; in that case, thanks and you’d normally be correct - I wouldn’t want people I wasn’t familiar with calling me “Peachy”.

That said, Jake’s a friend of mine who I’m frequently in touch with outside of Corona - so it’s a little different.

Again, I do appreciate what you were saying (now I understand it ;)) and as I said, you’d normally be correct.

Peach :slight_smile: [import]uid: 52491 topic_id: 11732 reply_id: 44589[/import]