Jump to content

HTML 5 Breakout game

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Awilum

Awilum

    Newbie

  • Members
  • Pip
  • 3 posts
Hello :c-smile:
I study the JS and HTML5, and wrote such a toy, its breakout.
Demo yet. All three levels.
Please test in terms of gameplay, and physics. It seems to me that physics has turned out not very good :( Collisions bricks and ball...

Play: http://awilum.webdev...d/arcanoid.html


Collisions ball with bricks


// Collissions with bricks

    rowheight = bricks.height + bricks.padding;

    colwidth = bricks.width + bricks.padding;

    row = Math.floor(ball.y/rowheight);

    col = Math.floor(ball.x/colwidth);

	


	// Ball collision with brick

    if (ball.y < bricks.rows * rowheight && row >= 0 && col >= 0 && level_bricks[row][col] == 1) {

        ball.dy = -ball.dy;

        level_bricks[row][col] = 0;

		score += 50;		

		bricks_destroed++; 

	}

	

	// Ball collision with rock

    if (ball.y < bricks.rows * rowheight && row >= 0 && col >= 0 && level_bricks[row][col] == 2) {

        ball.dy = -ball.dy;            

		level_bricks[row][col] = 1;

    }




#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Very nice game, and yes the collisions are alittle off. It appears when the ball collides with a brick its not colliding with the edge of the ball but rather with the center. I dont really know JS so im not sure how you would fix this. Also I think it would be nicer if the paddle was controlled from the center with the mouse instead of the mouse controlling the far left of the paddle, if you understand what I mean.

Nice work, and good luck. ~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
I find it quite nice actually, it is not too off in realism (being a scripting language) -- although I would add more than one life!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

although I would add more than one life!
It has 3 lives actually, the game kinda starts without warning a 2 balls can fly out of the screen before you even get the paddle over to them. You may want to work on that. ;)

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
The collision issue is that when the ball is going down and you hit something in the side, only the x-direction should change and not the y-direction. Just like hitting the side of the screen.
While hitting a brick on the side x remains and y switches. Which is the normal behaviour for hitting the brick from the top / bottom.

I'm not quite sure how easy or hard it is to check at which side a brick is hit, but once you've got that I don't think it's too hard to solve the collisions.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users