• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Mixing variable types in a numerical calculation patters Member Posts: 61 Threads: 17 Joined: Dec 2020 Reputation: 4 01-05-2021, 06:25 PM (This post was last modified: 01-05-2021, 06:51 PM by patters.) castleIntactAttr is the sum of the attributes for all four character positions occupied by the castle. It will be checked every increment of the cannon shot trajectories. If it changes, then the shot has hit the castle. However, depending on how fast the trajectory maths ends up once compiled, I may be able to use PLOTs instead of multiple DRAWs. If this is the case I can simply check the PLOT coordinates are not within box occupied by the castle characters and abandon this ATTR method. Since castleIntactAttr is the sum of four 8bit numbers it does go higher than 255, which is where I ran into the problem. The PEEK (n+4), PEEK (n+5) etc. are colour and brightness values from a lookup table of DEFB entries, since the castle sprites need different colours and brightness values depending on the landscape colours. The castle hasn't been drawn at this point so the ATTR function isn't useful here. I invoke this as part of a sub to update the castle graphics when the landscape or time of day changes, and so this is a good place to recalculate the castleIntactAttr after the graphics have changed. To understand this a bit better: castleIntactAttr=(64*CAST(UINTEGER, PEEK (n+4))+8*skyCol+PEEK (n+5)+64*PEEK (n+6)+8*skyCol+PEEK (n+7))*2         UINTEGER=(UBYTE*UINTEGER)+(UBYTE*UBYTE)+UBYTE+(UBYTE*UBYTE)+(UBYTE*UBYTE)+UBYTE                                    always<255           [font=Monaco, Consolas, Courier, monospace]always<255    [font=Monaco, Consolas, Courier, monospace]always<255       (they are attribute bits)[/font][/font] [font=Monaco, Consolas, Courier, monospace][font=Monaco, Consolas, Courier, monospace]So[/font][/font]         UINTEGER=    UINTEGER    +  UBYTE      +UBYTE+    UBYTE    +   UBYTE     +UBYTE At this last point will the compiler be intelligent enough to add all of these UBYTES to the UINTEGER left to right and hence not overflow? « Next Oldest | Next Newest »

 Messages In This Thread Mixing variable types in a numerical calculation - by patters - 01-05-2021, 12:50 AM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 12:13 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 01:15 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 01:22 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 01:42 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 01:51 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 03:31 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 04:06 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 04:44 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-05-2021, 05:58 PM RE: Mixing variable types in a numerical calculation - by patters - 01-05-2021, 06:25 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:36 AM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:55 AM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 02:59 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 05:14 PM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 06:00 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 06:19 PM RE: Mixing variable types in a numerical calculation - by patters - 01-06-2021, 06:51 PM RE: Mixing variable types in a numerical calculation - by boriel - 01-06-2021, 08:10 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)