OK here you go, all there.
Also L + R are like the tracks, so hold L + R to go forwards.
Can you zip up the entire project with the sounds for me to look at?
I had a decent shot at it and to be honest I can't get it to work even though the logic appears to be fine. I honestly think that the sound system of LuaPlayer is buggy as hell and system calls like playing sound, blitting to the screen are all on seperate threads which makes them very hard to use.
Sorry.
green=Color.new(0,255,0)
white = Color.new(255,255,255)
oldpad = Controls.read()
grass = Image.load("TankT/Grass.png")
block = Image.load("TankT/Building.png")
Bul = Image.load("TankT/Missile.png")
missile = Sound.load("TankT/Sounds/Missile.wav",false)
tankidle = Sound.load("TankT/Sounds/tankIdle.wav",true)
tankdrive = Sound.load("TankT/Sounds/tankDrive.wav",true)
tankdriveVoice = tankdrive:play()
tankidleVoice = tankidle:play()
screen.waitVblankStart(50)
tankdriveVoice:stop()
tankidleVoice:stop()
gamestate = "game"
animation = {}
animation[1] = Image.load("TankT/Tank/Tank0.png")
animation[2] = Image.load("TankT/Tank/Tank45.png")
animation[3] = Image.load("TankT/Tank/Tank90.png")
animation[4] = Image.load("TankT/Tank/Tank135.png")
animation[5] = Image.load("TankT/Tank/Tank180.png")
animation[6] = Image.load("TankT/Tank/Tank225.png")
animation[7] = Image.load("TankT/Tank/Tank270.png")
animation[8] = Image.load("TankT/Tank/Tank315.png")
animation[9] = Image.load("TankT/Tank/TankShoot.png")
animation[10] = Image.load("TankT/Tank/TankShoot2.png")
player = animation[1]
Player = { x = 30, y = 100 }
playerHeight = 26
playerWidth = 51
playerMove = "no"
Collision = "no"
acceleration = 0
loopCount = 0
loopCount2 = 0
turnCount = 1
Block = {}
Block[1] = { x = 20, y = 10, height = block:height(), width = block:width() }
Block[2] = { x = 350, y = 180, height = block:height(), width = block:width() }
Block[3] = { x = 210, y = 10, height = block:height(), width = block:width() }
Bullet = { f = "no", x = Player.x, y = Player.y, d = "r" }
---------------------Game loop-------------------------
function playgame()
if player == animation[1] or player == animation[5] then
playerHeight = 26
playerWidth = 51
end
if player == animation[3] or player == animation[7] then
playerHeight = 51
playerWidth = 26
end
if player == animation[2] or player == animation[4] or player == animation[6] or player == animation[8] then
playerHeight = 46
playerWidth = 46
end
PosToBlitX = Player.x - (playerWidth / 2 )
PosToBlitY = Player.y - (playerHeight / 2 )
pad = Controls.read()
screen:clear()
screen:blit(0,0,grass)
screen:blit(PosToBlitX, PosToBlitY, player)
for a = 1,3 do
screen:blit(Block[a].x,Block[a].y,block)
end
if Bullet.f == "yes" then
screen:blit(Bullet.x, Bullet.y, Bul)
end
------------------PlayerMove-------------------
if player == animation[1] and Collision == "no" then
Player.x = Player.x + acceleration
end
if player == animation[2] and Collision == "no" then
Player.x = Player.x + (acceleration / 2)
Player.y = Player.y + (acceleration / 2)
end
if player == animation[3] and Collision == "no" then
Player.y = Player.y + acceleration
end
if player == animation[4] and Collision == "no" then
Player.x = Player.x - (acceleration / 2)
Player.y = Player.y + (acceleration / 2)
end
if player == animation[5] and Collision == "no" then
Player.x = Player.x - acceleration
end
if player == animation[6] and Collision == "no" then
Player.x = Player.x - (acceleration / 2)
Player.y = Player.y - (acceleration / 2)
end
if player == animation[7] and Collision == "no" then
Player.y = Player.y - acceleration
end
if player == animation[8] and Collision == "no" then
Player.x = Player.x + (acceleration / 2)
Player.y = Player.y - (acceleration / 2)
end
if pad:r() and pad:l() then
playerMove = "yes"
else playerMove = "no"
end
if pad:r() and pad:r() ~= pad:l() then
turnCount = turnCount - 0.25
end
if pad:l() and pad:l() ~= pad:r() then
turnCount = turnCount + 0.25
end
--------------acceleration------------------
if pad:r() and pad:l() and Collision == "no" and acceleration <= 1.4 then
acceleration = acceleration + 0.01
end
if playerMove == "no" and acceleration >= 0.01 then
acceleration = acceleration - 0.01
end
if pad:square() and acceleration > 0 then
acceleration = acceleration - 0.05
end
if acceleration < 0 then
acceleration = 0
end
------------drivin sounds------------
if playerMove == "no" and tankidleVoice:playing() == false then
tankdriveVoice:stop()
tankidleVoice = tankidle:play()
screen:print( 1, 9, "IDLE", white )
end
if playerMove == "yes" and tankdriveVoice:playing() == false then
tankidleVoice:stop()
tankdriveVoice = tankdrive:play()
screen:print( 1, 9, "MOVING", white )
end
------------------playerOne stuff------------------------
if turnCount >= 0 and turnCount < 6 then player = animation[1]
elseif turnCount >= 6 and turnCount < 12 then player = animation[2]
elseif turnCount >= 12 and turnCount < 18 then player = animation[3]
elseif turnCount >= 18 and turnCount < 24 then player = animation[4]
elseif turnCount >= 24 and turnCount < 30 then player = animation[5]
elseif turnCount >= 30 and turnCount < 36 then player = animation[6]
elseif turnCount >= 36 and turnCount < 42 then player = animation[7]
elseif turnCount >= 42 and turnCount < 48 then player = animation[8]
end
if turnCount + 1 >= 48 then
turnCount = 1
end
if turnCount - 1 <= -1 then
turnCount = 47
end
--------------------shooting-------------------
if player == animation[1] and pad:cross() and oldpad:cross() ~= pad:cross() and Bullet.f == "no" then
Bullet.d = "r"
Bullet.x = Player.x + 25.5
Bullet.y = Player.y
Bullet.f = "yes"
player = animation[9]
acceleration = acceleration - 0.25
local sound = missile
voice = sound:play()
end
if player == animation[5] and pad:cross() and oldpad:cross() ~= pad:cross() and Bullet.f == "no" then
Bullet.d = "l"
Bullet.x = Player.x - 25.5
Bullet.y = Player.y
Bullet.f = "yes"
player = animation[10]
acceleration = acceleration - 0.25
local sound = missile
voice = sound:play()
end
if Bullet.f == "yes" and Bullet.d == "r" then
Bullet.x = Bullet.x + 2
end
if Bullet.f == "yes" and Bullet.d == "l" then
Bullet.x = Bullet.x - 2
end
if Bullet.x > 480 or Bullet.x < 0 or Bullet.y > 272 or Bullet.y < 0 then
Bullet.f = "no"
end
------------------Collision-----------------------
if playerMove == "yes" and (Player.x + playerWidth > Block[1].x) and (Player.x < Block[1].x + Block[1].width) and (Player.y + playerHeight > Block[1].y) and (Player.y < Block[1].y + Block[1].height) then
Collision = "yes"
else Collision = "no"
end
if playerMove == "yes" and (Player.x + playerWidth > Block[2].x) and (Player.x < Block[2].x + Block[2].width) and (Player.y + playerHeight > Block[2].y) and (Player.y < Block[2].y + Block[2].height) then
Collision = "yes"
end
if playerMove == "yes" and (Player.x + playerWidth > Block[3].x) and (Player.x < Block[3].x + Block[3].width) and (Player.y + playerHeight > Block[3].y) and (Player.y < Block[3].y + Block[3].height) then
Collision = "yes"
end
end
--------------------Main loop--------------------
while true do
if gamestate == "game" then
playgame()
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
end
OK, cheers anyway for your help. Not sure what to do now about SFX on the game though.
P.S- What do you think about the game(in early stages) so far.
-------------Edit----------------
Yeah!! I did it I got it to work now, its not the nicest of way to do it, but it works none the less.
thanks again Yaustar :).
In case you want to know this is how i did it -
--------Variable--------
soundCount = 0
--------Main loop--------
if gamestate == "game" and soundCount == 0 then
local sound = tankidle
voice = sound:play()
end
if gamestate == "game" and soundCount == 0 then
local sound = tankdrive
voice2 = sound:play()
end
if playerMove == "no" then
voice:volume(128)
voice2:volume(0)
soundCount = soundCount + 1
end
if playerMove == "yes" then
voice:volume(0)
voice2:volume(128)
end
Impressive hack considering what you had to work with.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks