Liberty BASIC Community Forum
« Turtle Graphics »

Welcome Guest. Please Login or Register.
Jul 24th, 2017, 7:40pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Turtle Graphics  (Read 54 times)
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 412
xx Turtle Graphics
« Thread started on: Jul 17th, 2017, 05:24am »

Good Morning
I plan on coding a graphical Turtle graphics
now I thort up this code
but it does not seem to be working out the way it is in my mind
Code:
'Add a sprite and locate it at x=10, y=30.
'Allow user to press arrow buttons to move sprite.
'Allow another event to take place, independently
'from user sprite movement.
nomainwin
loadbmp "smiley", "sprites\smiley.bmp"
loadbmp "landscape", "sprites\bg1.bmp"
WindowHeight = 350 : WindowWidth = 400
UpperLeftX = 10
UpperLeftY = 10
graphicbox #w.g, 0, 0, 400, 300
statictext #w.s, "",40,300,100,40
open "User-Controlled Sprite 2" for window_nf as #w
 #w "trapclose [quit]"
 #w.g "down"
 #w.g "background landscape"
 #w.g "addsprite guy smiley"
 spriteX = 10 : spriteY = 30
 #w.g "spritexy guy ";spriteX;" ";spriteY
 'set up event trapping for key presses
 #w.g "setfocus" 'MUST setfocus to graphicbox
 #w.g "when characterInput [updatePosition]"
 #w.g "drawsprites" 'update screen
 'save time program started in variable
 startTime=time$("seconds")
 timer 300, [updateDisplay]
wait
[updatePosition]
 '37 = left arrow
 '38 = up arrow
 '39 = right arrow
 '40 = down arrow
 'Arrow keys make Inkey$ two characters long,
 'so we check the rightmost character with
 'the right$() function.
 'right arrow = X gets bigger:
 if asc(right$(Inkey$,1))=39 then spriteX = spriteX + 3
 'left arrow = X gets smaller:
 if asc(right$(Inkey$,1))=37 then spriteX = spriteX - 3
 'up arrow = Y gets smaller:
 if asc(right$(Inkey$,1))=38 then spriteY = spriteY - 3
 'down arrow = Y gets bigger:
 if asc(right$(Inkey$,1))=40 then spriteY = spriteY + 3
[updateDisplay]
#w.g, "centersprite guy"
'if spriteY >153 and spriteX > 100 then
#w.g, "spritexy? guy"
input #w.g, x, y
 #w.g "down"
 #w.g "size 8; color blue"


  #w.g "set "; spriteX; " "; spriteY
  #w.g "flush"
  '#g "set 195 140"
'end if
 'locate sprite at new position and update display
 #w.g "spritexy guy ";spriteX;" ";spriteY
 #w.g "drawsprites"
 'display time elapsed since start of program
 #w.s spriteX;" ";spriteY
 wait
[quit]
 timer 0
 unloadbmp "landscape"
 unloadbmp "smiley"
 close #w : end
 

What I'm thinking is at each display update you get the X and Y of the sprite(Centre Sprite) then say down Command and then I suppose Flush command to make the drawing stick.
User IP Logged

KEVIN
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5366
xx Re: Turtle Graphics
« Reply #1 on: Jul 17th, 2017, 06:46am »

You cant really mix drawing and sprites. The background is redrawn each cycle so hiding any drawn graphics and the sprite is then rendered on top of the background.

So you would need to change the background each cycle. I am not recommending this just showing you it can be done. You lose the ability to scroll the background and there is a lot of flickering.


Code:
'Add a sprite and locate it at x=10, y=30.
'Allow user to press arrow buttons to move sprite.
'Allow another event to take place, independently
'from user sprite movement.
nomainwin
loadbmp "smiley", "sprites\smiley.bmp"
loadbmp "landscape", "sprites\bg1.bmp"
WindowHeight = 350 : WindowWidth = 400
UpperLeftX = 10
UpperLeftY = 10
graphicbox #w.g, 0, 0, 400, 300
statictext #w.s, "",40,300,100,40
open "User-Controlled Sprite 2" for window_nf as #w
 #w "trapclose [quit]"
 #w.g "down"
 'Liberty will stretch the landscape image
 'we need a 400x300 image so use getbmp
 'we lose the ability to scroll the background
 #w.g "background landscape ; drawsprites"
 #w.g "getbmp landscape 0 0 400 300"
 #w.g "background landscape"
 #w.g "addsprite guy smiley"
 #w.g "centersprite guy"
 #w.g "size 8; color blue"
 spriteX = 10 : spriteY = 30
 #w.g "spritexy guy ";spriteX;" ";spriteY
 'set up event trapping for key presses
 #w.g "setfocus" 'MUST setfocus to graphicbox
 #w.g "when characterInput [updatePosition]"
 #w.g "drawsprites" 'update screen
 'save time program started in variable
 startTime=time$("seconds")
 timer 300, [updateDisplay]
wait
[updatePosition]
 '37 = left arrow
 '38 = up arrow
 '39 = right arrow
 '40 = down arrow
 'Arrow keys make Inkey$ two characters long,
 'so we check the rightmost character with
 'the right$() function.
 'right arrow = X gets bigger:
 if asc(right$(Inkey$,1))=39 then spriteX = spriteX + 3
 'left arrow = X gets smaller:
 if asc(right$(Inkey$,1))=37 then spriteX = spriteX - 3
 'up arrow = Y gets smaller:
 if asc(right$(Inkey$,1))=38 then spriteY = spriteY - 3
 'down arrow = Y gets bigger:
 if asc(right$(Inkey$,1))=40 then spriteY = spriteY + 3

[updateDisplay]
#w.g, "spritexy? guy x y"
'redraw the current background so hiding the sprite
#w.g "drawbmp landscape 0 0 400 300"
'draw the addition to the line
'and getbmp the new background
  #w.g "set "; spriteX; " "; spriteY
  #w.g "getbmp landscape 0 0 400 300"
  #w.g "background landscape"

 'locate sprite at new position and update display
 #w.g "spritexy guy ";spriteX;" ";spriteY
 #w.g "drawsprites"
 'display time elapsed since start of program
 #w.s spriteX;" ";spriteY
 wait
[quit]
 timer 0
 unloadbmp "landscape"
 unloadbmp "smiley"
 close #w : end
 


To mix line drawing and images you need something like Dan's graphics engine which double buffers the screen. Or create your own double buffer with the blitter.


Since these are all more complex methods why not try leaving a trail of sprite dots instead?
User IP Logged

kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 412
xx Re: Turtle Graphics
« Reply #2 on: Jul 17th, 2017, 07:03am »

thank you Mr Rod this is exacty what I was thinking of

I thought of using a blnk background (white)

Kevin
User IP Logged

KEVIN
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls