PackyTacky - My First Proper Game

Show off your games, demos and other (playable) creations.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: PackyTacky - My First Proper Game

Post by undef »

Sam Storms wrote:
undef wrote:Nice idea!
I think apples shouldn't spawn in the same position twice in a row, what do you think?
A temporary speed up item could be interesting as well.
Very nice idea, I added it to my list for improvements for the next update :)

Ah, bug spotted, I've seen it a few times, but I wasn't able to properly fix it, so I thought instead of fixing it, I'll just change the color of the apple when that happens and it would add more than one point if the player eats it or subtract more than one point if the enemy eats it. So if I can't fix it, I'll probably end up doing that :) Thanks for trying it out. Cheers!
This can be easily fixed:

old:

Code: Select all

function Food:respawn()
    math.randomseed(os.time())
    f.x = math.random(gr.getWidth() - f.w)
    f.y = math.random(gr.getHeight() - f.h)
    if f.y < 32 then -- does not let food spawn outside the boundaries of the playing area
        f.y = f.y + 32
    end
end
suggestion:

Code: Select all

function Food:respawn()
    --math.randomseed(os.time()) I would only do this once, when you load the game
    local lastX, lastY = f.x, f.y
    f.x = math.random(gr.getWidth() - f.w)
    f.y = math.random(32, gr.getHeight() - f.h) -- is at least 32
    if f.x==lastX and f.y==lastY then
        f.x, f.y = -- put something deterministic here compared to the curent position, so that it is not only unlikely but IMPOSSIBLE 
                      -- that the same position repeats twice in a row (if you just run math.random again it is unlikely but possible)
    end
end
I hope that helps!
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: PackyTacky - My First Proper Game

Post by Sam Storms »

undef wrote: This can be easily fixed:

old:

Code: Select all

function Food:respawn()
    math.randomseed(os.time())
    f.x = math.random(gr.getWidth() - f.w)
    f.y = math.random(gr.getHeight() - f.h)
    if f.y < 32 then -- does not let food spawn outside the boundaries of the playing area
        f.y = f.y + 32
    end
end
suggestion:

Code: Select all

function Food:respawn()
    --math.randomseed(os.time()) I would only do this once, when you load the game
    local lastX, lastY = f.x, f.y
    f.x = math.random(gr.getWidth() - f.w)
    f.y = math.random(32, gr.getHeight() - f.h) -- is at least 32
    if f.x==lastX and f.y==lastY then
        f.x, f.y = -- put something deterministic here compared to the curent position, so that it is not only unlikely but IMPOSSIBLE 
                      -- that the same position repeats twice in a row (if you just run math.random again it is unlikely but possible)
    end
end
I hope that helps!
Helps a lot! Thanks a bunch :) I had the idea of storing the previous x and y coordinates, but I wasn't able to figure out what would I put in for the new position. What if I put this in the condition? Its using math.random but would it still be possible like this for an apple to spawn in the same position twice?

Code: Select all

if f.x == lastX and f.y == lastY then
    f.x, f.y = f.x + math.random(gr.getWidth() - f.w), f.y + math.random(32, gr.getHeight() - f.h)
end
EDIT: I just removed all the math.randomseed() calls (two, actually, one to respawn the apples and the second to reposition the enemy on the Y axis when he goes off screen) and replaced them by one single math.randomseed() call when love loads, and previously I did experience two or more apples appearing simultaneously at the same position, but now it didn't happen, I played a lot but it never happened :) Thanks again! :D
gestaltist
Prole
Posts: 49
Joined: Thu May 29, 2014 10:56 am

Re: PackyTacky - My First Proper Game

Post by gestaltist »

Kudos, it’s a nice little game.

I like the polished starting menu - I never get around to making menus because I find making them tedious.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: PackyTacky - My First Proper Game

Post by undef »

Code: Select all

if f.x == lastX and f.y == lastY then
    f.x, f.y = f.x + math.random(gr.getWidth() - f.w), f.y + math.random(32, gr.getHeight() - f.h)
end
EDIT: I just removed all the math.randomseed() calls (two, actually, one to respawn the apples and the second to reposition the enemy on the Y axis when he goes off screen) and replaced them by one single math.randomseed() call when love loads, and previously I did experience two or more apples appearing simultaneously at the same position, but now it didn't happen, I played a lot but it never happened :) Thanks again! :D
Yeah, with two random calls on a it becomes very unlikely that two apples appear at the same position in a row, on a 10x10 grid the probability is 0.01 percent.
But I think the following is a good rule of thumb:

If there is something in your program that should never happen, make sure it's impossible.

Code: Select all

if f.x == lastX and f.y == lastY then
    f.x = (f.x + math.random(gr.getWidth() - f.w) + 5)%GRIDWIDTH
end
This way in the 1 percent occasion that your the new position is equal to the old, the new apple will just move 5 gridpositions to the right (with periodic boundry conditions).
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: PackyTacky - My First Proper Game

Post by Sam Storms »

gestaltist wrote:Kudos, it’s a nice little game.

I like the polished starting menu - I never get around to making menus because I find making them tedious.
Thank you, I think its tedious as well but I do believe its pretty crucial :)
undef wrote: Yeah, with two random calls on a it becomes very unlikely that two apples appear at the same position in a row, on a 10x10 grid the probability is 0.01 percent.
But I think the following is a good rule of thumb:

If there is something in your program that should never happen, make sure it's impossible.

Code: Select all

if f.x == lastX and f.y == lastY then
    f.x = (f.x + math.random(gr.getWidth() - f.w) + 5)%GRIDWIDTH
end
This way in the 1 percent occasion that your the new position is equal to the old, the new apple will just move 5 gridpositions to the right (with periodic boundry conditions).
This is very nice, never thought of using modulo in there, but I'm not using any grid though, so I think it would be okay to put in the screen width in place of Gridwidth? I tested it and it worked fine, but I'm not very good at mathematics :P just enough to get me by, but its keeping the apples' coordinates within the boundaries; no apples spawned outside them.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: PackyTacky - My First Proper Game

Post by undef »

If you just place it on arbitrary screen coordinates, then the screen coordinate system is your grid.
Although it would then be possible that the next position of the apple is less far away from your position than the actual width of your apple.

I think it's recommendable for any programmer to study some mathematics, just think of it as very old codebase worth studying.
It surely helps me a lot all the time!
twitter | steam | indieDB

Check out quadrant on Steam!
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: PackyTacky - My First Proper Game

Post by Sam Storms »

Yeah, sometimes there's two apples in a line, but that won't pose much of a problem I think :)

I know math is good but I'm a university student and I've never ever been good at math even though I tried extremely hard to get good at it, so I try to stay away from it as much as I can :( If there's something that I don't know but I can use in my game development, I'll certainly go ahead and look it up and learn it, but that's just it, I won't go into much detail or related stuff after that unless that stuff would directly help me as well :P
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: PackyTacky - My First Proper Game

Post by Sam Storms »

Hello again everyone, I've been inactive for a while due to some stuff I was busy with :) But, I just updated PackyTacky to v2.0, all the suggestions and bug fixes we talked about in this topic have been implemented (thanks to undef for helping me fix the apples bug).

Summary of changes:

- FIXED: Two or more apples spawning at the same place one after the other
- Minor optimizations
- Renamed "startmenu.lua" to "menu.lua"
- Code cleanup
- Modified enemy speed increments
- Added option to take screenshot at game over
- Added temporary speed increasing powerups (Green apples!)
- Released for Mac OSX

My github repo has also been updated, so if anyone's interested, here's the link again: https://github.com/sammetal92/PackyTacky

All the old links still work. If they don't work for you, please inform me so I can fix it :) Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests