![]() |
![]() |
#1 |
Local Moderator
Join Date: Oct 2009
Location: Lancashire, UK
Age: 48
Posts: 1,739
|
AmigaBasic/Cando: Point and Click Walking Routine
Hi there
I've no idea if this is the right place for this. I'm making a point and click adventure demo using Cando (which is just a front-end for BASIC). When I click on a destination, my character will walk there using the routine below. (which I've added annotations for you) When I walk Right to Left, the character moves to the exact pixel and stops. But when I move from Left to Right, the character moves a bit too far to the right of my destination, then steps back to the correct place, and stops. I can't see what I am doing wrong. The routines and the walking frames are mirrored exactly. But why does walking backwards work, but walking forwards doesn't? Code:
Let Dest=MouseX ; use the current X positon of the mouse as the destination Let Count=PX ; note the current X position of the player and save it to Count If Room=1 If Dest>PX and Dest>64 ; anything less than X.64 is blocked on screen 1 While Count<Dest and PX=>64 ; while the player X is less than Dest. Let PX=PX+18 Let Count=Count+18 If Walk=0 ; if the player is stopped, or about to walk, clear screen Do "Draw Backdrop" EndIf Let Walk=Walk+1 ; increase the walk by 1 If Walk=1 and PX<208 or Walk=1 and PX>406 ; if the character is visible, show the next frame of walking. ShowBrush "pics/w2a.bsh",PX,PY EndIf If Walk=2 and PX<208 or Walk=2 and PX>406 ShowBrush "pics/w3a.bsh",PX,PY EndIf If Walk=3 and PX<208 or Walk=3 and PX>406 ShowBrush "pics/w4a.bsh",PX,PY EndIf If Walk=4 and PX<208 or Walk=4 and PX>406 ShowBrush "pics/w2a.bsh",PX,PY Let Walk=1 ; at the end of the loop, go to frame 2 (walk 2) EndIf If Count=>Dest and PX<208 or Count=>Dest and PX>406 ; if the walk is over, and character is visible, return to standing. ; ShowBrush "pics/w1a.bsh",PX,PY (this is not needed) Let Walk=0 EndIf Do "Draw Backdrop" ; draw backdrop and standing character EndLoop EndIf EndIf If Room<>1 If Dest>PX While Count<Dest and PX<600 Let PX=PX+18 Let Count=Count+18 If Walk=0 Do "Draw Backdrop" EndIf Let Walk=Walk+1 If Walk=1 ShowBrush "pics/w2a.bsh",PX,PY EndIf If Walk=2 ShowBrush "pics/w3a.bsh",PX,PY EndIf If Walk=3 ShowBrush "pics/w4a.bsh",PX,PY EndIf If Walk=4 ShowBrush "pics/w2a.bsh",PX,PY Let Walk=1 EndIf If Count=>Dest ; ShowBrush "pics/w1a.bsh",PX,PY Let Walk=0 EndIf Do "Draw Backdrop" EndLoop EndIf EndIf If Room=1 If Dest<PX and Dest>64 While Count>Dest and PX>64 Let PX=PX-18 Let Count=Count-18 If Walk=0 Do "Draw Backdrop" EndIf Let Walk=Walk+1 If Walk=1 and PX<208 or Walk=1 and PX>406 ShowBrush "pics/w4b.bsh",PX,PY EndIf If Walk=2 and PX<208 or Walk=2 and PX>406 ShowBrush "pics/w3b.bsh",PX,PY EndIf If Walk=3 and PX<208 or Walk=3 and PX>406 ShowBrush "pics/w2b.bsh",PX,PY EndIf If Walk=4 and PX<208 or Walk=4 and PX>406 ShowBrush "pics/w4b.bsh",PX,PY Let Walk=1 EndIf If Count=<Dest and PX<208 or Count=<Dest and PX>406 ; ShowBrush "pics/w1b.bsh",PX,PY Let Walk=0 EndIf Do "Draw Backdrop" EndLoop EndIf EndIf If Room<>1 If Dest<PX While Count>Dest Let PX=PX-18 Let Count=Count-18 If Walk=0 Do "Draw Backdrop" EndIf Let Walk=Walk+1 If Walk=1 ShowBrush "pics/w4b.bsh",PX,PY EndIf If Walk=2 ShowBrush "pics/w3b.bsh",PX,PY EndIf If Walk=3 ShowBrush "pics/w2b.bsh",PX,PY EndIf If Walk=4 ShowBrush "pics/w4b.bsh",PX,PY Let Walk=1 EndIf If Count=<Dest ; ShowBrush "pics/w1b.bsh",PX,PY Let Walk=0 EndIf Do "Draw Backdrop" EndLoop EndIf EndIf If Room<>4 and PX=>580 ; if character at edge, scroll screen Do "ScrollForwards" EndIf If Room<>1 and PX=<50 ; if character at left edge, scroll screen Do "ScrollBackwards" EndIf [ Show youtube player ] Last edited by lifeschool; 30 November 2023 at 19:10. |
![]() |
![]() |
#2 |
Registered User
Join Date: Jan 2022
Location: Wales
Posts: 92
|
I've never used AmigaBasic or CanDo, but have used other languages to make a few games, so I'm guessing as to your problem (if I'm reading your question correctly) based on my experiences over the years.
It sounds like to me that when you're adding to your current X position to move right, it eventually exceeds your maximum X so then steps backwards. When subtracting to move left, it just happens that your current X position matches the minimum X so it 'works'. If this is the case, then I see two solutions... (1) Before moving your character, do an X calculation and store in a temporary variable that you can use to compare to max and min X and make decisions from there. Using rough pseudo-code, something like this... Code:
CURRENT_X + MOVE = TEMP_X IF TEMP_X >= MAX_X CURRENT_X = MAX_X ELSE CURRENT_X = TEMP_X ENDIF PRINT CHARACTER_POSITION AT CURRENT_X (2) Set your minimum and maximum X values to be exactly divisible by the X movement of your character so the values are never exceeded. You would also have to factor in the mouse position x and round up/down to those divisible values. Could get messy! I would favour solution (1). Make the code do the work so if anything else changes later on such as you changing the starting position of the character, you don't end up having to work out stuff yourself and adjust. Hopefully that makes sense and if I've misread your question, apologies for wasting your time! |
![]() |
![]() |
#3 |
Local Moderator
Join Date: Oct 2009
Location: Lancashire, UK
Age: 48
Posts: 1,739
|
Thanks for your tips. In the end, I added a check after moving Player_X. It seems to work a lot better than before.
Code:
If Room=1 If Dest>PX and Dest>64 While Count<Dest and PX=>64 Let PX=PX+18 > If PX=>Dest > Let Count=Dest > Let PX=Dest > Let Walk=0 > Else > Let Count=Count+18 > EndIf > If Walk=0 and Count<>Dest Do "Draw Backdrop" EndIf Let Walk=Walk+1 If Walk=1 and PX<208 or Walk=1 and PX>406 ShowBrush "pics/w2a.bsh",PX,PY EndIf If Walk=2 and PX<208 or Walk=2 and PX>406 ShowBrush "pics/w3a.bsh",PX,PY EndIf If Walk=3 and PX<208 or Walk=3 and PX>406 ShowBrush "pics/w4a.bsh",PX,PY EndIf If Walk=4 and PX<208 or Walk=4 and PX>406 ShowBrush "pics/w2a.bsh",PX,PY Let Walk=1 EndIf If Count=>Dest and PX<208 or Count=>Dest and PX>406 ; ShowBrush "pics/w1a.bsh",PX,PY Let Walk=0 EndIf Do "Draw Backdrop" EndLoop EndIf EndIf Last edited by lifeschool; 30 November 2023 at 19:36. |
![]() |
![]() |
#4 |
Registered User
Join Date: Jan 2022
Location: Wales
Posts: 92
|
Glad you solved your problem!
|
![]() |
![]() |
#5 |
Phone Homer
Join Date: Jun 2006
Location: 5150
Posts: 5,887
|
You could try GRAC
|
![]() |
![]() |
#6 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,224
|
GRAC 2&3 are written in AmosPro (another BASIC) and source to version 2 is on Aminet. Walk zones are difficult to program but I could offer advice if you like.
|
![]() |
![]() |
#7 |
Local Moderator
Join Date: Oct 2009
Location: Lancashire, UK
Age: 48
Posts: 1,739
|
Thanks for the advice everyone.
I have used GRAC before, and I'm perhaps the only person on this planet using CanDo, but it is a pleasure to use it, and I'm not technical enough to use Blitz etc. My previous games are Holiday, and Beat Cancer/Empire Protector. All made with CanDo. https://lifeschool22.itch.io/ The walk routine is easy with Cando, just make a hit box as wide as the screen and activate the walking script on click. It's very easy. Another issue I'm having with my walking script for room 1 is the character pops up after walking past the cabin. The character refuses to appear until the end of the walk, and then it pops up and stops. I guess one way would be to have a bitmap of the cabin over the top, so the character is hidden, but the character still appears for a milli second each frame, until the bitmap is layed over it each time, unless I blank the walk during that section. |
![]() |
![]() |
#8 |
Registered User
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,772
|
Interesting...
I'd heard of CanDo, but had no idea it basically ;-) used Amiga BASIC on the backend... Have to admit I really liked line numbered BASICs and when I got my Amiga, was a bit disappointed when I fired up AmigaBASIC... Then I decided if I was going to lose line numbers, I'd jump to C... ;-) Great work!!! |
![]() |
![]() |
#9 |
A3000-Fan
Join Date: Sep 2008
Location: Germany
Posts: 323
|
|
![]() |
![]() |
#10 |
Local Moderator
Join Date: Oct 2009
Location: Lancashire, UK
Age: 48
Posts: 1,739
|
@desiv, didn't you used to have a penguin avatar? Yes C would be more ideal for coding, but it was always too complex for me. CanDo is like a GRAC for anything. I've seen dual-pane directory browsers made with it, spreadsheets and database etc, but it can also use basic commands.
It seems it is not true BASIC after all, but for the sake of If's and While's, and Let's, it is the same coding. Instead of GoSub, there is the command Do. It seems there are line numbers in the CanDo editor, but they are not supported for GoTo commands, and instead it jumps to defined 'bookmarks' I think? |
![]() |
![]() |
#11 |
Registered User
Join Date: Oct 2009
Location: Salem, OR
Posts: 1,772
|
Yeah, what happened to that Avatar? Didn't notice it was gone.
Now I have to find it again... ;-) (Fixed!!! Whew! Made that avatar over 20 years ago now! Well, added the boing to someone else's penguin that is..) OK, not AmigaBASIC, but yeah, very BASIC like in that scripting language... Last edited by desiv; 02 December 2023 at 03:32. |
![]() |
![]() |
#12 |
Registered User
Join Date: Jan 2014
Location: Belgrade / Serbia
Age: 41
Posts: 1,017
|
Nice! Its intresting to see what could be done with cando.
Once before I used cando or was it amigavision? to make a simple Where's Wally "game". Then I jumped to Blitz. Its not that harder. You should try. Though your project isnt that easy... |
![]() |
![]() |
#13 |
Local Moderator
Join Date: Oct 2009
Location: Lancashire, UK
Age: 48
Posts: 1,739
|
Well here it is, or at least the demo of the prototype.
![]() https://lifeschool22.itch.io/monkeye...-os3cando-demo This 3 screen mini game is finished but still contains a few bugs. I included the source code, if people want to play about with it. This was basically a proof of concept, although the objects flash, so really, it was a failed attempt. But anyway... I can also share the source of my other two games if anyone is interested. ![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Quest for Infamy - Point and click Adventure | Neil79 | Retrogaming General Discussion | 0 | 10 July 2014 15:18 |
What are the easiest, most accessible point and click adventures? | frikilokooo | Nostalgia & memories | 58 | 13 April 2012 12:35 |
Point and Click with a Soya Bean Machine? | cheesenpickle | Looking for a game name ? | 2 | 08 January 2006 13:18 |
Point n Click Adventures | Doozy | Amiga scene | 31 | 07 August 2002 02:40 |
|
|