Page 3 of 4

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 12:00 pm
by s-ol
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?
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.

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 12:58 pm
by Kreg
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)

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 2:15 pm
by s-ol
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)
Or maybe it's because of an if-elseif thing?

Code: Select all

if leftkey then
 ...
elseif rightkey then
 ...
elseif shootkey then
 ...
end
Like this you can only shoot when not moving.

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 3:19 pm
by Kreg
Nopre, I'm only using ifs here.

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
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?

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 3:39 pm
by Luke100000
It's your keyboard! Keyboards only can use a limited amount of keys at once. You can use your mouse to shoot.
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?
You use h before the table is ready.
When you write

Code: Select all

list = {a = "letter", b = "another letter"}
a and b will be generated at the same time.

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
I hope this was what you mean. :3

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 3:44 pm
by Kreg
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

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 4:03 pm
by s-ol
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
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)

(Also, as Enemy is an object, I would give it a lowercase Name.)

Re: Death of enemy, object removing and other stuff

Posted: Sun Dec 07, 2014 4:07 pm
by Kreg
Thanks.
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

Posted: Tue Jan 13, 2015 7:45 pm
by Kreg
After some time of lazy coding I made simple shmup where you shoot at incoming enemies, nothing special.
Shmup.zip
(36.55 KiB) Downloaded 112 times
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

Re: Death of enemy, obj. removing and other stuff (game adde

Posted: Sat Jan 17, 2015 2:39 pm
by Luke100000
I like that game! :awesome:
For some reason some bullets shift back few pixels, especially visible in case of big enemy's double shoot
table.remove breaks the loop, all bullets after this deleted one will not be updated in this tick.

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've created two loops, updating and deleting.
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
I didn't check the time of your game, but in your update function you create your keypressed.
You create this function 60 times per second! Put it outside of love.update, it will be faster. :awesome: