MIC 212 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

MIC 212

Description:

Display a static or rendered background. Check for input and update the ... Usually ASCII with Roman alphabet and numerals, plus accents and a few symbols. ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 26
Provided by: gilbert85
Category:
Tags: mic | accents

less

Transcript and Presenter's Notes

Title: MIC 212


1
MIC 212
  • Introduction to Games Programming in Visual Basic
    6
  • Semester 2
  • 2004

2
Lecture 2
  • Games programming
  • Visual Basic Programming

3
Games Programming
  • Example game program outline
  • Display title screen
  • Load sprites and sound
  • Display a static or rendered background
  • Check for input and update the players position
  • Process enemy positions using AI
  • Move each sprite to the new location
  • Check for collisions between the sprites
  • Increment the animation frame for each sprite
  • Loop back to step 4 until game over
  • Delete all game objects and free memory
  • End game

4
Key games programming steps
  • Initialisation of all media
  • Graphics, sounds, animation, text
  • Main event loop
  • Responding to user input
  • Moving the game on
  • Moving sprites (objects that clean up after
    themselves)
  • Animating sprites moving through frame cycle
  • Game logic checking for collisions, computing
    next action for all objects, calculating scores,
    levels, configuration phases, game over?
  • Game end
  • Highest score, bonus etc.

5
Games programming in Visual Basic
  • Initialisation of objects
  • properties
  • Main event loop programming
  • Responding to user input
  • Setting properties
  • call back methods, e.g., Timer1_Timer()
  • Game logic
  • Call back methods, subs
  • File and database management

6
Step when creating a VB 6 program
  • Create the Interface using forms editor
  • Set initial values for control properties
  • Write code for event handlers (call backs)

7
Changing properties
  • Controls (and other objects) have properties
    which have (constant) values
  • To change during design
  • Type the required value in the properties window
  • To change during the program (run-time)
  • Write code to set the value for a property

8
Changing colours palette
9
Writing Event Handlers
  • A.k.a procedures, subs, methods
  • Add/select a control.
  • Double click on the control to open the Code
    window.
  • Click on the Procedure box (upper right drop
    down) to find the event
  • Write the code for that event.

10
Example
  • Event handler for click event for Button
  • VB puts standard code in automatically
  • You complete the missing statements
  • Private Sub cmdButton_Click( )
  • txtBox.ForeColor vbRed
  • txtBox.Font.Size 24
  • txtBox.Text Hello
  • End Sub

11
Coding standards
  • Inline comments
  • set the background colour to red when the form
    loads
  • How does this work in a program?
  • --------------------------------------------------
    -
  • Option explicit
  • Private sub Form_load()
  • set the background colour to red when the form
    loads
  • Form1.backcolorvbred
  • End sub

12
Components of VB 6 Statements
  • Variables and Constants
  • Keywords (reserved words)
  • Operators and functions (including properties)
  • txtBox.ForeColor vbRed

Property (selection function)
Constant
Assignment Operator
Variable
13
Variables
  • A storage location in main memory whose value can
    change during program execution.
  • These storage locations can be referred to by
    their names (restrictions first letter, , .
    etc.)
  • Every variable has a Name, a Value, and a Type
    (and a Scope covered next week)
  • Example types Numeric and String
  • Dim Amount As Integer
  • Option Explicit forces declaration of variables -
    (General) (Declarations)
  • Numeric types byte, boolean, integer, long,
    single, double, currency, decimal, date

14
Keywords
  • Words that have predefined meaning to Visual
    Basic.
  • Can not be used as variable names.
  • Examples Print
  • Cls
  • If
  • While

15
Numeric Variables
  • Used to store numbers.
  • The value is assigned either by the programmer or
    by calculation
  • ApplesSold 10 ' The value 10 is assigned to the
    variable.
  • ApplesSold ApplesSold 1 ' The variable is
    incremented.

16
Constant
  • Similar to a variable, but can NOT change during
    the execution of a program
  • Can be declared (named, preferred)
  • Const Modulus As Single 4.17825 ' Value cant
    change
  • Or used directly (literal)
  • tax 0.02 (income - 500 dependence)
  • Types of Constants
  • numeric constants
  • string constants
  • Many pre-defined, see Visual Basic Constants in
    Index of Help

17
String Constants
  • A sequence of alphanumeric data
  • Contents depend on character set
  • Usually ASCII with Roman alphabet and numerals,
    plus accents and a few symbols.

18
Arithmetic Operations Hierarchy of Operations
  • Operator operation Basic
    expression
  • Exponentiation A
    B
  • Multiplication A
    B
  • / Division
    A / B
  • Addition
    A B
  • - Subtraction
    A B
  • Hierarchy what gets done when if there are no
    brackets ab cd e
  • and also work for strings!

19
Built in methods
  • Print is a method used to display data on the
    screen or printer.
  • Can be used to print value of variables.
  • Can be used to print value of arithmetic
    expressions.

20
Example of Print Statements
  • Private Sub cmdCompute_Click()
  • picResults.Print 3 - 2
  • picResults.Print 3 2
  • picResults.Print 3 / 2
  • picResults.Print 3 2
  • picResults.Print 2 (3 4)
  • End Sub

21
Example of Print Statement
  • picOutput.Print speed
  • picOutput.Print taxRate
  • picOutput.Print Class average is total / 3

22
Example
  • Dim x, y as integer
  • x 15
  • y 5
  • picOutput.Print (x y) / 2, x / y

23
Complex statements
  • Conditionals
  • If then else end if
  • Select Case x
  • Case 5 Console.WriteLine("x 5")
  • Case 10 Console.WriteLine("x 10")
  • Case 20 Console.WriteLine("x 20")
  • Case 30 Console.WriteLine("x 30")
  • End Select
  • Loops

24
Your first game a simple timed single player
activity-based game
  • Aim to follow instructions to reveal 5 words,
    place them in a sentence and type in the answer
    to a simple question
  • Player selects an answer and types in the textbox
  • Message is displayed in response to
    correct/incorrect answer
  • Player can retry

25
Design
  • Objects timer, labels (5 used to display text
    strings), textbox, 2 command buttons
  • Events
  • Timer starts as soon as game is started so player
    is timed on ability to assimilate instructions as
    well as complete the task
  • Player clicks on the 5 squares to reveal the
    words
  • Player clicks on button to submit answer
Write a Comment
User Comments (0)
About PowerShow.com