Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Graphic Programming Advanced Computer Programming.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Advertisements

Midterm 26 March 2015 (4:30-5:30 pm) – Rm5620 Closed book exam MC Questions only x25 Up to L(7) Methods Scope: video lectures (+Lab), forum discussions,
Practical Programming COMP153-08S Lecture: Repetition Continued.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
An array of controls Not particularly convenient in VB Examples: array of pictureboxes Array of textboxes Notes on Concentration game (a possible final.
Arrays. Declaring a Array With subscript: –Dim numbers(2) as Integer –Using variable as subscript: Dim arrayIndex as Integer = 10 Dim myArray(arrayIndex)
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Game Programming Advanced Computer Programming.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Lecture 8 Visual Basic (2).
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
VB.NET Additional Topics
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Game Programming Advanced Computer Programming.
Some graphics. Projects included A slideshow a dark moon moving phases of the moon billiards Your own icons and bitmaps Pie chart.
COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
1.NET Web Forms Graphics and Charts © 2002 by Jerry Post.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Two Forms Please use speaker notes for additional information!
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
Lab 10 Slides.
Practical Programming COMP153-08S Lecture: Repetition.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
IMS 3253: Forms, Controls, Properties, Events 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Program Elements Assignment.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
1 Dynamic Arrays ListBoxes, Dynamic Arrays, Dynamic Control Arrays ListBoxes are on pp and dynamic arrays are in Chapter 7 of Deitel, Deitel and.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Computer Science Up Down Controls, Decisions and Random Numbers.
1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.
Sub Procedures And Functions
Use TryParse to Validate User Input
Visual Basic Fundamental Concepts
Data Types, Arithmetic Operations
Use TryParse to Validate User Input
Computer Programming I
Introduction to VB programming
للمزيد زورونا على موقعنا الإلكتروني:
Visual Basic..
Advanced Computer Programming
Lesson Objectives Aims Key Words
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Graphic Programming Advanced Computer Programming Part - 2

13A-2 Lecture Objective After completing this Lecture: – Students will be able to understand how games are created in VB – Will be able to Identify Components used in Game Programming – Will use built-in routines to draw lines, ellipse, rectangles, and polygons – Will be able to create transparent items – Will be able to rotate items at any angle – Will be able to play sounds for all events

Crash Landing

Intro.PNG

BG.PNG

Ship.PNG

Flame.PNG

Pad.PNG

Crash.PNG

Green.PNG

Red.PNG

tmrMain Timer

Crash Landing picShip picFlame picFuel picCrash picBG picPad picSpeedpicAngle picPosition lblSpeed lblAngle lblPosition lblTime lblInfo lblMode

Coding Variables Dim Grav As Double Dim G As Double Dim Time As Integer Dim MaxTime As Integer Dim TimeLimited As Boolean Dim Crashed As Boolean Dim Landed As Boolean Dim SpeedOK As Boolean Dim AngleOK As Boolean = True Dim PositionOK As Boolean Dim AppPath As String = Mid(Application.StartupPath, 1, _ InStr(Application.StartupPath, "\bin")) Private FuelBitmap As Bitmap Private FuelGraph As Graphics Dim ShipX As Integer Dim ShipY As Integer Dim X As Integer = 0 Dim Y As Integer = 0 Dim XMin As Integer = -49 Dim YMin As Integer = 20 Dim XMax As Integer = Me.Width – 15 Dim YMax As Integer = Me.Height – 120 Dim PadX As Integer Dim PadY As Integer Dim Angle As Integer Dim Fuel As Double

Coding (Subroutines) Private Sub picBG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picBG.Click Me.lblInfo.Visible = False Me.picBG.ImageLocation = AppPath & "images\BG.png" PadX = 5 + Int(Rnd() * XMax - 45) PadY = Int(Rnd() * (YMax - 55)) If PadY > YMax Then PadY = YMax - 5 Me.picPad.Image = CType(Bitmap.FromFile(AppPath & "images\Pad.png"), Bitmap) Me.picPad.Parent = Me.picBG Me.picPad.BackColor = (Color.Transparent) Me.picPad.Left = PadX Me.picPad.Top = PadY Me.picPad.Visible = True ShipX = Int(Rnd() * XMax + 33) ShipY = YMin X = 0 Grav = 0 G = 0.25 Angle = 0 Crashed = False Landed = False Time = 0 MaxTime = (Abs(ShipX - PadX) + Abs(ShipY - PadY)) / 2 Fuel = FuelGraph.FillRectangle(Brushes.Green, 1, 1, 14, CInt(Fuel)) Me.picFuel.Image = FuelBitmap Me.picFuel.Left = XMax - 20 Me.picFuel.Visible = True Me.picShip.Visible = False Me.picCrash.Visible = False Me.picShip.Left = ShipX Me.picShip.Top = ShipY Me.picShip.Image = CType(Bitmap.FromFile(AppPath & "images\ship.png"), Bitmap) Me.picShip.Parent = Me.picBG Me.picShip.BackColor = (Color.Transparent) Me.picShip.Visible = True Me.tmrMain.Enabled = True Me.lblSpeed.Visible = True Me.picSpeed.Visible = True Me.lblAngle.Visible = True Me.picAngle.Visible = True Me.lblPosition.Visible = True Me.picPosition.Visible = True Me.lblMode.Visible = False End Sub

Coding (Subroutines) Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick If TimeLimited = True Then Time = Time + 1 lblTime.Text = MaxTime - Time If Time >= MaxTime And Crashed = False Then Crashed = True tmrMain.Enabled = False Me.lblInfo.Text = "Time Over!" Me.lblInfo.Visible = True Me.lblInfo.BringToFront() Me.picCrash.Left = 8 Me.picCrash.Top = 2 Me.picCrash.ImageLocation = AppPath & "images\Crash.png" Me.picCrash.Visible = True My.Computer.Audio.Play(AppPath & "sounds\Crash.wav") Me.tmrMain.Enabled = False Exit Sub End If 'If Fuel <= 0.0 Then ' Un-comment if Game ends on fuel empty ' Crashed = True ' tmrMain.Enabled = False ' Me.lblInfo.Text = "Out of Fule!" ' Me.lblInfo.Visible = True ' Me.lblInfo.BringToFront() ' Me.picCrash.Left = 8 ' Me.picCrash.Top = 2 ' Me.picCrash.ImageLocation = AppPath & "images\Crash.png" ' Me.picCrash.Visible = True ' My.Computer.Audio.Play(AppPath & "sounds\Crash.wav") 'End If FuelGraph.FillRectangle(Brushes.Black, 1, 1, 14, CInt(100 - Fuel)) Me.picFuel.Image = FuelBitmap Grav = Grav + G ShipY = ShipY + Grav ShipX = ShipX + X If Grav > 10 Then Grav = 10 If Grav < -10 Then Grav = -10 If ShipX > XMax Then ShipX = XMin If ShipX < XMin Then ShipX = XMax If ShipY < YMin Then ShipY = YMin Grav = 0 G = 0.25 End If Me.picShip.Left = ShipX Me.picShip.Top = ShipY If Grav < 5 Then Me.picSpeed.ImageLocation = AppPath & "images\Green.PNG" SpeedOK = True Else Me.picSpeed.ImageLocation = AppPath & "images\Red.PNG" SpeedOK = False End If If Angle > -10 And Angle < 10 Then Me.picAngle.ImageLocation = AppPath & "images\Green.PNG" AngleOK = True Else Me.picAngle.ImageLocation = AppPath & "images\Red.PNG" AngleOK = False End If If ShipX > PadX - 10 And ShipX < PadX + 10 Then Me.picPosition.ImageLocation = AppPath & "images\Green.PNG" PositionOK = True Else Me.picPosition.ImageLocation = AppPath & "images\Red.PNG" PositionOK = False End If Me.picFlame.Visible = False If SpeedOK = True And AngleOK = True And PositionOK = True And (ShipY > PadY - 60 And ShipY < PadY - 55) Then ShipY = PadY Crashed = False Landed = True Me.lblInfo.Text = "Perfect Landing!" Me.lblInfo.Visible = True Me.lblInfo.BringToFront() X = 0 Grav = 0 G = 0 Angle = 0 Me.tmrMain.Enabled = False Me.lblMode.Visible = True My.Computer.Audio.Play(AppPath & "sounds\Landing.wav") Else If ((ShipX > PadX - 55 And ShipX PadY - 60 And ShipY YMax Then Me.picCrash.Parent = Me.picShip Me.picCrash.BackColor = (Color.Transparent) Me.picCrash.Left = 8 Me.picCrash.Top = 2 Me.picCrash.ImageLocation = AppPath & "images\Crash.png" Me.picCrash.Visible = True Me.lblInfo.Text = "YOU CRASHED!" Me.lblInfo.Visible = True Me.lblInfo.BringToFront() X = 0 Grav = 0 G = 0 Crashed = True Landed = False Me.tmrMain.Enabled = False Me.lblMode.Visible = True My.Computer.Audio.Play(AppPath & "sounds\Crash.wav") End If End Sub

Coding (Subroutines) Private Sub frmCrash_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = 112 Then ' F1 Key is pressed to get help If Me.tmrMain.Enabled = True Then Me.tmrMain.Enabled = False MsgBox("Welcome to Crash Landing!" & Chr(13) & Chr(13) & "Your Aim is to safely Land your Rocket Ship on the Landing Pad." & Chr(13) & Chr(10) & "The Speed, Angle and Position indicators must be Green for Safe Landing." & Chr(13) & Chr(10) & "At the end of each game you can press T to toggle Time Limited Mode." & Chr(13) & Chr(13) & "Use these arrow keys to control the Ship:" & " Left Right" & Chr(13) & " v" & Chr(13) & " Thrust", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Crash Landing Help...") Me.tmrMain.Enabled = True Else MsgBox("Welcome to Crash Landing!" & Chr(13) & Chr(13) & "Your Aim is to safely Land your Rocket Ship on the Landing Pad." & Chr(13) & Chr(10) & "The Speed, Angle and Position indicators must be Green for Safe Landing." & Chr(13) & Chr(10) & "At the end of each game you can press T to toggle Time Limited Mode." & Chr(13) & Chr(13) & "Use these arrow keys to control the Ship:" & " Left Right" & Chr(13) & " v" & Chr(13) & " Thrust", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Crash Landing Help...") End If If (Landed = True Or Crashed = True) And e.KeyValue = 84 Then ' T key is pressed to Toggle Time Limited Mode TimeLimited = Not TimeLimited Me.lblTime.Visible = TimeLimited End If If Crashed = True Or Landed = True Then Exit Sub If Fuel > 0.0 Then If e.KeyValue = 40 Then ' Down Key is Pressed Grav = Grav - G * 2 Fuel = Fuel Me.picFlame.Left = ShipX (Angle / 4) Mod 10 Me.picFlame.Top = ShipY + 52 If Grav <> 0 Then Me.picFlame.Image = CType(Bitmap.FromFile(AppPath & "images\flame.png"), Bitmap) Me.picFlame.Parent = Me.picBG Me.picFlame.BackColor = (Color.Transparent) Me.picFlame.BringToFront() Me.picFlame.Visible = True My.Computer.Audio.Play(AppPath & "sounds\Fire.wav") End If If e.KeyValue = 37 Then ' Left Key is Pressed X = X - 1 Fuel = Fuel Angle = Angle + 5 End If If e.KeyValue = 39 Then ' Right Key is Pressed X = X + 1 Fuel = Fuel Angle = Angle - 5 End If Me.picShip.Image = CType(Bitmap.FromFile(AppPath & "images\ship.png"), Bitmap) RotateShip(Angle) End If End Sub

Coding (Subroutines) Private Sub frmCrash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.picBG.ImageLocation = AppPath & "images\Intro.png" My.Computer.Audio.Play(AppPath & "sounds\StartMusic.wav") FuelBitmap = New Bitmap(picFuel.Width, picFuel.Height) FuelGraph = Graphics.FromImage(FuelBitmap) Me.picFuel.Image = FuelBitmap Me.lblMode.Left = (Me.Width - Me.lblMode.Width - 10) / 2 End Sub

Coding (Subroutines) Private frmCrash_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize XMax = Me.Width - 15 If XMax < 40 Then XMax = 40 YMax = Me.Height If YMax < 40 Then YMax = 40 Me.picFuel.Left = XMax - 20 Me.lblInfo.Left = (Me.Width - Me.lblInfo.Width) / 2 Me.lblInfo.Top = (Me.Height - Me.lblInfo.Height) / 2.4 Me.lblMode.Left = (Me.Width - Me.lblMode.Width) / 2 Me.lblMode.Top = (Me.Height - 60) End Sub

Coding (Subroutines) Private Sub lblInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblInfo.Click picBG_Click(sender, e) End Sub Private Sub picShip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picShip.Click picBG_Click(sender, e) End Sub Private Sub picPad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPad.Click picBG_Click(sender, e) End Sub Private Sub picCrash_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCrash.Click picBG_Click(sender, e) End Sub

Coding (Subroutines) Private Sub RotateShip(ByVal RAngle As Single) ' Object Rotate Code courtesy of VB-Helper.com helper.com/howto_net_image_rotate.htmlhttp:// helper.com/howto_net_image_rotate.html ' Copy the output bitmap from the source image. Dim bm_in As New Bitmap(Me.picShip.Image) ' Make an array of points defining the ' image's corners. Dim wid As Single = bm_in.Width Dim hgt As Single = bm_in.Height Dim corners As Point() = { _ New Point(0, 0), _ New Point(wid, 0), _ New Point(0, hgt), _ New Point(wid, hgt)} ' Translate to center the bounding box at the origin. Dim cx As Single = wid / 2 Dim cy As Single = hgt / 2 Dim i As Long For i = 0 To 3 corners(i).X -= cx corners(i).Y -= cy Next i ' Rotate. Dim theta As Single = Single.Parse(Angle) * PI / Dim sin_theta As Single = Sin(theta) Dim cos_theta As Single = Cos(theta) Dim Xx As Single Dim Yy As Single For i = 0 To 3 Xx = corners(i).X Yy = corners(i).Y corners(i).X = Xx * cos_theta + Yy * sin_theta corners(i).Y = -Xx * sin_theta + Yy * cos_theta Next i ' Translate so Xx >= 0 and Yy >=0 for all corners. Dim xmin As Single = corners(0).X Dim ymin As Single = corners(0).Y For i = 1 To 3 If xmin > corners(i).X Then xmin = corners(i).X If ymin > corners(i).Y Then ymin = corners(i).Y Next i For i = 0 To 3 corners(i).X -= xmin corners(i).Y -= ymin Next i ' Create an output Bitmap and Graphics object. Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin)) Dim gr_out As Graphics = Graphics.FromImage(bm_out) ' Drop the last corner lest we confuse DrawImage, ' which expects an array of three corners. ReDim Preserve corners(2) ' Draw the result onto the output Bitmap. gr_out.DrawImage(bm_in, corners) ' Display the result. Me.picShip.Image = bm_out End Sub

Assignment 3 Create Your own Crash Landing Game – Create Software Requirement Document – Upload your code to the CMS system

Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education The End Questions?