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

Share your advanced PureBasic knowledge/code with the community.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

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

Post 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
Last edited by falsam on Sun Aug 18, 2013 9:46 pm, edited 3 times in total.

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

Sorry for my bad english and the Dunning–Kruger effect 🤪
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

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

Post 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.
pb 5.11
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post by ts-soft »

Image
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

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

Post 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)

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

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

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

Post 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.
I like logic, hence I dislike humans but love computers.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

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

Post 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)

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

Sorry for my bad english and the Dunning–Kruger effect 🤪
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

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

Post 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. :)

➽ Windows 11 64-bit - PB 6.21 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: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

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

Post 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 :)

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

Sorry for my bad english and the Dunning–Kruger effect 🤪
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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
Post Reply