now it just stays in the enter scene of the 2nd module… Rob said something about not being interactivity in there… what do you mean? (i don’t want to do any actions there… i want it to go through opponent scene through judge and then go to single player and wait for the player to touch on the image)
i will share the code i have in my original project… those were file i made just to try to make sense of scenes…
sorry for the length…
local storyboard = require(“storyboard”)
local singlePlayer2 = storyboard.newScene()
local twisted = require(“TF”)
local warwick = require(“Warwick”)
local global_data = require(“global_data”)
–forward declaration
local player_img,opponent,opponent_img,hero
–Find which character the player chose
local path = system.pathForFile(“Player.txt”,system.DocumentsDirectory)
local file = io.open(path,“r”)
local player = file:read("*a")
io.close(file)
file = nil
if (player == “TF”) then --when reading the file for player’s choise, IF the player chose TF, single player will start as follows
hero = 1
else
--if the player chose warwick, single player will start as follows…
hero = 2
end
local randNum = math.random(2) --creating an opponent randomly
if(randNum == 1) then
opponent = 1
else
opponent = 2
end
function singlePlayer2:createScene( event )
local group = self.view
local background = display.newImage(“Treeline.png”)
background.x = 150 ; background.y = 240
group:insert(background)
– body
local info =
{
text = "Round: "…global_data.round,
x = 150,
y = 150,
font = native.systemFontBold ,
fontSize = 20
}
local info_text = display.newText(info)
group:insert(info_text)
end
function singlePlayer2:enterScene(event )
local group = self.view
-------------------card creation----------------------------------------------------------------
function card1:touch( event )
if(global_data.attack_type == 1) then
local damage = twisted.basick_attack()
global_data.opponentHealth = opponent.getDamage(damage)
elseif(global_data.attack_type == 2) then
global_data.opponentHealth = opponent.getDamage(twisted.wild_cards(0))
elseif(global_data.attack_type == 3) then
--opponent.getDamage(twisted.pick_card(0))
elseif(global_data.attack_type == 4) then
global_data.opponentHealth = opponent.getDamage(twisted.stack_deck(0))
elseif(global_data.attack_type == 5) then
twisted.ulti(0)
end
storyboard.gotoScene(“opponent_scene”)
end
card1:addEventListener(“touch”,card1)
– body
end
function singlePlayer2:willEnterScene( event )
local group = self.view
local card1_count = math.random(5)
if(hero == 1 ) then
twisted = twisted.new()
player_img = twisted.setPositionForImage(50,470)
global_data.playerHealth = twisted.getCurHealth()
global_data.playerMana = twisted.getCurMana()
else
warwick = Warwick.new()
player_img = warwick.setPositionForImage(50,470)
end
if(opponent == 1) then
opponent = twisted.new()
opponent_img = twisted.setPositionForImage(250,50)
global_data.opponentMana = twisted.getCurMana()
global_data.opponentHealth = twisted.getCurHealth()
else
opponent = Warwick.new()
opponent_img =warwick.setPositionForImage(250,50)
global_data.opponentHealth = Warwick.getCurHealth()
global_data.opponentMana = Warwick.getCurMana()
end
group:insert(player_img)
group:insert(opponent_img)
local playerInfo_Health =
{
text = "HP = "…global_data.playerHealth,
x = 160,
y = 420,
font= native.systemFontBold,
fontSize = 20
}
local hp = display.newText(playerInfo_Health)
group:insert(hp)
local playerInfo_Mana =
{
text = "Mana = "…global_data.playerMana,
x = 170,
y = 455,
font = native.systemFontBold,
fontSize = 20
}
local mana = display.newText(playerInfo_Mana)
group:insert(mana)
local opponentInfo_health =
{
text = “HP =”…global_data.opponentHealth,
x = 70,
y = 50,
font = native.systemFontBold,
fontSize = 20
}
opponent_text_HP = display.newText(opponentInfo_health)
group:insert(opponent_text_HP)
local opponentInfo_Mana =
{
text = "Mana = "…global_data.opponentMana,
x = 85,
y = 75,
font = native.systemFontBold,
fontSize = 20
}
opponent_text_MANA = display.newText(opponentInfo_Mana)
group:insert(opponent_text_MANA)
if(card1_count == 1) then
card1 = display.newImage(“attack.png”)
card1.x = 50 ; card1.y = 240
global_data.attack_type2 = 1
elseif(card1_count == 2) then
card1 = display.newImage(“wild_cards.png”)
card1.x = 50 ; card1.y = 240
global_data.attack_type2 = 2
elseif(card1_count == 3) then
card1 = display.newImage(“pick_a_card.png”)
card1.x = 50 ; card1.y = 240
global_data.attack_type2 = 3
elseif(card1_count == 4) then
card1 = display.newImage(“stacked_deck.png”)
card1.x = 50 ; card1.y = 240
global_data.attack_type2 = 4
elseif(card1_count == 5) then
card1 = display.newImage(“destiny.png”)
card1.x = 50 ; card1.y = 240
global_data.attack_type2 = 5
end
group:insert(card1)
if(card1_count ~= 5) then
card2_count = math.random(5)
else
card2_count = math.random(4)
end
if(card2_count == 1) then
card2 = display.newImage(“attack.png”)
card2.x = 150 ; card2.y = 240
global_data.attack_type2 = 1
elseif(card2_count == 2) then
card2 = display.newImage(“wild_cards.png”)
card2.x = 150 ; card2.y = 240
global_data.attack_type2 = 2
elseif(card2_count == 3) then
card2 = display.newImage(“pick_a_card.png”)
card2.x = 150 ; card2.y = 240
global_data.attack_type2 = 3
elseif(card2_count == 4) then
card2 = display.newImage(“stacked_deck.png”)
card2.x = 150 ; card2.y = 240
global_data.attack_type2 = 4
elseif(card2_count == 5) then
card2 = display.newImage(“destiny.png”)
card2.x = 150 ; card2.y = 240
global_data.attack_type2 = 5
end
group:insert(card2)
if(card1_count ~= 5 and card2_count ~= 5) then
card3_count = math.random(5)
else
card3_count = math.random(4)
end
if(card3_count == 1) then
card3 = display.newImage(“attack.png”)
card3.x = 250 ; card3.y = 240
global_data.attack_type3 = 1
elseif(card3_count == 2) then
card3 = display.newImage(“wild_cards.png”)
card3.x = 250 ; card3.y = 240
global_data.attack_type3 = 2
elseif(card3_count == 3) then
card3 = display.newImage(“pick_a_card.png”)
card3.x = 250 ; card3.y = 240
global_data.attack_type3 = 3
elseif(card3_count == 4) then
card3 = display.newImage(“stacked_deck.png”)
card3.x = 250 ; card3.y = 240
global_data.attack_type3 = 4
elseif(card3_count == 5) then
card3 = display.newImage(“destiny.png”)
card3.x = 250 ; card3.y = 240
global_data.attack_type3 = 5
end
group:insert(card3)
– body
end
function singlePlayer2:exitScene(event )
local group = self.view
– body
end
singlePlayer2:addEventListener(“createScene”,singlePlayer2)
singlePlayer2:addEventListener(“enterScene”,singlePlayer2)
singlePlayer2:addEventListener(“willEnterScene”,singlePlayer2)
singlePlayer2:addEventListener(“exitScene”,singlePlayer2)
return singlePlayer2
------------opponent scene----------------
local storyboard = require(“storyboard”)
local opponent_scene = storyboard.newScene()
local global_data = require(“global_data”)
local rand_attack = math.random(3)
function opponent_scene:createScene(event)
print(“opponent create scene”)
local group = self.view
storyboard.purgeScene(“singlePlayer2”)
local info =
{
text = “OPPONENT’S TURN!!”,
x = 150,
y = 250,
font = native.systemFontBold,
fontSize = 30
}
local info_text = display.newText(info)
group:insert(info_text)
if(rand_attack == 1) then
print(“1”)
elseif(rand_attack == 2) then
print(“2”)
else
print(“3”)
end
end
function opponent_scene:enterScene( event )
print(“opponent enter scene”)
local group = self.view
if(rand_attack == 1) then
global_data.playerHealth = global_data.playerHealth - 30
elseif(rand_attack == 2) then
global_data.playerHealth = global_data.playerHealth - 50
else
global_data.playerHealth = global_data.playerHealth - 100
end
storyboard.gotoScene(“judge”)
end
function opponent_scene:exitScene( event )
print(“opponent exit scene”)
local group = self.view
– body
end
opponent_scene:addEventListener(“createScene”,opponent_scene)
opponent_scene:addEventListener(“enterScene”,opponent_scene)
opponent_scene:addEventListener(“exitScene”,opponent_scene)
return opponent_scene
-----------------------judge scene
local storyboard = require(“storyboard”)
local judge = storyboard.newScene()
local global_data = require(“global_data”)
local twisted = require(“TF”)
local warwick = require(“Warwick”)
function judge:createScene(event)
local group = self.view
print("round = "…global_data.round)
print("player hp = "…global_data.playerHealth)
print("opponent hp = "…global_data.opponentHealth)
storyboard.removeScene(“oppponent_scene”)
global_data.round = global_data.round + 1
if(global_data.opponentHealth > 0) then
storyboard.gotoScene(“singlePlayer2”)
else
local grats =
{
text = “YOU WIN!!!”,
x = 150,
y = 250,
font = native.systemFontBold,
fontSize = 50
}
local text = display.newText(grats)
group:insert(grats)
end
end
judge:addEventListener(“createScene”,judge)
return judge