1 of 45

JavaScript�GamesUsing JS GUI

2 of 45

How to create Games �in JS GUI

  • To create a Game we have to know basic things like
  • Create a sprite(hero or enemies)
  • Create a background.
  • Create controllers to move the object (or) sprite.

We have to create a game like this

click here to see game

3 of 45

How to create Background

We can create background by using background color or background image.

You can find background in Scene section as shown below.

Select this one to change the color.

Select this one to change image

Choose which color you want

4 of 45

Output

According to background color you can see the output here.

5 of 45

Create background image

Select this one to add background image.

Click here to select background images in gallery

6 of 45

Create a sprite(Hero)

This helps to create sprites

7 of 45

Create a sprite(Hero or enemy)

Click on this empty space you will find different types of sprites in gallery or you can draw the arrow in editor as shown below

8 of 45

Move your sprite

Select this one to move your Sprite

This option helps you to move the sprite in required direction

9 of 45

Fix borders to your sprite

As you can see how the sprite is moving out of the box.

To fix this problem we have to use my sprite stay in screen (block).

10 of 45

In sprites drag this one to workspace

Make sure that it should be ON

11 of 45

Output

Use your Arrow keys to move the bow around the screen.

12 of 45

Function (Coding Concept)

What is a Function? A function in coding is a set of instructions that you give to a computer to do a specific task.

It's like a recipe that you can use over and over again without having to write the whole recipe each time.

Imagine you have a toy robot that can do tricks. You can tell the robot to do a trick by writing instructions. One of the tricks is to spin around. Instead of telling the robot to turn right, turn right, turn right, and turn right every time you want it to spin, you can create a function called "spin."

13 of 45

Here's how it looks:

def spin():

turn_right()

turn_right()

turn_right()

turn_right()

Now, whenever you want the robot to spin, you just call the function: spin()

This makes it easier and faster to tell the robot to spin! Also it can be used multiple times by simply calling it.

14 of 45

Create Enemy

Create function called Enemyanimation as shown below.

15 of 45

Create Enemy

Click on this to select sprite

Drag this one to create one more sprite

Select this sprite

Click here to change player name

16 of 45

Create enemy

Now we have to move enemy from left to right.

Select these two options and change my sprite name to my sprite 2 by clicking on it.

17 of 45

Position in game panel

Imagine a graph on game panel like this.

Select x =155 pick random position for y from 7 to 107

18 of 45

Enemy position in game panel

Now we have to our enemy towards left direction that is in x direction, let see how.

19 of 45

Velocity (Physics Concept)

What is Velocity? Velocity is a way to describe how fast something is moving and in which direction.

It tells you where the object is going with what speed.

Example: Imagine you are riding your bike. If you are going 10 miles per hour to the east, your velocity is 10 miles per hour east. If you turn around and go 10 miles per hour to the west, your velocity changes to 10 miles per hour west.

So, velocity = speed + direction.

20 of 45

Position in game panel

Imagine a graph on game panel like this.

Our x position is at 155 that is at extreme right. Now have to move to left that is negative values of x . Choose VX= -89 and VY=0

21 of 45

Now we have make enemy move up and down

Vx to move left and right .

Vy to move up and down.

Set the sprite position

22 of 45

Game update

Our enemy has to appear for every 1350 millisecond.

Select this option and drag it

You can change time here

Now call Enemyanimation from game update

23 of 45

shoot arrow when A is pressed

Select this event to provide arrows when A is pressed

When A or space is pressed our bow has to project Arrow from it.

24 of 45

Projectile (Physics Concept)

What is a Projectile? A projectile is any object that is thrown or launched into the air and is only affected by gravity and air resistance. It moves along a curved path called a trajectory.

When you throw a basketball towards the hoop, the basketball is a projectile. When you throw it, it goes up in the air, moves forward, and then comes down into the hoop. The path that the basketball follows is called its trajectory.

25 of 45

Imagine you're at the park with a friend, and you have a ball. When you throw the ball to your friend, it goes up in the air and then comes back down into your friend's hands. The ball is a projectile, and the curved path it takes is its trajectory.

The stars (*) show the path the ball takes as it flies through the air.

26 of 45

Here's a simple drawing to help visualize it:

*

* *

* *

* *

* *

* *

–----------------

27 of 45

Project a Arrow from bow

Select this projectile to project Arrow from bow.

Click here to draw the arrow

Set Vx= 100 and Vy =0 to move horizontal right direction.

28 of 45

Destroy enemy with Arrow

  • When our projectile touches enemy, it has to destroy. Let’s see how to do it.

Drag this one to work space.

Select projectile from here

29 of 45

Game over when hero collides with enemy

  • When our enemy collide with the hero, hero has to destroy. Let’s see how to do it.

Drag this one to work space.

Select game over block from Game section

30 of 45

Game part 2

Create count down or life

Create score and change score

Create music for actions

Create animation for bird

31 of 45

How to create count down

In info you will find the score, time , life.

Drag this one to on start to set time

32 of 45

Create score

Drag this one to on start to create score. It is like creating a variable.

Drag this one to change the score we arrow(projectile) hits bird(enemy).

33 of 45

Create music

In music section you will find the music drag and drops as shown below. Drag them where ever you want.

As per our game requirement, we have to set the sound or music when arrow is released from bow and when enemy is destroyed.

Select this one to create sound .

34 of 45

Create music

Drag play sound block to on event and projectile over lapps.

35 of 45

Game end

Once the count down ends we have to end the game and show score on the screen.

36 of 45

Show final score

In the place of 0(zero ) drag score here.

37 of 45

Create Animation for Enemy

In Advanced section click on Extensions it will redirect to Extension page as shown in below. In Extensions page select animation.

38 of 45

Create Animation for Enemy

You will find the Animation section here

39 of 45

Create Animation for Enemy

  • In animation drag animate block to function as shown in below.

Change mySprite to mySprite2 and interval to 100ms

40 of 45

Create Animation for Enemy

Click on frames it will show the below window

Switch to gallery to select different frames

41 of 45

Create Animation for Enemy

Select this image

Click on this to add one more frame. Like this we need to have 4 frames.

42 of 45

Create Animation for Enemy

  • For each frame select this four images as shown below.

43 of 45

Create Animation for Enemy

Click on done to save the frames

44 of 45

Create Animation for Enemy

  • Final step is to Switch ON the loop button as shown below.

45 of 45