Fruit Ninja Game Using MIT App Inventor (With Elements & Code Explanation)

  

The Fruit Ninja Game is a simple action-based mobile game developed using MIT App Inventor where players slice fruits by swiping or tapping on the screen.

Fruits move randomly across the Canvas, and players earn points by slicing them before they disappear. Missing fruits may reduce lives or end the game.

This project is perfect for beginners to learn game logic, animation, collision detection, scoring systems, and event handling in a fun and interactive way.


 Game Overview

  • Fruits appear randomly on the screen

  • Fruits move (fly or fall) across the canvas

  • Player slices fruits using swipe or touch

  • Score increases for every successful slice

  • Game ends if too many fruits are missed


 ELEMENTS USED

 1. Canvas Component

  • Acts as the main game area

  • All fruits move inside the Canvas


 2. ImageSprite (Fruit Sprites)

  • Each fruit is an ImageSprite

  • Images like apple, banana, orange, etc.

  • Sprites move randomly across the screen


3. Clock.Timer Block

  • Controls fruit movement

  • Spawns new fruits at intervals

  • Adjust speed for difficulty levels


 4. set Sprite.X and Sprite.Y

  • Randomly changes fruit position

  • Simulates flying or falling motion

  • Creates animation effect


 5. Canvas.Dragged / Canvas.Touched

  • Detects swipe or tap action

  • Used for slicing fruits


 6. Sprite.CollidedWith / Touch Detection

  • Detects if swipe touches fruit

  • Confirms successful slice


 7. Score Variable

  • Stores player score

  • Increases when fruit is sliced


 8. set Sprite.Visible to false

  • Removes fruit after slicing

  • Makes slicing effect realistic


 9. Miss Counter / Game Over Condition

  • Counts missed fruits

  • Ends game when limit is reached


 CODE LOGIC EXPLANATION (Blocks Concept)


 1. Initialize Game (On Start)

  • Set Score = 0

  • Set MissCount = 0

  • Hide fruits initially

  • Enable Clock.Timer


 2. Spawn Fruits (Clock.Timer)

Every timer interval:

  • Set Sprite.Visible = true

  • Set Sprite.X to random number

  • Set Sprite.Y to bottom/top

  • Move sprite upward or downward


 3. Slice Detection (Canvas.Dragged)

When player swipes:

  • Check if swipe coordinates overlap fruit

  • If yes:

    • Increase score

    • Hide fruit

    • Play slice sound


 4. Miss Detection

If fruit reaches bottom of screen:

  • Increase MissCount

  • Hide fruit

If MissCount ≥ 3:

  • Stop Clock

  • Show “Game Over”

  • Display final score


 What Students Learn

✅ Event-driven programming
✅ Animation using sprites
✅ Collision detection
✅ Score tracking
✅ Random number usage
✅ Game over logic
✅ Variables and timers


 Optional Advanced Features

You can upgrade the game by adding:

  •  Bomb sprite (touching ends game)

  •  Slice sound effect

  •  Background music

  •  High score storage

  •  Timer countdown

  •  Increasing difficulty levels



ELEMENTS USED









DOWNLOAD AIA FILE FOR THIS PROJECT BY CLICKING THIS LINK









Comments