Game Design Blog
Catapult Pull



Catapult Pull


We have some code that detects the down arrow Key being pressed. If the catapult is loaded and the boy is nearby this pulls back the catapult.
The following code is used:

if (mcx.rocks_mc.catapult_mc.arm_mc._rotation>-90){
extrapull = mcx.rocks_mc.catapult_mc.sprite_obj.mass/200;

The arm of the catapult starts at angle -45 degrees (pointing up and left) and can be pulled back all the way to -90 degrees (pointing left).
The first line of code says to only keep pulling back the arm if its angle is greater than -90 degrees.

Next a value called extrapull is calculated by taking the mass of the rock being fired and dividing it by 200.
This means that heavy rocks pull back the arm faster, this is useful as heavy rocks need the arm to be pulled back further to reach the dam.
Finally we add our normal pullback amount to the extrapull value and subtract this from the arm angle.
This will be shown on the screen.

Catapult Fire

The fun bit! When the down arrow key is released, the rock is launched.
The following code is used:

power = Math.abs(cat_mc.arm_mc._rotation+45);
acceleration = (power*100)/cat_mc.sprite_obj.mass;

rads = Math.PI/4; // 45 degrees
projectile_mc.xspeed = acceleration*Math.sin(rads);
projectile_mc.yspeed = acceleration*Math.cos(rads);

"power" creates a number from 0 to 45 from the current angle of the catapult arm.
A maximum angle of -90 will become a power value of 45. [-90+45=-45; Math.abs() converts this to a positive number]
"acceleration" divides the power by the mass of the rock. Heavier rocks will need more power to accelerate to the same speed.
"rads" is the angle the rock is fired. This is fixed at 45 degrees, the actionscript Math functions works in Radians so this is calculated by dividing Pi by 4 (Pi = 180 degrees).

We separate out the forces acting on our rock into horizontal and vertical motion. This is done so we can easily change the X and Y position of the rock as it moves and also because of gravity which only acts vertically.
We know the angle and the total acceleration so we can use trigonometry to get our X and Y speeds. (imagine acceleration is the hypontenuse of a triangle; y is the opposite side and x is the adjacent)

Rock Flight
Everytime we update the screen the rock needs to change position.
The following code is used on the rock:


We incriment the X and Y co-ordinates of our rock by the speed values.
Then we update yspeed by subtracting the force of gravity, this means that yspeed will go down to zero and into negative values. When yspeed is negative the rock will be falling back down.
It is the effect of gravity that creates the arced flightpath of the rock.







Our guy is running around and picking up objects to use with his catapult. These are going to be various items but for now we will start with one generic type. We create a scattering of rocks on our game floor and each one is added to a list.

function game_spawn_rock(idname){
rock_mc = mcx.rocks_mc.attachMovie( idname, "rock_"+rocks_array.length, mcx.rocks_mc.getNextHighestDepth() );
rock_mc._y = gamevars.roadheight-rock_mc._height; //this places the rock flat on the ground
rock_mc._x = Math.round(Math.random()*900); //for now we place the rock in some random X position
rock_mc.spriteid = idname; //we save the clip ID so we can make a copy of it to carry later
rocks_array.push(rock_mc); //PUSH is a code way of saying add this to the end of my list.

Every game loop we run a function to check if the boy is in contact with a rock. This is done by looping through the entire list of rocks using the hitTest function to see if they are overlaping with the boy. If an overlap is detected the number of the rock is saved in a variable called boyvars.nearestrocknum.
If the boy overlaps more than one rock only the last one is stored as this will be the last one to be saved into boyvars.nearestrocknum.
Before we start boyvars.nearestrocknum is set to -1 which we will use to indicate there is no rock nearby.

If the boy is already carrying a rock then we cannot pickup another. Any rock being carried is stored in the variable boyvars.rock.
We check to see if this is empty before looking for rocks that can be picked up.

function game_loop_check_rocks(){
//check if we are carrying a rock
if (boyvars.rock==null){
//check for rocks
boyvars.nearestrocknum = -1;//reset to none before we start
for (n=0;n< rocks_array.length;n++){
if (mcx.boy_mc.hitTest(rocks_array[n])){
boyvars.nearestrocknum = n;//we are standing on a rock save its number

When we pick up a rock, the rock on the ground is hidden (this is so we can easily show it again if dropped) and a copy of the rock is shown being carried by the boy. If we drop a rock the hidden original is moved to the new positon where we dropped it and shown again.
When we put a rock on the catapult its not coming back so only then do we delete the hidden rock on the ground.
The co-ordinate axis for most movieclips is in the upper left corner. The Y values start at zero and increase as they go downwards.
With this in mind we can place any size of rock exactly above our boy by placing it at a Y value equal to the negative of its height.

function game_boy_pickup(){
rock_mc = rocks_array[boyvars.nearestrocknum];

//set a pointer into the rocks list
boyvars.rock = boyvars.nearestrocknum;

//reset this value so we cannot pickup more rocks

//create a rock carry graphic
clip = mcx.boy_mc.rock_carry_mc.attachMovie(rock_mc.spriteid,"clip",1);
clip._y=-clip._height;//This puts the rock above the boy graphic as if he is carrying it


//hide original mc

This code will be updated so that different items have different weight values. This will be used when firing from the catapult but also may be used to make the boy run slower when carrying heavy items.


Double Wires



Double Wires


Here is a good example of a flash game using Science and Maths effectively DOUBLE WIRES. In the game build you have to consider gravity & momentum as they're essential to the mechanics of the gameplay. Also, the player character uses a ragdoll model for the limbs. For more on ragdoll physics click HERE

And so it begins.



And so it begins.


As we revealed in the last blog, the idea for the game is basically to stop a dam bursting by keeping a giant cork in the hole. This cork blocking can be applied to many things in life which is the main reason we chose this as the winner. We like cork.

Currently the game screen layout is in the form of a very shoddy sketch in order to give 3D Phil an idea of where things will be. This is how it looks:


As you can see, that's a pretty wide image. This means we're going to need scrolling and you know we are going to get fancy on that. Over to 3D Phil to explain the code bits for the movement so far:



To start with I need to make the boy move left and right in the game area.
The Boy movieclip will move horizontally on the screen while the background movieclip moves in the opposite direction underneath him.
I will trigger a movement function from the keyboard events and pass a direction parameter: -1 for left and 1 for right.
The horizontal (x) position will increase when moving right and decrease when moving left.

function game_boy_move(dir:Number){
//boy clip
mcx.boy_mc._x += (gamevars.boyspeed/2)*dir;

//level 1 background
mcx.bg_mc._x -= (gamevars.boyspeed*2)*dir;
mcx.rocks_mc._x -= (gamevars.boyspeed*2)*dir;

I will try to explain this.

is a game setting where I am storing a number that controls how much the boy moves each time. This is currently set to 3 pixels.

is a reference to the horizontal position of the boy clip.

this adds a number to the current value.

this equation takes half the value of boyspeed and makes it positive or negative by multiplying it by the dir(direction) parameter which is either -1 or 1

The background layers are moved in the opposite direction by using -= this subtracts a number from the current value.

This function will eventually have extra code to stop movement at the left and right limits of the game area.
Also we will include parallax scrolling, this is where we have more than one background layer that move at different speeds to create the impression of depth and perspective.



We have a Winnaaaar!



We have a Winnaaaar!


Hello to you all. Last week we ran a competition for you to design a game which used Science and Maths at its heart and where you could get your idea made by us (and win a PSP 3000....oooooh).
There were a lot of entries to this, 262 in fact. Some were great, some were terrible but very amusing to read and a few required a team of 100 programmers & something other than Flash to make.
Let's take a look at a few shall we? See if you can guess which are good ideas and which are bad but funny.

Idea 122
"How about a game where you have to get pies into orbit around Weebls head or donkeys around Chris the ninja pirates head or a car around bobs so on and so on."

Idea 115
"There is a stack of weebl and bobs. You use the left and right arrows to try to keep them in the air for as long as possible because they wobble a lot.
It could be set out with the normal purple background and stuff and you simply have to move the bottom one to keep them up for the longest time.
Amazing yet simple."

Idea 185
"let it be scary and fun at the same time with loops and curve around the corner."

Idea 19
"A game where you have to bounce a ball into the goal, by rotating pre placed ramps and use of ball launchers (Like in TBA). Some levels could have alternate gravity, or alternating gravity, with powerups. The goal gets smaller and smaller and the level longer and longer every level, so it gets harder. Also, you can choose the power and angle at the ball is originally launched."

Thank you to everyone who entered. It's been fun reading through all the ideas, that's for sure.
And now...

Drrdrrddrrddrr (That's meant to be a drum roll sound if you were wondering).

...It's time to reveal the winner as chosen by us lot here at Weebl's Stuff and the guys who want to tell you how much Science and Maths rocks; DCSF.

The winner is:

Idea 42 by Noah Wentworth.
Noah's idea was well explained, sounds like a lot of fun and involves a giant cork (All will be revealed soon). Woohoo!

Well done Noah.

We shall be blogging about how the game is put together for the next few weeks as well so remember to check that out too.



Latest Stuff
Here Comes Spiderman

Here Comes Spiderman




It is a Cat Face Halloween special. Yes.

Behold My Mighty Steed

Behold My Mighty Steed

Steeds will be beheld. Verily.

Latest Peepl's Stuff
Investiture of the edible

Investiture of the edible

Once upon a perfect peril...

Universithing: Pilot

Universithing: Pilot

So here it is! I'm starting Uni this September, and as...

Drugs, drugs, drugs!

Drugs, drugs, drugs!

A young boy faces the horrors of crack use through the smooth...

Weebl's Tweets

OK. Everything seems to be working


Gonna try and do a stream of music making in a few minutes.


2 days of our advent calendar are now being worked on. only 22 more to make. THIS IS SO EASY. 。゚(゚´(00)`゚)゚。


Roll up, see what awesome stuff we have on offer!

Weebl's Stuff Retro Flight Bags!!

Weebl's Stuff Retro Flight Bags!! - £14.99