Commit e7083f64 authored by Claes's avatar Claes

Misc minor changes

parent 6546dcec
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <float.h>
#include "pwr.h" #include "pwr.h"
#include "pwr_baseclasses.h" #include "pwr_baseclasses.h"
#include "pwr_miscellaneousclasses.h" #include "pwr_miscellaneousclasses.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "co_time.h" #include "co_time.h"
#define BASE_SPEED 10 #define BASE_SPEED 10
#define MAX_ANGLE 60
static float my_random() { static float my_random() {
static unsigned int seed = 100; static unsigned int seed = 100;
...@@ -66,7 +68,7 @@ void Misc_PingPongFo_init( pwr_sClass_Misc_PingPongFo *o) ...@@ -66,7 +68,7 @@ void Misc_PingPongFo_init( pwr_sClass_Misc_PingPongFo *o)
void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
{ {
pwr_sClass_Misc_PingPong *co = (pwr_sClass_Misc_PingPong *) o->PlcConnectP; pwr_sClass_Misc_PingPong *co = (pwr_sClass_Misc_PingPong *) o->PlcConnectP;
if ( !co) if ( !co || fabs(co->Width < FLT_EPSILON))
return; return;
co->XCoordinate += co->Speed * tp->PlcThread->ScanTime * cos(co->Direction/180*M_PI); co->XCoordinate += co->Speed * tp->PlcThread->ScanTime * cos(co->Direction/180*M_PI);
...@@ -81,7 +83,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -81,7 +83,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
co->RightPos = *co->RightKnobPtr; co->RightPos = *co->RightKnobPtr;
else else
co->RightPos = co->RightSlider; co->RightPos = co->RightSlider;
switch ( co->Mode) { switch ( co->Mode) {
case pwr_eMisc_PingPongModeEnum_Idle: { case pwr_eMisc_PingPongModeEnum_Idle: {
if ( co->OldMode != co->Mode) { if ( co->OldMode != co->Mode) {
...@@ -100,7 +102,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -100,7 +102,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
co->Direction = -co->Direction + 180 + my_random() * 10; co->Direction = -co->Direction + 180 + my_random() * 10;
else else
co->Direction = -co->Direction - 180 + my_random() * 10; co->Direction = -co->Direction - 180 + my_random() * 10;
if ( fabs(co->Direction) > 45) if ( fabs(co->Direction) > MAX_ANGLE)
co->Direction = my_random() * 10; co->Direction = my_random() * 10;
} }
...@@ -151,7 +153,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -151,7 +153,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
co->Direction = -co->Direction + 180 + my_random() * 20; co->Direction = -co->Direction + 180 + my_random() * 20;
else else
co->Direction = -co->Direction - 180 + my_random() * 20; co->Direction = -co->Direction - 180 + my_random() * 20;
if ( fabs(co->Direction) > 45) if ( fabs(co->Direction) > MAX_ANGLE)
co->Direction = my_random() * 10; co->Direction = my_random() * 10;
co->Speed = BASE_SPEED * co->LeftLevel * co->LevelFactor; co->Speed = BASE_SPEED * co->LeftLevel * co->LevelFactor;
} }
...@@ -212,7 +214,8 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -212,7 +214,8 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
break; break;
} }
case pwr_eMisc_PingPongModeEnum_TwoPlayers: { case pwr_eMisc_PingPongModeEnum_TwoPlayers: {
if ( co->OldMode != co->Mode) { if ( co->OldMode != co->Mode || co->NewMatch) {
co->NewMatch = 0;
co->State = pwr_eMisc_PingPongStateEnum_ServeRight; co->State = pwr_eMisc_PingPongStateEnum_ServeRight;
time_GetTime( &co->StateShiftTime); time_GetTime( &co->StateShiftTime);
co->LeftScore = 0; co->LeftScore = 0;
...@@ -239,7 +242,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -239,7 +242,7 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
co->Direction = -co->Direction + 180 + my_random() * 20; co->Direction = -co->Direction + 180 + my_random() * 20;
else else
co->Direction = -co->Direction - 180 + my_random() * 20; co->Direction = -co->Direction - 180 + my_random() * 20;
if ( fabs(co->Direction) > 45) if ( fabs(co->Direction) > MAX_ANGLE)
co->Direction = my_random() * 10; co->Direction = my_random() * 10;
co->Speed = BASE_SPEED * co->LeftLevel * co->LevelFactor; co->Speed = BASE_SPEED * co->LeftLevel * co->LevelFactor;
} }
...@@ -323,5 +326,21 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -323,5 +326,21 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
break; break;
} }
} }
float height;
if ( fabs(co->Direction) < 90) {
if ( co->XCoordinate < co->Width * 3/4)
height = (1 - co->XCoordinate / co->Width * 4 / 3);
else
height = ((co->XCoordinate - co->Width * 3/4) / co->Width * 4);
}
else {
if ( co->XCoordinate < co->Width / 4)
height = (1 - co->XCoordinate / co->Width * 4);
else
height = ((co->XCoordinate - co->Width / 4) / co->Width * 4/3);
}
co->XShadow = co->XCoordinate + height * 4;
co->YShadow = co->YCoordinate + height * 1;
co->OldMode = co->Mode; co->OldMode = co->Mode;
} }
...@@ -1150,7 +1150,7 @@ pwr_exe: ...@@ -1150,7 +1150,7 @@ pwr_exe:
1204 0 1204 0
99 99
13 13
1302 1 1302 0
1303 3 1303 3
1304 0 1304 0
1305 0 1305 0
......
This diff is collapsed.
...@@ -121,7 +121,7 @@ Volume Miscellaneous $ClassVolume 0.0.0.9 ...@@ -121,7 +121,7 @@ Volume Miscellaneous $ClassVolume 0.0.0.9
Object RtBody $ObjBodyDef 1 08-APR-2011 08:56:23.47 Object RtBody $ObjBodyDef 1 08-APR-2011 08:56:23.47
Body SysBody 08-APR-2011 08:56:23.47 Body SysBody 08-APR-2011 08:56:23.47
Attr StructName = "Misc_PingPong" Attr StructName = "Misc_PingPong"
Attr NextAix = "_X33" Attr NextAix = "_X36"
EndBody EndBody
!/** !/**
! Mode idle, one player or two players. ! Mode idle, one player or two players.
...@@ -287,6 +287,20 @@ Volume Miscellaneous $ClassVolume 0.0.0.9 ...@@ -287,6 +287,20 @@ Volume Miscellaneous $ClassVolume 0.0.0.9
Attr TypeRef = "pwrs:Type-$Float32" Attr TypeRef = "pwrs:Type-$Float32"
EndBody EndBody
EndObject EndObject
Object XShadow $Attribute 34 25-MAY-2011 19:08:53.70
Body SysBody 25-MAY-2011 19:08:55.25
Attr PgmName = "XShadow"
Attr Flags = 1024
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
Object YShadow $Attribute 33 25-MAY-2011 19:09:01.74
Body SysBody 25-MAY-2011 19:09:02.90
Attr PgmName = "YShadow"
Attr Flags = 1024
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/** !/**
! Racket width. ! Racket width.
!*/ !*/
...@@ -349,7 +363,6 @@ Volume Miscellaneous $ClassVolume 0.0.0.9 ...@@ -349,7 +363,6 @@ Volume Miscellaneous $ClassVolume 0.0.0.9
Object LeftPos $Attribute 31 25-MAY-2011 10:51:24.12 Object LeftPos $Attribute 31 25-MAY-2011 10:51:24.12
Body SysBody 25-MAY-2011 10:51:26.62 Body SysBody 25-MAY-2011 10:51:26.62
Attr PgmName = "LeftPos" Attr PgmName = "LeftPos"
Attr Flags = 16777216
Attr TypeRef = "pwrs:Type-$Float32" Attr TypeRef = "pwrs:Type-$Float32"
EndBody EndBody
EndObject EndObject
...@@ -359,7 +372,6 @@ Volume Miscellaneous $ClassVolume 0.0.0.9 ...@@ -359,7 +372,6 @@ Volume Miscellaneous $ClassVolume 0.0.0.9
Object RightPos $Attribute 32 25-MAY-2011 10:51:37.69 Object RightPos $Attribute 32 25-MAY-2011 10:51:37.69
Body SysBody 25-MAY-2011 10:51:39.58 Body SysBody 25-MAY-2011 10:51:39.58
Attr PgmName = "RightPos" Attr PgmName = "RightPos"
Attr Flags = 16777216
Attr TypeRef = "pwrs:Type-$Float32" Attr TypeRef = "pwrs:Type-$Float32"
EndBody EndBody
EndObject EndObject
...@@ -401,6 +413,13 @@ Volume Miscellaneous $ClassVolume 0.0.0.9 ...@@ -401,6 +413,13 @@ Volume Miscellaneous $ClassVolume 0.0.0.9
Attr TypeRef = "pwrs:Type-$Float32" Attr TypeRef = "pwrs:Type-$Float32"
EndBody EndBody
EndObject EndObject
Object NewMatch $Attribute 35 26-MAY-2011 16:36:33.79
Body SysBody 26-MAY-2011 16:36:24.24
Attr PgmName = "NewMatch"
Attr Flags = 16778240
Attr TypeRef = "pwrs:Type-$Boolean"
EndBody
EndObject
Object OldMode $Attribute 22 08-APR-2011 15:09:14.47 Object OldMode $Attribute 22 08-APR-2011 15:09:14.47
Body SysBody 08-APR-2011 15:09:16.01 Body SysBody 08-APR-2011 15:09:16.01
Attr PgmName = "OldMode" Attr PgmName = "OldMode"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment