Author |
Topic: Simple game movement code (Read 704 times) |
|
Falan
New Member
member is offline


Posts: 2
|
 |
Simple game movement code
« Thread started on: Nov 29th, 2015, 8:37pm » |
|
Hi there I wonder if there are any examples of basic coding that I could use to make a character move around the screen and perhaps animate some enemies?
I have worked through the tutorials in BBC BASIC but I am having difficulty finding code for movements.
I want to have a simple screen that I can move around in and maybe interact with other things there. Possibly have enemies moving about to avoid, the usual things.
If there are any examples of this I would really appreciate any help finding them thanks
|
|
Logged
|
|
|
|
Richey
New Member
member is offline


Gender: 
Posts: 35
|
 |
Re: Simple game movement code
« Reply #1 on: Nov 30th, 2015, 02:11am » |
|
Hello Falan
in the first instance I would suggest referring firstly to Chapter 13 of the tutorial for information on using INKEY.
http://bbcbasic.co.uk/bbcwin/tutorial/chapter13.html
Then it's probably worth reading from there to chapter 19.
Hope this helps.
Best wishes.
|
« Last Edit: Nov 30th, 2015, 02:16am by Richey » |
Logged
|
|
|
|
Falan
New Member
member is offline


Posts: 2
|
 |
Re: Simple game movement code
« Reply #2 on: Nov 30th, 2015, 05:14am » |
|
Many thanks I will continue from Chapter 13 then thanks 
Edit- Ok thanks I read through those tutorials and I have looked at some game code. I cannot find anything simple enough to break down into chunks I can make sense of though.
I was hoping to draw a small window and then move a character (I already made some) around the screen. I think the 'space invaders' demo was close because it drew the window and gave control over the character left and right and also deleted the old character each time it moved.
It was frustrating though because there was a lot of other stuff going on. I would like to link up the movement on the screen to trigger a text based adventure script. I will keep searching but if anyone knows any real simple movement code I can adapt I would love to see it thanks.
|
« Last Edit: Nov 30th, 2015, 3:54pm by Falan » |
Logged
|
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: Simple game movement code
« Reply #3 on: Dec 1st, 2015, 5:14pm » |
|
Hi Falan,
OK, sounds like the text-based graphics in the tutorial are a good starting place for what you want. Is this too simple to be useful?
Code:
REM Set up a 640 x 512 pixel window and clear it to black
REM This mode gives us 80 characters wide and 32 deep
MODE 8
REM Set up player's initial position, in characters
playerx%=40
playery%=16
REPEAT
PRINT TAB(playerx%,playery%)," " :REM Clear out last position
t$=INKEY$(0) :REM check keyboard for instructions to move player
CASE t$ OF
WHEN "z","Z":playerx%-=1
WHEN "x","X":playerx%+=1
WHEN "a","A":playery%+=1
WHEN "q","Q":playery%-=1
ENDCASE
PRINT TAB(playerx%,playery%),"O" :REM Draw player in new position
WAIT 5 :REM Wait a while (partly to give your processor a rest!)
UNTIL playerx%<0 OR playerx%>79 OR playery%<0 OR playery%>31
By adding code to show your enemies, or the landscape, you could make it more interesting. By detecting (as shown in the tutorial using GET(x,y) you should be able to trigger a branch to the event in your text-based story.
Later you will probably want to use the graphics functions. In particular, you might want to look at using VDU 5 to tie text to the graphics cursor (which you can move with MOVE) to get finer control. Then you can use POINT to look at the colour of the screen there.
Hope that's useful,
D
|
|
Logged
|
|
|
|
KenDown
Full Member
member is offline


Posts: 181
|
 |
Re: Simple game movement code
« Reply #4 on: Dec 7th, 2015, 6:50pm » |
|
There are two methods to move things around the screen. The first uses the fact that if you EOR a number twice you get the original number. PRINT10EOR128 which gives you 138 PRINT138EOR128 gives you 10 again
GCOL3,9 x%=100 REPEAT CIRCLEFILLx%,100,20 g%=GET CIRCLEFILLx%,100,20 IFg%=137x%+=2 UNTILx%=1400
Press the right arrow key and the blue circle will move to the right. This works very nicely - until you start putting background in and then, because the circle is "painted" onto the screen, you will get funny results. Try putting a solid rectangle in the way of the circle to see what I mean.
(Incidentally, in immediate mode - click on the keyboard symbol in your BB4W window - type PRINTGET then press the left arrow key. That will give you the code for which you should test to get your circle moving left. Do the same (and adapt the program) to get the circle moving up and down.
As someone else has already pointed out, GET or INKEY(0) is a fairly slow way of getting user input. Using INKEY with a negative number (look up "INKEY" in the help supplied with BB4W) will be much faster - maybe even too fast!
The other method is to use sprites, but I won't tell you about that. It's far too complicated and is so clearly explained in the Help files that even I can understand it.
Hope this helps.
|
|
Logged
|
|
|
|
|