gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. July 29, 2010, 11:30:21 AM

Login with username, password and session length
11.07.10 - Small update without new games (only two version updates), but with a nice scoop of the current game development in the community with links. Cheers!

10.02.10 - I added a webpage for our recently completed Antagonist competition. Be sure to check it out. Smiley

09.02.10 - Another update! This one features no less than 9 games, including Slime Quest, Bowser's Story, Amarnath and others. Visit the main page for descriptions and downloads. Stay tuned for the official page of our Antagonist competition.
gfx
gfx
*
gfxgfx
gfxgfx gfxgfx
gfxgfx Home Help Search Login Register   gfxgfx
gfx gfx
gfx
Pages: [1]
Print
Author Topic: Multi Player Snake Game Made in 30 Minutes!  (Read 1631 times)
KristopherWindsor
Forum Sage
*****
Gender: Male
Posts: 321


The Thirsty Smiley


View Profile WWW Email
« on: February 26, 2008, 03:28:25 AM »

This game is simple, but maybe someone else can enhance it. ;-)
In this multi player version of snake, the two snakes are controlled by the joystick. (I only have one good joystick, so I configured the two analog pads to each control a snake; you will probably need to reconfigure the controls, anyway. Tongue)
The snakes can go over their own trails, but not the trails of the other players.
This game can easily be expanded to support 3 or 4 players if you have the hardware. ;-)

Code:
' Snake! v1.0
' (C) 2008 Innova and Kristopher Windsor

Const screenx = 800, screeny = 600, player_max = 2

Type player_type
  As Single x, y
  As Double angle
  As Single Ptr jx, jy
  As Uinteger c, score
End Type

Dim Shared As Single x1, x2, x3, x4
Dim Shared As player_type player(1 To player_max)

Screenres screenx, screeny, 32
Randomize Timer

Sub setup
  For i As Integer = 1 To player_max
    With player(i)
      .x = (i - .5) * screenx / player_max
      .y = screeny / 2
      .angle = Atn(1) * 2
      If .c = 0 Then
        'game has not started
        .c = Rgb(Rnd * 256, Rnd * 256, Rnd * 256)
        Select Case i
        Case 1
          .jx = @x1
          .jy = @x2
        Case 2
          .jx = @x4
          .jy = @x3
        End Select
      End If
    End With
  Next i
End Sub

setup

Do
  Getjoystick(0,, x1, x2, x3, x4)
 
  For i As Integer = 1 To player_max
    With player(i)
      If Abs(*.jy) + Abs(*.jx) > .08 Then .angle = Atan2(*.jy, *.jx)
      .x += Cos(.angle)
      .y += Sin(.angle)
      If .x < 0 Then .x += screenx
      If .x > screenx - 1 Then .x -= screenx
      If .y < 0 Then .y += screeny
      If .y > screeny - 1 Then .y -= screeny
      For i2 As Integer = 1 To player_max
        If i <> i2 Then
          If Point(.x, .y) = player(i2).c Then
            Circle (.x, .y), 8, &HFFFFFFFF
            player(i2).score += 1
            Print "Player " & i2 & " now has " & player(i2).score & " points"
            setup
            Sleep
            Cls
          End If
        End If
      Next i2
    End With
  Next i
 
  For i As Integer = 1 To player_max
    With player(i)
      Pset (.x, .y), .c
    End With
  Next i
 
  Sleep 10
Loop Until Inkey = Chr(27)

Print "Final Score:"
For i As Integer = 1 To player_max
  With player(i)
    Print "Player " & i & ": " & .score
  End With
Next i
Sleep
« Last Edit: February 26, 2008, 03:33:17 AM by KristopherWindsor » Logged

Lachie Dazdarian
Double dipper
Administrator
Forum Sage
*****
Gender: Male
Posts: 875


lachie13
View Profile WWW Email
« Reply #1 on: February 26, 2008, 04:34:51 PM »

I don't have a joystick so....but I liked the apperance of snakes.

Anyway, you know my general opinion about this sort of quick programs.

I would be intrigued if you made a snakes AI.
« Last Edit: February 26, 2008, 04:36:38 PM by Lachie Dazdarian » Logged

"Do you realize that using an array in the conventional memory is suicide?"

~ Kiyotewolf
KristopherWindsor
Forum Sage
*****
Gender: Male
Posts: 321


The Thirsty Smiley


View Profile WWW Email
« Reply #2 on: February 26, 2008, 07:01:26 PM »

I would be intrigued if you made a snakes AI.

It's much more fun with two real players. ;-)
And besides, I don't have a good strategy (to give to the AI) yet. Tongue
Logged

Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx