Quantcast
Destructoid - LK4O4's Community Blog




About Me
Hello there.

My name is Ryan and I work at a pretty prominent web company. I'm 22 years old, which probably makes me one of the youngest people at the company (out of over 100 people). I have half of a college degree, a full-time job, and now I've got a place to hang out and talk about awesome video games.

Feel free to talk to me! <3


== Currently Playing and Trying to Finish ==
Super Mario 3D Land
The Legend of Zelda: Skyward Sword
Pushmo
BIT.TRIP FLUX

== Recently Finished ==
Mighty Switch Force
The Legend of Zelda: Four Swords AE (Single Player)
Shin Megami Tensei: Devil Survivor Overclocked
VVVVVV
Mighty Flip Champs
Donkey Kong (Game Boy version)
Escapee GO!
Aura-Aura Climber
Resident Evil: The Mercenaries 3D
Shantae: Risky's Revenge
Dragon Quest Heroes: Rocket Slime
Elite Beat Agents (Normal Difficulty)
Paper Mario
Sonic Colors (Wii version)
BIT.TRIP FATE
Dragon Quest V: Hand of the Heavenly Bride (Bianca)
Mother 3 (Fan Translation)
Muramasa: The Demon Blade (Both Second Endings!)
BIT.TRIP RUNNER
Portal (Steam version)
Cave Story (Wii version)
Spartan: Total Warrior (GameCube version)
LostWinds: Winter of the Melodias
BIT.TRIP BEAT
BIT.TRIP VOID
BIT.TRIP CORE
Half-Life 2 (original Xbox version)
The Lost Vikings (Genesis version)
Pokemon HeartGold Version
Bangai-O Spirits (All 160+ Levels Cleared!)
Super Mario 64 DS
The Great Circus Mystery Starring Mickey & Minnie
The World Ends With You
Psychonauts
Braid
Ninja Gaiden Black (Normal Difficulty)
Chrono Trigger
Earthbound

== Still Playing On and Off ==
Art Style: Digidrive
Super Street Fighter 4: 3D Edition
Yomi (card game)
Tatsunoko vs. Capcom (FC: 4297 4386 7686)
Space Invaders Extreme 2

== Systems I Own and Love ==
Sega Genesis
Sega Dreamcast
Nintendo 3DS
Wii
Nintendo DS Lite
Xbox

== 3DS Friend Code ==
5241 1905 5146

== Wii System Code ==
4688 2108 9135 7828

== Tatsunoko vs Capcom ==
4297 4386 7686

== Monster Hunter Tri ==
11821Y
Gamer Profile
3DS friend code: 5241 1905 5146
Steam:
Battle:
PSN:
Mii: 4688 2108 9135 7828
Gamertag:
Following (30)
Alex Barbatsis
Animated Toupee
Anthony Burch
ArcticFox
Chad Concelmo
Char Aznable
charliesuh
Colette Bennett
darksydex3226
Darren Nakamura
Dead Movie Star
DtoidLosAngeles
Elsa
Funksy
Funktastic
garison
Jonathan Holmes
Kyle MacGregor
KyleGamgee
lapd
manasteel88
Mike Moran
Mortrialus
Niero
Nihil
nilcam
SEGA Addicts
UglyDuck
Xzyliac
ygro wok
Javascript Pong (shortblog)
LK4O4 | 11:52 PM on 12.26.2010 4 comments


Posted by: Ryan





I was trying to figure out how to get basic collision detection working from scratch, which is essentially getting boxes to know that they've intersected each other and to react appropriately. And while I was prototyping it out in Javascript, I was able to get some rectangular boxes to collide, and the whole thing looked a bit like Pong.

So I made a simple Pong copycat with just Javascript code and by repositioning <div> tags, and you can play with it here.

Player 1: Move with 'W' and 'S'
Player 2: Move with 'UP' arrow and 'DOWN' arrow
Reset game: Press 'Enter'

Because of the way browser inputs are handled, rapidly tapping the keys works much better than holding them down. Also, the game is only 500 pixels wide because I originally planned to embed it into a post with an iframe.


P.S. If you're interested, my collision detection function is essentially this:

var a = object1.x,
    b = object1.x + object1.width,
    c = object2.x,
    d = object2.x + object2.width,
    e = object1.y,
    f = object1.y + object1.height,
    g = object2.y,
    h = object2.y + object2.height;

if (a > d || c > b || e > h || g > f) {

    // rectangular objects are not colliding

} else {

    // rectangular objects are colliding

}

Note that this code depends on the objects intersecting for at least one frame, so it won't work for really fast objects (or really thin objects).



Is this post awesome? Vote it up!

2

Those who have fapped:  Enkido  


Post a comment! You can also post a photo below:

Comment with Facebook





Click connect and comment instantly!

Comment with Dtoid





New? SIGN UP - it takes 5 seconds

4 comments | showing # 1 to 4
prev next

Tubatic's Avatar - Comment posted on 12/27/2010 00:44
Tubatic
Nifty! I've wanted to get dirty and do some game coding in Javascript lately. When I get around to doing collision, I'll probably pull this up for a little guidance working examples always make more sense to me.
Enkido's Avatar - Comment posted on 12/27/2010 05:34
Enkido
That's pretty neat. I now know it is really hard to play pong against yourself.
LK4O4's Avatar - Comment posted on 12/27/2010 14:09
LK4O4
@Tubatic

Awesome! If you end up making anything, I'd love to see it!

But to let you know, Javascript is kind of a horrible environment for game coding. I just happened to use JS because it was sort of a quick, easy thing I could write. For a real game, I would maybe recommend ActionScript 3 (Flash) or something. But if you decide to actually go the JS route anyway, the <canvas> tag is a much better alternative to moving absolutely positioned <div>s around a screen like I did.
Darren Nakamura's Avatar - Comment posted on 12/27/2010 15:17
Darren Nakamura
Neat! I played a game against a stationary paddle and on one round it volleyed back at me five times before I finally lost. I felt pretty ashamed.
prev next

Comment with Facebook





Click connect and comment instantly!

Comment with Dtoid





New? SIGN UP - it takes 5 seconds

Comments policy

Destructoid is an open discussion community. You don't need to "audition" to post a comment - just speak your mind. We respect differing opinions on the site, so have at it. Be smart, funny, insightful, clueless, or cute -- but back it up with substance. Keep your cool, keep it fun. We only ask that you act respectfully and above all: don't be a troll and ruin it for everyone else. Don't bring down gamers or we'll, you know, gently shoot you in the face and stuff you into a flaming mailbox. Each comment is your opportuntity to make this community awesomer. Is that even a word?

Avoiding the banhammer only requires common sense: spamming, trolling, racism, NSFW stuff, and other forms of sucking will not be tolerated. If anyone is griefing please report abuse. Be good. Don't suck!