Jump to content
IGNORED

Floats in Constants?


Cybearg

Recommended Posts

Currently, this doesn't work:

 

const START_VELOCITY = 0.5

_velocity = START_VELOCITY

[code]

 

Is there a way to make floating numbers work with constants or perhaps to "fake it" by just setting the decimal-place variable to a constant?

 

The problem with the latter is that it doesn't seem to be clear-cut as to what real number is interpreted as what in decimal places. For instance, .3 looks like $4C or 76 in decimal, so I can't say I see the connection.

Link to comment
Share on other sites

I apologize in advance for not directly answering your question.

 

Stop noodling around with that weird fixed point variables stuff. Start using whole integers and bitwise operations.

 

If you need something to move at half speed just keep a counter variable that increments every main loop:

 

main

counter = counter + 1

 

then take the first bit and use to as a trigger to move the enemy:

 

if counter{0} then goto move_enemy

 

That ends up being .5 velocity if you move the enemy by a single pixel per movement.

Link to comment
Share on other sites

Did you use "dim _velocity = <var>.<var>"?

 

 

 

 

Stop noodling around with that weird fixed point variables stuff. Start using whole integers and bitwise operations.

 

Good luck with that if you are trying to do Breakout-style games or pinball games.

Link to comment
Share on other sites

Can't say I really know how it works
but it seems that if the variable who's
value you're assigning is not 8.8
you get the integer part of the 8.8 variable

dim var = a.b

c = var

is the same as

c = a



The fractional part is in 256ths

so .3 * 256 = 76.8 and bB truncates to 76


For named constants you can use def
but def is kind of flakey

def pi = 3.14

var = pi

var = var + pi

Link to comment
Share on other sites

I didn't really get it figured out, but I worked around it when I realized how the decimal place was handled. I was expecting it to be a 0-100 decimal place kind of thing, but it's fractions of 256, so 0.5 is 00 on var 1 and 128 on var 2. Pretty obvious, in hindsight.

 

Loon, up to now, I've used counters to time things. For instance:

 

 

 if !(counter & 3) then player1x = player1x + 1

 

It's worked alright, but I wanted to be able to incrementally increase the velocity, which that movement-skipping method can't do so easily, even if the results are essentially the same.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...