Hi all,
I’ve just started working with the SDK while having no programming experience except a few weeks of ‘Code Year’.
I started prototyping a game mechanic idea that I had using Gamesalad but I kept thinking that a better long-term approach would be try and learn coding as I go along using Corona.
That original prototype can be seen here: http://itssinclair.com/prototyping-part-2/ -
and this is the thinking behind it: http://itssinclair.com/a-game-concept/
I’ve already started to try and get something like that working with Corona, but I’m struggling already. I hope there’s someone here willing to help me get over this little mountain:
I want to tap my ‘player’ to ‘charge’ it up, then tap anywhere on the screen and make that object teleport to that area but I’m having only partial success - I can either tap the player object and ‘charge’ it up (switch image, and change the 'charge variable from 0 to 1), or I can simply teleport my object around the screen in accordance with my taps. BUT I can’t get these two functions to play nice together.
Here’s my code (set to teleport only):
[lua]-----------------------------------------------------------------------------------------
– main.lua
–screen bootstrap
display.setStatusBar(display.HiddenStatusBar)
local whiteBg = display.newRect(0,0,1024,768)
local player = display.newImage(“images/player.png”)
player.x = 200
player.y = 384
local enemy1 = display.newImage(“images/enemy1.png”)
–groups
playerGroup = display.newGroup()
enemyGroup = display.newGroup()
playerGroup:insert(player)
enemyGroup:insert(enemy1)
– upon direct tap, player image switches, and ‘charge’ state is set to 1
charge = 0
local function chargeUp(event)
local saveX = event.target.x
local saveY = event.target.y
if(charge == 0) then
player:removeSelf()
player = display.newImage(“images/charged.png”)
player.x = saveX
player.y = saveY
charge = 1
print(charge)
end
end
–player:addEventListener(“tap”, chargeUp)
– upon tapping anywhere on the screen while ‘charge’ is set to 1, the player image
– will teleport to the tapped location
local function teleport(event)
local teleportX = event.x
local teleportY = event.y
–if(charge == 1) then
player:removeSelf()
player = display.newImage(“images/player.png”)
player.x = teleportX
player.y = teleportY
charge = 0
print(charge)
–end
end
whiteBg:addEventListener(“tap”, teleport)[/lua] [import]uid: 121833 topic_id: 25790 reply_id: 325790[/import]
[import]uid: 52491 topic_id: 25790 reply_id: 104398[/import]