Post by D-Type on Aug 24, 2018 17:50:44 GMT -5
Hi All,
I'm writing this little City Bomber program that automatically (using a loop) moves a plane left to right across the screen and when you press a button, it should drop a bomb.
How does the program know where to start the bomb from? I take this from the position of the plane at the time the button is pressed.
Because of screen scaling I'm using, my loop that moves the plane goes from $-3F to $40, because zero is in the middle of the screen.
If I want to do some other calculations on those positions, it's awkward, because it depends on which side of the screen you're on, there are only $80 x-axis positions. You can't use simple rotates or + or - $80 to get an absolute number, if you get my drift.
So here's the question: If *YOU* are moving things around the screen using a loop, do you make the loop from, say $0 to $7F and then everytime you write to the screen, you offset it to account for 0 being in the middle, or do you make your loop like mine i.e. $-3F to $40 and deal with any other problems due to the scaled screen being e.g. only $80 pixels wide?
Or maybe I'm missing something that I'll also need to consider if I'm not scaling the whole screen to $-3F to $40?
Hopefully this makes sense...I'm new to this scaling thing, it's a bit mind bending
Any other tips?
Here's a code snippet:
I'm writing this little City Bomber program that automatically (using a loop) moves a plane left to right across the screen and when you press a button, it should drop a bomb.
How does the program know where to start the bomb from? I take this from the position of the plane at the time the button is pressed.
Because of screen scaling I'm using, my loop that moves the plane goes from $-3F to $40, because zero is in the middle of the screen.
If I want to do some other calculations on those positions, it's awkward, because it depends on which side of the screen you're on, there are only $80 x-axis positions. You can't use simple rotates or + or - $80 to get an absolute number, if you get my drift.
So here's the question: If *YOU* are moving things around the screen using a loop, do you make the loop from, say $0 to $7F and then everytime you write to the screen, you offset it to account for 0 being in the middle, or do you make your loop like mine i.e. $-3F to $40 and deal with any other problems due to the scaled screen being e.g. only $80 pixels wide?
Or maybe I'm missing something that I'll also need to consider if I'm not scaling the whole screen to $-3F to $40?
Hopefully this makes sense...I'm new to this scaling thing, it's a bit mind bending
Any other tips?
Here's a code snippet:
40 -3F \ end start -- ; These are the x-axis loop parameters
DO \ Start the x-axis loop
CR ." Stack:" .S ." Timer:" D009 C@ U. \ Send stack contents & 50Hz frame timer top byte to serial port
_Wait_Recal
_Intensity_5F
-3F -3F _Moveto_d \ x y -- ; Move to the bottom left of the screen
7F 20 CITY _Draw_VL_ab \ scale #vectors addr -- ; Draw the city from RAM
\
_Recalibrate
I J _Moveto_d _Dot_here \ I = x-axis loop index, J = y-axis loop index (not shown)
20 4 PLANE _Draw_VL_ab \ scale #vectors addr -- ; Draw the plane
\
BOMBY C@ C0 = \ -- f ; Is there a bomb on screen?
IF
_Read_Btns 0 <> \ -- f ; has a button been pressed?
IF
J BOMBY C! I BOMBX C! \ Store initial coordinates of bomb
THEN
ELSE \ Bomb is on screen
_Recalibrate
BOMBX C@ BOMBY C@ _Moveto_d _Dot_here \ Move beam to current bomb position and display a dot
BOMBY C@ 1- BOMBY C! \ Update bomb position
\
\ \ Debug code below, where the offsets start getting messy!
BOMBY C@ ." BY:" U. \ Dump bomb Y position to serial port
BOMBX C@ ." BX:" U. \ Dump bomb X position to serial port
BOMBX C@
8 / ." Block:" DUP U. \ Each city block is 8 pixels wide, to serial port
4 * ." Offset:" DUP U. \ Each city block consists of 2 XY positions = 4 characters
CITY + ." City Array Address:" U. \ Index into the city tower height array
.
.
THEN
.
.
LOOP