Chomper Stomping
jQuery/JavaScript/CSS 3/HTML 5, Java/PHP/Python/ActionScript, Git, Chrome/Firefox Extensions, Wordpress/Game/iPhone App Development and other random techie tidbits I've collected



video games

September 19, 2007

Prototyping

More articles by »
Written by: Christopher McCulloh

The first thing you do when you are exploring new territory in programming is prototyping. You will throw it away (you always throw away the first draft though), but you will learn from it.

I’ve been struggling with how to make my ball move, and at one point decided not to even tackle it, but to instead rely on an open source engine. But then I wouldn’t learn as much, and while I still might go in that direction, I have prototyped a system to “get the ball rolling”.

It’s acting funny though…

Here it is:

http://corsair.cs.iupui.edu:18041/chomperStomp/games/clink.html

You can make the ball roll with the arrow keys upon clicking on the flash movie if you so desire. Like I said though, it is acting a little funny. I have a few ideas about what I can do to fix it, but it’s fun to have this first iteration, and I thought I’d share it.

The method I used was to have three points that I measure against along the bottom of the ball. One to the left, one in the center, and one on the right. Dependant upon how many of these are touching “ground” will decide how the ball behaves (which way it rolls). I’ll paste the code in below, but remember that I wrote this code in 15 minutes and that it is only prototype code and thus very very crappy.

var leftSide = this._x - this._width/2;
var rightSide = this._x + this._width/2;
var bottomSide = this._y + this._width/2;
var topSide = this._y + this._width/2;

if(_root.theFloor.hitTest(leftSide, bottomSide, true)){
if(_root.theFloor.hitTest(rightSide, bottomSide, true)){
if(dy > 0){
dy = 0;
}
trace("flat surface");
}else if(_root.theFloor.hitTest(this._x, bottomSide, true)){
trace("sloped down to the right");
dx += _root.gravity;
dy += _root.gravity;
}else{
if(dx < 0){
dx = (dx * .96) * -1;
}
}
}else if(_root.theFloor.hitTest(rightSide, bottomSide, true)){
if(_root.theFloor.hitTest(leftSide, bottomSide, true)){
if(dy > 0){
dy = 0;
}
trace("flat surface");
trace(dy);
}else if(_root.theFloor.hitTest(this._x, bottomSide, true)){
trace("sloped down to the left");
dx -= _root.gravity;
dy += _root.gravity;
}else{
if(dx > 0){
dx = (dx * .96) * -1;
}
}
}else{
dy += _root.gravity;
}

if(_root.theFloor.hitTest(this._x, bottomSide, true)){
if(_root.theFloor.hitTest(this._x, bottomSide - 1, true)){
dy -= 1;
}
}



About the Author

Christopher McCulloh
E-Commerce developer at Finish Line Co-Author of HTML, XHTML and CSS All-in-one Desk Reference for Dummies Graduated from IU with a Bachelors of Media Arts and Science and a Certificate in Applied Computer Science. Tech Editor for Building Facebook Applications for Dummies and Building Websites All-in-one for Dummies 2nd Edition. Creator and maintainer of the Status-bar Calculator Firefox Extension Three years professional experience in Java E-Commerce Development and four years professional experience with PHP for a combined total of seven years professional JavaScript/HTML/CSS experience




 
 

 
Screen Shot 2012-05-02 at 10.23.54 AM

Douglas Crockford – JavaScript the Good Parts

Really good lecture on JavaScript, especially if you are new to the language from another language like Java.
by Christopher McCulloh
0

 
 
cloudwars

Let the Cloud Wars Begin!!!

This is all going the same direction. They are all going to end up with unlimited storage for the same price point per year, so, the sooner one of them calls it and just offers that, the better that one will do. They need to ju...
by Christopher McCulloh
0

 
 
logo

dynode Batch Get Item

Working a lot with node.js, dynode and dynamoDB recently. Still trying to wrap my head around it all. Had a horrible time getting dynode.batchGetItem to work. Here is the error I was getting: { name: 'AmazonError', type: 'Valid...
by Christopher McCulloh
0

 

 
mysqlerror

WP phpBB Bridge: Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given

Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in wp-content/plugins/wp-phpbb-bridge/inc/widgets/wpbb_topics_widget.php on line 149 This is an error caused by the fact that the WP phpBB Bridge pl...
by Christopher McCulloh
0

 
 
 

Events Calendar Pro Nav Formatting Messed up on Empty Calendar

The Events Calendar Pro (from http://tri.be/) has a few problems. If you are trying to figure out why a calendar with no events in that month has completely screwed up header navigation, just put this line of code inside of tab...
by Christopher McCulloh
5

 




2 Comments


  1. Welcome to WordPress! I forgot to add your new RSS feed, but I’m back.

    I just got the ball to fly through the bottom right wall. My ball is gone.


  2. Thanks for the welcome! I actually think I will have two separate blogs. A techie blog (this one) and a personal blog (without my name attached) somewhere else…

    Yep, your ball has serious problems. If you’re lucky you can get your ball to jump up in the air by persistently banging the wall. I’ve gotten it to go up really high by banging it into the wall.

    My algorithm is problematic in many many ways, and I have actually already improved it some since this prototype version. I know I am missing something really big here though, and my method is definitely not correct (or at all complete). It *kind* of works, but there has to be another way…



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>