Wuhan Gang - Virus Competition Entry

Started by STEVIE G, February 26, 2021, 19:06:54

Previous topic - Next topic

Steve Elliott

I much prefer modern jump dynamics where you have a short window to change direction or double jump.  Rather than old classics like Manic Miner where you got your jump wrong and can only sit and watch as the jump animation runs it's course so you hit something you wanted to avoid.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

STEVIE G

So just checked what int() was giving me for fractions incrementing at .5.  FFS!!  Why round up at 51.5 and down at 52.5, wheres the consistency? Is this normal?

Anywho, that explains the jerky animation. Floor seems to do the job int can't!

50.5 = 50
51.0 = 51
51.5 = 52 !
52.0 = 52
52.5 = 52 !
53.0 = 53
53.5 = 54

Cheers Steve, I'm looking to have air control around half ground acceleration, so retain launch velocity but can be modified sightly.

Steve Elliott

Quote
Why round up at 51.5 and down at 52.5, wheres the consistency? Is this normal?...Floor seems to do the job int can't!

That's ridiculous, IMO .5 and up and you should *always* round up.  So you're rounding down with floor then, at least it's now consistant.  You should have a command/toggle for rounding up or down.

Quote
Cheers Steve, I'm looking to have air control around half ground acceleration, so retain launch velocity but can be modified sightly.

Cool.  Yes, reward the skillful player with the option to adjust mid-flight.


Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Derron

Quote from: STEVIE G on March 06, 2021, 17:50:26
So just checked what int() was giving me for fractions incrementing at .5.  FFS!!  Why round up at 51.5 and down at 52.5, wheres the consistency? Is this normal?

Anywho, that explains the jerky animation. Floor seems to do the job int can't!

50.5 = 50
51.0 = 51
51.5 = 52 !
52.0 = 52
52.5 = 52 !
53.0 = 53
53.5 = 54

This is because "50.5" is not stored as "50.5" but as something which computer 1 prints as "50.5000003" and the other one as "50.4999997".

So when you do "mynumber :+ 0.5" it might result in "50.4999997 + 0.5" = "50.9999997". Then casting it to int just removes the fraction stuff -> 50.


Nonetheless it does not explain how "int(51.5)" can result in 52.

bye
Ron

STEVIE G

Thought good old 'Ron would explain this one, thank you. Float precision is gash!

blinkok

floor(number+0.5)
That is if floor works

Derron

#21
Quote from: blinkok on March 06, 2021, 21:06:17
floor(number+0.5)
That is if floor works

if you do the "+0.5" you should be able to just int(thisnumberthen) instead of running through floor()

4.99+0.5 = 5.49 ... int(5.49) = 5
4.51+0.5 = 5.01 ... int(4.51) = 4
4.01+0.5 = 4.51 ... int(4.51) = 4

but if you somehow store 4.5 (so 4.499997 or 4.500003) stuff can fail (4.99997 = 4, 5.00003 = 5)


Had this issue (again) some few weeks ago - all my computers "rounded down" (mine were always x.99999997) but a single computer of a user had an issue ((x+1).000003) ... exactly such a one. Invested some days to move from "double/float" to "long/int" for time stuff. Was hard to narrow down  -as even other users were not able to replicate the issue. The issue was, that for this particular user the game started on "day 2" not "day 1" and he never reported it before :)



bye
Ron

blinkok

Quoteif you do the "+0.5" you should be able to just int(thisnumberthen) instead of running through floor()
In that case, wouldn't int() have exactly the same functionality as floor()?

iWasAdam

Stevie, I completely agree with you and have had exactly the same issues with floats not being precise. Here's how I eventually decided to deal with it:

first decide on your precision: 10 positions per unit or 100 positions. You could have 8 or 23 too.

int precision = 10
int positionX = 0
float fX

now you can use positionX with ints, add subtract with ints, the result will always be what you thought it would be, collision etc

when  you need the float version just:
fX = float(positionX) / precision

fX will always be an approximate value




Derron

Quote from: blinkok on March 07, 2021, 01:19:16
Quoteif you do the "+0.5" you should be able to just int(thisnumberthen) instead of running through floor()
In that case, wouldn't int() have exactly the same functionality as floor()?

what do you think is faster?

Another thing to note (which is important!)
int() -> truncates towards 0
floor() -> truncates towards -inf

example:
int(3.5) = 3
floor(3.5) = 3

int(-1.5) = -1
floor(-1.5) = -2


Also noteworthy: Floor() returns :double
So you cast to integer at the end too.
If your numbers are positive, I would prefer "int" as it should be (did not test that) faster.


I use the int(x+0.5) trick for "mathematical" rounding ">x.5 and <(x+1).5" results in "(x+1)".



Regarding Adams trick/hint:
There were types/classes handling stuff like this. "BigNumbers" or similar stuff. In blitzmax ng you could use "overloading" to overload operators (so "precisionNumber + precisionNumber" would not need the extra division)

The issue you get with Adam's approach is when it comes to root, potencing ...
10^2 = 100
100^2 = 10000

You need to handle the precision potencing too. Think same to say for sinus, cosinus ... and all this stuff. So you might end up with a Struct (speaking about NG) which handles all the math stuff in methods. and then overload the operators to "ease the pain".


But if you only use it with addition/subtraction etc - then KISS like Adam suggested.

Ahh before I forget: using the precision-trick means you limit the integer range! Each precision "step" takes away one digit on the "left side". So maybe at the end you need to use "long" so your numbers still "fit".

bye
Ron

STEVIE G

Quote from: iWasAdam on March 07, 2021, 07:38:13
Stevie, I completely agree with you and have had exactly the same issues with floats not being precise. Here's how I eventually decided to deal with it:

first decide on your precision: 10 positions per unit or 100 positions. You could have 8 or 23 too.

int precision = 10
int positionX = 0
float fX

now you can use positionX with ints, add subtract with ints, the result will always be what you thought it would be, collision etc

when  you need the float version just:
fX = float(positionX) / precision

fX will always be an approximate value

Yeah, was thinking this might be the best way to go. Cheers.   I'll persevere for a bit as close to nailing it.

STEVIE G

#26
Today I made the decision to have no traditional menus. What you say, how does that work? Well ....

The entire menu, level select, character select and options are they're own level (the team HQ) so you do everything with your character.

Go down to the options terminals to change stuff and see the results on the teams lounge tv.
If you have the keycard (unlockable after level 1) you can go into the team changing room next to the pool to swap your character.
Start any stage (unlocked as you progress) at any time or redo z previous one for more stars. I left space for more.
The red door is where the boss is going to be.

Really pleased with how this works. Screenshot below.

http://www.steviegoodwin.plus.com/images/Untitled/WG16.png

Derron

The options look all the same to me :-)


Yeah - sometimes these "playable settings" are nice - yet it might be good to have shortcuts to beam the player to the areas ... "o...ptions". Depends on how many things you are placing in there. Aside of that: good idea.


bye
Ron

STEVIE G

Quote from: Derron on March 07, 2021, 22:57:10
The options look all the same to me :-)


Yeah - sometimes these "playable settings" are nice - yet it might be good to have shortcuts to beam the player to the areas ... "o...ptions". Depends on how many things you are placing in there. Aside of that: good idea.


bye
Ron

The option you're standing beside shows on the monitor, it then changes if you interact with it. You'll probably only need to use options once. Stuff like sound and screen res. If I get time ill have different  consoles graphics. I might also add key bindings in a similar way.

STEVIE G

Menu / HQ now finished and can now get on with the rest of the game.  ;D

Updated icons for options which are gfx res, gfx mode, 3 x sound volumes and no of players. Had fun with the later as when you change to 2 players another appears on the shelf upper right. If you then change to 1 player he explodes. Rince and repeat for a blood fest.  :))

Joy pad support is also in, you need 2 for coop. Have not added key / button config into menu (maybe if time allows) but you can at least edit these in the options file.

HQ now has a proper boss office with red leather furnishing, a picture of the 4 team members and a trophy which you can nab if you get into the room. Also a couple of leather benches by the options tv. Was going to add a Pool Table but this is enough for now. Shot below of me changing from 2 to 1 player.

http://www.steviegoodwin.plus.com/images/Untitled/WG17.png