c#
a9/10-30-17/Propeller/.vs/Propeller/v15/.suo
a9/10-30-17/Propeller/Propeller.sln
Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26430.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Propeller", "Propeller\Propeller.csproj", "{50DE1BA6-57FF-43FC-8F1A-7558D49CC060}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {50DE1BA6-57FF-43FC-8F1A-7558D49CC060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {50DE1BA6-57FF-43FC-8F1A-7558D49CC060}.Debug|Any CPU.Build.0 = Debug|Any CPU {50DE1BA6-57FF-43FC-8F1A-7558D49CC060}.Release|Any CPU.ActiveCfg = Release|Any CPU {50DE1BA6-57FF-43FC-8F1A-7558D49CC060}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal
a9/10-30-17/Propeller/Propeller/App.config
a9/10-30-17/Propeller/Propeller/bin/Debug/Propeller.exe
a9/10-30-17/Propeller/Propeller/bin/Debug/Propeller.exe.config
a9/10-30-17/Propeller/Propeller/bin/Debug/Propeller.pdb
a9/10-30-17/Propeller/Propeller/Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Propeller { public partial class Form1 : Form { List<Propeller> props; Brush circleBrush; double changeAmount = .05; public Form1() { InitializeComponent(); props = new List<Propeller>(); circleBrush = new SolidBrush(Color.Green); } private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { props.Add(new Propeller(new Point(200, 200), i * 2 * Math.PI / 10)); } props[0].Revolution += Form1_Revolution; Graphics grp = this.CreateGraphics(); foreach (Propeller prop in props) { prop.Draw(grp); } } private void Form1_Revolution(object sender, EventArgs e) { int numberOfRevolutions = int.Parse(tsslRevolutions.Text); numberOfRevolutions++; tsslRevolutions.Text = numberOfRevolutions.ToString(); } private void btnDraw_Click(object sender, EventArgs e) { Graphics grp = this.CreateGraphics(); foreach (Propeller prop in props) { prop.Draw(grp); } } private void timer1_Tick(object sender, EventArgs e) { foreach (Propeller prop in props) { prop.Move(changeAmount); } this.Refresh(); } private void tbTimerInterval_Scroll(object sender, EventArgs e) { timer1.Interval = -tbTimerInterval.Value; } private void tbAmountMoved_Scroll(object sender, EventArgs e) { changeAmount = tbAmountMoved.Value / 100.0; } private void Form1_Paint(object sender, PaintEventArgs e) { foreach (Propeller prop in props) { prop.Draw(e.Graphics); } e.Graphics.FillEllipse(circleBrush, new Rectangle(props[0].Middle.X - 10, props[0].Middle.Y - 10, 20, 20)); } } }
a9/10-30-17/Propeller/Propeller/Form1.Designer.cs
namespace Propeller { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.tbTimerInterval = new System.Windows.Forms.TrackBar(); this.tbAmountMoved = new System.Windows.Forms.TrackBar(); this.button1 = new System.Windows.Forms.Button(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.tsslRevolutions = new System.Windows.Forms.ToolStripStatusLabel(); ((System.ComponentModel.ISupportInitialize)(this.tbTimerInterval)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tbAmountMoved)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // // timer1 // this.timer1.Enabled = true; this.timer1.Interval = 50; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // tbTimerInterval // this.tbTimerInterval.Location = new System.Drawing.Point(567, 126); this.tbTimerInterval.Maximum = -1; this.tbTimerInterval.Minimum = -100; this.tbTimerInterval.Name = "tbTimerInterval"; this.tbTimerInterval.Orientation = System.Windows.Forms.Orientation.Vertical; this.tbTimerInterval.Size = new System.Drawing.Size(45, 209); this.tbTimerInterval.TabIndex = 0; this.tbTimerInterval.Value = -50; this.tbTimerInterval.Scroll += new System.EventHandler(this.tbTimerInterval_Scroll); // // tbAmountMoved // this.tbAmountMoved.Location = new System.Drawing.Point(618, 126); this.tbAmountMoved.Maximum = 100; this.tbAmountMoved.Name = "tbAmountMoved"; this.tbAmountMoved.Orientation = System.Windows.Forms.Orientation.Vertical; this.tbAmountMoved.Size = new System.Drawing.Size(45, 209); this.tbAmountMoved.TabIndex = 1; this.tbAmountMoved.Value = 5; this.tbAmountMoved.Scroll += new System.EventHandler(this.tbAmountMoved_Scroll); // // button1 // this.button1.Location = new System.Drawing.Point(97, 74); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 2; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel1, this.tsslRevolutions}); this.statusStrip1.Location = new System.Drawing.Point(0, 472); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(708, 22); this.statusStrip1.TabIndex = 3; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; this.toolStripStatusLabel1.Size = new System.Drawing.Size(72, 17); this.toolStripStatusLabel1.Text = "Revolutions:"; // // tsslRevolutions // this.tsslRevolutions.Name = "tsslRevolutions"; this.tsslRevolutions.Size = new System.Drawing.Size(13, 17); this.tsslRevolutions.Text = "0"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(708, 494); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.button1); this.Controls.Add(this.tbAmountMoved); this.Controls.Add(this.tbTimerInterval); this.DoubleBuffered = true; this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); ((System.ComponentModel.ISupportInitialize)(this.tbTimerInterval)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tbAmountMoved)).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Timer timer1; private System.Windows.Forms.TrackBar tbTimerInterval; private System.Windows.Forms.TrackBar tbAmountMoved; private System.Windows.Forms.Button button1; private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; private System.Windows.Forms.ToolStripStatusLabel tsslRevolutions; } }
a9/10-30-17/Propeller/Propeller/Form1.resx
text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 17, 17 104, 17
a9/10-30-17/Propeller/Propeller/obj/Debug/CoreCompileInputs.cache
6e6a7313ee0eb791485f29384e4f1c7dfaec9ded
a9/10-30-17/Propeller/Propeller/obj/Debug/DesignTimeResolveAssemblyReferences.cache
a9/10-30-17/Propeller/Propeller/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.csproj.FileListAbsolute.txt
S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\bin\Debug\Propeller.exe.config S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\bin\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\bin\Debug\Propeller.pdb S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.csprojResolveAssemblyReference.cache S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.Form1.resources S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.Properties.Resources.resources S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.csproj.GenerateResource.Cache S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-25-17\Propeller\Propeller\obj\Debug\Propeller.pdb S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\bin\Debug\Propeller.exe.config S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\bin\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\bin\Debug\Propeller.pdb S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.csprojResolveAssemblyReference.cache S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.Form1.resources S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.Properties.Resources.resources S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.csproj.GenerateResource.Cache S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-27-17\Propeller\Propeller\obj\Debug\Propeller.pdb S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\bin\Debug\Propeller.exe.config S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\bin\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\bin\Debug\Propeller.pdb S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.csprojResolveAssemblyReference.cache S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.Form1.resources S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.Properties.Resources.resources S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.csproj.GenerateResource.Cache S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.exe S:\mhodges\CPSC 275-02\10-30-17\Propeller\Propeller\obj\Debug\Propeller.pdb
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.csproj.GenerateResource.Cache
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.csprojResolveAssemblyReference.cache
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.exe
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.Form1.resources
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.pdb
a9/10-30-17/Propeller/Propeller/obj/Debug/Propeller.Properties.Resources.resources
a9/10-30-17/Propeller/Propeller/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
a9/10-30-17/Propeller/Propeller/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
a9/10-30-17/Propeller/Propeller/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
a9/10-30-17/Propeller/Propeller/Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace Propeller { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
a9/10-30-17/Propeller/Propeller/Propeller.cs
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Propeller { class Propeller { public event EventHandler<EventArgs> Revolution; public Point Middle { get; private set; } public double Length { get; private set; } public double Angle { get; private set; } public Pen Pen { get; private set; } public Pen BackgroundPen { get; private set; } public Propeller(Point middle, double angle) { Middle = middle; Length = 101; Angle = angle; Pen = new Pen(Color.Chocolate, 5); BackgroundPen = new Pen(SystemColors.Control, 5); } public void Draw(Graphics grp) { float height = (float)(Length * Math.Sin(Angle)); float width = (float)(Length * Math.Cos(Angle)); PointF endPoint = new PointF(Middle.X + width, Middle.Y + height); grp.DrawLine(Pen, Middle, endPoint); } public void Undraw(Graphics grp) { float height = (float)(Length * Math.Sin(Angle)); float width = (float)(Length * Math.Cos(Angle)); PointF endPoint = new PointF(Middle.X + width, Middle.Y + height); grp.DrawLine(BackgroundPen, Middle, endPoint); } public void Move(double amount) { Angle += amount; if (Angle >= 2 * Math.PI) { // Raise Revolution event object sender = this; EventArgs eventArgs = new EventArgs(); // Reset the angle so it's smaller the 2 Pi Angle -= 2 * Math.PI; if (Revolution != null) { Revolution(sender, eventArgs); } } } } }
a9/10-30-17/Propeller/Propeller/Propeller.csproj
Debug AnyCPU {50DE1BA6-57FF-43FC-8F1A-7558D49CC060} WinExe Propeller Propeller v4.5.2 512 true AnyCPU true full false bin\Debug\ DEBUG;TRACE prompt 4 AnyCPU pdbonly true bin\Release\ TRACE prompt 4 Form Form1.cs Form1.cs ResXFileCodeGenerator Resources.Designer.cs Designer True Resources.resx SettingsSingleFileGenerator Settings.Designer.cs True Settings.settings True
a9/10-30-17/Propeller/Propeller/Properties/AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Propeller")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Propeller")] [assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("50de1ba6-57ff-43fc-8f1a-7558d49cc060")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
a9/10-30-17/Propeller/Propeller/Properties/Resources.Designer.cs
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace Propeller.Properties { /// <summary> /// A strongly-typed resource class, for looking up localized strings, etc. /// </summary> // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// <summary> /// Returns the cached ResourceManager instance used by this class. /// </summary> [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if ((resourceMan == null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Propeller.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// <summary> /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// </summary> [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } } }
a9/10-30-17/Propeller/Propeller/Properties/Resources.resx
text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
a9/10-30-17/Propeller/Propeller/Properties/Settings.Designer.cs
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace Propeller.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } } }
a9/10-30-17/Propeller/Propeller/Properties/Settings.settings
a9/Assignment 9.docx
CPSC 275
Fall 2017
Assignment 9: Piñata Game
Due: November 13 Late assignments not accepted
Overview
A few years ago, Google created a piñata game for its 15th anniversary. For this assignment, you will create a (somewhat less great) version of that game. You may work in groups of 2 for this assignment. You have an extended amount of time, but be sure to use it well—you will likely need the full time. (Google’s game is still available, if you’re feeling ambitious you can change yours to be more like Google’s—or awesome in other ways—as long as you meet the basic requirements: http://www.google.com/doodles/googles-15th-birthday)
The individual classes will be graded by hand, just to make sure they meet the requirements listed below. The rest of the program will be graded based on performance only, with both the professor and the other students grading the assignment. You must have the classes listed but you may adapt the fields and methods if you’d like—if you make changes, your grade will be based on how well organized and encapsulated they are. Most importantly, Form1 should know as little about the bat and piñata as possible.
Application Design
The game is played is played by swinging a bat at a moving piñata. The player’s goal is to hit the piñata as many times as possible without missing.
The piñata: the piñata should swing from the top of the program. Every time it is hit, the piñata should swing faster (and optionally higher as well). The piñata should respond to the hit—moving at the new speed in the direction the bat was moving. The piñata will not need to be realistic in a few ways: the piñata can keep swinging at the same speed indefinitely; also while a pendulum is faster at the bottom of its arc and slower at the top, your piñata can swing at the same speed from one end to the other.
The bat: the user swings the bat by pressing the space bar or enter key. The bat should swing forward (hopefully hitting the piñata), then swing back to the original spot. The user should not be able to swing again until the bat returns to the original spot. If the user hits the piñata, they gain an extra point (and the piñata behaves as described above). If the user misses the piñata, they lose the game. The bat should not be able to hit the piñata more than once per swing, and should only be able to hit the piñata on the initial swing, not the way back returning the bat to the start. The current points and high score should be shown at the bottom (high score can be just for that running of the program—doesn’t need to be remembered between programs.
Game play: when the user loses, the game should display a message (like a message box) and then reset, allowing the player to start again. The player should also be able to pause the game by pressing ‘p’ and then continue the game by pressing ‘p’ again.
Required Classes
You must define the following classes. Again, the fields and methods are just recommendations.
The Main Form:
· Has fields for a bat and a piñata
· Has a timer, which calls the pinata’s tick method and the bats tick method, then calls the Form’s refresh method so everything is redrawn
· loseGame, a method which displays a message to the user and resets the game
· The paint method should call the piñata and bat’s draw methods
Pinata Class:
· Fields:
· angle, the current angle of the piñata
· angle_change, the amount that the angle changes each step in the animation
· minAngle and maxAngle, the furthest the the piñata should go in each direction
· tick, a method which should advance the piñata in the animation. If the piñata reaches one end, this method should turn it around (reverse the angle_change)
· draw, a method which draws the piñata (should be passed a Graphics object)
· hit, a method that’s called if the bat contacts the piñata, and does the proper adjustments to the piñata (speeding it up, optionally making it swing higher)
· reset, resets the piñata to the original settings—it should be passed a Graphics object
Bat class:
· Fields:
· angle, and angle_change, similar to piñata
· phase, which uses an enumeration to track whether the bat is swinging forward, backwards, or is ready to swing
· tick, a method which should advance the piñata in the animation. If the piñata reaches the end of the swing, it should begin returning in the other direction. If the piñata returns to the start, it should stop.
· draw, a method that draws the piñata (should be passed a Graphics object)
· swing, which starts the player swinging if appropriate
· isCollision, which is passed a piñata object and returns true if the bat is contacting the piñata.
Grading
Your grade will be determined by three parts: my evaluation of the gameplay, other students’ evaluation of the gameplay, and my evaluation of whether the program follows the guidelines above (code is divided well between classes and there’s very little about the piñata and bat in Form1, for example).
Tips
· Start early on this project, it’s a lot of work, even with extra time and an extra person. “Budget” your time by making smaller goals—getting the piñata working, then getting the bat, then detecting collisions—then create time-frames for those goals. If your first project is to get the piñata moving, and it takes you a week, there won’t be time to finish the other parts of the project.
· Start with one piece of the project at a time—create the piñata class and get it drawn in its initial position first, then have it “tick” and move a little bit forward. Once you can repeat that, worry about having it go in both directions. But make sure you’re paying attention to the time for the project—make sure you’re making enough progress with these small goals. You can do the bat first, instead, if that seems more natural.
· First, we’re going to only care if the bat is contacting the ball at a particular tick. In theory, if the bat and ball move a large amount on a tick, the could “jump” the ball during the tick—at first be to it’s right, and end up all the way over to its left in the next tick. We’ll want to make sure the piñata and bat don’t move huge amounts at each tick to avoid that (even if they move small amounts it can still happen right at the end of the bat, but it normally won’t be too obvious if it does).
· That means, after each tick’s code has moved the piñata and bat, we’ll want to call a method to figure out if the bat is hitting the piñata at that moment. It turns out finding out whether a line segment and circle intersect is mathematically challenging (a good solution using linear algebra is here: http://stackoverflow.com/questions/1073336/circle-line-segment-collision-detection-algorithm but that’s more complicated than we’ll probably want.
· We’re going to simplify a little to avoid the math above. Start by figuring out if the point at the end of the bat is in the circle. It’s actually easy to figure out if a point is in a circle—just find the distance between the point and the center of the circle ( ); if that distance is less than the radius, then the point is in the circle—otherwise it’s not.
· We want to add a little more because the bat may hit the piñata, but not the tip of that bat, so we’ll see if a few other points on that bat might hit the piñata. It’s easy to find some other points by combining the points at the base (the end of the bat that doesn’t move—let’s call that point 1) and the tip (the end that does move—let’s call that point 2). To get a point that is 90% of the way to the tip, use 90% of point 2 and 10% of point 1: x would be .9*x2 + .1 * x1 and you can calculate the y value using a similar formula. You can use that to find a few points on the bat that might hit the piñata, then calculating the distance with those points as well—if any of the points is contacting the piñata, then there’s a hit.