need some advice...

Post Reply
Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

need some advice...

Post by Joel »

Hi everybody.
Was playing around with sprites and sounds... and when running the program, I can see some ghost-pictures for a fraction of a second. the boat upside-down to be precise

Anybody an idea how to prevent it??

Thanks in advance, Joel

Code: Select all

/*
COLORS used in code
'y': comments
'' :main progamm
'g':find rapidly the line
'b':sub-programms
'c':functions
'r':watch it!!special lines that might cause some trouble 
'm':DATA
''
*/
'{{/Bibliothek/coord_trans}}
'{{/Bibliothek/maths}}
'{{/Bibliothek/utilities}}

OPTION ANGLE RADIANS
OPTION BASE 1
OPTION SPRITE POS CENTRAL
SET TOOLBAR OFF
GET ORIENTATION p
SET ORIENTATION p

DEBUG=0

'colours of waves
blue2$="0,0,1"
blue1$="0.181,0.177,.8"
col$(1)="0.864,0,0" 'hull
col$(2)="0.521,0.369,0.147" 'mast
col$(3)=".8,.8,.8" 'sail

'set cst-coordinates
xmax=5
xmin=-xmax
ymax=xmax*SCREEN_HEIGHT()/SCREEN_WIDTH()
ymin=xmin*SCREEN_HEIGHT()/SCREEN_WIDTH()

pi=3.1416


'r'
'file
filename$="seagulls.wav"
'geometry of wave
num_waves=3 ' number of waves on screen 
sin_r=.2 'magnitude of wave

'sprite: position and movement
y_peak_wave=-2 'upper pos of wave (magnitude_position) when displayed as sprite 
additional_squarelength=3 'number of units lower square ends below bottom of screen 
wave_move_mag=1.5 'magnitude of how waves roll back and forth max:2.5

'boat params
boat_pitch_mag=pi/24
boat_y_mag=.2
y_mid_boat=-2.8 'middle position of sprite (boat)
x_endpos_boat=-7 'x-posistion where boat makes turn(both ends)
x_pos_boat=7 'initial position of boat
delta_x_boat=-.001 'speed of boat
''
GOSUB load_sound

y_peak_pos_wave=y_peak_wave+additional_squarelength
h_square=y_peak_pos_wave-2*sin_r-ymin
y_correction=additional_squarelength

'creating sprites
create_wave_sprite("wave_blue1",blue1$)
create_boat_sprite("boat",col$)
create_wave_sprite("wave_blue2",blue2$)

'results from function
sprite_wave_h=create_wave_sprite.sprite_wave_h

SPRITE "wave_blue1" AT tc_x(0), tc_y(sprite_wave_h/2+ymin-y_correction)
SPRITE "wave_blue1" SHOW

SPRITE "wave_blue2" AT tc_x(0+sprite_cst_w/2), tc_y(sprite_wave_h/2+ymin-y_correction)
SPRITE "wave_blue2" SHOW

SPRITE "boat" AT tc_x(0)+1000,tc_y(y_mid_boat)
SPRITE "boat" SHOW

IF DEBUG THEN
 draw_sys ! draw_ticks(1,1)
ENDIF

GRAPHICS ! GRAPHICS CLEAR 0.781,0.948,1 '0.372,0.695,1
flipboat=0 ! pitch_sense=1
LOOP:
FOR phi=0 TO 2*pi STEP 0.001
 tau=-(ATAN2(ACCEL_Y(),ACCEL_X())-ATAN2(1,0))
 dlt_x=wave_move_mag*SIN(phi) ! dlt_rho=boat_pitch_mag*SIN(phi) ! dlt_y=boat_y_mag*SIN(phi)
 SPRITE "wave_blue1" AT tcr_x(dlt_x,sprite_wave_h/2+ymin-y_correction,tau), tcr_y(dlt_x,sprite_wave_h/2+ymin-y_correction,tau) ANGLE -tau
 SPRITE "wave_blue2" AT tcr_x(-dlt_x,sprite_wave_h/2+ymin-y_correction,tau), tcr_y(-dlt_x,sprite_wave_h/2+ymin-y_correction,tau) ANGLE -tau
 x_pos_boat+=delta_x_boat
 
 IF ABS(x_pos_boat)>ABS(x_endpos_boat) THEN
  delta_x_boat*=-1
  x_endpos_boat*=-1
  flipboat=1-flipboat
  pitch_sense*=-1
 ENDIF
   
 SPRITE "boat" AT tcr_x(x_pos_boat,dlt_y+y_mid_boat,tau),tcr_y(x_pos_boat,dlt_y+y_mid_boat,tau) ANGLE -tau*pitch_sense+dlt_rho FLIP flipboat
 IF TOUCH_X(0)>0 THEN END
NEXT phi
GOTO LOOP
END 'of main


'c'
DEF create_boat_sprite(sprite_name$,col$())
 sprite_height=5
 sprite_width=3
 
 'arrange coordinates
 xmin_old=.xmin ! ymin_old=.ymin ! xmax_old=.xmax ! ymax_old=.ymax 
 .xmin=0 ! .xmax=2*xmax_old
 .ymax=sprite_height ! .ymin=.ymax-(ymax_old-ymin_old)
 xmin=.xmin ! xmax=.xmax ! ymin=.ymin ! ymax=.ymax
 
 SPRITE sprite_name$ BEGIN tc_x(sprite_width), tc_y(0) '0:is the point for sprite height - counts from angle
  IF .DEBUG THEN 
   GRAPHICS ! GRAPHICS CLEAR 1,1,1
  ENDIF
  FOR element=1 TO 3
   FILL COLOR insepstr$(1,col$(element),","),insepstr$(2,col$(element),","),insepstr$(3,col$(element),",")
   counter=0
   DO
    counter+=1
    READ data_x,data_y
    x(counter)=tc_x(data_x/2) ! y(counter)=tc_y(data_y/2)
   UNTIL data_x=999 'stop sign
   FILL POLY x,y COUNT counter-1
  NEXT element
 SPRITE END
 
 'restore coordinate_params
 .xmin=xmin_old ! .xmax=xmax_old ! .ymin=ymin_old ! .ymax=ymax_old 
 DATA 0,7,6,7,3,4,999,999,3,7,3,10,3.2,10,3.2,7,999,999,3.2,8,5,8,3.2,10,999,999 'wanne, mast,segel
END DEF ' of create_boat_sprite
'==============================
DEF create_wave_sprite(sprite_name$,col$) 
 'save old coordinate_params
 xmin_old=.xmin ! ymin_old=.ymin ! xmax_old=.xmax ! ymax_old=.ymax 
 
 'copy geometry of wave
 sin_r=.sin_r
 num_waves=.num_waves
 h_square=.h_square
 
 'adapting user-screen for sprite-creation
 .xmin=0 ! .xmax=2*xmax_old
 .ymax=h_square+2*sin_r ! .ymin=.ymax-(ymax_old-ymin_old)
 xmin=.xmin ! xmax=.xmax ! ymin=.ymin ! ymax=.ymax
 
 sprite_wave_w=(xmax_old-xmin_old)/num_waves*(num_waves+2) ! sprite_wave_h=h_square+2*sin_r
 
 'sprite-creation
 debug_tc_x=tc_x(sprite_wave_w) ! debug_tc_y= tc_y(sprite_wave_h) ! debug_0=tc_y(0)
 DRAW COLOR insepstr$(1,col$,","),insepstr$(2,col$,","),insepstr$(3,col$,",")
 
 SPRITE sprite_name$ BEGIN tc_x(sprite_wave_w), tc_y(0) '0:is the point for sprite height - counts from angle
 
  IF .DEBUG THEN 
   GRAPHICS ! GRAPHICS CLEAR 1,1,1
  ENDIF
  
  FOR k=0 TO num_waves+2 STEP (num_waves)/SCREEN_WIDTH() '1/(sprite_wave_w/get_unit_x) 'unit_x shouldn't have changed with change of .xmin...
   DRAW LINE tc_x(k*sprite_wave_w/(num_waves+2)), tc_y(sin_r*SIN(2*.pi*k)+sin_r+h_square) TO tc_x(k*sprite_wave_w/(num_waves+2)),tc_y(0)
  NEXT k
  GRAPHICS MODE CLEAR
  FOR k=0 TO num_waves+2 STEP (num_waves)/SCREEN_WIDTH() '1/(sprite_wave_w/get_unit_x) 'unit_x shouldn't have changed with change of .xmin...
   DRAW LINE tc_x(k*sprite_wave_w/(num_waves+2)), tc_y(sin_r*SIN(2*.pi*k)+sin_r+h_square) TO tc_x(k*sprite_wave_w/(num_waves+2)),0 '=tc_y(.ymax)
  NEXT k
  
  GRAPHICS MODE NORMAL
 SPRITE END
 
 'restore coordinate_params
 .xmin=xmin_old ! .xmax=xmax_old ! .ymin=ymin_old ! .ymax=ymax_old 
END DEF 'of create_wave_sprite
'==============================LIBS==============================
DEF draw_sys()
 IF .ymin=0 AND .ymax=0 THEN 
  .ymin=.xmin*SCREEN_HEIGHT()/SCREEN_WIDTH() ! .ymax=.xmax*SCREEN_HEIGHT()/SCREEN_WIDTH()
 ENDIF
 IF .xmin=0 AND .xmax=0 THEN 
  .xmin=.ymin*SCREEN_WIDTH()/SCREEN_HEIGHT() ! .xmax=.ymax*SCREEN_WIDTH()/SCREEN_HEIGHT()
 ENDIF
 DRAW LINE tc_x(.xmin),tc_y(0) TO  tc_x(.xmax),tc_y(0)
 DRAW LINE tc_x(0),tc_y(.ymin) TO tc_x(0),tc_y(.ymax)
END DEF 
'================= 
DEF draw_ticks(tick_x,tick_y)
 IF .ymin=0 AND .ymax=0 THEN 
  .ymin=.xmin*SCREEN_HEIGHT()/SCREEN_WIDTH() ! .ymax=.xmax*SCREEN_HEIGHT()/SCREEN_WIDTH()
 ENDIF
 IF .xmin=0 AND .xmax=0 THEN 
  .xmin=.ymin*SCREEN_WIDTH()/SCREEN_HEIGHT() ! .xmax=.ymax*SCREEN_WIDTH()/SCREEN_HEIGHT()
 ENDIF 
 FOR n=tick_x TO .xmax STEP tick_x
  DRAW LINE tc_x(n),tc_y(0)-5 TO tc_x(n), tc_y(0)+5
 NEXT n
 
 FOR n= -tick_x TO .xmin STEP -tick_x
  DRAW LINE tc_x(n),tc_y(0)-5 TO tc_x(n), tc_y(0)+5 
 NEXT n
 
 
 FOR n=tick_y TO .yMAX STEP tick_y 
  DRAW LINE tc_x(0)-5,tc_y(n) TO tc_x(0)+5, tc_y(n)
 NEXT n
 
 FOR n=-tick_y TO .ymin STEP -tick_y
  DRAW LINE tc_x(0)-5,tc_y(n) TO tc_x(0)+5, tc_y(n)
 NEXT n
END DEF
'=================
DEF tcr_x(x,y,tau)
 RETURN tc_x(rot_x(x,y,tau))
END DEF
'=================
DEF tcr_y(x,y,tau)
 RETURN tc_y(rot_y(x,y,tau))
END DEF
'=================
DEF rot_x(x,y,tau)
 phi=ATAN2(y,x)
 r=SQR(x*x+y*y)
 RETURN r*COS(phi+tau)
END DEF
'=================
DEF rot_y(x,y,tau)
 phi=ATAN2(y,x)
 r=SQR(x*x+y*y)
 RETURN r*SIN(phi+tau)
END DEF
'=================
DEF tc_x(x)
 'calculate min& max values when those are left to zero respecting screen-ratio 
 IF .ymin=0 AND .ymax=0 THEN 
  .ymin=.xmin*SCREEN_HEIGHT()/SCREEN_WIDTH() ! .ymax=.xmax*SCREEN_HEIGHT()/SCREEN_WIDTH()
 ENDIF
 IF .xmin=0 AND .xmax=0 THEN 
  .xmin=.ymin*SCREEN_WIDTH()/SCREEN_HEIGHT() ! .xmax=.ymax*SCREEN_WIDTH()/SCREEN_HEIGHT()
 ENDIF 
 
 'calculate gradient, linear transormation function  
 mx=SCREEN_WIDTH() /(.xmax-.xmin)
 x0=(-1)*.xmin*mx
 tc_x=x*mx+x0
END DEF
'=================
DEF tc_y(y)
 IF .ymin=0 AND .ymax=0 THEN 
  .ymin=.xmin*SCREEN_HEIGHT()/SCREEN_WIDTH() ! .ymax=.xmax*SCREEN_HEIGHT()/SCREEN_WIDTH()
 ENDIF
 IF .xmin=0 AND .xmax=0 THEN 
  .xmin=.ymin*SCREEN_WIDTH()/SCREEN_HEIGHT() ! .xmax=.ymax*SCREEN_WIDTH()/SCREEN_HEIGHT()
 ENDIF
 my=SCREEN_HEIGHT() / (.ymin-.ymax)
 y0=(-1)*.ymax*my
 tc_y=y*my+y0
END DEF
'=================
DEF insepstr$(section,s1$,S2$)
 IF MAX(LEN(s1$),LEN(s2$))=LEN(s1$) THEN 's1 the longest?
  separator$=s2$ ! string$=s1$ 'shortest is separator
 ELSE
  string$=s2$ ! separator$=s1$
 ENDIF
  
 IF string$="" THEN RETURN "ERROR" '-1 problematisch bei der auswertung. Stoppzeichen definieren und übergeben?
 'insepstr$(2,",","123,4567,890") -> 4567
 option_base_=OPTION_BASE()
 OPTION BASE 1
 length=LEN(string$)
 IF INSTR(string$,separator$,1)=-1 AND section=1 THEN RETURN string$ '-1 'trennzeichen nicht vorhanden
 pos2=0
 FOR n= 1 TO section
  pos1=pos2+1 
  IF pos1<=LEN(string$) THEN pos2=INSTR(string$,separator$,pos1) ELSE RETURN "ERROR" '-1
  IF pos2 = -1 THEN BREAK 'letztes komma fehlt
 NEXT n
  IF n=section AND pos1<=length THEN pos2=length+1 'letzte komma fehlt
  IF n<section THEN RETURN "ERROR" '-1 'weniger sections als erwartet
  '(n=section und noch zeichen übrig: letztes komma fehlt, sonst zuwenig sections
  
  RETURN MID$(string$,pos1,pos2-pos1)
 OPTION BASE option_base_
END DEF
'b'
load_sound:
IF FILE_EXISTS(filename$) THEN
 MUSIC "seagulls" LOAD filename$ 
 MUSIC "seagulls" LOOP
ELSE
 a$="soundbible.com/grab.php?id=191&type=wav"
 HTTP a$ GETDIM t,n
 FILE filename$ WRITEDIM t,n
 WHILE NOT FILE_EXISTS(filename$) ! END WHILE
 MUSIC "seagulls" LOAD filename$
 MUSIC "seagulls" LOOP
ENDIF
RETURN 'of load_sound
IMG_2195.PNG
IMG_2195.PNG (70.17 KiB) Viewed 5965 times
Last edited by Joel on Fri Jan 20, 2017 4:08 pm, edited 6 times in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: need some advice...

Post by rbytes »

Yes, I found a couple of lines that hinted at the problem.

'SPRITE "boat" AT tc_x(0),tc_y(y_mid_boat)
SPRITE "boat" SHOW

I wasn't sure why the first line was commented out, so I uncommented it. Still saw the flash.
I tried commenting out the second line and then the boat didn't appear at all.

So I added 1000 to the x coordinate to push the boat offscreen to the right. I figured it would probably be moved continuously by the code that followed, but at least it wouldn't be on-screen when first shown.

It worked.

SPRITE "boat" AT tc_x(0)+1000,tc_y(y_mid_boat)
SPRITE "boat" SHOW

Wow, nice effects! Will this be a game?
The only thing that gets me down is gravity...

Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

Re: need some advice...

Post by Joel »

Hey Ricardo,
you're very fast - wow!!
Thank you! That would help a lot.
This strange effect happens every now and than in one or the other program. I have no idea what it is... So thanks a lot for your hint!!!

Game: No, don't think so...was just playing around with sprites (I intended to glue one sprite (period of a sine-oscillation) to the other, but it didn't work, you saw a thin line....such things, you know)
Last edited by Joel on Wed Jan 18, 2017 1:47 am, edited 1 time in total.

Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

Re: need some advice...

Post by Joel »

I discovered by the way, that it is a lot of fun playing around with the numbers in this line:

a$="soundbible.com/grab.php?id=191&type=wav" 'change the numbers 192...193 e.g.

you should delete the "seagulls.wav" first...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: need some advice...

Post by rbytes »

I will give that a try. Thanks!
The only thing that gets me down is gravity...

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: need some advice...

Post by Operator »

Another similar approach would be to show
the sprites after the first calc. in the main
loop and not before...

...
IF TOUCH_X(0)>0 THEN END


IF sprite_show_flag = 0 THEN
SPRITE "boat" SHOW
SPRITE "wave_blue1" SHOW
SPRITE "wave_blue2" SHOW
sprite_show_flag = 1
END IF

NEXT phi

Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

Re: need some advice...

Post by Joel »

Hi Operator,
thanks for the hint. I'm going to follow your hint in my program, which seems to be more accurate, while I'll follow ricardos hint to correct the program here - quick and dirty, hehehe

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: need some advice...

Post by rbytes »

That Soundbible download routine is great. Thanks, Joel.
The only thing that gets me down is gravity...

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: need some advice...

Post by GeorgeMcGinn »

All you need is:

Change the boat to a smaller battleship/aircraft carrier
Add bomber or bombers

Let the computer play either the pilot or the boat captain, human plays the other.

Now you've got a game where the ship tries to shoot the bomber out of the sky, and the bomber tries to sink the boat.

Make the boat and bomber small enough, the bomber moves faster, now and the pieces small enough, you have greater distance between them, so timing is everything. And smooth out the waves a little so it messes up the bomber's aim (dam, if the the bow didn't duck down below a wave my bomb would have it it.

Sounds like a great game in the making.

I know how hard it was for Dutchman to write his Submarine game, but it is one I can't stop playing.

George.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Post Reply