Page 148 - KEC Khaitan C5 Flipbook
P. 148

Step 2: Adding Enemy Cars
                     Create Two Enemy Cars:


                    var car1 = createSprite(100, 200);

                    car1.setAnimation("car1");

                    car1.scale = 0.6;

                    var car2 = createSprite(325, 350);

                    car2.setAnimation("car2");

                    car2.scale = 0.6;
                    o    These enemy cars move downwards and act as obstacles.

                  •  o    Tip: Pick different car sprites for variety.

                  Step 3: Adding Start and Restart Sprites

                     Create the Restart Button:

                    var restart = createSprite(200, 200);

                    restart.setAnimation("restart");

                    restart.scale = 0.8;

                    restart.visible = false;

                    o   The restart button is hidden at the start and appears when the player loses.
                     Create the Start Button:


                    var start = createSprite(200, 200);

                    start.setAnimation("start");
                    o   The start button is visible at the beginning and disappears once the game starts.

                  •  o   Tip: Customize the start/restart buttons to make them more engaging.

                  Step 4: Creating Boundaries

                     Create Edges for the Player Car to Bounce Off:

                    o   This prevents the player car from moving off the screen.

                    o   Edge sprites act as invisible walls to keep the player on the road.
                  Step 5: Programming Player Movement

                     Add Left and Right Navigation:


                    if(keyDown("left")){





                  146   Premium Edition-V
   143   144   145   146   147   148   149   150   151   152   153