An Introduction to Game Programming with Flash: Object Oriented Programming

433 views
289 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
433
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

An Introduction to Game Programming with Flash: Object Oriented Programming

  1. 1. An Introducton to Game Programming with Flash 2. Object Oriented Programming
  2. 2. What is O-O? Researching problem from a perspectve of: ● Objects ● Dependencies ● Relatons What can be O-O? ● Analysis ● Design ● Programming
  3. 3. Why O-O? Easier: ● Analysis ● Design ● Programming and maintenance Why is it so important?
  4. 4. package foo { public class Person { private var name:String; public function Person(name:String) { this.name = name; } public function introduce():String { return "My name is " + name; } } } 1 2 3 4 5 Class
  5. 5. import foo.Person; var person:Person = new Person("John Smith"); person.introduce(); //My name is John Smith 1 2 Object
  6. 6. package foo { public class Rapper extends Person { public function Rapper(name:String) { super(name); } } } import foo.Rapper; var snoopDog:Rapper = new Rapper("Snoop Dogg"); snoopDog.introduce(); //My name is Snoop Dogg 1 2 3 Inheritance
  7. 7. package foo { public class Rapper extends Person { public function Rapper(name:String) { super(name); } override public function introduce():String { return "YO! " + super.introduce(); } } } import foo.Rapper; var snoopDog:Rapper = new Rapper("Snoop Dogg"); snoopDog.introduce(); //YO! My name is Snoop Dogg 2 3 Polymorphism 1
  8. 8. Enakpsulaton Hiding implementaton and exposing only desired API Access modifiers: ● public – for everyone ● protected – only for the same class or subclasses ● internal – only for the same package ● private – only the same class
  9. 9. Interface package foo { public interface IPerson { function introduce():String; } } 1 2
  10. 10. Statc fields and methods package foo { public class Math { public static const PI:Number = 3.14; public static function abs(value:Number):Number { return (value >= 0) ? value : -value; } } } Math.PI; //3.14 Math.abs(-5); //5 1 2 3
  11. 11. Good practces ● Single Responsibility Principle ● Open/Closed Principle ● Liskov Substtuton Principle ● Interface Segregaton Principle ● Dependency Inversion Principle ● ... ● Don't Repeat Yourself ● Law of Demeter ● ... ● COMMON SENCE!
  12. 12. Jet&Giant
  13. 13. git clone git://github.com/krzysztof-o/epi- wdpg.git Jet&Giant
  14. 14. Task 1 Moving a Giant: ● Giant can move horizontally and vertcally ● smoothing
  15. 15. Task 2 Enemies: ● Two classes should inherit from Enemy ● Enemy_1 moves quickly, along straight line ● Enemy_1 need single hit to be destroyed ● Enemy_2 moves slowly, along sine wave ● Enemy_2 needs double hit to be destroyed enemy_1 enemy_2
  16. 16. Task 3 Giant – Enemy collision: ● Collision causes showing boom animaton ● Collision takes one Giant's life
  17. 17. Task 4 Shootng enemies: ● Enemies can shoot with random frequency ● Hitting Giant with bullet takes one life

×