Are your bullets maybe colliding with the player who fires them? Set a bullet.owner field to that player and ignore him in the collision code for that bullet.Kreg wrote:Neverming about previous question, I can just use images.
But I have more important one:
I started doing bullet making code and I have seen that I can't shoot bullets when I'm moving diagonally, except up-right, why? How to fix it?
EDIT: This is happening when I use space (" ") key to create single bullet, but when i binded it to "z" it works correctly. Why?
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.
Re: Death of enemy, object removing and other stuff
Re: Death of enemy, object removing and other stuff
Nope, I have only bullet-enemy collision for now.
When I had a key for players creating (I was toying with it), some key weren't working when I was moving diagonally (I'm using arrowkeys)
When I had a key for players creating (I was toying with it), some key weren't working when I was moving diagonally (I'm using arrowkeys)
Re: Death of enemy, object removing and other stuff
Or maybe it's because of an if-elseif thing?Kreg wrote:Nope, I have only bullet-enemy collision for now.
When I had a key for players creating (I was toying with it), some key weren't working when I was moving diagonally (I'm using arrowkeys)
Code: Select all
if leftkey then
...
elseif rightkey then
...
elseif shootkey then
...
end
Re: Death of enemy, object removing and other stuff
Nopre, I'm only using ifs here.
And another question. How I can do calculation in table?
Now enemy never spawns below screen, that's good, but thing is I had to use "hei", because using h[eight] in calculation pops up an error about lack of global "h". Why?
And another question. How I can do calculation in table?
Code: Select all
function MakeEnemy()
local hei = lvm(25,40) -- one thing
local Enemy =({
dead = nil,
w = lvm(25,40),
h = hei, -- look here too
s = lvm(50,70),
color1 = lvm(0,255),
color2 = lvm(0,255),
color3 = lvm(150,255),
x = 820,
y = lvm(0,600-hei)}) -- other thing
table.insert(enemyList, Enemy)
end
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: Death of enemy, object removing and other stuff
It's your keyboard! Keyboards only can use a limited amount of keys at once. You can use your mouse to shoot.
When you write
a and b will be generated at the same time.
That's the reason why I write:
I hope this was what you mean.
You use h before the table is ready.Now enemy never spawns below screen, that's good, but thing is I had to use "hei", because using h[eight] in calculation pops up an error about lack of global "h". Why?
When you write
Code: Select all
list = {a = "letter", b = "another letter"}
That's the reason why I write:
Code: Select all
local hei = lvm(25,40) -- one thing
local e = { } --e for enemy
e.dead = nil
e.w = lvm(25,40)
e.h = hei
e.s = lvm(50,70)
e.color1 = lvm(0,255)
e.color2 = lvm(0,255)
e.color3 = lvm(150,255)
e.x = 820
e.y = lvm(0,600 - e.h)}) -- Ha it's working :D
enemyList[#enemyList+1] = e --or table insert, it doesn't matter
Re: Death of enemy, object removing and other stuff
No. I said that my code works.
I just don't want to use the local "hei" and use randomized number added to "h", then use that "h" in calculation.
Something like this:
I just don't want to use the local "hei" and use randomized number added to "h", then use that "h" in calculation.
Something like this:
Code: Select all
function MakeEnemy()
local Enemy =({
dead = nil,
w = lvm(25,40),
h = lvm(25,40)
s = lvm(50,70),
color1 = lvm(0,255),
color2 = lvm(0,255),
color3 = lvm(150,255),
x = 820,
y = lvm(0,600-h)})
table.insert(enemyList, Enemy)
end
Re: Death of enemy, object removing and other stuff
And that's just what he said, you can't reference h in the same "process" you define it, h will only exist once the full assignment is done. You can just leave out y though and later do Enemy.y =lvm(0,600-Enemy.h)Kreg wrote:No. I said that my code works.
I just don't want to use the local "hei" and use randomized number added to "h", then use that "h" in calculation.
Something like this:Code: Select all
function MakeEnemy() local Enemy =({ dead = nil, w = lvm(25,40), h = lvm(25,40) s = lvm(50,70), color1 = lvm(0,255), color2 = lvm(0,255), color3 = lvm(150,255), x = 820, y = lvm(0,600-h)}) table.insert(enemyList, Enemy) end
(Also, as Enemy is an object, I would give it a lowercase Name.)
Re: Death of enemy, object removing and other stuff
Thanks.
That means I will have more work than I wanted...
I guess it's time to use images and metatables.
That means I will have more work than I wanted...
I guess it's time to use images and metatables.
Re: Death of enemy, obj. removing and other stuff (game adde
After some time of lazy coding I made simple shmup where you shoot at incoming enemies, nothing special.
Arrows: movement or up/down in menu
z: shoot
Esc: back to menu
Enter: option choosing in menu
I have two issues with game:
1. For some reason some bullets shift back few pixels, especially visible in case of big enemy's double shoot
2. I have feel that my computer heats up more than it should when lauching the game often or maybe it's launching GIMP often, I don't know
Arrows: movement or up/down in menu
z: shoot
Esc: back to menu
Enter: option choosing in menu
I have two issues with game:
1. For some reason some bullets shift back few pixels, especially visible in case of big enemy's double shoot
2. I have feel that my computer heats up more than it should when lauching the game often or maybe it's launching GIMP often, I don't know
- 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
I like that game!
I solve this problem with this way:
I've created two loops, updating and deleting.
You create this function 60 times per second! Put it outside of love.update, it will be faster.
table.remove breaks the loop, all bullets after this deleted one will not be updated in this tick.For some reason some bullets shift back few pixels, especially visible in case of big enemy's double shoot
I solve this problem with this way:
Code: Select all
function BulletUpdate(dt)
for i,e in pairs (bullets) do
e.x = e.x + e.s * dt
end
for i,e in pairs (bullets) do
if e.x < -25 or e.x > 800 then
table.remove(bullets,i)
end
end
end
I didn't check the time of your game, but in your update function you create your keypressed.2. I have feel that my computer heats up more than it should when lauching the game often or maybe it's launching GIMP often, I don't know
You create this function 60 times per second! Put it outside of love.update, it will be faster.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 11 guests