2 Replies - 420 Views - Last Post: 31 January 2013 - 12:30 PM

#1 NickClayborne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-January 13

Making a game, and could use some help

Posted 31 January 2013 - 12:21 PM

So, I started off with a new game idea, and I realize that in my scope of time, I am unsure I'd be able to complete it the way I would like to. This is the original topic:

http://www.dreaminco...1&#entry1794225

With that in mind, I decided that instead of bouncing the ball back and forth in an arch, and you click it to bounce it off of your character, I want to make it so that the ball just bounces between your character (red) and the character on the right (blue) and the boundaries are where you score. Based on this code that I have, I got a lot of work to do, and I need to figure out which direction I need to go from here.

<html>
<body onkeydown="arrowkeycheck();">
<script>



<script type='text/javascript'>

//Click the button to get the ball to move

//Ball Movement section
function move_right(){
blueball.left=blueball.left+100;
}

//LOWER LEVEL ANIMmATION CODE - DON'T MODIFY 
// requestAnim shim layer by Paul Irish
    window.requestAnimFrame = (function(){
      return  window.requestAnimationFrame       || 
              window.webkitRequestAnimationFrame || 
              window.mozRequestAnimationFrame    || 
              window.oRequestAnimationFrame      || 
            file:///C:/Users/Nick/Documents/New%20Game/ball.jpg  window.msRequestAnimationFrame     || 
              function(/* function */ callback, /* DOMElement */ element){
                window.setTimeout(callback, 1000 / 60);
              };
    })();

function animate() {    
    requestAnimFrame( animate );
    update_ball();
}

//END OF LOWER LEVEL ANIMmATION CODE 

//MAKE A LOG FUNCTION TO HELP WITH DEBUGGING
function log(msg){
  document.getElementById('log').innerHTML = msg;
}

//YOUR UPDATE FUNCTION - MOST OF YOUR CODE WILL LIVE HERE
function update_ball(){

  var right = blueball.left + blueball.style.width;
  var bottom = blueball.top + blueball.style.height;
	
	if (screen.width < right){
		dx = -dx;		
	}
	
  if (screen.height < bottom){
		dy = -dy;
	}
	
  if (blueball.left < 0) {
  	dx = -dx;
  }
	
  if (blueball.top < 0) {
  	dy = -dy;
  }
	
	blueball.left = blueball.left + dx;
  blueball.style.left = blueball.left + 'px';
  
	blueball.top = blueball.top + dy;
  blueball.style.top = blueball.top + 'px';
  
  log ('left: ' + blueball.left);
}

//initialization of the game
var dx = 0;
var dy = 0;
blueball.left = 40;
blueball.top = 450;
animate();

</script>
	

<img style="position:absolute; top:450px; left:40px; id="blueball" src="ball.jpg" width="30"/>

<div style="position:absolute; top:420px; width:30px; height:80px; background-color:red"></div>
<div style="position:absolute; top:420px; left:800px; width:30px; height:80px; background-color:blue"></div>


<div id="width:1200px; height:1px; color=black" ></div>


<button onclick="move_right();">Move to the Right</button>
</body>

</html>


Objectives from here:

1. Make the ball bounce around, stopping as it hits the left and right walls
2. Add a top and bottom boundary
3. Make ball bounce off of the divs (paddle)
4. Create a scoreboard to go on the top left
5. Create a way to cause the ball hitting the walls to increase the score
6. Make a way that the red div will always be attached to the mouse, so that when you move your mouse, the cursor always controls the red paddle
7. Make the blue paddle always moving up and down on the far right side of the screen, moving between the top and bottom boundary.
8. Make the speed of the blue paddle increase with time

Is This A Good Question/Topic? 0
  • +

Replies To: Making a game, and could use some help

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3197
  • View blog
  • Posts: 10,710
  • Joined: 12-December 12

Re: Making a game, and could use some help

Posted 31 January 2013 - 12:30 PM

I see you decided to ignore my advice about parseInt (and the spelling or arc :)).
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,463
  • Joined: 12-June 08

Re: Making a game, and could use some help

Posted 31 January 2013 - 12:30 PM

Where's the question? If this is a continuation of the previous post then great - keep it there and do not create duplicate topics. If this is just passing information then I suggest you would put on your blog.

My Account -> Edit my blog

http://www.dreaminco...p=blog&type=all

Either way I am going to close the topic. PM me if you have a question about the 'why'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1