Football Manager Type Game

Anything QL Software or Programming Related.
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Football Manager Type Game

Post by Andrew »

vanpeebles wrote:I'd like to see the robot program!
I still have a back-up on a tape. But I do not know if the tape is still good - it was stored for 32 years. And it is a chinese brand tape, so it was not very good to start with.
But I will have to find a way to convert it to digital (I do not have a working tape player)


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Football Manager Type Game

Post by vanpeebles »

Brick wall and also a doggie having a whistle against the tv gantry.
Attachments
replay8.png


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: Football Manager Type Game

Post by dilwyn »

I know vanpeebles said he didn't intend to do any coding for a football game, but I did offer to write a simple little animation demo, so here it is.

It simply lets 22 players wander aimlessly and randomly around a football pitch (a bit like some Premier League soccer teams!).

It doesn't have user defined graphics, it's complex enough as it is, so it just uses characters from QL font 2 as players, but uses character ranges from CHR$(128) for team 1 and from CHR$(160) for team 2. When you get around to adding user defined graphics, this would allow 3 characters per player, one for running left, one for running right and one for standing still. There's a handy little article called Fun With Fonts for working with fonts and user defined graphics on my website at http://www.dilwyn.me.uk/docs/articles/funfonts.zip. Shows how to use the Toolkit 2 extensions to handle user defined fonts, rather than relying on POKE_L statements as has already been explained.
footballdemo.jpg
It just draws a very basic football pitch and overlays 22 player graphics, moving them around at random. The program is written in BASIC. Was written on QPC2 so might need minor changes for other systems, possibly (haven't had time to check).

The demo uses two sets of arrays to hold the co-ordinates of each player - teamx% and teamy% store the 'new' positions and oldx% and oldy% remember the old co-ordinates before moving to erase the character. OVER -1 is used for printing the characters. OVER -1 causes the colours to be XORed into the existing pixels on the screen, in effect if the same character is printed twice in the same location, the second printing erases the first one.

The speed of the demo is controlled by the variable delay% (the lower the value, the faster the demo runs). It's used in an INKEY$ statement which detects ESC to quit. The snag of course is that pressing a key shortens the delay specified in INKEY$ so you get a temporary speedup. Good enough for the demo.

Rather than say too much about the program (I already lost a large draft of this message this morning when the Forum refused to SUBMIT the post with a "403" error), I'll just let you copy the part in CODE below, run it to see it in action and offer to answer any questions you may have. It's just a quick and dirty demo of character animation, I'm sure you'll have fun studying and learning as you make improvements. The program has plenty of REM statements to help you understand what's going on.

It shows just how much array space is needed to store fairly simple animations like this. Real sprite packages would let you specify whether sprites just go in which direction, where from, how far, whether they wrap around the screen, whether they bounce back and forth or repeat in the same direction or stay still at the end, and possibly for 3D type graphics "planes" or "layers" which allow checking if graphics on the same layer or depth have collided while allowing objects further back or nearer just pass each other without causing a collision.

Have fun - if there's interest, and I get time, I might do a simple little tutorial article on moving graphics, like the fonts article, as it's a subject I don't see covered that much.

Code: Select all

100 REMark football demo
110 delay%    = 5 : REMark speed (lower value=faster)
120 team1ink% = 2 : REMark colour of team 1 players
130 team2ink% = 4 : REMark colour of team 2 players
140 :
150 WINDOW 512,256,0,0 : PAPER 0 : INK 7 : CLS : REMark full screen
160 :
170 REMark create arrays to store co-ordinates of all 11 players
180 DIM teamx%(1,10),teamy%(1,10)
190 REMark arrays to store co-ordinates of players just before they move
200 DIM oldx%(1,10),oldy%(1,10)
210 :
220 Draw_Pitch : REMark draw basic outline of a soccer pitch
230 :
240 REMark draw starting positions of players, use OVER -1 even here
250 REMark so that player characters don't erase pitch lines
260 OVER -1
270 FOR a = 0 TO 10
280   REMark starting positions for each player, team(0) on left,
290   REMark team(1) in right half
300   teamx%(0,a) = RND(0 TO 256-6)
310   teamy%(0,a) = RND(0 TO 256-10)
320   teamx%(1,a) = RND(256 TO 512-6)
330   teamy%(1,a) = RND(0 TO 256-10)
340   INK team1ink% : CURSOR teamx%(0,a),teamy%(0,a) : PRINT CHR$(128+a);
350   INK team2ink% : CURSOR teamx%(1,a),teamy%(1,a) : PRINT CHR$(161+a);
360   INK 7
370 END FOR a
380 OVER 0
390 :
400 REPeat program
410   IF INKEY$(delay%) = CHR$(27) THEN EXIT program : REMark ESC=quit
420   :
430   REMark update player positions at random for demo
440   FOR a = 0 TO 10
450     :
460     REMark remember existing position of team 1 player
470     oldx%(0,a) = teamx%(0,a)
480     oldy%(0,a) = teamy%(0,a)
490     :
500     REMark set new position for team 1 player at random. Note that as
510     REMark PRINT does not wrap pixels at end of line as a sprite
520     REMark would, we have to be careful of getting too close to the
530     REMark right and bottom edges to prevent out of range errors.
540     teamx%(0,a) = teamx%(0,a)+RND(-6 TO 6) : REMark up to 6 pixels
550     IF teamx%(0,a) < 0 THEN
560       teamx%(0,a) = 0 : REMark check left edge
570     ELSE
580       IF teamx%(0,a) > (512-6) THEN teamx%(0,a) = 512-6 : REMark right
590     END IF
600     teamy%(0,a) = teamy%(0,a) + RND(-5 TO 5)
610     IF teamy%(0,a) < 0 THEN
620       teamy%(0,a) = 0 : REMark check top edge
630     ELSE
640       IF teamy%(0,a) > (256-10) THEN teamy%(0,a) = 256-10
650     END IF
660     :
670     REMark remember existing position for team 2 player
680     oldx%(1,a) = teamx%(1,a)
690     oldy%(1,a) = teamy%(1,a)
700     :
710     REMark set new position for team 2 player at random
720     teamx%(1,a) = teamx%(1,a) + RND(-6 TO 6)
730     IF teamx%(1,a) < 0 THEN teamx%(1,a) = 0
740     IF teamx%(1,a) > (512-6) THEN teamx%(1,a) = 512-6
750     teamy%(1,a) = teamy%(1,a) + RND(-5 TO 5)
760     IF teamy%(1,a) < 0 THEN teamy%(1,a) = 0
770     IF teamy%(1,a) > (256-10) THEN teamy%(1,a) = 256-10
780   END FOR a
790   :
800   Draw_Players : REMark erase and redraw and players who've moved
810   :
820 END REPeat program
830 :
840 DEFine PROCedure Draw_Players
850   OVER -1 : REMark XOR drawing
860   FOR a = 0 TO 10
870     REMark erase player from old position if moved
880     INK team1ink% : REMark team 1 player
890     IF oldx%(0,a) <> teamx%(0,a) OR oldy%(0,a) <> teamy%(0,a) THEN
900       CURSOR oldx%(0,a),oldy%(0,a)   : PRINT CHR$(128+a);
910       CURSOR teamx%(0,a),teamy%(0,a) : PRINT CHR$(128+a);
920     END IF
930     INK team2ink% : REMark team 2 player
940     IF oldx%(1,a) <> teamx%(1,a) OR oldy%(1,a) <> teamy%(1,a) THEN
950       CURSOR oldx%(1,a),oldy%(1,a)   : PRINT CHR$(161+a);
960       CURSOR teamx%(1,a),teamy%(1,a) : PRINT CHR$(161+a);
970     END IF
980     INK 7 : REMark back to white ink
990   END FOR a
1000   OVER 0
1010 END DEFine Draw_Players
1020 :
1030 DEFine PROCedure Draw_Pitch
1040   REMark outline (full screen on QL)
1050   BLOCK 2,256,0,0,7   : BLOCK 508,1,2,0,7
1060   BLOCK 2,256,510,0,7 : BLOCK 508,1,2,255,7
1070   REMark halfway line
1080   BLOCK 2,252,255,1,7
1090   REMark the left penalty area
1100   BLOCK 74,1,2,50,7
1110   BLOCK 74,1,2,256-50,7
1120   BLOCK 2,155,74,51,7
1130   REMark the right penalty area
1140   BLOCK 74,1,512-76,50,7
1150   BLOCK 74,1,512-76,256-50,7
1160   BLOCK 2,155,512-76,51,7
1170   REMark the centre circle
1180   Draw_Circle 256,128,42,34
1190 END DEFine Draw_Pitch
1200 :
1210 DEFine PROCedure Draw_Circle (x,y,rx,ry)
1220   REMark this procedure draws circles, to avoid having to try to
1230   REMark marry up the graphics co-ordinates of CIRCLE command.
1235   REMark use smaller STEP values for better quality circles
1240   LOCal r
1250   FOR r = 0 TO 2*PI STEP PI/2/rx
1260     BLOCK 2,1,256+rx*SIN(r),128+ry*COS(r),7
1270   END FOR r
1280 END DEFine Draw_Circle


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Football Manager Type Game

Post by vanpeebles »

That's excellent, hopefully all of our ideas will spark someone into giving it a bash :) A friend of mine is working on an away team ground too!


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: Football Manager Type Game

Post by dilwyn »

vanpeebles wrote:That's excellent, hopefully all of our ideas will spark someone into giving it a bash :)
My thoughts exactly!

Using character graphics is pretty basic and crude, but it does give a nice 'retro' feel to simple animated games.


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Football Manager Type Game

Post by vanpeebles »

Coupe of seagulls, one is enjoying a carton of chips :lol:
Attachments
seagulls.gif


User avatar
RalfR
Aurora
Posts: 870
Joined: Fri Jun 15, 2018 8:58 pm

Re: Football Manager Type Game

Post by RalfR »

:D :D :D


4E75 7000
User avatar
Cristian
Aurora
Posts: 960
Joined: Mon Feb 16, 2015 1:40 pm
Location: Veneto

Re: Football Manager Type Game

Post by Cristian »

:lol:


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Football Manager Type Game

Post by vanpeebles »

Bit more work and I've started on a left side too! Bit more space behind goal on that side!!
Attachments
replayleft8.png
replayleft8.png (8.87 KiB) Viewed 2605 times
replay8.png


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Football Manager Type Game

Post by vanpeebles »

Bit more work on the left side:
Attachments
replayleft8.png
replayleft8.png (10.26 KiB) Viewed 2552 times


Post Reply