summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormottelet <stephane.mottelet@utc.fr>2020-07-03 10:57:24 +0200
committerCédric DELAMARRE <cdl@esi-group.com>2020-08-07 16:06:53 +0200
commiteda5a8ef5a2b37d17f36a2a75105d72253235a6d (patch)
treeee557f903a7fbb5b083e07826e51ad3f3cd61886
parent8a5f74923d586e91997c9c4a944707b00deee847 (diff)
downloadscilab-6.1.zip
scilab-6.1.tar.gz
[graphics] ensure cross-platform 120fps in pong demo6.1
Change-Id: I163b90c4ffb97b1dc3ff9c9212c1e860fa1231cc
-rw-r--r--scilab/modules/graphics/demos/anim/pong/pong.sce21
1 files changed, 15 insertions, 6 deletions
diff --git a/scilab/modules/graphics/demos/anim/pong/pong.sce b/scilab/modules/graphics/demos/anim/pong/pong.sce
index 94a72ec..1669b23 100644
--- a/scilab/modules/graphics/demos/anim/pong/pong.sce
+++ b/scilab/modules/graphics/demos/anim/pong/pong.sce
@@ -1,5 +1,5 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2019 - Stéphane Mottelet 2// Copyright (C) 2020 Stéphane Mottelet
3// 3//
4// This file is hereby licensed under the terms of the GNU GPL v2.0, 4// This file is hereby licensed under the terms of the GNU GPL v2.0,
5// For more information, see the COPYING file which you should have received 5// For more information, see the COPYING file which you should have received
@@ -30,7 +30,7 @@ function pong()
30 //ball 30 //ball
31 xrect(0.5, 0.5, wph, wph) 31 xrect(0.5, 0.5, wph, wph)
32 hb = gce() 32 hb = gce()
33 VMAX = 1e-3; 33 VMAX = 5e-3;
34 vb = [VMAX VMAX]; 34 vb = [VMAX VMAX];
35 35
36 k=2; 36 k=2;
@@ -38,13 +38,18 @@ function pong()
38 38
39 messagebox(msprintf("Click OK to release ball %d",3-k),"","","OK","modal") 39 messagebox(msprintf("Click OK to release ball %d",3-k),"","","OK","modal")
40 40
41 dt = 1/120;
42 realtimeinit(dt);
43 realtime(0);
44 kt=0;
45 tic();
41 while %t 46 while %t
42 M = MouseInfo.getPointerInfo(); 47 M = MouseInfo.getPointerInfo();
43 X=double(M.getLocation().x)-gcf().figure_position(1); 48 X=double(M.getLocation().x)-gcf().figure_position(1);
44 49
45 MOUSE_X = xchange(X,0,"i2f") 50 MOUSE_X = xchange(X,0,"i2f")
46 if is_handle_valid(f) 51 if is_handle_valid(f)
47 paddle_x = hp.data(1) + 1e-1*(MOUSE_X-wpx/2-hp.data(1)); 52 paddle_x = hp.data(1) + 30*dt*(MOUSE_X-wpx/2-hp.data(1));
48 paddle_x = min(max(0,paddle_x),1-wpx); 53 paddle_x = min(max(0,paddle_x),1-wpx);
49 ball = hb.data(1:2) + vb; 54 ball = hb.data(1:2) + vb;
50 else 55 else
@@ -66,9 +71,12 @@ function pong()
66 break 71 break
67 end 72 end
68 hb.data(1:2) = [.5,.5]; 73 hb.data(1:2) = [.5,.5];
69 VMAX=1e-3; 74 VMAX=5e-3;
70 vb=[VMAX VMAX]; 75 vb=[VMAX VMAX];
71 messagebox(msprintf("Click OK to release ball %d",3-k),"","","OK","modal") 76 messagebox(msprintf("Click OK to release ball %d",3-k),"","","OK","modal")
77 realtimeinit(dt);
78 realtime(0);
79 kt=0;
72 elseif ball(1) + wph > paddle_x && ball(1) < paddle_x+wpx 80 elseif ball(1) + wph > paddle_x && ball(1) < paddle_x+wpx
73 d = (ball(1)+wph/2) - (paddle_x+wpx/2); 81 d = (ball(1)+wph/2) - (paddle_x+wpx/2);
74 vb= VMAX*[max(-1,min(1,d/(wpx/2-wph/2))),1]; 82 vb= VMAX*[max(-1,min(1,d/(wpx/2-wph/2))),1];
@@ -76,9 +84,10 @@ function pong()
76 end 84 end
77 if is_handle_valid(f) 85 if is_handle_valid(f)
78 hp.data(1) = paddle_x; 86 hp.data(1) = paddle_x;
79 hb.data(1:2) = hb.data(1:2) + vb; 87 hb.data(1:2) = hb.data(1:2) + 100*dt*vb;
80 end 88 end
81 sleep(1) 89 kt=kt+1;
90 realtime(kt)
82 end 91 end
83 messagebox("GAME OVER !","","","OK","modal") 92 messagebox("GAME OVER !","","","OK","modal")
84end 93end