Friday, 27 May 2016

Almost done with Mon Petit Croissant game!

You can take a look how it's going to look like here:



 

Friday, 13 May 2016

Platform Game Tutorial 04 - hero death

In this tutorial we are going to make our hero actor react to the obstacles and enemies. Basically, our hero will die the moment it hits these actors.

Watch this animation below:


You can see that the actor bounced upwards and shows a "dead" image and then falls downwards off screen. What you are seeing there is an actor called deadHero that has been spawned the moment the hero actor hits the spikes. The hero actor will be destroyed.


Alright to do this, create another actor called deadHero.
Add the image called
dead1.png into the actor.








Add this behaviour into it:

Accelerate:
Direction: 270
Acceleration: 200
Relative to: scene


 Add this rule into it:

If game.heroDead is false
 
    change attribute:
      self.Motion.LinearVelocity.X to 50
 
      self.Motion.LinearVelocity.Y to 200
 
      game.heroDead to true




If self.Position.Y < -50
 
    change attribute:
      game.lives to game.lives-1
 
      Spawn Actor: hero,
          position x=20, y=50
          relative to scene


    change attribute:
      game.heroDead to false

This rule means that after the deadHero falls off-screen it will spawn the hero actor back to its original position at x=20 and y=50 in the game. It will also reset the game.heroDead to FALSE, so that the heroImage actor can appear and attach back to the hero actor.


Next, go into the hero actor and add this Rule inside it:

When Any conditions are valid:
If actor collides with actor of type : spikes
If actor collides with actor of type : EnemyA 
 
      Spawn Actor: deadHero,
          position x=0, y=0
          relative to actor

     Destroy


Alright we're done! Let's preview our game.

Wait for the next tutorial coming up soon!

Thursday, 12 May 2016

Platform game tutorial 03 - Obstacles and Enemies

In this tutorial, we are going to create obstacles for the hero to avoid, and enemies the hero has to avoid or destroy.

Obstacle


1) Create an actor and let's name it spikes.



2) Add the image called spike1.png into the actor.

3) Change the horizontal wrap to Tile.




4) Click and drag the spikes actor onto the stage. Resize the spikes actor on stage to make it longer. You will notice that the spikes image will be repeated/tiled.




Enemies

Create another actor called EnemyA.
Add the image enemyA1.png into it.
Add 3 actor attributes:

startX      value: 0     (real)
endX       value: 0     (real)
speed      value: 50   (integer)





Add the animate behavior with these 4 images


Add these behaviours into it:

Accelerate:
Direction: 270
Acceleration: 200
Relative to: scene

change attribute:
self.Motion.LinearVelocity.X to self.speed

Collide
Bounce when colliding with actor : platform



Add these rules into it:

When Any conditions are valid:

     If self.Position.X > self.endX
     if self.Position.X < self.startX

   change attribute:
     self.Motion.LinearVelocity.X to  - self.Motion.LinearVelocity.X





If self.Motion.LinearVelocity.X > 0

   change attribute:
     self.Graphics.Flip Horizontally to true

otherwise/else

       change attribute:
       self.Graphics.Flip Horizontally to false


Now drag the EnemyA actor onto the stage.

Change the value of the actor’s instance attributes:

startX and endX to your desired position on the stage.




Make sure the value of startX is lesser than endX. This will make the enemy move from left to right continuously.


Preview your game!

We will continue on to the next tutorial where we will make the hero react to the obstacles and enemies.

Wednesday, 11 May 2016

Platform Game tutorial 02 - Animating the hero

If you have finished the first tutorial, great job!

Now let's move on to the 2nd part of the tutorial. It is a little bit challenging but if you follow these steps closely, you should be ok :)

let's start with....

Step 1:

In Tutorial 1 we have created 6 attributes:

    a) buttonLeft [boolean]
    b) buttonRight [boolean]
    c) buttonJump [boolean]
    d) maxJumpCount [Integer]
    e) heroSpeed [Integer] set this to 200
    f) heroJumpHeight [Integer] set this to 250

Now let's Create 9 more attributes!

    g) heroX   [real]
    h) heroY   [real]
    i) heroDead  [boolean]
    j) lives  [integer]    set this to 3
    k) heroShoot  [boolean]
    l) heroDirection   [integer]    set this to 1
    m) ringsCollect   [integer]
    n) doorUnlock   [boolean]
    o) key   [boolean]

So altogether you will have all these attributes shown below:


Step 2:

Let's track the X and Y position of the hero actor so that other actors know where the hero actor is on the screen. This is useful when you want to stick something onto the hero actor or you want the enemies to know where the hero is so that it can chase after the hero.

    a) Go into the hero actor
    b) add 4 behaviors:

         i)   [constrain Attribute] game.heroX to self.Position.X
         ii)  [constrain Attribute] game.heroY to self.Position.Y
         iii) [change Attribute]    self.Color.Alpha to 0
         iv) control camera



Step 3:

Right now our hero is just a simple white rectangle. Let's add the animations and images to the heroImage actor by adding rules to it. We won't be doing this to the hero actor because we want to make the heroImage actor "stick" to the hero actor.

Go into the heroImage actor (which you have already created in tutorial 1)

     i) Add the image walk2.png into the actor


     ii) Next add a RULE.

              when game.heroDead is false

                  [change attribute]       self.Color.Alpha    to   1
                  [constrain Attribute]   self.Position.X       to   game.heroX
                  [constrain Attribute]   self.Position.Y       to   game.heroY + 5


                  otherwise/else

                 [change attribute] self.Color.Alpha to 0

           You can refer to the screenshot below:



Step 4:

Now we will add the walking animation when the hero moves to the left.

In the heroImage actor,

i) Add another RULE.

              when game.buttonLeft     is   true
               when game.buttonRight  is   false

                  [change attribute]       self.Graphics.Flip Horizontally to   true
                  Animate (add the images walk1.png, walk2.png, walk3.png, walk4.png)

           You can refer to the screenshot below:


ii) Now we'll make the animation when the hero moves to the Right.
 
     Copy the RULE above, paste below it and just change:

               when game.buttonLeft    is  FALSE
               when game.buttonRight  is  TRUE
               [change attribute]       self.Graphics.Flip Horizontally to   FALSE

 see the screenshot below:




iii) Next, when both Left and Right button is pressed, stop the animation and show just One image.

        Copy the RULE above, paste below it and just change:

               when game.buttonLeft    is  TRUE
               when game.buttonRight  is  TRUE
               [change image]  set Image  to:  walk2

               otherwise/else

               [change attribute] self.Motion.Linear.Velocity.X to 0


 see the screenshot below:
 



iv) Next, when both Left and Right button is NOT pressed, stop the animation and show just One image.

        Copy the RULE above, paste below it and just change:

               when game.buttonLeft    is  FALSE
               when game.buttonRight  is  FALSE
               [change image]  set Image  to:  walk2
 
               otherwise/else

               [change attribute] self.Motion.Linear.Velocity.X to 0


 see the screenshot below:





Step 5:

Finally, we'll make the animation for the hero when it jumps.

Add another RULE.

              when game.maxJumpNum = 1

                  Animate (add the images jump1.png, jump2.png, jump3.png, jump4.png, jump5.png)





 Now preview your game!
Continue on to tutorial 3