Thanks! I'm going to try it out.
PS. It works!
PS2. There is yet another thing. While this isn't some serious thing, but still noticeable: When I hold down a movement key in directions where I collide with map border and then shot, bullet shows few pixels further than a ship.
ex. I go up and collide with map borders, then I shot - bullet shows above me.
Do I need to make map borders - player collision boolean and then move all fired bullets by x pixels or there is more smart way?
When I put shot code on top of player updating code, then all bullets warps in direction ship moves.
Death of enemy, obj. removing and other stuff (game added)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: Death of enemy, obj. removing and other stuff (game adde
Reset the coords after map colliding and then shoot. In the moment you are creating bullets at your old position, the wrong one.
I've found your precise control, put it before colliding, it will work!
This is the code, when I will write it:
I edited this:
1. insert local variable 'speed' where you can control your speed per tick. I used it for precise control
2. I sort a little bit moving and colliding, doesn't make something, it looks only cleaner
3. Move shooting to the end of the function
Good luck!
I've found your precise control, put it before colliding, it will work!
This is the code, when I will write it:
Code: Select all
function Movement(dt)
for i,e in ipairs(playerList) do
bursttimer = bursttimer + 1 * dt
xvel=0
yvel=0
leftcrush = false
rightcrush = false
--precise control
local speed = e.s
if love.keyboard.isDown("lshift") then
speed = e.s/2
end
if love.keyboard.isDown("right") then --if player goes right...
xvel = speed
psystem:setLinearAcceleration(-300, -2, 0, 2)
psystem:setEmissionRate(40)
elseif love.keyboard.isDown("left") then --if player goes left
xvel = -speed
psystem:setLinearAcceleration(-25, -2, 0, 2)
psystem:setEmissionRate(10)
else
psystem:setLinearAcceleration(-100, -2, 0, 2);psystem:setEmissionRate(15)
end
-- if player goes down...
if love.keyboard.isDown("down") then
yvel = speed
end
-- if players goes up...
if love.keyboard.isDown("up") then
yvel = -speed
end
--X-collision
local oldX = e.x
e.x = e.x + (xvel*dt)
for i2,e2 in pairs (enemyList) do
if CheckCollision(e.x,e.y,e.w,e.h, e2.x,e2.y,e2.w,e2.h) == true then
if e.x <= e2.x then
e.x=oldX
leftcrush = true
end
if e.x >= e2.x then
e.x=oldX
rightcrush = true
end
e.x = e.x - e2.s * dt
end
end
--Y-collision
local oldY = e.y
e.y = e.y + (yvel*dt)
for i2,e2 in pairs (enemyList) do
if CheckCollision(e.x,e.y,e.w,e.h, e2.x,e2.y,e2.w,e2.h) == true then
if e.y <= e2.y then
e.y=oldY
end
if e.y >= e2.y then
e.y=oldY
end
end
end
-- if crushed, you die
if rightcrush and leftcrush then e.dead = true end
if e.HP < 1 then e.dead = true end
-- map collision
if e.x+e.w >=800 then e.x = oldX end
if e.x <=0 then e.x = oldX end
if e.y <= 0 then e.y = oldY end
if e.y+e.h >= 600 then e.y = oldY end
-- shoot button
if love.keyboard.isDown("z") then
if bursttimer >= 0.1 then
for i,e in ipairs(playerList) do
MakeBullet(e.x+(e.w/2),e.y+(e.h/2),1,'player') end -- place where bullet show
effect:play()
effect:rewind()
bursttimer =0
end
end
end
end
1. insert local variable 'speed' where you can control your speed per tick. I used it for precise control
2. I sort a little bit moving and colliding, doesn't make something, it looks only cleaner
3. Move shooting to the end of the function
Good luck!
Re: Death of enemy, obj. removing and other stuff (game adde
Thank you, this works.
I'm slowly getting to make enemy waypoint system, so enemy could go to given positions.
Enemy class have tx and ty tables, where x and y coordinates are stored. For now, when I click with my left mouse button, it adds it's x position to enemys tx table and y position to ty table, enemy aims to get there, then removes coordinates from tables and take on another position if I clicked with mouse more.
Now I need to invent something, which would give the enemy coordinates at creation. I could use MakeEnemy() and insert coords like this : MakeEnemy(x1,y1 ,x2,y2 ,x3,y3 ,x4,y4 ect), but that would means I will have to set maximum amount of waypoints (like 6, for example), because in creation funtion I have to write down value assigment to table (e.tx[#e.tx + 1]= x1 ; e.tx[#e.tx + 1]= x2 ect.)
But it's minor problem: I can set max 10 waypoints, probably that much won't be used anyway.
Or could work with local variables and make it be used by MakeEnemy() or something...
I'm slowly getting to make enemy waypoint system, so enemy could go to given positions.
Enemy class have tx and ty tables, where x and y coordinates are stored. For now, when I click with my left mouse button, it adds it's x position to enemys tx table and y position to ty table, enemy aims to get there, then removes coordinates from tables and take on another position if I clicked with mouse more.
Now I need to invent something, which would give the enemy coordinates at creation. I could use MakeEnemy() and insert coords like this : MakeEnemy(x1,y1 ,x2,y2 ,x3,y3 ,x4,y4 ect), but that would means I will have to set maximum amount of waypoints (like 6, for example), because in creation funtion I have to write down value assigment to table (e.tx[#e.tx + 1]= x1 ; e.tx[#e.tx + 1]= x2 ect.)
But it's minor problem: I can set max 10 waypoints, probably that much won't be used anyway.
Or could work with local variables and make it be used by MakeEnemy() or something...
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: Death of enemy, obj. removing and other stuff (game adde
Code: Select all
function MakeEnemy(x, y)
local e = { }
e.x = x
e.y = y
e.newWaypoint(x, y) = function(self, x, y)
self.waypoints[#self.waypoints+1] = {x = x, y = y}
end
e.waypoints = { }
end
MakeEnemy(10, 20)
enemys[1]:newWaypoint(40, 50)
enemys[1]:newWaypoint(0, 10)
Now you can add waypoints after creating the enemy too.
Re: Death of enemy, obj. removing and other stuff (game adde
It may give me an idea how to work my code, but there is one thing:
Doesn't it means I will have to know in what position in "enemys" table object is?
Edit.
Another thing
I try to make function for starting one enemy wave, but when I add check like
It doesn't work, but when I remove the check, the code start, spawning thousand of enemies due to lack of control.
I show the part of the code if somebody needed to check:
Edit
I guess I fixed the spawning problem
Code: Select all
MakeEnemy(10, 20)
enemys[1]:newWaypoint(40, 50)
enemys[1]:newWaypoint(0, 10)
Edit.
Another thing
I try to make function for starting one enemy wave, but when I add check like
Code: Select all
if first_stage_check == 0 then -- I mean that line
first_stage()
first_stage_check = 1
end
I show the part of the code if somebody needed to check:
Code: Select all
--------------------
--in 'spawnplan' file
-------------------
first_stage_check = 0
function first_stage()
local x = 500
local y = 540
for i=1, 5 do
MakeEnemy(500,600 ,x,y-60, -120,y-40, 0,0, 0,0 ,0,0 ,0,0, 0,0)
x=x+50;y=y-40
end
end
-----------
--in main.lua
----------
if first_stage_check == 0 then -- I mean that line
first_stage()
first_stage_check = 1
end
Edit
I guess I fixed the spawning problem
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], Majestic-12 [Bot] and 5 guests