freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

Inspired by the Falling Sand Game!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    freebasic.net Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
mambazo
Sr. Member
PostPosted: Jan 26, 2006 2:56    Post subject: Inspired by the Falling Sand Game! Reply with quote

I wont tell ya anything, see if you can figure out how to reach the goals!

Code:
' Flow Control

' Mambazo@gmail.com

' Ideas:
'
' Warp hole. Sand goes in one node, comes out the other ;)
'
' More Sand Types


Option Explicit

#DEFINE ScrW 800
#DEFINE ScrH 600

Const VOID = 0
Const WATER = 1
Const WATERRIGHT = 2
Const WATERLEFT = 3
Const SAND = 4
Const SANDRIGHT = 5
Const SANDLEFT = 6
Const WALL = 7
Const CURSOR = 10
Const LIGHTBOX = 11
Const DARKBOX = 12
Const LIGHTKILLER = 13
Const DARKKILLER = 14

Const B_Size = ScrW * ScrH

SCREENRES ScrW, ScrH, 8,3',&h1

Palette 1, 255,255,255
Palette 2, 255,255,255
Palette 3, 255,255,255
Palette 4, 100,100,100
Palette 5, 100,100,100
Palette 6, 100,100,100
Palette 10, 255,0,0
Palette 7, 155,100,40
Palette 11, 255,255,255
Palette 12, 100,100,100
Palette 13, 70,70,70
Palette 14, 205,205,205

Randomize Timer

Dim As String in
Dim As Integer i, j, Boff, MouseX, MouseY, Buttons, _
                                Wheel, TotalWater, ButtonHold, _
                                MouseXo, MouseYo, PenSize, Wheelo, _
                                ScoreLight, GoalLight, ScoreDark, GoalDark, RandX, RandY, _
                                Grains, GrainToggle, seconds

Dim As Byte pixel
Dim As Double t, Rand, tsec

start:
Cls

Boff = 1

SETMOUSE ,,0

Print "Press any key to begin!"
Sleep

SCREENSET 2,1
Cls
Dim Buffer As Byte Ptr
Buffer = SCREENPTR


Grains = 3000
PenSize = 2

ScoreDark = 0
ScoreLight = 0
GoalLight = 500
GoalDark = 500

' Fixed Level
For i = 0 To 6
        RandX = Int(Rnd*(ScrW-20))
        RandY = Int(Rnd*(ScrH-180))+80
        Line (RandX,RandY)-(RandX+20,RandY+20),DARKKILLER,BF
        RandX = Int(Rnd*(ScrW-20))
        RandY = Int(Rnd*(ScrH-180))+80
        Line (RandX,RandY)-(RandX+20,RandY+20),LIGHTKILLER,BF
Next i

tsec = Timer
seconds = 1
Do
        Boff = (Boff + 1) Mod 2
        If Timer > tsec + 1 Then seconds += 1: tsec = Timer
       
        t = Timer
       
        in = Inkey$
         MouseXo = MouseX: MouseYo = MouseY: Wheelo = Wheel
         GETMOUSE MouseX, MouseY, Wheel, Buttons
        
        SCREENLOCK
       
        If Grains > 0 Then
                If GrainToggle = 0 Then GrainToggle = 1 Else GrainToggle = 0
                If GrainToggle = 0 Then Pset (ScrW/2+Int(Rnd*8),8),WATER
                If GrainToggle = 1 Then Pset (ScrW/2+Int(Rnd*8),8),SAND
                Grains -= 1
        End If
       
        If Buttons And MouseX > -1 Then
                If (Buttons And 4) And ButtonHold = 0 Then
                        ButtonHold = 1
                        PenSize = (PenSize * 2) Mod 32
                        If PenSize < 2 Then PenSize = 2
                End If
                If (Buttons) And ButtonHold = 0 Then
                        ButtonHold = 1
                        MouseXo = MouseX: MouseYo = MouseY
                End If
               
                If (buttons And 2) And ButtonHold = 1 Then
                        For i = 0 To PenSize
                                For j = 0 To PenSize
                                        Line (MouseXo+i,MouseYo+j)-(MouseX+i,MouseY+j),0
                                Next j
                        Next i
                End If
                If (buttons And 1) And ButtonHold = 1 Then
                        For i = 0 To PenSize
                                For j = 0 To PenSize
                                        Line (MouseXo+i,MouseYo+j)-(MouseX+i,MouseY+j),7
                                Next j
                        Next i
                End If               
        Else
                ButtonHold = 0
        End If
           
                ' GOALS!           
            Circle (20,ScrH -20),10,LIGHTBOX,,,,F
                Circle (ScrW-20,ScrH -20),10,DARKBOX,,,,F

           
                For i = (B_Size - Boff - 1) To 1 Step -2
                        pixel = Buffer[i]
                       
                        If Buffer[i+ScrW] = DARKBOX And (pixel = SAND Or pixel = SANDRIGHT Or pixel = SANDLEFT)Then
                                ScoreDark += 1
                                Buffer[i] = VOID
                        End If
                        If Buffer[i+ScrW] = LIGHTBOX And (pixel = WATER Or pixel = WATERRIGHT Or pixel = WATERLEFT)Then
                                ScoreLight += 1
                                Buffer[i] = VOID
                        End If
                        If Buffer[i+ScrW] = LIGHTBOX And (pixel = SAND Or pixel = SANDRIGHT Or pixel = SANDLEFT)Then
                                ScoreLight -= 10
                                Buffer[i] = VOID
                        End If
                        If Buffer[i+ScrW] = DARKBOX And (pixel = WATER Or pixel = WATERRIGHT Or pixel = WATERLEFT)Then
                                ScoreDark -= 10
                                Buffer[i] = VOID
                        End If
            If Buffer[i+ScrW] = DARKKILLER And (pixel = SAND Or pixel = SANDRIGHT Or pixel = SANDLEFT)Then
                                Buffer[i] = VOID
                                Buffer[i+ScrW] = VOID
                        End If
                        If Buffer[i+ScrW] = LIGHTKILLER And (pixel = WATER Or pixel = WATERRIGHT Or pixel = WATERLEFT)Then
                                Buffer[i] = VOID
                                Buffer[i+ScrW] = VOID
                        End If

                        pixel = Buffer[i]                       
                       
                        ' Handle Water
                        If pixel = WATER Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID And Buffer[i+1] = VOID And Buffer[i-1] = VOID Then
                                                Buffer[i] = VOID
                                                Buffer[i+ScrW] = WATER
                                        Else
                                                Rand = Rnd
                                                If Rand < .5 Then Buffer[i] = WATERRIGHT
                                                If Rand > .5 Then Buffer[i] = WATERLEFT
                                        End If                         
                                End If
                        End If
                        If pixel = WATERLEFT Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID Then
                                                Buffer[i] = VOID
                                                Rand = Rnd
                                                If Rand <.5 Then Buffer[i+ScrW] = WATERRIGHT
                                                If Rand >.5 Then Buffer[i+ScrW] = WATER
                                        Else
                                                If (Buffer[i-1] = VOID) Then
                                                        Buffer[i] = VOID
                                                        Buffer[i-1] = WATERLEFT
                                                   Else
                                                           Buffer[i] = WATERRIGHT
                                                   End If
                                        End If                         
                                End If
                               
                        End If
                        If pixel = WATERRIGHT Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID Then
                                                Buffer[i] = VOID
                                                Rand = Rnd
                                                If Rand <.5 Then Buffer[i+ScrW] = WATERLEFT
                                                If Rand >.5 Then Buffer[i+ScrW] = WATER
                                        Else
                                                If (Buffer[i+1] = VOID) Then
                                                        Buffer[i] = VOID
                                                        Buffer[i+1] = WATERRIGHT
                                                   Else
                                                           Buffer[i] = WATERLEFT
                                                   End If
                                        End If                         
                                End If
                        End If

                        ' Handle Sand
                        If pixel = SAND Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID And Buffer[i+1] = VOID And Buffer[i-1] = VOID Then
                                                Buffer[i] = VOID
                                                Buffer[i+ScrW] = SAND
                                        Else
                                                Rand = Rnd
                                                If Rand < .5 Then Buffer[i] = SANDRIGHT
                                                If Rand > .5 Then Buffer[i] = SANDLEFT
                                        End If                         
                                End If
                        End If
                        If pixel = SANDLEFT Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID Then
                                                Buffer[i] = VOID
                                                Rand = Rnd
                                                If Rand <.5 Then Buffer[i+ScrW] = SANDRIGHT
                                                If Rand >.5 Then Buffer[i+ScrW] = SAND
                                        Else
                                                If (Buffer[i-1] = VOID) Then
                                                        Buffer[i] = VOID
                                                        Buffer[i-1] = SANDLEFT
                                                   Else
                                                           Buffer[i] = SANDRIGHT
                                                   End If
                                        End If                         
                                End If
                               
                        End If
                        If pixel = SANDRIGHT Then
                                If i < (B_Size - ScrW) Then
                                        If Buffer[i+ScrW] = VOID Then
                                                Buffer[i] = VOID
                                                Rand = Rnd
                                                If Rand <.5 Then Buffer[i+ScrW] = SANDLEFT
                                                If Rand >.5 Then Buffer[i+ScrW] = SAND
                                        Else
                                                If (Buffer[i+1] = VOID) Then
                                                        Buffer[i] = VOID
                                                        Buffer[i+1] = SANDRIGHT
                                                   Else
                                                           Buffer[i] = SANDLEFT
                                                   End If
                                        End If                         
                                End If
                        End If
                Next i
       
        SCREENCOPY 2,1
        SCREENSET 1,2
       
        Line (MouseX,MouseY)-(MouseX+PenSize,MouseY+PenSize),10,B
        Locate 1,1: Print "Seconds Elapsed: "; seconds
        Locate 2,1:Print "Pen Size:"; PenSize
        Locate 3,1:Print "Light Sand:"; ScoreLight; " /"; GoalLight
        Locate 4,1:Print "Dark Sand:"; ScoreDark; " /"; GoalDark
        SCREENSET 2,1
       
        SCREENUNLOCK
       
        While Timer < t + 0.005: Sleep 1: Wend
Loop Until in = Chr$(27) Or (ScoreLight >= GoalLight And ScoreDark >= GoalDark)

SCREENSET 1,1
Color 15: Print "You scored:"; (ScoreLight+ScoreDark)-(seconds)
Print "Play Again? Y/N"

Do
in = Inkey$
If in = "y" Then Goto start
Loop Until in="n"


SETMOUSE ,,1


Last edited by mambazo on Jan 27, 2006 12:57; edited 2 times in total
 
Back to top
View user's profile Visit poster's website MSN Messenger
Ryan
Sr. Member
PostPosted: Jan 26, 2006 3:32    Post subject: Reply with quote

Very very cool. I didn't beat it but I figured out how to score properly. I just don't have the patience to play through a whole game at the moment. ;-)
 
Back to top
View user's profile Send e-mail Visit poster's website
axipher
Master
PostPosted: Jan 26, 2006 16:05    Post subject: Reply with quote

I'm guessing it's something to do with sending the dots over the blocks to get rid of the different colors and sending them to there right color circle, but I never played long enough to figure that out and try it, I will tonight though, and it's great by the way, a stroke of genius.
 
Back to top
View user's profile Send e-mail MSN Messenger
Ryan
Sr. Member
PostPosted: Jan 26, 2006 17:21    Post subject: Reply with quote

Sshhh... no revealing game secrets. ^_^
 
Back to top
View user's profile Send e-mail Visit poster's website
mambazo
Sr. Member
PostPosted: Jan 26, 2006 18:07    Post subject: Reply with quote

:p

I'll be using this as a prototype for a proper game. I've got a few ideas for it already, but I won't be working on this until Arena - To The Death is complete.
 
Back to top
View user's profile Visit poster's website MSN Messenger
Ryan
Sr. Member
PostPosted: Jan 26, 2006 18:26    Post subject: Reply with quote

hehe Good enough for me. ^_^
 
Back to top
View user's profile Send e-mail Visit poster's website
Nexinarus

PostPosted: Jan 27, 2006 0:57    Post subject: Reply with quote

i got -1500 points and pushed escape.. did i win? :P
 
Back to top
View user's profile Send e-mail Visit poster's website
mambazo
Sr. Member
PostPosted: Jan 27, 2006 1:18    Post subject: Reply with quote

lol, t'was a valliant effort i'm sure ;)
 
Back to top
View user's profile Visit poster's website MSN Messenger
Deleter
Master
PostPosted: Jan 27, 2006 2:16    Post subject: Reply with quote

i got 491 but i cant prove it since the screenshot didn't work x(
 
Back to top
View user's profile
axipher
Master
PostPosted: Jan 27, 2006 3:26    Post subject: Reply with quote

Deleter wrote:
i got 491 but i cant prove it since the screenshot didn't work x(


alt + enter then print screen...
 
Back to top
View user's profile Send e-mail MSN Messenger
counting_pine
Site Admin
PostPosted: Jan 27, 2006 3:50    Post subject: Reply with quote

Could you make it run in a window by default please? I prefer it when programs don't change my screen resolution.
(Note, if you do this, you'll have to add in a check to make sure it only draws lines when the mouse is within the window. Otherwise, if you move the mouse out of the window while holding the button, it will draw a line to the top left corner of the screen. And make the player curse.)
 
Back to top
View user's profile Send e-mail
mambazo
Sr. Member
PostPosted: Jan 27, 2006 12:58    Post subject: Reply with quote

Code updated, just for you counting_pine, I added 1 line, gosh that was tricky ;)
 
Back to top
View user's profile Visit poster's website MSN Messenger
red_Marvin

PostPosted: Jan 27, 2006 13:49    Post subject: Reply with quote

Hiscore: 840 Yay!
 
Back to top
View user's profile Visit poster's website MSN Messenger
mambazo
Sr. Member
PostPosted: Jan 27, 2006 13:54    Post subject: Reply with quote

Wow, even I didn't get that much!! perhaps take a screenshot of your highscore next time! Would be fun to make an online high score somewhow. ill add that to the project notes ;)
 
Back to top
View user's profile Visit poster's website MSN Messenger
mambazo
Sr. Member
PostPosted: Jan 27, 2006 14:02    Post subject: Reply with quote

New high score chaps! ;)

 
Back to top
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Tips and Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode