160 likes | 174 Views
Learn how to create an animated VGA graphics ping-pong video game with dynamic display generation and controlled paddle motion. Includes layers, physics, and game controls.
E N D
EEL 3705 / 3705LDigital Logic Design Spring 2007Instructor: Dr. Michael FrankModules #90-99 (Extra Slides): Design Examples Module #93: Animated VGA Graphics–Ping-Pong Video Game M. Frank, EEL3705 Digital Logic, Fall 2006
Ping-Pong VideogameExample Dynamic Display Generation, Layered Graphics, Controlled Paddle Motion M. Frank, EEL3705 Digital Logic, Fall 2006
Real-World Ping-Pong Table Image credit: Wikipedia M. Frank, EEL3705 Digital Logic, Fall 2006
Ping-Pong Game Display Mocked-up here as a Powerpoint animation Ball Leftpaddle Rightpaddle “Midline” “Net” M. Frank, EEL3705 Digital Logic, Fall 2006
Plan for Game Controls • Left pushbutton FLEX_PB1 will control left player’s paddle • Held down = move down, released = move up • Right button controls right paddle similarly M. Frank, EEL3705 Digital Logic, Fall 2006
Plan for game’s “physics” • When the ball hits a wall, it bounces elastically • Horizontal or vertical velocity will change sign • When the ball hits a paddle… • Its vertical velocity (vy) will increase or decrease depending on which direction paddle is moving • Paddle moving up vertical velocity decreases • Paddle moving down vertical velocity increases • Its horizontal velocity (vx) will change sign (bounce) • Its absolute value will increase if the ball hits near the center of the paddle (a “good hit”) • Its absolute value will decrease if the ball hits near the edge of the paddle (a “glancing blow”) M. Frank, EEL3705 Digital Logic, Fall 2006
Prioritized Color Layer Combiner • Allows one graphics object to override another… M. Frank, EEL3705 Digital Logic, Fall 2006
Table Surface Stipple Color Layer Generator • Pure green makes for an overly bright table surface, so instead we use an XOR gate to create a green-on-black checkerboard stipple pattern implementedby this circuit M. Frank, EEL3705 Digital Logic, Fall 2006
Game Display Generator (top half) Note we use two instances of the color_mixer module to combine the outputs of the table, midline, and net renderers M. Frank, EEL3705 Digital Logic, Fall 2006
Paddle Renderer (only left paddle so far) Left paddle is rendered as a 10×50 pixel blue rectangle starting at y coordinate lpy (input) M. Frank, EEL3705 Digital Logic, Fall 2006
Entire Ping-Pong Display Renderer (so far) Altogether we’re using three of our color_mixer modules in order to correctly combine the graphics on the playing surface, midline, net, and paddle layers. (default black background) green stipple Increasinggraphics layerpriority white midline black net blue paddle M. Frank, EEL3705 Digital Logic, Fall 2006
Left Paddle Controller Circuit Comparatorallows paddley to be updated iff its new value is in the range [0,480−50]= [0,430] Adder increments/decrements paddley coordinate indirection determinedby pushbutton #1 M. Frank, EEL3705 Digital Logic, Fall 2006
Top-Level Circuit for Ping-Pong Game (so far) M. Frank, EEL3705 Digital Logic, Fall 2006
Demonstration of Game Display (so far) • We can hook up the board directly to the lecture hall video projector in order to demonstrate the left paddle’s live functionality to the class… M. Frank, EEL3705 Digital Logic, Fall 2006
Ping-Pong Ball Sprite Design Planning the bitmap Approx. on-screenappearance DEPTH = 10; WIDTH = 10; ADDRESS_RADIX = HEX; DATA_RADIX = BIN; CONTENT BEGIN 0 : 0001111000; 1 : 0111111110; 2 : 0111111110; 3 : 1111111111; 4 : 1111111111; 5 : 1111111111; 6 : 1111111111; 7 : 0111111110; 8 : 0111111110; 9 : 0001111000; END; ball_sprite.mif M. Frank, EEL3705 Digital Logic, Fall 2006
Still to do on ping-pong game… • You might like to try some of these yourself! • Add 2nd, red paddle on right, controlled by PB2 • Create a ball object, implement game physics • Adjust movement speeds for best playability • Add a scoreboard using the 7-segment display • Hook up an external speaker to the expansion bus • and generate “beep” sounds when the ball bounces off a wall or a paddle or goes out of bounds Done exceptfor red paddlemovement M. Frank, EEL3705 Digital Logic, Fall 2006