Quote:
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