Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CIRCLE - a 2 player game for VGA picomite GAME and NES controllers
Author | Message | ||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
As a test for the PIONES PIO statemachine reader of NES controllers I wrote a small simple game. The game gave so much fun that I decided to finish it (add a simple intro and restart options). Objective of the game is to have 2 players (Blue and Red) outwit each other in trying to grow their circle beyond screen dimensions. Growing the circe when you eat green fruit that randomly appears on screen. But watch out, you cannot bump into eachother, the one who does, shrinks... Have fun playing... 'circle, a 2 player game for VGA picomite GAME 'features PIONES - PIO SPI for dual NES controller 'VGApicomiteGAME board revision 1.4 '---------------------------- IO pin configuration ------------------------- 'pin asignment K8/sm0 K7/sm1 'data (in) gp1 gp4 'latch (out) gp2 gp5 'clk (out) gp3 gp22 'reserve pins for PIO1 sm0 SetPin gp1,pio1:SetPin gp2,pio1:SetPin gp3,pio1 'sm0 SetPin gp4,pio1:SetPin gp5,pio1:SetPin gp22,pio1 'sm1 'power the 2 ports K8 and K7 if needed SetPin gp14,dout:Pin(gp14)=1 SetPin gp15,dout:Pin(gp15)=1 '------------------------------ PIO configuration -------------------------- 'PIO1 execute frequency f=100000 'pio config PIO1 sm0 s0=2^19 'default with IN shift left, OUT shift right p0=Pio(pinctrl 1,1,1,GP1,GP3,GP2,GP3) 'GP1=IN base GP2=SET GP3=OUT/SIDESET 'pio config PIO1 sm1 s1=2^19 'default with IN shift left, OUT shift right p1=Pio(pinctrl 1,1,1,GP4,GP22,GP5,GP22) 'GP4=IN base, GP5=SET GP22=OUT/SIDESET '------------------------------ PIO program (comment) ----------------------- 'pio1 sm0 program, identical code for sm0 and sm1, clock is side set pin 'adr/instr/comment '0 E081 'set pindir latch, out [side 0] '1 E000 'set latch low [side 0] '2 A0EB 'MOV null inverted to OSR [side 0] '3 6081 'OUT 1 bit OSR to pindirs [side 0] set clock output '4 E001 'latch high [side 0] latch pulse '5 E000 'latch low [side 0] '6 E027 'load X with value 7 [side 0] '7 A0C3 'mov NULL to ISR [side 0] '8 4001 'shift 1 bit data in ISR [side 0] '9 1048 'JMP X-- to &h8 [side 1] this is the clock pulse 'A 8000 'push ISR [side 0] 8 bits to fifo 'B 0004 'jmp to &h4 [side 0] next cycle '&h0C....&h1F not used '------------------------- END PIO program (comment) -------------------------- 'pio1 program in data statements Dim a%(7)=(&h6081A0EBE000E081,&hA0C3E027E000E001,&h0004800010484001,0,0,0,0,0) 'program and start the PIO1 state machines PIO program 1,a%() 'program PIO1 PIO init machine 1,0,f,p0,,s0,0 'init sm0 from address &h00 PIO init machine 1,1,f,p1,,s1,0 'init sm1 from address &h00 (same code) PIO start 1,0 'start PIO1 sm0 PIO start 1,1 'start PIO1 sm1 Dim h%(5) '------------------------------ MAIN level ----------------------------------- MODE 2:CLS 'initial values for the players and the target food 'target (green) index 0, left player (K8/port A/blue) index 1 'right player (K7/port B/ red) index 2 sz=MM.HRes/40 'x,y are coordinates, r=radius, c=color, s=speed x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green) x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5 x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=5 introscreen 'u1=0:u2=0 'scores player 1 and 2 'the game uses framebuffer to prevent screen drawing artefacts FRAMEBUFFER create FRAMEBUFFER write f 'initial target Circle x0,y0,r0,,,c0,c0 '---------------------- this is the main game loop -------------------------- 'the game stops when one player size exceeds the screen limits Do 'read the FIFO's that contain the NES controller keys PIO read 1,0,5,h%() 'read 5 words from FIFO sm0 p1=255-h%(4) 'converto to value 0-15 PIO read 1,1,5,h%() 'read 5 words from FIFO sm1 p2=255-h%(4) 'converto to value 0-15 'wipe old positions players Circle x1,y1,r1,,,0,0 Circle x2,y2,r2,,,0,0 'move players v1=0:v2=0 If (p1 And 2) Then v1=v1+s1:x1=x1-s1 If (p1 And 1) Then v1=v1+s1:x1=x1+s1 If (p2 And 2) Then v2=v2+s2:x2=x2-s2 If (p2 And 1) Then v2=v2+s2:x2=x2+s2 If (p1 And 8) Then v1=v1+s1:y1=y1-s1 If (p1 And 4) Then v1=v1+s1:y1=y1+s1 If (p2 And 8) Then v2=v2+s2:y2=y2-s2 If (p2 And 4) Then v2=v2+s2:y2=y2+s2 'allow wrap around If x1<0 Then x1=x1+MM.HRes If x1>MM.HRes Then x1=x1-MM.HRes If y1<0 Then y1=y1+MM.VRes If y1>MM.VRes Then y1=y1-MM.VRes If x2<0 Then x2=x2+MM.HRes If x2>MM.HRes Then x2=x2-MM.HRes If y2<0 Then y2=y2+MM.VRes If y2>MM.VRes Then y2=y2-MM.VRes 'calculate distances d12=Sqr((x1-x2)^2 + (y1-y2)^2) d10=Sqr((x1-x0)^2 + (y1-y0)^2) d20=Sqr((x0-x2)^2 + (y0-y2)^2) 'game rules, collision between players is punished 'player who moves is culprit If d12<(r1+r2) Then If v1>0 Then r1=r1/2 If v2>0 Then r2=r2/2 r1=Max(r1,1) r2=Max(r2,1) EndIf 'you eat, you grow.... If d10<(r1+r0) Then r1=r1*2:newfood If d20<(r0+r2) Then r2=r2*2:newfood 'write new player /target positions and sizes Circle x1,y1,r1,,,c1,c1 Circle x2,y2,r2,,,c2,c2 Circle x0,y0,r0,,,c0,c0 'decide winner If r1>MM.VRes/2 Then Text MM.HRes/2,MM.VRes/2,"Blue Wins","CM",1,1,RGB(yellow) u1=u1+1 prestart EndIf If r2>MM.VRes/2 Then Text MM.HRes/2,MM.VRes/2,"Red Wins","CM",1,1,RGB(yellow) u2=u2+1 prestart EndIf 'score update Text 0,0,Str$(u1),"LT",1,1,RGB(blue) Text MM.HRes,0,Str$(u2),"RT",1,1,RGB(red) 'update screen FRAMEBUFFER copy f,n,b Pause 50 Loop Until p1=&h40 'loop until B key press CLS Text MM.HRes/2, MM.VRes/2, "Bye","CM",1,1,RGB(yellow) FRAMEBUFFER copy f,n,b End 'show player info and hold restart until controller key pressed Sub prestart Text MM.HRes/2,30+MM.VRes/2,"A=restart, B=stop","CM",1,1,RGB(yellow) FRAMEBUFFER copy f,n,b Do Pause 50 PIO read 1,0,5,h%() 'read 5 words from FIFO sm0 p1=255-h%(4) 'convert to value 0-255 Loop Until p1=&h80 Or p1=&h40 CLS 'x,y are coordinates, r=radius, c=color, s=speed x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green) x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5 x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=5 'initial target Circle x0,y0,r0,,,c0,c0 End Sub 'seed new green circle Sub newfood Circle x0,y0,r0,,,0,0 x0=MM.HRes*Rnd() y0=MM.VRes*Rnd() End Sub 'the introscreen Sub introscreen CLS Text MM.HRes/2,MM.VRes/2-50,"CIRCLE","CM",1,2,RGB(yellow) Pause 2000 Text MM.HRes/2,MM.VRes/2,"a 2 player game","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+20,"for VGA picomite GAME","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+40,"and 2 NES controllers","CM",1,1,RGB(yellow) Pause 1500 Box 0,MM.VRes/2-10,MM.HRes,MM.VRes,,0,0 Pause 1500 Text MM.HRes/2,MM.VRes/2,"arrows to move, B to stop","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+20,"eat green to grow and win","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+40,"avoid collisions","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+60,"--- GET READY ---","CM",1,1,RGB(yellow) Pause 2000 End Sub With any effort this game can be shrunk to less than 5k, making it a possible candidate for the contest....(yeah, it is closed).... Edited 2022-07-09 03:55 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
An update for the Circle game: Circle2. The game still requires 2 NES controllers connected to the VGApicoGAME board. The game is fast paced game for 2 players. Target is to eat apples and grow in size. Tactics can keep opponent away from food. The player who moves when colliding into the other looses weight... Win counter in top corners. All graphics are circle commands (hence the name....) Please enjoy.... 'circle, a 2 player game for VGA picomite GAME 'features PIONES2 - PIO SPI for dual NES controller 'VGApicomiteGAME board revision 1.4 '---------------------------- IO pin configuration ------------------------- 'pin asignment K8/sm0 K7/sm1 'data (in) gp1 gp4 'latch (out) gp2 gp5 'clk (out) gp3 gp22 'reserve pins for PIO1 sm0 SetPin gp1,pio1:SetPin gp2,pio1:SetPin gp3,pio1 'sm0 SetPin gp4,pio1:SetPin gp5,pio1:SetPin gp22,pio1 'sm1 'power the 2 ports K8 and K7 if needed SetPin gp14,dout:Pin(gp14)=1 SetPin gp15,dout:Pin(gp15)=1 '------------------------------ PIO configuration -------------------------- 'PIO1 execute frequency f=100000 'pio config PIO1 sm0 s0=2^19 'default with IN shift left, OUT shift right p0=Pio(pinctrl 1,1,1,GP1,GP3,GP2,GP3) 'GP1=IN base GP2=SET GP3=OUT/SIDESET 'pio config PIO1 sm1 s1=2^19 'default with IN shift left, OUT shift right p1=Pio(pinctrl 1,1,1,GP4,GP22,GP5,GP22) 'GP4=IN base, GP5=SET GP22=OUT/SIDESET '------------------------------ PIO program (comment) ----------------------- 'pio1 sm0 program, identical code for sm0 and sm1, clock is side set pin 'adr/instr/comment '0 E081 'set pindir latch, out [side 0] '1 E000 'set latch low [side 0] '2 A0EB 'MOV null inverted to OSR [side 0] '3 6081 'OUT 1 bit OSR to pindirs [side 0] set clock output '4 E001 'latch high [side 0] latch pulse '5 E000 'latch low [side 0] '6 E027 'load X with value 7 [side 0] '7 A0C3 'mov NULL to ISR [side 0] '8 4001 'shift 1 bit data in ISR [side 0] '9 1048 'JMP X-- to &h8 [side 1] this is the clock pulse 'A 8000 'push ISR [side 0] 8 bits to fifo 'B 0004 'jmp to &h4 [side 0] next cycle '&h0C....&h1F not used '------------------------- END PIO program (comment) -------------------------- 'pio1 program in data statements Dim a%(7)=(&h6081A0EBE000E081,&hA0C3E027E000E001,&h0004800010484001,0,0,0,0,0) 'program and start the PIO1 state machines PIO program 1,a%() 'program PIO1 PIO init machine 1,0,f,p0,,s0,0 'init sm0 from address &h00 PIO init machine 1,1,f,p1,,s1,0 'init sm1 from address &h00 (same code) PIO start 1,0 'start PIO1 sm0 PIO start 1,1 'start PIO1 sm1 Dim h%(5) '------------------------------ MAIN level ----------------------------------- MODE 2:CLS 'initial values for the players and the target food 'target (green) index 0, left player (K8/port A/blue) index 1 'right player (K7/port B/ red) index 2 sz=MM.HRes/40 'x,y are coordinates, r=radius, c=color, s=speed x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green) x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5 x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=5 cw=rgb(white) introscreen 'u1=0:u2=0 'scores player 1 and 2 'the game uses framebuffer to prevent screen drawing artefacts FRAMEBUFFER create FRAMEBUFFER write f 'initial target food counter=0 '---------------------- this is the main game loop -------------------------- 'the game stops when one player size exceeds the screen limits Do 'read the FIFO's that contain the NES controller keys PIO read 1,0,5,h%() 'read 5 words from FIFO sm0 p1=255-h%(4) 'converto to value 0-15 PIO read 1,1,5,h%() 'read 5 words from FIFO sm1 p2=255-h%(4) 'converto to value 0-15 'wipe old positions players eraseplayers 'move players v1=0:v2=0:dx1=0:dx2=0:dy1=0:dy2=0 If (p1 And 2) Then inc v1,1:inc x1,-s1:dx1=-1 If (p1 And 1) Then inc v1,1:inc x1,s1:dx1=1 If (p1 And 8) Then inc v1,1:inc y1,-s1:dy1=-1 If (p1 And 4) Then inc v1,1:inc y1,s1:dy1=1 If (p2 And 2) Then inc v2,1:inc x2,-s2:dx2=-1 If (p2 And 1) Then inc v2,1:inc x2,s2:dx2=1 If (p2 And 8) Then inc v2,1:inc y2,-s2:dy2=-1 If (p2 And 4) then inc v2,1:inc y2,s2:dy2=1 'allow wrap around If x1<0 Then x1=x1+MM.HRes If x1>MM.HRes Then x1=x1-MM.HRes If y1<0 Then y1=y1+MM.VRes If y1>MM.VRes Then y1=y1-MM.VRes If x2<0 Then x2=x2+MM.HRes If x2>MM.HRes Then x2=x2-MM.HRes If y2<0 Then y2=y2+MM.VRes If y2>MM.VRes Then y2=y2-MM.VRes 'calculate distances d12=Sqr((x1-x2)^2 + (y1-y2)^2) d10=Sqr((x1-x0)^2 + (y1-y0)^2) d20=Sqr((x0-x2)^2 + (y0-y2)^2) 'game rules, collision between players is punished 'player who moves is culprit If d12<(r1+r2) Then If v1>0 Then r1=r1/1.5 If v2>0 Then r2=r2/1.5 r1=Max(r1,3) r2=Max(r2,3) EndIf 'you eat, you grow.... If d10<(r1+r0) Then r1=r1*2:newfood If d20<(r0+r2) Then r2=r2*2:newfood 'write new player /target positions and sizes drawplayers food 'decide winner If r1>MM.VRes/2 Then Text MM.HRes/2,MM.VRes/2,"Blue Wins","CM",1,1,RGB(yellow) u1=u1+1 prestart EndIf If r2>MM.VRes/2 Then Text MM.HRes/2,MM.VRes/2,"Red Wins","CM",1,1,RGB(yellow) u2=u2+1 prestart EndIf 'score update Text 0,0,Str$(u1),"LT",1,1,RGB(blue) Text MM.HRes,0,Str$(u2),"RT",1,1,RGB(red) 'update screen FRAMEBUFFER copy f,n,b Pause 50 Loop Until p1=&h40 'loop until B key press CLS Text MM.HRes/2, MM.VRes/2, "Bye","CM",1,1,RGB(yellow) FRAMEBUFFER copy f,n,b End 'show player info and hold restart until controller key pressed Sub prestart Text MM.HRes/2,30+MM.VRes/2,"A=restart, B=stop","CM",1,1,RGB(yellow) FRAMEBUFFER copy f,n,b Do Pause 50 PIO read 1,0,5,h%() 'read 5 words from FIFO sm0 p1=255-h%(4) 'convert to value 0-255 Loop Until p1=&h80 Or p1=&h40 CLS 'x,y are coordinates, r=radius, c=color, s=speed x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green) x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5 x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=5 'initial target food End Sub 'seed new green circle Sub newfood c=c0:c0=0:food:c0=c 'erase old food x0=MM.HRes*Rnd() y0=MM.VRes*Rnd() End Sub 'the introscreen Sub introscreen CLS Text MM.HRes/2,MM.VRes/2-50,"CIRCLE","CM",1,2,RGB(yellow) Pause 2000 Text MM.HRes/2,MM.VRes/2,"a 2 player game","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+20,"for VGA picomite GAME","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+40,"and 2 NES controllers","CM",1,1,RGB(yellow) Pause 1500 Box 0,MM.VRes/2-10,MM.HRes,MM.VRes,,0,0 Pause 1500 Text MM.HRes/2,MM.VRes/2,"arrows to move, B to stop","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+20,"eat green to grow and win","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+40,"avoid collisions","CM",1,1,RGB(yellow) Pause 1500 Text MM.HRes/2,MM.VRes/2+60,"--- GET READY ---","CM",1,1,RGB(yellow) Pause 2000 End Sub sub food Circle x0-4,y0-2,r0,,,c0,c0 Circle x0+4,y0,r0,,,c0,c0 line x0-3,y0,x0+5,y0-2*r0,1,c0 end sub sub eraseplayers circle x1,y1,r1+10,,,0,0 Circle x2,y2,r2+10,,,0,0 end sub sub drawplayers inc counter,1 'if r1>50 then c1=rgb(cyan) else c1=rgb(blue) 'draw player if v1>0 then 'draw player 1 body Circle x1,y1,r1,,,c1,c1 'eyes when moving v=0.7+(v1=1)*0.3 'sqrt 2 if 45 degrees dy=6*dy1:dx=6*dx1 circle x1+v*((dx1*r1)-dy),y1+v*((dy1*r1)+dx),5,,,cw,cw circle x1+v*((dx1*r1)+dy),y1+v*((dy1*r1)-dx),5,,,cw,cw circle x1+v*((dx1*(r1+2)-dy)),y1+v*((dy1*(r1+2))+dx),2,,,9,9 circle x1+v*((dx1*(r1+2)+dy)),y1+v*((dy1*(r1+2))-dx),2,,,0,0 else 'draw player 1 body Circle x1,y1,r1,,,c1,c1 'not moving, eyes sleepy circle x1+6,y1+2,5,,,cw,cw circle x1-6,y1+2,5,,,cw,cw circle x1+6,y1-1,5,,,c1,c1 if counter and 28 then circle x1-6,y1+4,2,,,0,0 else circle x1-6,y1-1,5,,,c1,c1 end if end if 'if r2>50 then c1=rgb(cyan) else c1=rgb(blue) 'draw player if v2>0 then 'draw player 1 body Circle x2,y2,r2,,,c2,c2 'eyes when moving v=0.7+(v2=1)*0.3 'sqrt 2 if 45 degrees dy=6*dy2:dx=6*dx2 circle x2+v*((dx2*r2)-dy),y2+v*((dy2*r2)+dx),5,,,cw,cw circle x2+v*((dx2*r2)+dy),y2+v*((dy2*r2)-dx),5,,,cw,cw circle x2+v*((dx2*(r2+2)-dy)),y2+v*((dy2*(r2+2))+dx),2,,,9,9 circle x2+v*((dx2*(r2+2)+dy)),y2+v*((dy2*(r2+2))-dx),2,,,0,0 else 'draw player 1 body Circle x2,y2,r2,,,c2,c2 'not moving, eyes sleepy circle x2+6,y2+2,5,,,cw,cw circle x2-6,y2+2,5,,,cw,cw circle x2+6,y2-1,5,,,c2,c2 if counter+14 and 30 then circle x2-6,y2-1,5,,,c2,c2 else circle x2-6,y2+4,2,,,0,0 end if end if end sub Edited 2022-08-19 04:36 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
PicomiteVGA PETSCII ROBOTS |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1114 |
Goedemorgen looks nice ... just, i dont have 2 Controllers so far and I am only one person, so I couldn't enjoy it so much ;-) Next step could be a AI for a Computeropponent :-) 'no comment |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Hi Martin, Thank you for your response. Yes, I also realized that the audience in this forum are not the type that share their hobby with friends at home and would/could playtest games for multiple players. There is lot's of love for the topic on the forum, but in essence the forum members are loners, that have a friends community on the internet. Not as much at their homes. I am in the happy circumstance I can invite my wife to play (and she actually does), and have 2 grand children that would playtest. But not all are so fortunate. So I guess the 2 port GAMEpicoVGA is doomed... Single port it is, with AI to play against. At the moment I have no intention to add AI, but that may change when long winter nights bring the idea's how to do it. I currently have no clue how to design a AI that could be tuned to different levels. Regards, Volhout Edited 2022-08-19 18:30 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1114 |
Your Listing is very helpful from the educational perspective, to see how Piones is applied in practice. For this reason alone, I am very grateful. At the moment I am waiting for the delivery of right angle connectors for VGA and joysticks. Here, in the countryside, you don't have an electronics-part-store, so you have to order everything. But somehow, one get used to this . -- Good to read that your wife and grandchildren share your hobby, or at least support you Since my girlfriend doesn't share my enthusiasm for making music, programming and electronics, I don't have time for this on weekends. My daughter is just as crazy as I am, but she hasn't lived with me for a long time. So you are right, "Single port it is" . Tot ziens Mart!n this is, how far my work on the PicoGameBoard has progressed till now. Edited 2022-08-19 19:22 by Martin H. 'no comment |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4043 |
Hi Volhout, Thanks for sharing. I'm having to ration my time at the moment so haven't had a chance to do much more than fire it up on MMB4W after commenting out all the PicoMite specific stuff, it's not playable like that but it looks interesting. Hopefully things will quiet down when the kids (and wife) go back to school and then maybe I will be able to give it more attention. I'm sure my wife will play it with me once we get a moment and I'll show it to my RISC OS cronies at our next meeting too. Maybe it's just on a slow burn, I still think (controller woes aside) that the PicoGAME VGA is a fun platform but it needs a push on the appropriate social media channels and it seems none of us are really into that. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
We need the internet gurus to show us how to get our *mites linked by serial over IP using ESPxxxx (or whatever) so we can get our multiplayer gaming action going, just like the kiddies. Visit Vegipete's *Mite Library for cool programs. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
That leaves me out then. :) I get confused by COM ports, I don't need IP stuff to confuse me any further. You can link a couple (or more?) of Version 2 PicoGAMEs via the JDY-40 at 2.4GHz though, although it's not exactly a substitute for IP. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Slightly modified version for MMB4W. On holiday only a PC with MMB4W...so all focus is on that... 'circle_one, a single player game for VGA picomite GAME 'play against AI 'this version is adapted to MMB4W   '------------------------------ setup MMB4W ---------------------------  ' MODE 2  CLS  AIspeed=2  'initial values for the players and the target food 'target (green) index 0, player (keyboard - blue) index 1 'right player (AI - red) index 2  sz=MM.HRes/40  'x,y are coordinates, r=radius, c=color, s=speed  x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green)  x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5  x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=1'5  cw=RGB(white)  'intro and start score reset  introscreen  u1=0:u2=0  'scores player and AI   'initial target  food  counter=0   '---------------------- this is the main game loop -------------------------- 'the game stops when one player size exceeds the screen limits   Do   'read keyboard   a$=inkey$   If Asc(a$)=131 Then p1=1   If Asc(a$)=130 Then p1=2   If Asc(a$)=128 Then p1=8   If Asc(a$)=129 Then p1=4   if asc(a$)=27 then p1=16 'read AI   moveAI   'wipe old positions players   eraseplayers   'move players   v1=0:v2=0:dx1=0:dx2=0:dy1=0:dy2=0   If (p1 And 2) Then Inc v1,1:Inc x1,-s1:dx1=-1   If (p1 And 1) Then Inc v1,1:Inc x1,s1:dx1=1   If (p1 And 8) Then Inc v1,1:Inc y1,-s1:dy1=-1   If (p1 And 4) Then Inc v1,1:Inc y1,s1:dy1=1   if (p1 and 16) then v1=0:dx1=0:dy1=0       '<ESC> stops   If (p2 And 2) Then Inc v2,1:Inc x2,-s2*AIspeed:dx2=-1   If (p2 And 1) Then Inc v2,1:Inc x2,s2*AIspeed:dx2=1   If (p2 And 8) Then Inc v2,1:Inc y2,-s2*AIspeed:dy2=-1   If (p2 And 4) Then Inc v2,1:Inc y2,s2*AIspeed:dy2=1   'allow wrap around   If x1<0 Then x1=x1+MM.HRes   If x1>MM.HRes Then x1=x1-MM.HRes   If y1<0 Then y1=y1+MM.VRes   If y1>MM.VRes Then y1=y1-MM.VRes   If x2<0 Then x2=x2+MM.HRes   If x2>MM.HRes Then x2=x2-MM.HRes   If y2<0 Then y2=y2+MM.VRes   If y2>MM.VRes Then y2=y2-MM.VRes     'calculate distances   d12=Sqr((x1-x2)^2 + (y1-y2)^2)   d10=Sqr((x1-x0)^2 + (y1-y0)^2)   d20=Sqr((x0-x2)^2 + (y0-y2)^2)   'game rules, collision between players is punished 'player who moves is culprit   If d12<(r1+r2) Then    If v1>0 Then r1=r1/1.5    If v2>0 Then r2=r2/1.5    r1=Max(r1,3)    r2=Max(r2,3)   EndIf   'you eat, you grow....   If d10<(r1+r0) Then r1=r1*2:newfood   If d20<(r0+r2) Then r2=r2*2:newfood   'write new player /target positions and sizes   drawplayers   food   'decide winner   If r1>MM.VRes/2 Then    Text MM.HRes/2,MM.VRes/2,"Blue Wins","CM",1,1,RGB(yellow)    u1=u1+1    prestart   EndIf   If r2>MM.VRes/2 Then    Text MM.HRes/2,MM.VRes/2,"Red Wins","CM",1,1,RGB(yellow)    u2=u2+1    prestart   EndIf   'score update   Text 0,0,Str$(u1),"LT",1,1,RGB(blue)   Text MM.HRes,0,Str$(u2),"RT",1,1,RGB(red)   'update screen   Pause 50  Loop Until a$="b"   CLS  Text MM.HRes/2, MM.VRes/2, "Bye","CM",1,1,RGB(yellow) End   '------------------------------- subs ------------------------------ sub moveAI  AIx=int((x0-x2)/2)  AIy=int((y0-y2)/2)  p2=0 'decide preferred direction  if abs(AIx)>=abs(AIy) then 'X is preferred direction   movAIx  end if  if Abs(AIx)<=abs(AIy) then 'Y preferred direction   movAIy  end if end sub  sub movAIx  if AIx<0 then   p2=p2+2  else   p2=p2+1  end if end sub  sub movAIy  if AIy<0 then   p2=p2+8  else   p2=p2+4  end if end sub   'show player info and hold restart until controller key pressed Sub prestart  Text MM.HRes/2,30+MM.VRes/2,"A=continue, B=stop","CM",1,1,RGB(yellow)   Do   Pause 50   a$=inkey$  Loop Until a$="a" or a$="b"   if a$="b" then end  CLS 'x,y are coordinates, r=radius, c=color, s=speed 'speed is increased every level...so prepare.....  x0=MM.HRes/2:y0=MM.VRes/3:r0=sz:c0=RGB(green)  x1=MM.HRes/3:y1=2*MM.VRes/3:r1=sz:c1=RGB(blue):s1=5+(u1+u2)/4  x2=2*MM.HRes/3:y2=2*MM.VRes/3:r2=sz:c2=RGB(red):s2=1+(u1+u2)/4  'initial target  food End Sub   'seed new green circle Sub newfood  c=c0:c0=0:food:c0=c 'erase old food  x0=MM.HRes*Rnd()  y0=MM.VRes*Rnd() End Sub   'the introscreen Sub introscreen  CLS  Text MM.HRes/2,MM.VRes/2-50,"CIRCLE ONE","CM",1,2,RGB(yellow)  Pause 2000  Text MM.HRes/2,MM.VRes/2,"a single player game","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+20,"for MMB4W","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+40,"and keyboard control","CM",1,1,RGB(yellow)  Pause 1500  Box 0,MM.VRes/2-10,MM.HRes,MM.VRes,,0,0  Pause 1500  Text MM.HRes/2,MM.VRes/2,"arrows to move, B to stop","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+20,"eat apples to grow and win","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+40,"avoid collision while moving","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+60,"<ESC> to stop, avoid collision damage","CM",1,1,RGB(yellow)  Pause 1500  Text MM.HRes/2,MM.VRes/2+80,"--- GET READY ---","CM",1,1,RGB(yellow)  Pause 2000 End Sub  Sub food  Circle x0-4,y0-2,r0,,,c0,c0  Circle x0+4,y0,r0,,,c0,c0  Line x0-3,y0,x0+5,y0-2*r0,1,c0 End Sub  Sub eraseplayers  Circle x1,y1,r1+10,,,0,0  Circle x2,y2,r2+10,,,0,0 End Sub  Sub drawplayers  Inc counter,1 'if r1>50 then c1=rgb(cyan) else c1=rgb(blue) 'draw player  If v1>0 Then 'draw player 1 body   Circle x1,y1,r1,,,c1,c1 'eyes when moving   v=0.7+(v1=1)*0.3 'sqrt 2 if 45 degrees   dy=6*dy1:dx=6*dx1   Circle x1+v*((dx1*r1)-dy),y1+v*((dy1*r1)+dx),5,,,cw,cw   Circle x1+v*((dx1*r1)+dy),y1+v*((dy1*r1)-dx),5,,,cw,cw   Circle x1+v*((dx1*(r1+2)-dy)),y1+v*((dy1*(r1+2))+dx),2,,,9,9   Circle x1+v*((dx1*(r1+2)+dy)),y1+v*((dy1*(r1+2))-dx),2,,,0,0  Else 'draw player 1 body   Circle x1,y1,r1,,,c1,c1 'not moving, eyes sleepy   Circle x1+6,y1+2,5,,,cw,cw   Circle x1-6,y1+2,5,,,cw,cw   Circle x1+6,y1-1,5,,,c1,c1   If counter And 28 Then    Circle x1-6,y1+4,2,,,0,0   Else    Circle x1-6,y1-1,5,,,c1,c1   EndIf  EndIf  'if r2>50 then c1=rgb(cyan) else c1=rgb(blue) 'draw player  If v2>0 Then 'draw player 1 body   Circle x2,y2,r2,,,c2,c2 'eyes when moving   v=0.7+(v2=1)*0.3 'sqrt 2 if 45 degrees   dy=6*dy2:dx=6*dx2   Circle x2+v*((dx2*r2)-dy),y2+v*((dy2*r2)+dx),5,,,cw,cw   Circle x2+v*((dx2*r2)+dy),y2+v*((dy2*r2)-dx),5,,,cw,cw   Circle x2+v*((dx2*(r2+2)-dy)),y2+v*((dy2*(r2+2))+dx),2,,,9,9   Circle x2+v*((dx2*(r2+2)+dy)),y2+v*((dy2*(r2+2))-dx),2,,,0,0  Else 'draw player 1 body   Circle x2,y2,r2,,,c2,c2 'not moving, eyes sleepy   Circle x2+6,y2+2,5,,,cw,cw   Circle x2-6,y2+2,5,,,cw,cw   Circle x2+6,y2-1,5,,,c2,c2   If counter+14 And 30 Then    Circle x2-6,y2-1,5,,,c2,c2   Else    Circle x2-6,y2+4,2,,,0,0   EndIf  EndIf  End Sub  > There are several strategies to win from the AI (the red creature). Block, travel across window edges, Use <ESC> to stop (and not get damage whe the red creature bumps into you). Only when moving during the collision you get damage. Or simply delay your opponent by accepting damage, but make him shrink also.... Have fun, Volhout Edited 2023-08-11 00:20 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Print this page |