Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

A Snake Game (Slither.io clone) and Some Questions

em2em2
edited May 9 in Code Sharing Posts: 10

A screenshot:

IMG_2731
I'm the tiny guy in the middle :‌)

If you want the game, copy the code from this page, then use Codea's "paste into project" feature to install it (I don't know how to create an installer). Controls should be self-explanatory. Please pardon my terribly messy code.
I also have a few questions.
1. What are best code practices I should follow?
2. How can I make the game run smoother?
3. How can I make smarter A.I. snakes?
And finally,
4. How could I allow multiplayer over WiFi? I have tried experimenting with LuaSocket for multiplayer games like this to no avail—you can find some code for it in the game, but it obviously doesn't do anything but print a worthless IP address.

Update: I have tried to fix the errors in the project—they were a problem wth dependencies I took from a space battle game I downloaded somewhere (thanks @Attila717). If you see any more errors, please inform me.

Comments

  • Posts: 69

    @em2 I'm having trouble with your code. When I run your project, wrap() appears undefined. Do you have any dependancies that this project relies on that you haven't included?

  • em2em2
    Posts: 10

    Oops! Sorry. I thought Codea exported dependencies when I used "copy project code". I'll fix it.

  • em2em2
    Posts: 10

    Is it working now?

  • dave1707dave1707 Mod
    Posts: 5,903

    @em2 The game works now and looks interesting. I'll look at the code later.

  • dave1707dave1707 Mod
    Posts: 5,903

    @em2 As I said, the game looks interesting. There's a few thing you need to fix. There are times where the FPS goes down to 7 and as you mentioned, gets jerky. You have a lot of code that's not being used (button class) which I think you intend to use later. Try to indent your code consistently. Sometimes you indent, other times you don't. Put a blank line before your functions so it's easier to see where a function starts. Sometimes you don't. Also, remove blank lines where you don't really need them. Instead of moving your finger on the screen to move the snake, maybe using a joystick so the screen is more visible. There's some names that flash when the game starts and you should set the screen to full screen. You're off to a good start and just need minor changes. As for multiplayer using sockets, you're in luck because I just got a second iPad and I have multiplayer code running on them. I have a simple TRON type game to demo how to use sockets. I just need to fix some bugs and reduce the game to a minimum so the socket code is more obvious and not the game.

  • Posts: 69

    @em2 This discussion might help you with sockets. https://codea.io/talk/discussion/6344/luasocket-questions/p1

  • em2em2
    Posts: 10

    @dave1707 Is your TRON type game ready? I would really like to see it.

  • dave1707dave1707 Mod
    Posts: 5,903

    @em2 See the discussion Multiplayer game using sockets a few discussions down.

Sign In or Register to comment.