Department of Electrical and Computer Engineering Facebook page


  • DEPARTMENT
    • Overview
    • Computing
    • Facilities
    • Organizations
    • Educational Objectives
    • Student Outcomes
    • Scholarship Awards
    • Employment
    • Advisory Committee
    • Contact
  • ACADEMICS
    • Undergraduate
      • Computer Eng.
      • Electrical Eng.
      • Ambassadors
    • Graduate
      • Information for Prospective Students
      • ECE Graduate Handbook
      • Graduate Forms
      • Ph.D. Qualifying Exam
      • Distance Education
      • Frequently Asked Questions (FAQ)
    • Courses
    • Student Survival kit
    • Distance Learning
  • PEOPLE
    • Faculty
    • Staff
  • PROSPECTIVE STUDENTS
    • Overview
    • FAQ
    • Considering ECE
    • Scholarships
    • PC Requirements
    • Office of Admissions
  • RESEARCH
    • Overview
    • Signal Processing & Communications
    • Digital Systems & Microelectronics
    • Power & High Voltage
    • Research Centers
      • Emerging Materials Research Laboratory
      • High Voltage Laboratory
      • Robotics
    • HPCC
  • ALUMNI
Ball Control - Ece
Personal tools
  • Log in
Views
  • Page
  • Discussion
  • View source
  • History

Ball Control

From Ece

Jump to: navigation, search

// ball_control.v // Created by Justin Davis, January 2005 // Modified by Patrick Duckworth, April 2007 // Target board: Pegasus by Digilent, Inc. // // Controls the location of the ball // Output the X and Y coordinates where the ball should be drawn // Determines when it has hit a wall or paddle and act accordingly //

module ball_control (clk, paddleY, ballX, ballY,lives,score); input clk; input [9:0] paddleY; output [9:0] ballX, ballY; output [7:0] lives; output [7:0] score;

  reg x,y;

reg [16:0] counter; reg [10:0] rand;



parameter WALLWIDTH = 20; parameter TOTALROWS = 479; parameter TOTALCOLS = 639; parameter PADDLEWIDTH = 20; parameter PADDLELENGTH = 80; parameter BALL = 20;

reg ballX; reg ballY; reg lives; reg score;

initial begin ballX = 10'b0100000000;

  ballY = 10'b0100000000;
  x=0;

y=1; lives = 8'b00000100; score = 8'b00000000; end


always@(posedge clk) begin if (lives >= 1) begin counter = counter+1; end else begin counter = 16'b0000000000000001; end


// Pseudo randomization of bomb placement if (rand >= 11'b01001000000) begin rand = 11'b00000000000; end if (rand == 11'b00000000000) begin rand = 11'b00000100000; end rand = rand+1;

// Bomb control if (counter == 16'b0000000000000000) begin // If bomb hits paddle if (((ballY+BALL) > (TOTALROWS-PADDLEWIDTH)) && ((ballX+BALL) >= paddleY) && (ballX <= (paddleY+PADDLELENGTH))) begin x = 1; y = 0; score = score+1; end

// If bomb misses paddle else if ((ballY+BALL) > (TOTALROWS-PADDLEWIDTH) || ballX <=0 || ballX >= (TOTALCOLS-BALL)) begin // if paddle misses bomb subtract a life if ((ballY+BALL) > (TOTALROWS-PADDLEWIDTH)) begin lives = lives - 1; end

// set the next bomb placement ballX=rand; x=0; y=1; ballY = 10'b0000010101; end

// bomb movement if (y==1) begin ballY = ballY+1; end else begin ballY = ballY-1; end if (x==1) begin if (ballX >= paddleY+((PADDLELENGTH-BALL)/2)) begin ballX = ballX+2; end else begin ballX = ballX-2; end end end end endmodule

Retrieved from "http://www.ece.msstate.edu/wiki/index.php/Ball_Control"
Navigation
  • Main Page
  • Community portal
  • Current events
  • Recent changes
  • Random page
  • Help
SEARCH
TOOLBOX
LANGUAGES
 
Toolbox
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
Powered by MediaWiki
  • This page was last modified on 25 April 2007, at 09:44.
  • This page has been accessed 787 times.
  • Privacy policy
  • About Ece
  • Disclaimers

Mississippi State University Home| PO Box 9571, Mississippi State, MS 39762 | Main Office: 1.662.325.3912

Bagley College of Engineering | Mississippi State University| Legal| Webmaster| Intranet

Page modified: Tue, 23 Sep 2008 15:18:39 CDT