It is currently Sun Jul 05, 2020 5:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: [2D] Crazy Snake
PostPosted: Mon Jul 27, 2015 2:53 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 608
Location: France
Vera wrote:
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.
Todo list
Vera wrote:
switching the key-commands on one level [right turns left etc.]
I did it. The game was unplayable. May be at the beginning of the game. Todo list.
Vera wrote:
Is it be possible to free examinekeyboard under certain conditions and recontinue it afterwards?
I'm not sure that's possible with PureBasic. BUT
Vera wrote:
feature request for a 'pause'.
YES ....

New version for CrazySnake.
Adding a pause: Press the spacebar to bring the game to pause (or continue).

Add : Pause when the game lost focus.

The first message code and update
:idea: viewtopic.php?f=16&t=62548

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

_________________

➽ Windows 10 - PB 5.62 & PB 5.70 LTS

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Tue Jul 28, 2015 9:09 am 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 11, 2009 1:56 pm
Posts: 858
Location: Essen (Germany)
Hi falsam,
that 'Pause' is really good to have :-)

falsam wrote:
Contrairement à ce que dit la doc, ExamineKeyboard() renvoie bien une valeur.
It seems a lucky feature ;-)
But on Linux ExamineKeyboard() stays valid so that the 'auto-pause' doesn't occure. And like I mentioned above, ExamineKeyboard occupies (nearly) all keys for the OS while the application is running and even with lost focus*.

I already searched the forum for hours yesterday to find a solution how to deactivate a WindowedScreen or its parent window to somehow mute the app to regain all keycommands, but successless until now. Maybe it's only achivable via API.

* Yeah I found out this morning while testing again and checking GetActiveWindow() that the focus of the WindowedScreen is only really lost is the app is minimized (or if I double-click the windowtitle to fold the window to its title only).
In these cases the key-occupation is freed, ExamineKeyboard() returns 0 and 'auto-pause' will be set.

Hey that's good to know for a start 8)

_________________
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi

Missing a download-file on the forums? ~ check out this backup page.


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Tue Jul 28, 2015 2:48 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 608
Location: France
The first sound version of Crazy Snake is available.

:arrow: http://s242132022.onlinehome.fr/download/purebasic/CrazySnake.zip (Source + Media)

Thank you to everyone who helped me achieve this release. I hope that you will be crazy at the end of the game.

_________________

➽ Windows 10 - PB 5.62 & PB 5.70 LTS

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Tue Jul 28, 2015 10:04 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1766
Location: Uttoxeter, UK
@falsam,

Brilliant. :D
Now works perfectly on the Mac; the problem has gone away!
Music is fine.
Pause ok, too.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Wed Jul 29, 2015 11:33 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 608
Location: France
davido wrote:
Now works perfectly on the Mac; the problem has gone away!
Very good news. Thank You Davido.

_________________

➽ Windows 10 - PB 5.62 & PB 5.70 LTS

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Wed Jul 29, 2015 11:39 am 
Online
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3710
Location: Utah, USA
Here are fixes for 2 bugs that were introduced by me.

The first bug makes the game end if the snake enters the square in the top-left corner. It is caused by some leftover and unneeded code. The fix is to remove the code.

The second bug makes the snake detect a collision with itself by allowing the snake to collide with where its tail part used to be before it moved. It is caused by a combination in the way the snake was updated and the detection for collision with itself. It is corrected by moving the collision detection after the update of the snakes length.

Previous code:
Code:
AddElement(Snakes()) ;add a new part for the head at the front of snake
     
      If Snakes()\x = SnakePart\x + 16 * vx And Snakes()\y = SnakePart\y + 16 * vy
        vx * -1
        vy * -1
      EndIf
      Snakes()\x = SnakePart\x + 16 * vx
      Snakes()\y = SnakePart\y + 16 * vy
     
      SnakePart = Snakes() ;save information for new head part
     
      ;-Collide(head, target)
      If SnakePart\x = tx And SnakePart\y = ty
        TargetCreate = #True
        UpdateSquares = #True
        Score + 1
        PlaySound(#Sound_FindTarget, #PB_Sound_MultiChannel, 100)
      EndIf
     
      ;-Collide(head, Body)
      While NextElement(Snakes())
        If SnakePart\x = Snakes()\x And  SnakePart\y = Snakes()\y
          Boom = #True
          Break
        EndIf
      Wend
     
      If UpdateSquares = #False
        ;Remove tail part to keep snake the same length
        LastElement(Snakes())
        DeleteElement(Snakes())
      Else
        ;Adds an element to the body of the snake, it does so by NOT removing the tail part
        UpdateSquares = #False
      EndIf


Replacement code:
Code:
      AddElement(Snakes()) ;add a new part for the head at the front of snake
     
;       If Snakes()\x = SnakePart\x + 16 * vx And Snakes()\y = SnakePart\y + 16 * vy
;         vx * -1
;         vy * -1
;       EndIf
      Snakes()\x = SnakePart\x + 16 * vx
      Snakes()\y = SnakePart\y + 16 * vy
     
      SnakePart = Snakes() ;save information for new head part
     
      ;-Collide(head, target)
      If SnakePart\x = tx And SnakePart\y = ty
        TargetCreate = #True
        UpdateSquares = #True
        Score + 1
        PlaySound(#Sound_FindTarget, #PB_Sound_MultiChannel, 100)
      EndIf
     
      If UpdateSquares = #False
        ;Remove tail part to keep snake the same length
        LastElement(Snakes())
        DeleteElement(Snakes())
      Else
        ;Adds an element to the body of the snake, it does so by NOT removing the tail part
        UpdateSquares = #False
      EndIf
     
      ;-Collide(head, Body)
      FirstElement(Snakes())
      While NextElement(Snakes())
        If SnakePart\x = Snakes()\x And  SnakePart\y = Snakes()\y
          Boom = #True
          Break
        EndIf
      Wend



Another effect may or may not be a bug. It seems like it is to me though. The effect is based on the window coordinates. The window's inner coordinates is used instead of the frame coordinates. When the effect is in play is using these coordinates it nudges the window off the bottom of the screen if 'up' or 'down' is pushed.

Previous code:
Code:
  WX = WindowX(#MainForm, #PB_Window_InnerCoordinate)
  WY = WindowY(#MainForm, #PB_Window_InnerCoordinate)


Replacement code:
Code:
  WX = WindowX(#MainForm, #PB_Window_FrameCoordinate)
  WY= WindowY(#MainForm, #PB_Window_FrameCoordinate)

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Thu Jul 30, 2015 11:22 am 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 11, 2009 1:56 pm
Posts: 858
Location: Essen (Germany)
You're rocking it falsam ~ Image ~ the sound-version is great

I missed the blue bubles and the 'default' right-left movement beyond the final Case ... so I re-inserted them ;-)

Ar-s' Sound_Logo is a good addition. As it only apears at game-start I tested it as game-end-sound too which is nice.

Thanks Demivec for realising that the first square got buggy, as I had thought my key-down-event was delayed too much for that corner. (I do encounter delayed or failing key-events now and then when there's too much action in a level and think it's due to my 'slow' PC.)

cheers ~ Vera

ps: I much appreciate the code-developements as it gives me a lot to learn from Image

_________________
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi

Missing a download-file on the forums? ~ check out this backup page.


Top
 Profile  
Reply with quote  
 Post subject: Re: [2D] Crazy Snake
PostPosted: Tue Nov 24, 2015 1:39 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Aug 08, 2010 3:32 pm
Posts: 349
Location: Manchester UK
59!

Very good :) well done.

_________________
----

R Tape loading error, 0:1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye