Death of enemy, obj. removing and other stuff (game added)

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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Death of enemy, object removing and other stuff

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Kreg
Prole
Posts: 26
Joined: Sat Nov 23, 2013 11:39 pm

Re: Death of enemy, object removing and other stuff

Post 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)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Death of enemy, object removing and other stuff

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Kreg
Prole
Posts: 26
Joined: Sat Nov 23, 2013 11:39 pm

Re: Death of enemy, object removing and other stuff

Post 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?
User avatar
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

Post 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
Kreg
Prole
Posts: 26
Joined: Sat Nov 23, 2013 11:39 pm

Re: Death of enemy, object removing and other stuff

Post 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
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Death of enemy, object removing and other stuff

Post 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.)

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Kreg
Prole
Posts: 26
Joined: Sat Nov 23, 2013 11:39 pm

Re: Death of enemy, object removing and other stuff

Post by Kreg »

Thanks.
That means I will have more work than I wanted...
I guess it's time to use images and metatables.
Kreg
Prole
Posts: 26
Joined: Sat Nov 23, 2013 11:39 pm

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

Post 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
User avatar
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

Post 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:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], MrFariator and 7 guests