IS660Z Programming Games Using Visual Basic Overview of Cannonball.

Slides:



Advertisements
Similar presentations
Introduction to 2-Dimensional Motion
Advertisements

Introduction to 2-Dimensional Motion
Section 3-5: Projectile Motion
Visual Basic: ballistics
Agenda 1) Warm-Up 5 min 2) Vocab. Words 10 min 3) Projectile Motion Intro. 15 min 4) Pre-Lab Vectors 15 min 5) Vector Lab 30 min Spring scale.
Chapter 4: Kinematics in 2D  Motion in a plane, vertical or horizontal  But, the motion in the x- and y-directions are independent, except that they.
Projectile Motion Neglecting air resistance, what happens when you throw a ball up from the back of a moving truck? Front? Behind? In?
Page 24 #10 If the stone had been kicked harder, the time it took to fall would be unchanged.
Projectile Motion. 2 components of all projectile motion: Horizontal component (vx) is constant. Vertical component (vy) is affected by gravity.
Motion in Two Dimensions
Projectile Motion Type I Type II. Projectile Motion Any object that has been given an initial thrust, then moves only under the force of gravity. The.
3-3 Projectile Motion Two Dimensional Motion of Objects  Projectile Motion – If air resistance is disregarded, projectiles follow parabolic trajectories.
Motion in 2-Dimensions. Projectile Motion A projectile is given an initial force and is then (assuming no air resistance) is only acted on by gravity.
Introduction to 2-Dimensional Motion. 2-Dimensional Motion Definition: motion that occurs with both x and y components. Each dimension of the motion can.
Introduction to TouchDevelop
AIM: How can we describe the path of an object fired horizontally from a height above the ground? DO NOW: A ball rolls off a table top with an initial.
Projectile Motion Neglecting air resistance, what happens when you throw a ball up from the back of a moving truck? Front? Behind? In? GBS Physics Demo.
Kinematics in 2-Dimensional Motions. 2-Dimensional Motion Definition: motion that occurs with both x and y components. Example: Playing pool. Throwing.
Projectiles.
Projectile Motion Horizontally Launched Projectiles Projectiles Launched at an Angle A.S – Due Friday, 11/14 Text Reference: chapter 3.
Projectile Motion Projectile Fired Horizontally. A cannonball shot from a cannon, a stone thrown into then air, a ball rolling off the edge of table,
Projectile motion.
Projectile Motion Previously, we studied motion in one direction (linear motion) Projectiles follow a curved path (nonlinear motion) The velocity of a.
Agenda 1) Warm-Up 5 min 2) Turn-in Blue “Vector” Folder! 3) Vocab. Words 10 min 4) Finish Projectile Motion fill-in- blank Notes. 10 min 5) New Formulas.
Copyright Sautter Motion in Two Dimension - Projectiles Projectile motion involves object that move up or down and right or left simultaneously.
Ch 3 – Two-Dimensional Motion and Vectors. Scalars vs. Vectors ► Scalar – a measurement that has a magnitude (value or number) only  Ex: # of students,
PHYS 20 LESSONS Unit 2: 2-D Kinematics Projectiles Lesson 5: 2-D Projectiles.
Projectile Motion The motion of an object that is thrown and moves along a curved path through the influence of gravity, only.
Two-Dimensional Motion and Vectors CP: 6.1 A gun with a muzzle velocity of 1000 ft/sec is shot horizontally. At the same time an identical bullet is.
B2.2.  Projectiles follow curved (parabolic) paths know as trajectories  These paths are the result of two, independent motions  Horizontally, the.
[My] Experiences building games in Visual Basic & Flash Focus on 'cannonball' Jeanine Meyer Math Senior Seminar.
Projectile Motion The motion of an object that is thrown and moves along a curved path through the influence of gravity, only.
Projectiles at an Angle Hardest thing yet.. A progression: A)Freefall Review: A ball drops for 3 s. How far does it fall? How fast is it going after 3.
Agenda 1) Warm-Up 5 min 2) Vocab. Words 10 min 3) Projectile Motion fill-in- blank Notes. 15 min 4) New Formulas 5 min 5) Example Problems 15 min 6) Blue.
Two Dimensional Motion Two components: Horizontal (x-axis) & Vertical (y-axis)
Programming games using Visual Basic Detecting a position on top/within a rectangle, near a point, past a line Mouse events.
CHAPTER 6 SECTION 1 Projectile Motion. Objects launched either horizontally or at an angle are considered to be projectiles. All motion can be analyzed.
(a) 1, (b) 3 Fig. 4-6, shows the direction of acceleration for a particle located at its tail, and its length (representing the acceleration.
To start Which hits the ground first? What assumptions are you making?
Projectile Motion Chapter 5.4 – 5.6 Notes. Projectile Motion A projectile is any object that moves through the air or space, acted on only by gravity.
Dropped object Lab Displacement vs Time for accelerated motion.
Unit 3: Projectile Motion
Physics Support Materials Higher Mechanics and Properties of Matter
(Constant acceleration)
Motion in Two Dimensions EQ: What is a projectile?
Physics Section 3.3 Properties of Projectile Motion
Final vertical velocity?
Projectile Motion Physics Honors.
Unit 3: Projectile Motion
Projectile Motion.
Projectile motion.
Projectile Motion.
Projectile Motion.
Projectile Motion.
Introduction to 2-Dimensional Motion
Warm-Up 09/13/10 Please express the Graphic Vector Addition Sums in MAGNITUDE-ANGLE format (last two pages of PhyzJob packet)
Agenda (10/15) Pick-up guided notes (on front table)
The height of the building
Projectile motion Projectile Motion Subject to Gravity Assumptions:
Bellringer What is the difference between the words vertical and horizontal? What does the word projectile mean? How is one dimensional (1D), two dimensional.
Projectile Motion.
Projectiles.
Motion in Two Dimensions EQ: What is a projectile?
What do you think a “launch” looks like?
Projectile Motion.
Introduction to 2-Dimensional Motion
Projectile Motion.
Projectile Motion Physics Honors.
Vector addition allows us to consider movement in 2-D
Presentation transcript:

IS660Z Programming Games Using Visual Basic Overview of Cannonball

Computer graphics coordinate system Using a timer Ballistics Drag and drop Cannonball

Coordinates and Positioning Visual Basic controls are positioned through Top and Left properties Width and Height properties determine the size

Coordinates for lines Lines are positioned in terms of x1, y1, x2, y2 values X1,Y1 is one point X2,Y2 is the second point But notice Y2 is less than Y1?

Coordinate system Computer systems are backwards on Y axis The Left/X values increase moving to the right The Top/Y values increase moving DOWN the screen Therefore when you use code to move things you need to know this!

Timer control Has very few properties Interval must be non- zero for timer to work Enabled = true turns on the timer, enabled = false turns it off Can use multiple timers

Managing timers Timer appears in design view, but not when the game is running Interval is in milliseconds -- If a timer named timFalling has Enabled set to True and Interval set to 500 then timFalling_Timer will happen every ½ second

Ballistics Try out Cannonball if you haven’t already Notice the ball takes an arc like path This is natural motion of object subject to gravity The calculation of the motion of an object subject to gravity is call ballistics

Simulation has two parts Ball is moving both horizontally (across) and vertically (up and down) Our simulation uses two formulas to the ball in both directions and take gravity into account Horizontal motion continues with no acceleration (no change) Vertical motion is changed by gravity “Physics” & computer graphics requires: when cannonball is shot out of cannon at an angle, your code must resolve the initial velocity vector into horizontal and vertical components (see p. 86) Velocity is defined as speed and direction

Timer event and ballistics Timer event carries out the animation At each occurrence of the timer event, a new position for the ball is calculated and the cannonball’s positional properties are updated These calculations apply formulas from ballistics

Animating the cannonball Step 1: resolving the vectors, i.e. determining initial horizontal and vertical speed (based on angle of cannon and speed from scrollbar) Step 2: repositioning the cannonball over time

What Events? Step 1: FIRE! Click event Step 2: Timer event

Resolving the vectors Angle vx = v * Cos (Theta) vy = v * Sin (Theta) Where v is velocity coming out of cannon, theta is the angle, vx is horizontal velocity, vy is vertical velocity. Angle (traditional name is theta)

Formulas to calculate motion Constant velocity (horizontal) Distance traveled = velocity * time New_position = velocity*time + old_position Acceleration (vertical) let g=acceleration New_velocity = g * time + old_velocity Average velocity =.5 * g*time+old_velocity New_position =.5*g*time*time+old_velocity*time+old_position

Horizontal and vertical velocities (VB code) X2,Y2 is endpoint of cannon, TT is elapsed time xx, yy is new (recalculated) position Horizontal velocity (vx) is constant: xx = vx * TT + X2 Vertical velocity (vy) changes (decelerates): yy =.5 * g *(TT * TT) - vy * TT + Y2

Overview of cannonball FIRE ! Command button calculates initial horizontal and vertical velocity from scroll bar and the angle of the line representing the cannon Timer event will increment variable for time and apply the equations of motion to the cannonball (a shape control object) Timer event also does calculation to determine if cannonball has hit the ground or hit the target

3 Stage implementation Staged implementation is highly recommended for all but the smallest of projects. 1. Cannonball moves through the air. No checks to stop it! Stop execution by clicking on stop button on toolbar. 2. Check for hitting ground or hitting target. 3. Implement event handlers for changing speed, moving tip of cannon & target.

Drag and drop (Stage 3) player is able to change the angle of the cannon player is able to move the target Three mouse events are used to do this

Three Mouse Events Drag and drop looks like one event, but it is actually implemented across three Form events MouseDown – signals beginning of drag MouseMove – signals re- positioning of object MouseUp – signals drag and drop is over

Drag and drop logic MouseDown - if mouse arrow is cannon tip or target, drag and drop begins (Boolean is set to True) MouseMove - as long as Boolean is True cannon/target is repositioned MouseUp - drag and drop ends (Boolean is False)

Drag and drop Booleans blnCannonMove set to True in MouseDown if mouse arrow is over cannon tip set to False in MouseUp blnTargetMove set to True in MouseDown if mouse arrow is over cannon tip set to False in MouseUp Both are globals

Is mouse arrow over cannon? MouseDown event has x,y parameters containing mouse arrow location closetocannon function (p. 105) returns True if mouse arrow is “near” cannon Test is if x,y is within 100 twips of end of cannon (it would take great dexterity to hit it EXACTLY. Why?)

Is mouse arrow over target? Is X between Left and Left + Width? Is Y between Top and Top - Height? If both are True, mouse arrow is over target. See p. 92

Moving the cannon Cannon is repositioned in MouseMove (if blnCannonMove is True) Endpoint of cannon (X2,Y2) is changed to X,Y (mouse arrow location) see p. 93

Moving the target In MouseDown offset (distance) from mouse arrow to Top, Left is stored in sngDragx, sngDragy Target is repositioned in MouseMove (if blnTargetMove is True) Left is changed to X - sngDragx Top is changed to Y - sngDragy see p. 94

Why do we need sngDragx, sngDragy? Top, Left is here Mouse arrow (X,Y) is here Target would move here without sngDragx, sngDragy Wrong: Left = X Top = Y Right: Left = X - sngDragx Top = Y - sngDragy

Review Computer coordinate system Using timers Simulating flight using ballistics Drag and drop