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
-
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):
Explanation:
-
turn 15 degreessets the starting direction -
move 50 pixelsgives speed to the ball -
Small
waitvalues make motion smooth -
if on edge, bouncekeeps the ball inside the court
This creates realistic ball movement
Step 2: Player Setup (Right-Side Player)
Code:
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:
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:
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:
Explanation:
-
Same hit animation for fairness
-
Visual feedback when opponent hits the ball
How to Play the Game
-
Move your mouse up and down
-
Player follows the mouse on the right side
-
Hit the ball when it comes near
-
Watch the opponent return the ball





Comments
Post a Comment