gfxgfxFreeBASIC Games Directory Forumgfxgfx
gfx gfx
gfx
Welcome, Guest. Please login or register. November 23, 2017, 10:57:32 AM

Login with username, password and session length
14.09.2014 - Check the results of our latest game dev competition here: http://games.freebasic.net/forum/index.php?topic=606.0
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 5356 times)
KristopherWindsor
Forum Sage
*****
Gender: Male
Posts: 363


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. ;-)

' 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: 1255


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

"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist
KristopherWindsor
Forum Sage
*****
Gender: Male
Posts: 363


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.18 | SMF © 2013, Simple Machines
Cerberus design by Bloc
Valid XHTML 1.0! Valid CSS!
gfx
gfxgfx gfxgfx