Results 1 to 6 of 6

Thread: Simple Snake Game - Castle Game Engine

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Nice example.

    I haven't actually tried your game as I don't have Lazarus installed on this computer but after taking a quick look at your code I believe I found a small error/bug.

    When you are setting the window size you are using maxx for calculating both window height and window width. Shouldn't you be using maxy when calculating window height?

    Also after looking at your TRabbit.ResetRabbit procedure I fear that when snake becomes really big and occupies most of the playfield this procedure would take quite some time before being able to place the rabbit at new location since the random point could be often generated at position that is currently occupied by snake.
    You could solve this by having additional list of all free cells where rabbit can be placed so you would be simply randomly choosing one of this list items (cells) instead of choosing random coordinates (one random call and no loop).
    But the problem is that such list would have to be constantly updated on every snake move which could lead to its own overhead especially at the start of the game where such list would contain lots of items due to lots of free spaces which would result in lots of data movement when an list item is removed..
    So perhaps you could use current approach until the snake size reaches certain point like 75% of its maximum size (the number of all cells on the game map) and then switch to using list of free cells as suggested above.

    EDIT: By the way I recommend you rename your unit1.pas to some more meaningful name which would allow others to quickly realize what it is used for.
    Last edited by SilverWarior; 08-11-2016 at 06:46 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •