Hi everyone,
This is the first time I post topic in the forums. I have been learning LOVE for almost a month, and it deeply attracts me.
The small program in the attachment is a tank game, the player could move around and click space to shoot the enemy.
It is also my first love game.... so please give me some advice about the learn road map, very thanks!!
a small tank game
a small tank game
- Attachments
-
- tank.love
- a tank game
- (41.09 KiB) Downloaded 232 times
Re: a small tank game
Error wrote:Code: Select all
Error game.lua:54: bad argument #1 to 'rad' (number expected, got nil) Traceback [C]: in function 'rad' game.lua:54: in function 'draw' main.lua:28: in function 'draw' [C]: in function 'xpcall'
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
- SneakySnake
- Citizen
- Posts: 94
- Joined: Fri May 31, 2013 2:01 pm
- Contact:
Re: a small tank game
math.random expects its arguments to be integers. If they are not, weird things could happen.
In this case, math.random seems to sometimes return a value >= 5. Don't ask me why,
game.direction[5] is not a valid direction. This ultimately results in the error davisdude posted above.
You also repeat the same piece of code multiple times. You should probably turn it into a function.
Here is a patch that fixes the error, and also turns the repeated code into a function: https://gist.github.com/crumblingstatue ... 41b91128f2
The diff is a bit messed up because the code uses mixed space/tab indentation.
EDIT: On an unrelated note, does the game window have to be so high? I use a resolution of 1024x768. I know that today, most people use resolutions higher than that, but still. It does not seem necessary for this game.
Here, you are trying to call math.random with non-integer arguments:http://www.lua.org/manual/5.1/manual.html wrote: When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].
Code: Select all
ev.direction = game.direction[math.floor(math.random(1.01, 4.99))]
game.direction[5] is not a valid direction. This ultimately results in the error davisdude posted above.
You also repeat the same piece of code multiple times. You should probably turn it into a function.
Here is a patch that fixes the error, and also turns the repeated code into a function: https://gist.github.com/crumblingstatue ... 41b91128f2
The diff is a bit messed up because the code uses mixed space/tab indentation.
EDIT: On an unrelated note, does the game window have to be so high? I use a resolution of 1024x768. I know that today, most people use resolutions higher than that, but still. It does not seem necessary for this game.
Re: a small tank game
Your collision handling is messed up.
Enemies can't go through walls but you can???
Enemies colliding with enemies give weird results.
And of course, you need
Need a scoring system.
Good start - keep at it.
Enemies can't go through walls but you can???
Enemies colliding with enemies give weird results.
And of course, you need
Code: Select all
math.random(10,49)/10
Need a scoring system.
Good start - keep at it.
Re: a small tank game
Very thanks SneakySnake!SneakySnake wrote:math.random expects its arguments to be integers. If they are not, weird things could happen.
Here, you are trying to call math.random with non-integer arguments:http://www.lua.org/manual/5.1/manual.html wrote: When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].In this case, math.random seems to sometimes return a value >= 5. Don't ask me why,Code: Select all
ev.direction = game.direction[math.floor(math.random(1.01, 4.99))]
game.direction[5] is not a valid direction. This ultimately results in the error davisdude posted above.
You also repeat the same piece of code multiple times. You should probably turn it into a function.
Here is a patch that fixes the error, and also turns the repeated code into a function: https://gist.github.com/crumblingstatue ... 41b91128f2
The diff is a bit messed up because the code uses mixed space/tab indentation.
EDIT: On an unrelated note, does the game window have to be so high? I use a resolution of 1024x768. I know that today, most people use resolutions higher than that, but still. It does not seem necessary for this game.
You really give me some good ideas about programming, such as exploring the api document, reduce the redundant code...
about the height of the window, I think the size of the player, enemy, as well as the brick should adjust their size to suit different kinds of size, right?
Re: a small tank game
Hi Ref, thanks for your kindly advices, I will complete the game and think about how to success the game.Ref wrote:Your collision handling is messed up.
Enemies can't go through walls but you can???
Enemies colliding with enemies give weird results.
And of course, you needCode: Select all
math.random(10,49)/10
Need a scoring system.
Good start - keep at it.
Who is online
Users browsing this forum: No registered users and 0 guests