Timer Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
coke905
Citizen
Posts: 52
Joined: Tue Jun 05, 2012 1:46 am

Re: Timer Help

Post by coke905 »

K thanks that what i was wondering now im making a tank game and im having extreme problems with the bullets, ive seen the PEW PEW tutorials for the bullets it works ONLY if i want to shoot up but id like to figure out how i could do it all directions, its a top down rpg game so i need the bullets to go
right,left,up,down. i set variables if you press space and ur facing right then ShotDir == 0 etc 90 up, 270 down, 180 left.

But i understand that is doesnt work cause it keeps looping through the Player.Shots table so if u face left then shoot then u turn back around and shoot all the bullets goes towards where the players facing. Im really stuck.

Code: Select all


function InitPlayer()
	Player = {}
	Player.hp = 68
	Player.x = 150
	Player.y = 150
	Player.Speed = 115
	
	Player.shots = {}
	Player.BulletSpeed = 190
	
	PlayerImageDown = love.graphics.newImage("Images/tank_1.png")
	PlayerImageLeft = love.graphics.newImage("Images/tank_2.png")
	PlayerImageRight = love.graphics.newImage("Images/tank_3.png")
	PlayerImageUp = love.graphics.newImage("Images/tank_4.png")
	
	PlayerImage = PlayerImageRight
end

function PlayerShoot()
	local shot = {}
	shot.x = Player.x + PlayerImage:getWidth()/2
	shot.y = Player.y + PlayerImage:getHeight()/2

	table.insert(Player.shots, shot)
end

function MoveBullets(dt)
	for i,v in ipairs(Player.shots) do	
			v.x = v.x + Player.BulletSpeed * dt
	end
end

function PlayerMove(dt)
	if love.keyboard.isDown("right") then
		Player.x = Player.x + Player.Speed * dt
		PlayerImage = PlayerImageRight
		Dir = 0
	elseif love.keyboard.isDown("left") then
		Player.x = Player.x - Player.Speed * dt
		PlayerImage = PlayerImageLeft
		Dir = 180
	elseif love.keyboard.isDown("up") then
		Player.y = Player.y - Player.Speed * dt
		PlayerImage = PlayerImageUp
		Dir = 90
	elseif love.keyboard.isDown("down") then
		Player.y = Player.y + Player.Speed * dt
		PlayerImage = PlayerImageDown
		Dir = 270
	end
	
	if love.keyboard.isDown(" ") then
		PlayerShoot()
		if PlayerImage == PlayerImageRight then
			Dir = 0
			ShotDir = 0
		elseif PlayerImage == PlayerImageLeft then
			Dir = 180
			ShotDir = 180
		elseif PlayerImage == PlayerImageUp then
			Dir = 90
			ShotDir = 90
		elseif PlayerImage == PlayerImageDown then
			Dir = 270
			ShotDir = 270
		end
	end
end

function DrawPlayer()
	love.graphics.draw(PlayerImage,Player.x,Player.y)
	
	for i,v in ipairs(Player.shots) do
		love.graphics.rectangle("fill", v.x, v.y, 2, 5)
	end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 70 guests