Mini-curso JavaFX Aula3 UFPB

3,755 views
3,750 views

Published on

Slides da 3ª aula do mini-curso de JavaFX que ministrei na UFPB

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,755
On SlideShare
0
From Embeds
0
Number of Embeds
2,011
Actions
Shares
0
Downloads
152
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mini-curso JavaFX Aula3 UFPB

  1. 1. Raphael Marques Mestrando em Informática da UFPB jose.raphael.marques@gmail.com raphaelmarques.wordpress.com
  2. 2. 2
  3. 3. var video = Media{ source: "http://..." }; var player = MediaPlayer{ media: video autoPlay: true }; var view = MediaView{ mediaPlayer: player }; 3
  4. 4. 4
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. 8
  9. 9. 9
  10. 10. 10
  11. 11. 11
  12. 12. 12
  13. 13. 13
  14. 14. 14
  15. 15. 15
  16. 16. 16
  17. 17.  Site:  http://sites.google.com/site/joseraphaelmarques/  Link lateral: RaceFX  Sessão: Parte 1  Link na página: src completo  Descompactar no pacote racefx 17
  18. 18.  Site:  http://sites.google.com/site/joseraphaelmarques/  Link lateral: RaceFX  Sessão: Parte 2  Link na página: src baixar  Descompactar no pacote racefx 18
  19. 19. 19
  20. 20. public class Track{ public-init var down: Image; public-init var top: Image; public-init var layout: Image; var layoutView = ImageView{image: layout}; public-read var downView = ImageView{image: down}; public-read var topView = ImageView{image: top}; public function isTrack(x: Number, y: Number):Boolean{ return layoutView.contains(x,y); } } 20
  21. 21. 21
  22. 22. public-init var track: Track; function updateMove(factor: Number):Void{ var vx = Math.cos(angle) * vel * factor; var vy = -Math.sin(angle) * vel * factor; var i = x + vx; var j = y + vy; if(not track.isTrack(i, j)){ vel = 0; }else{ x = i; y = j; } } 22
  23. 23. 23
  24. 24. def track = Track{ down: Image { url: "{__DIR__}track1down.png" } top: Image { url: "{__DIR__}track1top.png" } layout: Image { url: "{__DIR__}track1layout.png" } } 24
  25. 25. 25
  26. 26. var checkpoint1 = Polygon{ points: [219,1,247,1,247,137,219,137] }; var checkpoint2 = ... var checkpoint3 = ... var checkpoint4 = ... var checkpointcar1 = checkpoint2; var checkpointcar2 = checkpoint2; 26
  27. 27. 27
  28. 28. var laps1 = 0; var laps2 = 0; var laps1Text = Text {...} var laps2Text = Text {...} 28
  29. 29. function checkLaps(){ if(checkpointcar1.contains(car1.x, car1.y)){ if(checkpointcar1 == checkpoint1){ laps1++; checkpointcar1 = checkpoint2; }else ... } if(checkpointcar2.contains(car2.x, car2.y)){ ... } } 29
  30. 30. public override function create():Node{ Group{ content: [ track.downView, car1, car2, track.topView, laps1Text, laps2Text, ] } } 30
  31. 31. 31
  32. 32.  Site:  http://sites.google.com/site/joseraphaelmarques/  Link lateral: RaceFX  Sessão: Parte 3  Link na página: src baixar  Descompactar no pacote racefx  Baixe o src completo da parte 2 se necessário. 32
  33. 33. 33
  34. 34. Server Client Internet 34
  35. 35. Server Client Internet 35
  36. 36. Server Client Internet 36
  37. 37. Server Client Internet 37
  38. 38.  Client  Server  SenderCar  float x;  float y;  float angle;  ReceiverListener  public void receive(SenderCar car);  MySocket  public void send(SenderCar car); 38
  39. 39. 39
  40. 40. public var socket: MySocket; public function update(time: Long):Void{ ... if(vel != 0){ updateMove(factor); socket.send(new SenderCar(x,y,angle)); } } 40
  41. 41. override function receive(car: SenderCar):Void{ //evitar deadlock FX.deferAction( function ():Void{ this.x = car.x; this.y = car.y; this.angle = car.angle; } ); } 41
  42. 42. 42
  43. 43. 43
  44. 44. 44
  45. 45. 45
  46. 46. Button { text: "PLAY LOCAL“ … action: function() { close(); game.play(); } } 46
  47. 47. function close():Void{ var timeline = Timeline { keyFrames : [ KeyFrame { time: 1s values : translateX => -640 tween Interpolator.LINEAR } ] }; timeline.play(); } 47
  48. 48. 48
  49. 49. public var rede = false; public var server = false; function update():Void{ ... if(not rede){ car2.update(time); } ... } 49
  50. 50. public function reset():Void{ ... if(rede and not server){//client car1.y = 90; car2.y = 50; }else{//server ou local car1.y = 50; car2.y = 90; } … } 50
  51. 51. function checkKey(code:KeyCode,value:Boolean){ if(code == KeyCode.VK_LEFT){ ... } else ... } else if(not rede){ if(code == KeyCode.VK_A){ ... } else ... } } 51
  52. 52. 52
  53. 53. var game = Game{ rede: false server: false }; 53
  54. 54. 54
  55. 55. Raphael Marques Mestrando em Informática da UFPB jose.raphael.marques@gmail.com raphaelmarques.wordpress.com

×