999credits - My new Flash Game Site

I’ve recently launched my Flash Game website, 999credits (http://www.999credits.com) On this page i am currently hosting 286 free online games and more are addded every day - each and every one hand-picked for its quality. So support me; tell your friends,Digg it, Facebook it, Twitter it, StumbleUpon it, and spam those who love you (please, oh please spam those who love you)

The site

BTW: It has just earned its first dollar! (Too bad i’ve spent 10$ on advertising :D )

Easy PHP development using PDT

I have started using the PDT plugin for Eclipse, for my PHP development. It is an amazing tool for PHP development. The code completion features you’ve com to expect when using Eclipse coupled with extensive PHP method knowledge, PHPDoc integration, and last but best, the Zend Debugger, makes this the best PHP editor i have tried to date. Try it out yourself:

http://www.eioba.com/a74961/getting_started_with_eclipse_php_development_tools_pdt

Bachelor of Computer Science

I have just finished my Bachelor in CS (not counter-strike :

D) which received a review of A+, so that’s nice. This was the paper i turned in
bachelor paper

Design Patterns

I am currently reading Design Patterns: Elements of Reusable Object-Oriented Software” and only halfway through the book, I can already say that apart from the one that taught me OOPD* it is the most valuable programming book i have ever read. If you program OOPD, do yourself a HUGE favour and read it - better sooner than later!

* (I you don’t know what OOPD is, read about Object Oriented Programming and Design - before you fully grasp that concept, this book is of no value to you)

Clogging!

I am starting a new word trend - clogging.

[to clog, clogging] “The act of commenting on a blog”

Hopefully it will catch on

SQL best practices, part 1

I am starting an SQL “best practices” list here in the blog. Hopefully, it will help some poor souls to avoid making some of the mistakes that i’ve made, and make the world a more safe place DB-wise. This is the first part. Each time an update is posted, I will repost the whole lsit with the new additions.

SQL best practices:

  1. When inserting data, ALWAYS write both columns and value name. This means to write this:
    INSERT INTO fruits (name,taste,dollar_price)
     
    VALUES ('apple','delicious',1)

    Instead of this:

    INSERT INTO fruits
     
    VALUES ('apple','delicious',1)

    This is extremely important, as it will allow you to separate your code from the database organisation. When you do it this way, the code won’t mind if you add extra columns (or attributes as they actually are named) to your DB tables. If you don’t include the column names, adding so will BREAK your code.
    Not including the column names is actually considered very poor design practice.

Enough is enough, George Lucas (spoiler alert)

Well, actually not that much of a spoiler, actually, as I think you won’t miss much.

I saw the Indiana Jones movie yesterday. It was a sad experience.

The plot buildup was from the beginning non-existant.

Indy (now age what - 60-65?) could as picking his nose beat 20 young russian soldiers

The plot advance was also very easily handled - no need to search for clues, let’s just have a crazy man tell them were to go all the time.

Last, but ceartainly not lest - Aliens?!?

Summing up, at no time during the movie did i forget that i was sitting ina movie theater, watching a movie (you know that feeling when you forget you are watching a movie that GOOD movies create.)

To reiterate - it was a sad, sad sight seeing George Lucas butcher another of his old masterpieces. The worst part is, as a trailer before the movie, they showed an animated version of Star Wars - The Clone Wars (which has been running as a spin-off on Cartoon Network for some time.) I wonder if Lucas has used a combination of 3D engines from that show to butcher another of his mastyerpieces even more. He has certainly taken the cleaver in his hand. Houen out.

SQL Join

Here’s a little SQL trick that will save some laguage (e.g. PHP) code and make your programs more readable when querying a database (DB).

Often you need to select something from one DB table and use that information with info from another table to get the full picture. Instead of doing this with two queries and language-based code in between (e.g. sorting through an array of results), you can write it all in just one SQL query. Behold:

1
2
3
SELECT W.pay, E.id, E.name, E.address
FROM work_log W, employees E
WHERE (W.pay > 500 AND W.employee_id = E.id)

This will return pay, id, name and address of all employees that earn more than 500 (dollars per month, fx.). The main thing is the

1
W.employee_id = E.id

line, which ensures that the Employee (E) table data match the Work (W) table data

Things to keep in mind coding

Here’s a few things i’ve picked up in my years of having programming as both my study, hobby, and work.

  1. Comment your code. It makes it so much easier for yourself to reuse and change it, if you can see what it’s supposed to do.
  2. If you are using a loop (for, while, etc.) always look for parts of it that can be put outside the loop.
    Code outside the loop is executed once, code inside is executed a lot more. (*)
  3. Division is heavier (requires more computation power) than multiplication. Not enough so that you should multiply twice instead of one division, but more. (*)
  4. If you are programming OOP (Object-Oriented Programming), know that an instance variable used in a function is more RAM-expensive, and processor-intensive than a variable passed as argument.
  5. If you are not using OOP for programming, start using OOP. It is the way of scalability. I will be posting more about OOP and why to use it at a later time.

(*) Depend on the intelligence of the compiler, but better safe than sorry!

I will be editing this with more of these as I sober up/remember them, and give a heads up in a new post when I deem it finished.

Ball Bounce using Vectors

My friend Søren who studies mathematics helped me tremendously getting vector reflection to work. Basically, i want to have ball bounce to work using vectors.This means that if a balls direction is vector v, and the ball hits a straight wall W, having a vector w as its direction (e.g. from top to bottom) , then the wall will have a vector, l, which is orthogonal to w. What I then want is to mirror the balls direction around this vector l. This will make the ball properly bounce off the wall using vectors.

The formula to do this is:

Reflection formula

(from this Wikipedia page )

Where l is (- v.y, v.x)

Søren helped me understand this formula. His last words when he heard I managed to get it to work was: “Math - It works, bitches!”

Wanna see it work?

This movie requires Flash Player 9

Now that’s one bouncing ball - absolutely NO trigonometry - not one single cos/sin

I’ll be posting more about vector animation and the flash classes for achieving it when i finish programming it - i wan’t to have more collision checking done first. And before anynoe asks: Yes - it can be used for collision checking against curving/weird (non-straight) lines and circles (other balls) as well.

Why would you wan’t to use only vectors you ask?

  1. Vectors are easy to use when updating objects - no need to convert angles to coordinates to determine how much to move the ball (and no need to waste computing power doing so)
  2. cos/sin operations are very processor intensive (best to avoid that)