[2D] Crazy Snake

Advanced game related topics
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

Thanks Davido :wink:
davido wrote: After all you called 'Crazy Snake'
And crazy code :mrgreen: Yessss i'm crazy ..... Ha ha ha

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [2D] Crazy Snake

Post by davido »

@falsam
I've carried out a few tests with the following observations:

At score 5: the playing area starts to rotate, slowly, clockwise.
As soon as it rotates through 90 degrees the playing area suddenly drops! The vertex is then at the centre of the board so that nearly half the playing area is hidden.
This nearly always occurs about score 8 or 9 but only disappears when score = 10.

I presume the changes which occur later are programmed by you:

At score 15 the board shrinks! Then becomes normal a few scores later.
Later (about score = 27) the playing area is squeezed on the left & right to form a vertical rectangle! This becomes normal later.
At score 32: the playing area goes crazy: rapid flashing pastel colours. Fortunately it reverts to normal at score = 38.

I trust that this helps a little.
If there is anyway I can help further, I will be pleased to assist.
DE AA EB
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

Thanks for your help davido and thank you for the time you spent on this game to see what happens.
davido wrote:the playing area suddenly drops!
This is not normal. I have not coded a sprite moving down. !!
davido wrote:I presume the changes which occur later are programmed by you
Yes : Rotate, Zoom, Bounce and flashing.

Unfortunately, coding with windows, I can not debug the problem you encounter with mac os and linux.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [2D] Crazy Snake

Post by davido »

@falsam,

Thanks for taking the time to look at this issue. Its much appreciated. :D
DE AA EB
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

Demivec worked on the code overnight. Fixing bugs and adding surprises if you achieved the score of 45 points.

The code is updated. See the first message. I would like some feedback with Mac OS and Linux. Thank you and have fun.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: [2D] Crazy Snake

Post by Vera »

Hi falsam,
I'm too a fan of snake-games and I like your Crazy Snake a lot ~ thank you :D
w0w ~ level 33 really knocked me over and Ar-s' window-movement is a surprising challenge :o

Sorry it doesn't full work for all platforms at the moment ... but I still enjoy it so much on Linux that I'd like to share my current variation and hope it's of joy for others too.

Two changes I'd like to show separately, as they might be of specific interest, so you don't need to search them in the code.

A: added 'ElseIf GameOver = 1...' to allow a restart at the end of the game:

Code: Select all

; ======================================
  If GameOver = 2 Or FirstStart = #True

; ....

  ElseIf GameOver = 1                    ; to allow restarting the game
    If KeyboardReleased(#PB_Key_Up)
      GameOver = 2
    EndIf
    
  EndIf
; ======================================
B: added 3 arrow-key-commands to startscreen to allow easy setting of the starting-score:

Code: Select all

; ======================================
Global inScore.i = 0     ; needed new variable

; ....

  If GameOver = 2 Or FirstStart = #True
    
    If KeyboardReleased(#PB_Key_Right)                ; 2 keys to en-/decrease StartingScore
      If inScore < 33
        inScore +1
      Else
        inScore = 0
      EndIf
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
    EndIf
    If KeyboardReleased(#PB_Key_Left)
      If inScore > 0
        inScore -1
      Else
        inScore = 33
      EndIf
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
    EndIf
    If KeyboardReleased(#PB_Key_Down)                ;  key for a random StartingScore
      inScore = Random(33)
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
   EndIf
    
   
    If KeyboardReleased(#PB_Key_Up)
     
      FirstStart = 0
; ....
      Boom = 0
      Score = inScore      ; org= 0 ... apply specific startingscore  vs
; ======================================
Please enjoy and adjust the colorings to hit your taste ~ greets Vera Image

Code: Select all

; ==================================
;-TOP

; Crazy Snake by falsam - 07/Juil/2015 - PB 5.31 ~ nearly fully crossplatform

; http://www.purebasic.fr/french/viewtopic.php?f=2&t=15291
; http://www.purebasic.fr/english/viewtopic.php?f=16&t=62548

; added: 08.07 - Ar-s: mouvement de fenetre (Dir.s, WX, WY)
; changed / added ...26.07 - Vera:
; - commented all commands that 'issued' on Linux [rotate, zoom]
; - enabled restart at game-end [ElseIf GameOver = 1]
; - 3 arrow-key-commands (reft/right/down) to choose StartingScore [range 0-33]
;  + windowtitle-hint 
; - added SnakeEndColor
; - various playing with the game- and snake-colors and 'endscreen'
; ~~~ playing to be continued :-)
; ==================================


EnableExplicit

Enumeration
  #MainForm
EndEnumeration

Global Event
Global UpdateSquares.b
Global Vx=1, Vy=0         ;Velocity x & y
Global x1, y1, x2, y2
Global KLR.b = #True      ;Left Key & Right Key enable
Global KUD.b = #True      ;Up key & down key enable
Global n
Global FirstStart = #True, GameOver = 0
Global TargetCreate, tx, ty
Global SquareColor
Global Score, BestScore
Global Boom.b
Global Font15, Font20, font25, font40
Global Angle.f
Global ZoomX, ZoomY, BounceX.f, BounceY.f, Sens
Global StartTime.f, TimeOut.f
Global ScreenDefaultColor, GameDefaultColor, GameColor, TextColor, LineColor
Global SnakeHeadColor, SnakeBodyColor, SnakeOutlineColor, SnakeEndColor
Global Text.s, PosX, PosY.f
Global Dir.s                  ; neu Ar-S
Global WX,WY                  ; neu Ar-S
Global inScore.i = 0 , colSwitch = 0   ; vs

;Game Sprite
Global Game

;Snake
Structure Snake
  x.i
  y.i
EndStructure
Global NewList Snakes.Snake()

;Engine Init
InitSprite()
InitKeyboard()

;Load Font
Font15 = LoadFont(#PB_Any, "System", 15)
Font20 = LoadFont(#PB_Any, "System", 20)
Font25 = LoadFont(#PB_Any, "System", 25)
Font40 = LoadFont(#PB_Any, "Courier New", 40 ,#PB_Font_Bold)

;Color
ScreenDefaultColor = RGB(127, 182, 127)
GameDefaultColor   = RGB(143, 188, 143)
LineColor          = RGB(210, 180, 140)
TextColor          = RGB(255, 255, 255)

SnakeHeadColor     = RGB(210, 180, 140)
SnakeEndColor     = RGB(167, 193, 123)          ; vs
SnakeBodyColor     = RGB(255, 248, 220)
SnakeOutlineColor  = RGB(184, 134, 11)

;Screen
OpenWindow(#MainForm, 0, 0, 600, 600, "Crazy Snake", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 600, 600,0,0,0)

;Create Game
Game = CreateSprite(#PB_Any, 400, 400)
TimeOut = 200

Repeat
  WX = WindowX(#MainForm);, #PB_Window_InnerCoordinate)   ; new Ar-S
  WY= WindowY(#MainForm);, #PB_Window_InnerCoordinate)
  
  Repeat
    Event = WindowEvent()
     
    Select Event   
      Case #PB_Event_CloseWindow
        End
    EndSelect 
  Until Event=0
   
  FlipBuffers()
  ClearScreen(RGB(220, 220, 220))
 
  ExamineKeyboard()
 
  If FirstStart = #True
    ClearList(Snakes())
   
    For n = 0 To 3
      AddElement(Snakes())
      With Snakes()
        \x = 192 - 16 * n
        \y = 192
        x1 = \x
        y1 = \y
      EndWith
    Next
  EndIf
  
  ;- START
  
  If GameOver = 2 Or FirstStart = #True
    
    If KeyboardReleased(#PB_Key_Right)                ; vs
      If inScore < 33
        inScore +1
      Else
        inScore = 0
      EndIf
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
    EndIf
    If KeyboardReleased(#PB_Key_Left)
      If inScore > 0
        inScore -1
      Else
        inScore = 33
      EndIf
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
    EndIf
    If KeyboardReleased(#PB_Key_Down)
      inScore = Random(33)
      SetWindowTitle(#MainForm, "Crazy Snake ~ "+ Str(inScore))
   EndIf
    
   
   SnakeEndColor = RGB(167, 193, 123)        ; reset defaults vs
   SnakeBodyColor = RGB(255, 248, 220)
   
    If KeyboardReleased(#PB_Key_Up)
     
      FirstStart = 0
     
      ;Add 4 Squares to snake
      ClearList(Snakes())
      For n = 0 To 3
        AddElement(Snakes())
        With Snakes()
          \x = 192 - 16 * n
          \y = 192
          x1 = \x
          y1 = \y
        EndWith
      Next     
       
      ;Reset Game Setup
      StartTime.f = 0
;       RotateSprite(Game, 0, #PB_Absolute)
;       ZoomSprite(Game, 400, 400)
      DisplaySprite(Game, 400, 400)
     
      Boom = 0
      Score = inScore            ; org= 0 ... other score to start in specific level  vs
      KLR = #True          ; Left Key & Right Key enable
      KUD = #True          ; Up key & down key enable
      vx = 1 : vy = 0      ; Snake starts right
     
      TargetCreate = #True
     
      Angle = 0 :
      ZoomX = 0 : ZoomY = 0
      BounceX = 0 : BounceY = 0 : Sens = 1     
      GameColor = GameDefaultColor
      GameOver = #False
    EndIf
    
  ElseIf GameOver = 1                    ; vs to allow restarting the game
    If KeyboardReleased(#PB_Key_Up)
      GameOver = 2
    EndIf
    
  EndIf
     
  If GameOver = #False
    ;-Keybord events
    If KeyboardPushed(#PB_Key_Left) And KLR = #True
      vx = - 1 : vy = 0 : KLR = #False : KUD = #True
      Dir.s = "G"                                      ; 4x neu Ar-S
     
    ElseIf KeyboardPushed(#PB_Key_Right) And KLR = #True
      vx = 1 : vy = 0 : KLR = #False : KUD = #True
      Dir.s = "D"

    ElseIf KeyboardPushed(#PB_Key_Up) And KUD = #True
      vy = -1 : vx = 0 : KUD = #False : KLR = #True
      Dir.s = "H"
   
    ElseIf KeyboardPushed(#PB_Key_Down) And KUD = #True
      vy = 1 :  vx = 0 : KUD = #False : KLR = #True
      Dir.s = "B"
    EndIf
   
    ;- Updates the position of the snake
    If ElapsedMilliseconds() - StartTime  > TimeOut
      StartTime = ElapsedMilliseconds()
      ForEach Snakes()
        If ListIndex(Snakes()) = 0
          ;Updates the head
          x1 = Snakes()\x         ; Memorise old X position
          y1 = Snakes()\y         ; Memorise old Y position
         
          PushListPosition(Snakes())
          NextElement(Snakes())
          If x1 + 16 * vx = Snakes()\x And y1 + 16 * vy = Snakes()\y 
            vx * -1
            vy * -1
          EndIf
          PopListPosition(Snakes())         
         
          Snakes()\x + 16 * vx
          Snakes()\y + 16 * vy
         
          ;- Collide(head, target)
          If Snakes()\x = tx And Snakes()\y = ty
            TargetCreate = #True
            UpdateSquares = #True
            Score + 1
          EndIf
         
          ;- Collide(head, Body)
          PushListPosition(Snakes())
          While NextElement(Snakes())
            If Snakes()\x = x1 And  Snakes()\y = y1
              Boom = #True
            EndIf
          Wend
          PopListPosition(Snakes())
         
        Else
          ;- Updates the body
          x2 = Snakes()\x
          y2 = Snakes()\y
          Snakes()\x = x1
          Snakes()\y = y1
          x1 = x2
          y1 = y2
        EndIf
      Next 
     
      If UpdateSquares = #True
        ; Adds an element to the body of the snake
        AddElement(Snakes())
        Snakes()\x = x1
        Snakes()\y = y1
        UpdateSquares = #False
      EndIf
     
      n = 0
     ;EndIf
   
     ;- Create target
      While TargetCreate = #True
        ;New X
        While TargetCreate = #True
          tx = Random(384)
          If Mod(tx, 16) = 0
            TargetCreate = #False
          EndIf
        Wend
        TargetCreate = #True
     
        ;New y
        While TargetCreate = #True
          ty = Random(384)
          If Mod(ty, 16) = 0
            TargetCreate = #False
          EndIf
        Wend
        TargetCreate = #True
     
        ;Intersection with the snake ?
        ForEach Snakes()
          With Snakes()
            If \x <> Tx And \y <> Ty
              ;UpdateSquares = #True
              TargetCreate = #False
            EndIf
          EndWith
        Next   
      Wend
    EndIf
  EndIf
 
  ;- Drawing Game
 
  ;Draw Score 
  StartDrawing(ScreenOutput())
  Box(0, 0, 600, 600, ScreenDefaultColor)
 
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(Font20))
  DrawText(20, 15, "Crazy Snake", TextColor)
  DrawText(450, 15, "Score " + Str(Score), TextColor)
 
  DrawingFont(FontID(Font15))
  DrawText(400, 560, "falsam (2015-2015)", TextColor)
 
  StopDrawing()
 
  ;Draw GameSprite
  StartDrawing(SpriteOutput(Game))
  Box(0, 0, 400, 400, GameColor)
   
  ;Draw Grid
  Global gx
  For gx = 0 To 399 Step 16
    LineXY(gx, 0, gx, 399, LineColor)
    LineXY(0, gx, 399, gx, LineColor)
  Next 
  ;Draw Grid outline
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(0, 0, 400, 400, LineColor)
  DrawingMode(#PB_2DDrawing_Default)     
 
  ;Draw Snake
  ForEach Snakes()
    With Snakes()
      Select ListIndex(Snakes())
        Case 0                         ; First square
          SquareColor = SnakeHeadColor
         
        Case ListSize(Snakes()) - 1    ; Last square
;           SquareColor = SnakeHeadColor
          SquareColor = SnakeEndColor        ; vs
         
        Default
          SquareColor = SnakeBodyColor
      EndSelect   
 
      DrawingMode(#PB_2DDrawing_Default)     
      Box(\x, \y, 16, 16, SquareColor)
     
      DrawingMode(#PB_2DDrawing_Outlined)
      Box(\x, \y, 16, 16, SnakeOutlineColor)     
    EndWith
  Next
   
  ;Draw target
  DrawingMode(#PB_2DDrawing_Default)
  Box(tx, ty, 16, 16, RGB(127, 255, 0))
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(tx, ty, 16, 16, RGB(0, 0, 0))
   
   
  StopDrawing()
   
  ;Display game
   DisplaySprite(Game, (600 - SpriteWidth(Game))/2 + PosX, ((600 - SpriteHeight(Game))/2) + PosY)

  ;- Game effect
  If GameOver = #False
   
    Select Score         
      Case 0 To 2 ;Bounce game ++
        TimeOut = 200
        BounceX + 0.03 : BounceY + 0.03
        Angle + 0.1
        PosX = BounceX * Cos(Angle)
        PosY = BounceY * Cos(Angle)
        If Angle = 1
          Angle = 0
        EndIf
       
      Case 3 To 4 ;Bounce Game --
        If BounceX > 0
          BounceX - 0.04 : BounceY - 0.04
        EndIf
       
        Angle + 0.1
       
        PosX = BounceX * Cos(Angle)
        PosY = BounceY * Cos(Angle)
       
        If Angle = 1
          Angle = 0
        EndIf
       
      Case 5
        Angle = 0 : PosX = 0 : PosY = 0
        SnakeBodyColor = RGB(255, Random(248), 220)
               
      Case 6 To 9 ;Right Rotate
        TimeOut = 200
        If Angle < 45
          Angle + 0.05
;           RotateSprite(Game, 0.05, #PB_Relative) 
        EndIf
        If colSwitch = 0
        SnakeBodyColor = RGB(255, 248, 220)
        GameColor = RGB(Random(143), 188, 143)
        colSwitch = 1 : EndIf
        
      Case 10 To 14 ;Left Rotate
        TimeOut = 200
        If Angle > 0
          Angle - 0.05
;           RotateSprite(Game, -0.05, #PB_Relative)
        EndIf
        If colSwitch = 1
        GameColor = GameDefaultColor
        colSwitch = 0 : EndIf
        
        
        Select Dir                         ;  new Ar-S   (new place)
          Case "G"
            ResizeWindow(#MainForm, WX-10, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            Dir.s="none"
          Case "D"
            ResizeWindow(#MainForm, WX+10, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            Dir.s="none"
          Case "H"
            ResizeWindow(#MainForm, #PB_Ignore, WY+10, #PB_Ignore, #PB_Ignore)
            Dir.s="none"
          Case "B"
            ResizeWindow(#MainForm, #PB_Ignore, WY-10, #PB_Ignore, #PB_Ignore)
            Dir.s="none"
        EndSelect
        
        
      Case 15 To 19 ;Reduce the size of the game.
        TimeOut = 200
        If SpriteWidth(Game) <> 250
;           ZoomSprite(Game, SpriteWidth(Game) - 1, SpriteWidth(Game) - 1)
        EndIf
        If colSwitch = 0
        GameColor = RGB(143, Random(188), 143)
        colSwitch = 1 : EndIf

     
      Case 20 To 22 ;Reduce the size of the game.
        TimeOut = 200
        If SpriteWidth(Game) <> 400
;           ZoomSprite(Game, SpriteWidth(Game) + 1, SpriteWidth(Game) + 1)
        EndIf
        If colSwitch = 1
        SnakeBodyColor = RGB(Random(255), 248, 220)
        GameColor = GameDefaultColor
        colSwitch = 0 : EndIf
    
      Case 23 ;Change the speed
        TimeOut = 150
        SnakeBodyColor = RGB(255, 248, 220)
     
       
;         Select Dir                         ;  new Ar-S (org-place)
;           Case "G"
;             ResizeWindow(#MainForm, WX-10, #PB_Ignore, #PB_Ignore, #PB_Ignore)
;             Dir.s="none"
;           Case "D"
;             ResizeWindow(#MainForm, WX+10, #PB_Ignore, #PB_Ignore, #PB_Ignore)
;             Dir.s="none"
;           Case "H"
;             ResizeWindow(#MainForm, #PB_Ignore, WY+10, #PB_Ignore, #PB_Ignore)
;             Dir.s="none"
;           Case "B"
;             ResizeWindow(#MainForm, #PB_Ignore, WY-10, #PB_Ignore, #PB_Ignore)
;             Dir.s="none"
;         EndSelect
       
        
      Case 24 ;Change the speed
        TimeOut = 100 
        SnakeHeadColor = RGB(210, 16, 9)        ; vs
     
      Case 25 ;Change the speed
        TimeOut = 50
        BounceX + 0.03 : BounceY + 0.03         ; vs
        Angle + 0.1
        PosX = BounceX * Cos(Angle)
        PosY = BounceY * Cos(Angle)
        If Angle = 1
          Angle = 0
        EndIf
        
      Case 26 ;Change the speed
        TimeOut = 150
        SnakeHeadColor = RGB(210, 180, 140)      ; vs
        SnakeBodyColor = RGB(255, 88, 82)
     
      Case 27 To 29 ;Reduce the size of the game. (Strange: the sprite moves upward)
        TimeOut = 200
        If SpriteWidth(Game) <> 250
          ZoomX=-1
;           ZoomSprite(Game, SpriteWidth(Game) + ZoomX, 400)
        EndIf
        If colSwitch = 0                         ; vs ...
        SnakeBodyColor = RGB(255, 248, 220)
        GameColor = RGB(143, Random(188), 143)
        colSwitch = 1 : EndIf
    
      Case 30 To 32 ;Original Size
        TimeOut = 200
        If SpriteWidth(Game) <> 400
          ZoomX = 1
          If SpriteHeight(Game) <> 400
            ZoomY = 1
          Else
            ZoomY = 0
          EndIf
;           ZoomSprite(Game, SpriteWidth(Game) + ZoomX, SpriteWidth(Game) + ZoomY)
        EndIf
        If colSwitch = 1
        GameColor = GameDefaultColor
        colSwitch = 0 : EndIf
        
      Case 33 To 36 ;Random color
        TimeOut = 150
        GameColor = RGB(Random(255),Random(255),Random(255))
     
      Default ; Fastest speed
        TimeOut - 0.001
        GameColor = GameDefaultColor
       
    EndSelect
  EndIf
   
  ;- Out of bound or Game over
  FirstElement(Snakes())
  With Snakes()
    If (\x > 384 Or \x < 0 Or \y > 384 Or \y < 0 Or Boom = #True) And GameOver <> 2
      GameOver = 1 ; org: 1 , 2-um sofort neu zu spielen
     
      If SpriteWidth(Game) <> 10
;         ZoomSprite(Game, SpriteWidth(Game)-10, SpriteWidth(Game) - 10)
         GameColor = RGB(0, 0, 0)
         SnakeBodyColor = RGB(228, 222, 197)
         SnakeEndColor = RGB(Random(167), Random(193), Random(123))
       Else
        GameOver = 2      ; this never occurs  vs
      EndIf
    EndIf
  EndWith 
 
  ;Game Over
  If GameOver = 2 Or FirstStart = #True
   
    If Score > BestScore
      BestScore = Score
    EndIf
       
    StartDrawing(ScreenOutput())
    Box(0, 0, 600, 600, ScreenDefaultColor)

    DrawingMode(#PB_2DDrawing_Transparent)
   
    If FirstStart = #True
      DrawingFont(FontID(Font40))
      Text = "Crazy Snake"
      DrawText((600 - TextWidth(Text))/2, 100, Text, TextColor)   
    Else
      DrawingFont(FontID(Font40))
;       Text = "You Died"
      Text = "S.o°l°o.ng Snake"             ; vs
      DrawText((600 - TextWidth(Text))/2, 100, Text, TextColor)   
   
      DrawingFont(FontID(Font25))
      Text = "Score: " + Str(Score)
      DrawText((600 - TextWidth(Text))/2, 200, Text, TextColor)
     
      DrawingFont(FontID(Font25))
      Text = "Best Score: " + Str(BestScore)
      DrawText((600 - TextWidth(Text))/2, 300, Text, TextColor)
    EndIf
   
    Text = "Press up arrow key to start new game"
    Angle + 0.1
    PosY = 20 * Cos(Angle)
    If angle = 1
      angle = 0
    EndIf
   
    DrawingFont(FontID(Font25))
    DrawText((600 - TextWidth(Text))/2, 500 + PosY, Text, TextColor )
       
    StopDrawing()
  EndIf
 
Until KeyboardPushed(#PB_Key_Escape)

; =========================================
ps: Is it possible to apply effects to higher levels like this ? :
If Case > 40 to 70 Step 5
Change color xy // or speed ...
EndIf
pps: I just saw you've updated your Snake today 8) I'll give it a try as of next.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

Hello Vera. I played with your code. I'll change my code with some of your suggestions. I think you'll have fun with the code I updated today. Demivec added stunning animations. Trying to exceed 45 points.

:idea: The code was updated today in the first message.
http://www.purebasic.fr/english/viewtop ... 16&t=62548

:idea: You can also download it on github.
https://github.com/falsam/CrazySnake

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [2D] Crazy Snake

Post by davido »

@falsam,
Very good, thank you. :D
DE AA EB
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

davido wrote:Very good, thank you.
Hooo thank Davido. No problem with Mac OS ?

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [2D] Crazy Snake

Post by davido »

@falsam,

Sorry, I failed to mention that the problem still occurs, on my Mac.
As the problem is not of your making, I didn't want to keep on complaining! :)

By-the-way it does not occur on every run.
Even when it does happen, I am sometimes able to solve it.

Nice game - I like it. Thank you.
DE AA EB
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: [2D] Crazy Snake

Post by Vera »

falsam wrote:Hello Vera. I played with your code. I'll change my code with some of your suggestions.
Hey that's nice to hear :D
I think you'll have fun with the code I updated today. Demivec added stunning animations.
indeed _ Image _ Image _ _ Image _ _ _ häppi thanks to Demivec


~ @all have a good week ahead ~ Vera
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: [2D] Crazy Snake

Post by bbanelli »

I don't know if that's a feature or a bug, but sometimes, new dot/cookie/apple/whatever snake eats appear within it's current occupying space.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

bbanelli wrote:I don't know if that's a feature or a bug, but sometimes, new dot/cookie/apple/whatever snake eats appear within it's current occupying space.
With the code of the first message?

http://www.purebasic.fr/english/viewtop ... 16&t=62548

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [2D] Crazy Snake

Post by falsam »

A New version for CrazySnake.

Added two layers
The first layer will appear before the snake display.
The second layer is displayed after the snake display

The first message code and update
:idea: http://www.purebasic.fr/english/viewtop ... 16&t=62548

and the GitHub
:idea: https://github.com/falsam/CrazySnake

An example of the rear layer in point 5 and in paragraphs 41-43.
An example of the foreground layer in paragraphs 59-63.

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: [2D] Crazy Snake

Post by Vera »

w0w falsam _ that's just crazy ;-) _ thank you

I have a small issue and a great side-effect to tell about.
If the game ends before the TileSeparation is back to normal the clipping after resetting it will diplay the sprite displaced at around x/y = 400/400. All trials to reposition the end-sprite to its default position failed ... so I rather commented it out for good. Besides that tiled end-view is rather nice to see.

That's what I commented out:

Code: Select all

If SpriteWidth(Game) <> 10
;   If TileSeparation > 0
;     TileSeparation = 0
; ;    ClipSprite(Game, #PB_Default, #PB_Default, #PB_Default, #PB_Default)
;   EndIf
Now when continue playing that last tileseparation stays valid for the following [restarting] levels that you play. (Until you cross again those levels that decrease the separation).

That's pure fun :-)
Image

I'm thinking about a further idea where the snake doesn't stop at the screen-sides but re-enters again on the opposite side.
Another one is: switching the key-commands on one level [right turns left etc.]

And last but not least a feature request for a 'pause'.
I also noticed today, that while CrazySnake is running, no keycommands are available on the PC for other activity. Is it be possible to free examinekeyboard under certain conditions and recontinue it afterwards? If so, it could be well combined with a pause-feature.

~ cheers ~ Vera
Post Reply