AlienInvaders - my first game

Show off your games, demos and other (playable) creations.
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

AlienInvaders - my first game

Post by Larsii30 »

Hey everyone,

I'm new in this community and in programming with lua/Löve2D.
I work on a 'small' first game called AlienInvaders .

(and btw sorry for my bad english :D)
I would like to know, what you are thinking about my code and hoped you can give me some tips how I could do things better.

The game is still anfinished at the moment, but it's core features are in. The most complicated thing for me was to move the aliens correctly.
some ideas whats I could do better ?

Greets from germany. !
Attachments
AlienInvader.love
Version 0.0.2
(534.94 KiB) Downloaded 343 times
4ROS4
Prole
Posts: 7
Joined: Mon Sep 19, 2011 10:24 am

Re: AlienInvaders - my first game

Post by 4ROS4 »

Hi!

I quite like the graphics, the aliens are really funny.

The first thing that i saw in your code is abusive new line and no indentation: (it's not a technical problem but it's for readability of your code)

Your code (for example):

Code: Select all

function love.load ()

img.load()

end
Your code should better be like that:

Code: Select all

function love.load()
      img.load()
end
if a line begins with “function”, “repeat”, “while” or ends with “then”, “do” or “{“, it’s the start of a block. If the line is equal to “end” or “}” or starts with “until”, it’s the end of a block. Each block should be put to the right.. You can achieve it with a lot of editors pressing the tab touch.


I liked the concept folder wich contains the changelog and the aim of the game, it's a good initiative even if i didn't understood everything due to german ;)

Another thing is that:

Code: Select all

TEsound.play ("sfx/gun.wav")
Don't put a space between function name and the opening bracket.


And last thing:

Code: Select all

if test == true then
     print("lol")
end
equals:

Code: Select all

if test then
     print("lol")
end
For the rest, I didn't see ugly things, and I have to go to work... Java and android will kill me! :death:

Good luck and continue working!
Last edited by 4ROS4 on Tue Sep 20, 2011 9:19 am, edited 1 time in total.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: AlienInvaders - my first game

Post by kraftman »

why shouldnt you put a space between the function name and opening bracket?

You don't need the .lua extension in require, and the game won't run in newer versions of love with it .

Other than that, its a great first game!
4ROS4
Prole
Posts: 7
Joined: Mon Sep 19, 2011 10:24 am

Re: AlienInvaders - my first game

Post by 4ROS4 »

Just for better understanding. It's not an obligation like indentation...
Most of the people do that..
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: AlienInvaders - my first game

Post by kikito »

I recently heard one saying the other day:
When, don't write that code the compiler understands; write it so that other people understand it
In all languages, putting the function name next to the parenthesis it refers to is pretty much a standard convention. At least one language (ruby) gives you a warning when you put a space in between (In my opinion, this is proof enough that it's worse than a bad indentation)

So, please think of your fellow programmers, and remove that space. Also, if you remove that habit, it'll make your life easier, too; you will work more easily with code written by others, since that is the standard. In the last place, your code will look more professional - just like it does when it has proper indentation.
When I write def I mean function.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: AlienInvaders - my first game

Post by kraftman »

Change it to

Code: Select all

TEsound.play                                                       "sfx/gun.wav"


just to annoy people.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: AlienInvaders - my first game

Post by GijsB »

kraftman wrote:Change it to

Code: Select all

TEsound.play                                                       "sfx/gun.wav"


just to annoy people.
HAhahahahaah!!
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: AlienInvaders - my first game

Post by Larsii30 »

woah . First, thank you guys. :)
kraftman wrote:
You don't need the .lua extension in require,...
Thanks.
4ROS4 wrote:Hi!

I quite like the graphics, the aliens are really funny.

The first thing that i saw in your code is abusive new line and no indentation: (it's not a technical problem but it's for readability of your code)

Your code (for example):

Code: Select all

function love.load ()

img.load()

end
Your code should better be like that:

Code: Select all

function love.load()
      img.load()
end
Oh, okay. I'll keep it in mind.
4ROS4 wrote:
I liked the concept folder wich contains the changelog and the aim of the game, it's a good initiative even if i didn't understood everything due to german ;)
This concept folder is reaally important for me. On the one hand its helpful to check what I've done and to think about what I could do next. On the other hand it encourages me to see yey, I had a concept and I solved this and this problem with the game. Great to learn things.
4ROS4 wrote: Another thing is that:

Code: Select all

TEsound.play ("sfx/gun.wav")
Don't put a space between function name and the opening bracket.
[/quote"]

Hm, I'll try it out. :)
4ROS4 wrote: And last thing:

Code: Select all

if test == true then
     print("lol")
end
equals:

Code: Select all

if test then
     print("lol")
end
oh. o.o Thats... much easier! Thanks. I'm here to learn.
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: AlienInvaders - my first game

Post by Larsii30 »

Now I stopped to program this mini-game because with this game I learned a lot about how to write code and figure things out, but I started very bad to program and its now totally ugly code and it whould be to much work to rewrite it anyway.

The game IS playable but it isn't very difficult to win.
If you got a bit feedback, I whould really interested .

I tried to get the file as small as possible.
AlienInvader005.love
Version 0.0.5
Controls Arrows Left, Right - Space = Fire , Enter = Gamestart
(192.62 KiB) Downloaded 244 times
Greets. :)
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: AlienInvaders - my first game

Post by tentus »

Larsii30 wrote:Now I stopped to program this mini-game because with this game I learned a lot about how to write code and figure things out, but I started very bad to program and its now totally ugly code and it whould be to much work to rewrite it anyway.

The game IS playable but it isn't very difficult to win.
If you got a bit feedback, I whould really interested .

I tried to get the file as small as possible.
AlienInvader005.love
Greets. :)
Hm. On my machine, the aliens move only occasionally. Is that by design?

Also, please consider this alternative version of your main.lua:

Code: Select all

require "bullets"
require "player"
require "aliens"
require "TEsound"
require "img"

function love.load()
	math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
	lg = love.graphics
	lk = love.keyboard
	rnd = math.random(1,6)
	g = {
		State = "menu",
		Start = false
	}
	time = {
		timer = 0,
		timer2 = 0,
		start = 0,
	}
	reset = 0
	aliens.load()
	img.load()
end


function love.update(dt)
	if g.State == "menu" then
		-- do nothing
	elseif g.State == "game" then
		time.timer = time.timer + dt
		time.timer2 = time.timer2 + dt
		bullets.shot()
		player.move()
		aliens.hit()
		aliens.start()
		TEsound.cleanup()
		aliens.checkLast()
	end
end

function love.draw()
	player.colAliens()
	img.draw()
	--[[ DEBUG INFO
	lg.print ("Debuginfos:",1,1)
	lg.print ("playerX:"..player.X,1,20)
	lg.print ("bulletsX:"..bullets.X,1,20*2)
	lg.print ("bulletsY:"..bullets.Y,1,20*3)
	lg.print ("aliens[2].y:"..aliens[2].y,1,20*4)
	lg.print ("NR:"..nr,1,20*6)
	]]
	-- GEWONNEN-TEXT
	if aliens.allDead() and player.colAliens() == 0 then
		lg.print("         EPIC WIN !", lg.getWidth()/3,lg.getHeight()/3)
		lg.print("(press Escape for the main menu)", lg.getWidth()/3-30,lg.getHeight()/3+200)
	end
	if player.colAliens() == 1 then
		g.State = "menu"
	end
	if g.State == "menu" then
		lg.print("Press Enter to Start",lg.getWidth()/3+10,lg.getHeight()/3+100)
	end
end
I took out some unneeded newlines and changed some indentation. You've sort of got how indentation is supposed to be used, but not quite. The idea is that its used to show what is inside of what, rather than what follows what, which is how I think you were using it.

Also, I switched an if out for an elseif (elseif g.State == "game" then). The idea is, you only want one of the chunks to run. If the State was "menu", then it couldn't also be "game", so by making the if an elseif, we let the game skip the second chunk. Elseif is a fantastic tool, try to get a good handle on it and it will serve you well.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest