Hi,
I'm new to the love community and hope you guys can help me out a bit. I am a coding beginner and keen to improve my coding skills
I have made this game and need advice on how to improve the code and use of language in order to take it further. If anyone can give me any coding tips they will be much appreciated
The game is based on an idea I've had for a long time now but lacked the coding knowledge to make it. I used to work with QBasic a long time ago and only just discovered how easy using more up to date languages are.
Some info on the Game:
its a cliched zombie shooter so far but I have plans to make it something more unique in the future. At the moment you can shoot and kill zombies and reload
and that's about it. Zombies can't hurt you right now. It's a very basic start just to get the idea into a functioning program.
Keys:
"W,A,S,D": Movement
"Space": Shoot
"C": Crouch
"R": Reload
Any advice is welcome, hope you guys can help.
Need help with new game
Need help with new game
- Attachments
-
- ShootoutZ.love
- (814.68 KiB) Downloaded 264 times
Last edited by Pin222 on Thu Nov 21, 2013 8:52 pm, edited 1 time in total.
If you like to shoot pixels with pixels using pixels check out my game progress here: http://love2d.org/forums/viewtopic.php?f=5&t=76060
Re: Need help with new game
Welcome to the community!
This works, but it takes up more memory (not that that's really your primary concern at this point, but just thought I'd let you know...).
Instead, do it like this:
Also, instead of doing it all seperately, you could make them all a quad. This saves space and is easier for you to use. Using this, you can also set the filter to them all at once, instead of with a for-loop.
As for the drawing, it might be easier for you to do images without any offset for collision testing purposes and things like that.
I like the way you did your animation! It's pretty nifty!
You should never, EVER hard-code variables like this! Hard-coding isn't a good way to do things. Instead of 20 and 4, you could make a new variable called player.ox, player.oy (o for offset). If you do this, it will be easier to change later. Instead of changing all the 20s and 4s, you only have to change one variable.
In the player.lua, I don't know how you're planning on doing it, but...
It seems like dt doesn't really matter here. Again, I don't know how you're going to be doing it, but I would make the argument the gun you're changing to. Also, in this bit:
It seems like it would be easier to have all of the weapons pre-loaded in player.weapon, and then have another variable, called something like player.weapon set, and then make it equal to the 'rifle' table. This will also make it easier to apply power-ups and things later, if the power-ups go away after losing the gun/etc.
Also: in on lines 45 & 46, pnum and inum should be local. ALWAYS make variables either local or part of a local table. This will prevent confusion later.
On line 47, I think every weapon should have it's own firing sound, which is another advantage to having that table. It would allow you to have non-gun weapons, like hammers, swords, etc.
Since I told you to make the tables local, return the main table at the end of the file. For example:
is what you would use for your player.lua file. Then, in main.lua, you would do
I also like your main.lua by the way. A lot of newer coders and even some more experienced coders try to make everything happen in main.lua, which just won't work. Yours is nice and clean!
Don't really have a comment on conf.lua, except that there are variable, just so that you know.
Very polished code! Nice start!
Note: after putting anal in the file the game works fine.
One note: I don't know if I am just great at your game or it's just coded that way, but every time I shoot I hit a zombie.
Also, zombies in the back spurt blood first.
Good job!
On all the files, for example, zombile.lua, you don't need to do:Error
main.lua 4: module 'anal' not found:
...
Code: Select all
zombie = {}
zombie.img = {}
zombie.img[1] = love.graphics.newImage("art/zwalk1.png")
...
Instead, do it like this:
Code: Select all
zombie = {
img = {
love.graphics.newImage("art/zwalk1.png"),
love.graphics.newImage("art/zwalk2.png"),
love.graphics.newImage("art/zwalk3.png"),
love.graphics.newImage("art/zwalk4.png"),
...
}
}
As for the drawing, it might be easier for you to do images without any offset for collision testing purposes and things like that.
I like the way you did your animation! It's pretty nifty!
Code: Select all
if v.y < player.y + 20 and v.y > player.y - 4 and v.currentAnim ~= "dead" then
In the player.lua, I don't know how you're planning on doing it, but...
Code: Select all
function player.changeWeapon(dt) -- changes current weapon
Code: Select all
if player.weapon.type == "rifle" then
player.weapon.magSize = 30
player.weapon.maxRange = 100
player.weapon.fireRate = 2
player.weapon.reloadTime = 20
player.weapon.damage = 1
player.weapon.bulletNum = player.weapon.magSize
end
end
Also: in on lines 45 & 46, pnum and inum should be local. ALWAYS make variables either local or part of a local table. This will prevent confusion later.
On line 47, I think every weapon should have it's own firing sound, which is another advantage to having that table. It would allow you to have non-gun weapons, like hammers, swords, etc.
Since I told you to make the tables local, return the main table at the end of the file. For example:
Code: Select all
return player
Code: Select all
player = require "player"
Don't really have a comment on conf.lua, except that there are variable, just so that you know.
Very polished code! Nice start!
Note: after putting anal in the file the game works fine.
One note: I don't know if I am just great at your game or it's just coded that way, but every time I shoot I hit a zombie.
Also, zombies in the back spurt blood first.
Good job!
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Need help with new game
Meh, that is way too strong. It's generally a good practice not to hard-code constants, but I use hard-coded constants all the time in my own code.davisdude wrote:You should never, EVER hard-code [s]variables[/s]constants like this!
That should bedavisdude wrote:Code: Select all
player = require "player"
Code: Select all
local player = require "player"
Help us help you: attach a .love.
Re: Need help with new game
thanks davisdude and robin for the quick response
I removed the code that was causing the error and re-uploaded it as a .love for you guys. I was planning to use the AnAl library so all my animation frames are on a sprite sheet and not single files. I haven't got my head round the usage of the library yet. But I think instead I will first try the Quad method you were talking about.
roughly
Bit more about the game:
The plan is for it to be a survival shooter where you battle against zombies (cliche i know but why reinvent the wheel... at least not right now anyway) and have the ability to recruit other NPCs . I am researching using module functions for when I want to add allies and enemy NPCs so I don't have to code them all separately. like this http://www.coronalabs.com/blog/2011/08/ ... technique/ If anyone can point me in the right direction with this let me know.
Thanks a lot for the input, it's good to get other minds to look at a project at a different angle. This help is exactly what I was looking for. I will keep the thread posted for updates I make, I'm sure you guys will be interested in where I want to take the game
I removed the code that was causing the error and re-uploaded it as a .love for you guys. I was planning to use the AnAl library so all my animation frames are on a sprite sheet and not single files. I haven't got my head round the usage of the library yet. But I think instead I will first try the Quad method you were talking about.
Yeah you got me there, just being a bit sloppyCODE: SELECT ALL
if v.y < player.y + 20 and v.y > player.y - 4 and v.currentAnim ~= "dead" then
You should never, EVER hard-code variables like this! Hard-coding isn't a good way to do things. Instead of 20 and 4, you could make a new variable called player.ox, player.oy (o for offset). If you do this, it will be easier to change later. Instead of changing all the 20s and 4s, you only have to change one variable.
do you mean something like this:CODE: SELECT ALL
if player.weapon.type == "rifle" then
player.weapon.magSize = 30
player.weapon.maxRange = 100
player.weapon.fireRate = 2
player.weapon.reloadTime = 20
player.weapon.damage = 1
player.weapon.bulletNum = player.weapon.magSize
end
end
It seems like it would be easier to have all of the weapons pre-loaded in player.weapon, and then have another variable, called something like player.weapon set, and then make it equal to the 'rifle' table. This will also make it easier to apply power-ups and things later, if the power-ups go away after losing the gun/etc.
Code: Select all
--preset the weapon tables
player.weapon.rifle(1) = 30 -- mag size
player.weapon.rifle(2) = 100 -- max range
etc..
player.weapon.pistol(1) = 10
player.weapon.pistol(2) = 50
etc..
--change currentWeapon variable to change weapon type
currentWeapon = rifle
-- get mag size of current weapon
player.weapon.currentWeapon(1)
Yeah it's a little too accurate at the moment. Right now it doesn't take into account the distance from the target or other factors to effect the hit chance. Also one bullet can kill say 10 zombies in a row and also make a bullet ground hit animation in front of them all. This I plan to improve with stuff like bullet trajectory and penetration, right now it just detects if the zombie is in line with the player and rolls a dice for a hit chance.One note: I don't know if I am just great at your game or it's just coded that way, but every time I shoot I hit a zombie.
Also, zombies in the back spurt blood first.
Bit more about the game:
The plan is for it to be a survival shooter where you battle against zombies (cliche i know but why reinvent the wheel... at least not right now anyway) and have the ability to recruit other NPCs . I am researching using module functions for when I want to add allies and enemy NPCs so I don't have to code them all separately. like this http://www.coronalabs.com/blog/2011/08/ ... technique/ If anyone can point me in the right direction with this let me know.
Thanks a lot for the input, it's good to get other minds to look at a project at a different angle. This help is exactly what I was looking for. I will keep the thread posted for updates I make, I'm sure you guys will be interested in where I want to take the game
If you like to shoot pixels with pixels using pixels check out my game progress here: http://love2d.org/forums/viewtopic.php?f=5&t=76060
Re: Need help with new game
No problem!pin222 wrote:thanks davisdude and robin for the quick response
That is one way you could do it...pin222 wrote:do you mean something like this:roughlyCode: Select all
--preset the weapon tables player.weapon.rifle(1) = 30 -- mag size player.weapon.rifle(2) = 100 -- max range etc.. player.weapon.pistol(1) = 10 player.weapon.pistol(2) = 50 etc.. --change currentWeapon variable to change weapon type currentWeapon = rifle -- get mag size of current weapon player.weapon.currentWeapon(1)
Well, just thought I'd let you know...pin222 wrote:Yeah it's a little too accurate at the moment. Right now it doesn't take into account the distance from the target or other factors to effect the hit chance. Also one bullet can kill say 10 zombies in a row and also make a bullet ground hit animation in front of them all. This I plan to improve with stuff like bullet trajectory and penetration, right now it just detects if the zombie is in line with the player and rolls a dice for a hit chance.
I know, but I guess I just wanted to emphasize the importance...Robin wrote:Meh, that is way too strong. It's generally a good practice not to hard-code constants, but I use hard-coded constants all the time in my own code.
You're right, I see my mistake. However, they do use the player table in their zombie.lua, so I guess that defeats the entire purpose. It's still a good habit to keep, though.Robin wrote:That should beCode: Select all
local player = require "player"
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: Need help with new game
I actually quite enjoyed the game
So here is some notes and comments :
Positives first :
-Its different from what i expected, as normally its a zombie shooter in the style of isometric or topdown trying to go for a realism effect... Thus many kudos to you .
-I absolutely love the animations and images! That pixelly goodness!
Though : (Negatives)
-Running right up to zombies and shooting them is probably the best way to go, so i hope there's plans to make it so zombies prevent that.
-I hope you have some way of indicating our ammo and a indication of reloading would be nice..
---But these issues are linked with the stage/or completion of game and thus are not incredibly important, do note however they are mentioned as i felt they are what would have made it abit more fun and easier to work with .
Other comments :
I do love them animations ....
-I noticed the slowing down with movement etc, pretty nice you got that it rather than a simple changing of a y value.
-The graphic style you use is wonderful -- I gave a happy cheer when i saw the pixelly goodness
-The gmae can be hard if you set a goal, i tried making it so zombies wont make it across half screen... it held up untill i missed 4 shots and they caught up haha.
-Keep up the good work! Im wanting to play this when its done
So here is some notes and comments :
Positives first :
-Its different from what i expected, as normally its a zombie shooter in the style of isometric or topdown trying to go for a realism effect... Thus many kudos to you .
-I absolutely love the animations and images! That pixelly goodness!
Though : (Negatives)
-Running right up to zombies and shooting them is probably the best way to go, so i hope there's plans to make it so zombies prevent that.
-I hope you have some way of indicating our ammo and a indication of reloading would be nice..
---But these issues are linked with the stage/or completion of game and thus are not incredibly important, do note however they are mentioned as i felt they are what would have made it abit more fun and easier to work with .
Other comments :
I do love them animations ....
-I noticed the slowing down with movement etc, pretty nice you got that it rather than a simple changing of a y value.
-The graphic style you use is wonderful -- I gave a happy cheer when i saw the pixelly goodness
-The gmae can be hard if you set a goal, i tried making it so zombies wont make it across half screen... it held up untill i missed 4 shots and they caught up haha.
-Keep up the good work! Im wanting to play this when its done
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: Need help with new game
If I run, I can't shot. This is good by a sniper or something like this, but if I have a machinegun I don´t have to aim, but then the hit-rate are less than with aim.
But I like this game and his aminations!
Here is a list of things I want (only ideas):
-more typs of zombie
-more weapons
-tanks, rockets, ... (maybe to hard )
-You must protect a base, if a zombie reach them, you lose.
keep up the good work!
But I like this game and his aminations!
Here is a list of things I want (only ideas):
-more typs of zombie
-more weapons
-tanks, rockets, ... (maybe to hard )
-You must protect a base, if a zombie reach them, you lose.
keep up the good work!
Re: Need help with new game
Even though it's a bit barebones right now, the animation and the feeling of shooting and seeing the zombies die is quite satisfying
Email: ic4ruz39@gmail.com
Who is online
Users browsing this forum: Amazon [Bot] and 2 guests