Tynker Tennis Game – Step-by-Step Coding Guide

In this project, we create a Tennis Game using Tynker where:

  • A tennis ball moves continuously and bounces inside the court

  • Two players stand on opposite sides of the court

  • When a player touches the ball, a tennis attack animation plays

  • One player is controlled by the mouse, and the other behaves like an automatic opponent


This project helps students understand:
  • Continuous motion

  • Ball bounce physics

  • Mouse-based control

  • Animation on collision

  • Simple opponent logic

 Game Objective

  • Keep the tennis ball in motion

  • Hit the ball using the player characters

  • Observe realistic movement and bounce inside the tennis court

 Game Elements Used

 Actors

  • Player (actor) – Controlled by mouse

  • Opponent (actor1) – Auto-moving player

 Game Object

  • Tennis Ball

 Background

  • Tennis court background with boundaries

 Step-by-Step Coding Guidelines

 Step 1: Tennis Ball Movement & Bounce

Code (Tennis Ball):

on start
→ turn 15 degrees
→ forever
→ move 50 pixels
→ wait 0.001 secs
→ wait 0.005 secs
→ if on edge, bounce

Explanation:

  • turn 15 degrees sets the starting direction

  • move 50 pixels gives speed to the ball

  • Small wait values make motion smooth

  • if on edge, bounce keeps the ball inside the court

 This creates realistic ball movement



 Step 2: Player Setup (Right-Side Player)

Code:

on start
→ animate Side Run
→ forever
→ go to mouse-pointer
→ go to right edge
→ point towards left edge
→ set rotation style left-right

Explanation:

  • Player follows the mouse vertically

  • Locked to the right side of the court

  • Always faces the opponent

  • Prevents unwanted rotation

 This gives smooth mouse-based paddle control

 Step 3: Player Attack Animation on Ball Contact

Code:

when touching Tennis Ball occurs
→ animate Side Bow Attack

Explanation:

  • Plays a hit animation when ball touches player

  • Makes the game visually engaging

  • Introduces event-triggered animation

 Step 4: Opponent (Left-Side Player) Movement

Code:

on start
→ forever
→ go to Tennis Ball
→ go to left edge
→ move 10 pixels
→ wait 0.005 secs
→ if on edge, bounce
→ set rotation style left-right

Explanation:

  • Opponent automatically follows the ball

  • Stays on the left side

  • Acts like a basic AI player

  • Adds challenge to the game

 Great intro to AI-style behavior

 Step 5: Opponent Attack Animation

Code:

when touching Tennis Ball occurs
→ animate Side Bow Attack

Explanation:

  • Same hit animation for fairness

  • Visual feedback when opponent hits the ball

 How to Play the Game

  1. Move your mouse up and down

  2. Player follows the mouse on the right side

  3. Hit the ball when it comes near

  4. Watch the opponent return the ball







 

Comments