new shoot method
This commit is contained in:
		
							parent
							
								
									8fdbc3d0df
								
							
						
					
					
						commit
						1286d93daa
					
				
							
								
								
									
										23
									
								
								player.lua
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								player.lua
									
									
									
									
									
								
							@ -30,6 +30,17 @@ function Player:new(p, x, y, health, image, speed)
 | 
			
		||||
	self.originY = self.height / 2
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function Player:shoot(bulletSpeed)
 | 
			
		||||
	local cos = math.cos
 | 
			
		||||
	local sin = math.sin --optimisation
 | 
			
		||||
	local offsetX = cos(self.rotation) * self.width / 2
 | 
			
		||||
	local offsetY = sin(self.rotation) * self.height / 2
 | 
			
		||||
	local bulletX = self.x + offsetX
 | 
			
		||||
	local bulletY = self.y + offsetY
 | 
			
		||||
	local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation)
 | 
			
		||||
	return newBullet
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function Player:update(dt)
 | 
			
		||||
	local cos = math.cos
 | 
			
		||||
	local sin = math.sin --optimisation
 | 
			
		||||
@ -52,11 +63,7 @@ function Player:update(dt)
 | 
			
		||||
 | 
			
		||||
		if EnableKeyPress1 == true then
 | 
			
		||||
			if love.keyboard.isDown("space") then
 | 
			
		||||
				local offsetX = math.cos(self.rotation) * self.width / 2
 | 
			
		||||
				local offsetY = math.sin(self.rotation) * self.height / 2
 | 
			
		||||
				local bulletX = self.x + offsetX
 | 
			
		||||
				local bulletY = self.y + offsetY
 | 
			
		||||
				local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation)
 | 
			
		||||
				local newBullet = self:shoot(bulletSpeed)
 | 
			
		||||
				table.insert(Bullets1, newBullet)
 | 
			
		||||
				KeyPressTime1 = KeyDelay1
 | 
			
		||||
				EnableKeyPress1 = false
 | 
			
		||||
@ -86,11 +93,7 @@ function Player:update(dt)
 | 
			
		||||
 | 
			
		||||
		if EnableKeyPress2 == true then
 | 
			
		||||
			if love.keyboard.isDown("return") then
 | 
			
		||||
				local offsetX = math.cos(self.rotation) * self.width / 2
 | 
			
		||||
				local offsetY = math.sin(self.rotation) * self.height / 2
 | 
			
		||||
				local bulletX = self.x + offsetX
 | 
			
		||||
				local bulletY = self.y + offsetY
 | 
			
		||||
				local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation)
 | 
			
		||||
				local newBullet = self:shoot(bulletSpeed)
 | 
			
		||||
				table.insert(Bullets2, newBullet)
 | 
			
		||||
				KeyPressTime2 = KeyDelay2
 | 
			
		||||
				EnableKeyPress2 = false
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user