Page 1 of 1

Kanoid : Breakout Game on the canvas (What strange idea?)

Posted: Fri Oct 12, 2012 10:28 pm
by falsam
Updated for 5.11+

Kanoid (Contraction of canvasnoid) is an arcade-like breakout.

Control a paddle positioned at the bottom of the screen from left to right with the mouse to bounce a ball on the edges to destroy bricks.

You can go to the next level (3 in this version) when all the bricks are destroyed or when the bricks lowest reach the bottom of the screen.

Image

The bricks have 1 to 4 lives materialized by a number on each brick.

Once destroyed a brick can release a bonus or a malus.
-Increase / decrease the size of the racket.
-Increase / decrease the size of the ball.
-Increase / decrease the speed of the ball
-Increase / decrease in life.
-Enable / Disable the Glue on the racket.
-Enable / Disable shooting mode.

Two observers were present to judge your fighting.
The first stores rebounds. After ten rebounds without touching a brick, he informs the second observer and changes the horizontal and vertical speed of the ball.
 
This second observer gives you another ten rebounds to destroy the bricks. Each brick hit gives you one bounce. If you are unable to destroy bricks, the level is dropped and goes to the next.

Mouse and keyboard shortcuts.
The mouse to move the paddle.
Left-click Free mode or shooting the ball.
Right click Reverses the horizontal trajectory of the ball.
Esc Quit the game
Pause Game Pause.
C Clip / unclip the mouse
N New Game.

I could use the sprites :) but I wanted to tease the canvas.

:arrow: Download Kanoid (Source + sound 3,8 Mo)

If you already have kanoid folder, you can download the source only.
:arrow: Download Kanoid Update (Source only 7 Ko)

I think I still have a bug. Sometimes the ball is stuck on the edges. If this is the case: Pause button.

Licence : Use As You Like :)

Original thread : http://www.purebasic.fr/french/viewtopi ... =2&t=13232

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 9:44 am
by gnasen
Nice one and runs really smooth. Its very interesting to use a canvas for this, however it uses much ressources, my executing CPU is fully engaged.

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 10:00 am
by ts-soft
Image

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 11:09 am
by falsam
gnasen wrote:my executing CPU is fully engaged.
This method consumes too much cpu. On average 45% with four computers equipped with Intel Centrino 2 (2.4 Ghz) or Intel I3 (3.0 Ghz).

75% Cpu with a computer equipped with an Intel P4 (2.4 Ghz)

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 11:52 am
by Joakim Christiansen
gnasen wrote:however it uses much ressources, my executing CPU is fully engaged.
He probably just need to add a little delay in the loop, maybe 10 milliseconds will fix it.

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 12:01 pm
by falsam
Joakim Christiansen wrote:He probably just need to add a little delay in the loop, maybe 10 milliseconds will fix it.
or Event = WaitWindowEvent(3)

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 12:16 pm
by wilbert
I tried your code on OS X.
The #VK_ constants are not defined on OS X. Should they be defined or are those Windows only ?
If I replace them by #PB_Shortcut_ like #PB_Shortcut_N, the keys work fine.

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 12:27 pm
by falsam
wilbert wrote:I tried your code on OS X.
The #VK_ constants are not defined on OS X. Should they be defined or are those Windows only ?
If I replace them by #PB_Shortcut_ like #PB_Shortcut_N, the keys work fine.
I forgot to set the F1 key for Mac users.

Checks your enumation section with this code.

Code: Select all

 ;OSX Environment
  #VK_C = 67        ;Mouse Clip / Unclipe on the canvas
  #VK_N = 78        ;New Game
  #VK_PAUSE = 19    ;Pause
  #VK_ESCAPE = 27   ;Leaves the game
  #VK_F1  = 112     ;F1
I think it should work without using pure basic shortcuts.

Code update. Thank you for this observation. :)

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sat Oct 13, 2012 4:07 pm
by falsam
The version 1.60 is a small update that shows the horizontal and vertical velocity of the ball at the top left of the screen.

You can download the full version with sounds or only the source code to include in the folder containing sounds Kanoid.

The first message is updated.

Enjoy :)

Re: Kanoid : Breakout Game on the canvas (What strange idea

Posted: Sun Oct 14, 2012 6:05 am
by wilbert
falsam wrote:Checks your enumation section with this code.

Code: Select all

 ;OSX Environment
  #VK_C = 67        ;Mouse Clip / Unclipe on the canvas
  #VK_N = 78        ;New Game
  #VK_PAUSE = 19    ;Pause
  #VK_ESCAPE = 27   ;Leaves the game
  #VK_F1  = 112     ;F1
I think it should work without using pure basic shortcuts.
Unfortunately it doesn't. The key values are not the same. On my iMac, these are the values for #PB_Shortcut_

Code: Select all

#PB_Shortcut_C = 99
#PB_Shortcut_N = 110
#PB_Shortcut_Pause = 0; (No pause key on OS X)
#PB_Shortcut_Escape = 27
#PB_Shortcut_F1 = 378
Maybe you could use

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  #VK_C = 99        ;Mouse Clip / Unclipe on the canvas
  #VK_N = 110       ;New Game
  #VK_PAUSE = 112   ;Pause (P instead of PAUSE)
  #VK_ESCAPE = 27   ;Leaves the game
  #VK_F1  = 378     ;F1
CompilerEndIf