Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Pacman Str(), still more horrible than the original


  • Please log in to reply
45 replies to this topic
Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Bugs:
Yes, they are a lot of bug, I have only fix event when 3 ghost are stuck ( 2 ghost eat one, and spawn at middle ) If a_index > 100 then p%i%:=185+i-x%i%
I include a peuso buffer for saving character in ghosts but if you eat a ghost at "~" they are a bug too, and a ghost can hide a the last point for win ( that's why now I don't use stringreplace, map, map, ., ., errorlevel but mxp variable )
And other bugs or special events... I think you have discover all, I have only do a tiny script, I spend more time to play than to code it :O

Fonts: courier bold is a very old school view and sans serif with monospaced, that's why it's was my choice, but lucida console is good too

SoundBeep: old school ambiance...
loop 13 -> soundbeep, exp(ln(440)+(a_index-1)/12*ln(2)) , 100
it's a tempered chromatic game, in short 440 = middle A, 12=semitone in a full octave, 440*2=880= middle hight A ( octave = double or half... in hertz ) , use - and not + for a down and not a up game
if you want to know more, search mathematic function for music and physical sound... becarefull they are 3 game, just intonation, pythagor game, and tempered game (easy use for computer)... if you do not understand the log neperian tell you that your ear does every day :O

Ghost intel: my ghost is not intelligent, that's why my map is very special and short, a ghost change direction when he touchs a wall, so we need a good managment with walls for create a lot of way loop...
For create a real AI, we need to add waypoint (at cross way) and range between ghost and pacman... I did choice do creat a tiny script.

Without AI! but good wall managment and change direction when it touchs a wall                                         
 
  
simple changer
                                    
oooo.ooooo                                          
oooo.ooooo
oooo......  <- changer here ..
......oooo  <- changer here ..
ooooo.oooo     (2x2 square point, block are not aligned, reverse direction)
ooooo.oooo

multi changer , try it :D it's the mess with settimer at 10ms
                                          
....o.....o....          
ooo.o.ooo.o.ooo             
....o.....o....          
.o.....o.....o.          
.o.ooo.o.ooo.o.             
.o.....o.....o.          
....o.....o....          
ooo.o.ooo.o.ooo            
....o.....o....

simple multi loop

ooooooooo
oooo....o
o....oo.o  <- changer at middle of this line
o.oo.oo.o     (block are not aligned, small and large loop, reverse direction)
o.oo.oo.o
o.......o
ooooooooo


                                         
original map          
I keep it because:
1- I created it with logic
2- I selected it with empirism
   (ghost dispatching was acceptable)

+----------+-----------+
|..o.......|........o..|
|.---.|.--.|.-.|.|.---.|
|.....|........|.|.....|
+-+.|.|.------.|.|.|.+-+
  |.|.|.        .|.|.|  
--+..... +~~~~+ .....+--
<< .---- |1234| ----. >>
--+..... +----+ .....+--
  |.|.|.        .|.|.|  
+-+.|.|.|.------.|.|.+-+
|.....|.|...@....|.....|
|.---.|.|.-.|.--.|.---.|
|..o........|.......o..|
+-----------+----------+    

for a visual look with wall changer ghost direction (char=X)
+x---x-x--x+x-x-x-x---x+
x..o.......x........o..x
|.-x-.|.--.|.-.|.|.-x-.|
x.....x........x.x.....x
+x+.|.|.x-xxxx.x.|.|.+x+
  |.|.x.        .x.|.|  
--x..... x~~~~x .....x--
<< .-x-x |1234| x-x-. >>

Customize: my version can't to be customized, we need to include more global variable and calculate maxpoint, max egs, line weight, where are teleporter (>>), and other things... sry
( loop, parse, mychar -> maxchar:=a_index -> msgbox % maxchar-1 )

Hehe, gratz MasterFocus, for enhance this script :) I edit my first post to talk about your version.

Fabiolus2010
  • Guests
  • Last active:
  • Joined: --
MasterFocus,


Trying to have a glimpse off your script and run it but get error when trying to run.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Have you edited something?
The code should work fine as provided.
What error are you getting?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Laraptor
  • Members
  • 41 posts
  • Last active: Jan 19 2011 09:48 PM
  • Joined: 29 Jan 2010
---------------------------
New AutoHotkey Script.ahk
---------------------------
Error at line 131.

Line Text: SubStr(gui_Board, 1, glob_GhostsOffset+glob_NextSpot-1) glob_NextSpot SubStr(gui_Board,
Error: Missing ")"

The program will exit.
---------------------------
OK
---------------------------




that is the error msg i get. I did not change anything in the code

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
I found the problem the line got seperated when he posted it :(
Alter it so to remove the extra enters and it should work :)
gui_Board := SubStr(gui_Board, 1, glob_GhostsOffset+glob_NextSpot-1) glob_NextSpot SubStr(gui_Board, glob_GhostsOffset+glob_NextSpot+1)


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Yeah. Change that and it'll work fine.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Fabiolus2010
  • Guests
  • Last active:
  • Joined: --
Thanks for the quick reply and for your good eyes, geez I going through the script trying to see what was going on.


Cheers

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
If you use the Wingdings font, you could get closer to the open/closed mouth of Pacman with char codes 0xDB..0xDE. It could alternate with a bullet to mimic the original effects. Even better, download some spacial fonts for free, e.g http://www.fontspace...category/pacman.

Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Thanks for this suggestion but:
Webdings is a good font but we can't find all the needed chars :(
Wingdings is very good but this fonts is not monospaced (all chars havn't the same width)
Monospaced fonts are very rare now, and sans serif two but it's just good for transparency...
Anybody know how to create a custom font ? :) but never mind, Courier is a very old school view I like it, it's like an ascii art :O

Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
I try an attempt to do a simple artificial intelligence, it's simple in my case, it check cross road and calculate the good direction , However it's a challenge , great difficulty :O it's just a try and not balanced... need to loose more time with this script...

#SingleInstance force
#NoEnv
#Persistent

str:="+----------+-----------+`n"
str.="|..o.......|........o..|`n"
str.="|.---.|.--.|.-.|.|.---.|`n"
str.="|.....|........|.|.....|`n"
str.="+-+.|.|.------.|.|.|.+-+`n"
str.="  |.|.|.        .|.|.|  `n"
str.="--+..... +~~~~+ .....+--`n"
str.="<< .---- |1234| ----. >>`n"
str.="--+..... +----+ .....+--`n"
str.="  |.|.|.        .|.|.|  `n"
str.="+-+.|.|.|.------.|.|.+-+`n"
str.="|.....|.|...@....|.....|`n"
str.="|.---.|.|.-.|.--.|.---.|`n"
str.="|..o........|.......o..|`n"
str.="+-----------+----------+`n"
str.=" life:0   score:"
spd:=175, pts:=0
gui, font, CWhite Bold, Courier
Gui, Color, black
gui, add, text, vmap, %str%
gui, show,, PACMAN Ascii

Start:
map:=str , inv:=0 , mxp:=141 , mxo:=4
x1:=x2:=x3:=x4:=-25 , y1:=y2:=y3:=y4:=-26 , z1:=z2:=z3:=z4:=-24
xP:=-1 , yP:=-2 , zP:=0
b1:=b2:=b3:=b4:=" "
Guicontrol,, map, %map%%pts%
sleep 500
SetTimer, Update, %spd%
sleep %spd%
SetTimer, Arrows, 30
return

Arrows:
if GetKeyState("Up")
  xP:=-25 , yP:=-26 , zP:=-24
if GetKeyState("Down")
  xP:=25 , yP:=24 , zP:=26
if GetKeyState("Left")
  xP:=-1 , yP:=-2 , zP:=0
if GetKeyState("Right")
  xP:=1 , yP:=0 , zP:=2
return

Update:
pP:=InStr(map, "@")
If ( pP+xP = 177 )
  pP:=198
else If ( pP+xP = 198 )
  pP:=177
cP:=SubStr(map, pP+xP, 1)
If ( cP = "+" || cP = "-" || cP = "|" || cP = "~" )
  xP:=bxP , yP:=byP , zP:=bzP
else
  bxP:=xP , byP:=yP , bzP:=zP
cP:=SubStr(map, pP+xP, 1)
If !( cP = "+" || cP = "-" || cP = "|" || cP = "~" )
  {
  If ( cP = "1" || cP = "2" || cP = "3" || cP = "4" )
    {
    if inv
      {
      map := SubStr(map, 1, 185+cP-1) . cP . SubStr(map, 185+cP+1)
      tmp:=b%cP% , b%cP%:=" " , cP:=tmp , pts+=200
      }
    else
      Goto GameOver
    }
    StringReplace, map, map, @, %a_space%
    map := SubStr(map, 1, pP+yP) "@" SubStr(map, pP+zP)
    If ( cP = "." )
      pts+=5 , mxp-=1
    If ( cP = "o" )
      inv:=20, pts+=50 , mxo-=1
  }

if ( mxp=0 && mxo=0 )
  Goto YouWin

if inv > 0
  inv--
else
  {
  loop 4
    {
    i:=a_index
    p%i%:=InStr(map, i)

; ArtificialWaypoint
wmap:=25
cross1 := SubStr(map, p%i%-wmap, 1)
cross2 := SubStr(map, p%i%+wmap, 1)
cross3 := SubStr(map, p%i%-1, 1)
cross4 := SubStr(map, p%i%+1, 1)
crosscount:=0
loop 4
{
  If ( cross%a_index% = "-" || cross%a_index% = "|" || cross%a_index% = "+" || cross%a_index% = "~" )
    crosscount++
}
if crosscount <= 1 ; If they are 3 or more char "way"
{
; ArtificialIntelligence
wmap:=25
posxP:=Mod(pP, wmap) , posyP:=Floor(pP/wmap)+1

  posx%i%:=Mod(p%i%, wmap) , posy%i%:=Floor(p%i%/wmap)+1
  directionV := posyP-posy%i% = 0 ? "NONE" : ( posyP-posy%i% < 0 ? "Up" : "Down" ) ; vertical direction
  directionH := posxP-posx%i% = 0 ? "NONE" : ( posxP-posx%i% < 0 ? "Left" : "Right" ) ; horizontal direction
  directionC1 := abs(posxP-posx%i%) < abs(posyP-posy%i%) ? directionV : directionH ; long direction
  directionC2 := abs(posxP-posx%i%) >= abs(posyP-posy%i%) ? directionV : directionH ; short direction
  directionC0 := x%i%>3 ? "Up" : ( x%i%>0 ? "Left" : ( x%i%<-3 ? "Down" : "Right" )) ; reverse direction
  if (directionC1 = directionC0)
    directionC1:=directionC2
  if (directionC1="Up")
    x%i%:=-25 , y%i%:=-26 , z%i%:=-24
  if (directionC1="Down")
    x%i%:=25 , y%i%:=24 , z%i%:=26
  if (directionC1="Left")
    x%i%:=-1 , y%i%:=-2 , z%i%:=0
  if (directionC1="Right")
    x%i%:=1 , y%i%:=0 , z%i%:=2
}

    c%i% := SubStr(map, p%i%+x%i%, 1)
    If !( c%i% = "@" || c%i% = "." || c%i% = " " || c%i% = "~" || c%i% = "o" )
      {
      loop
        {

if a_index = 1
{
; ArtificialIntelligence (BIS, same code, just need a function with i param)
wmap:=25
posxP:=Mod(pP, wmap) , posyP:=Floor(pP/wmap)+1

  posx%i%:=Mod(p%i%, wmap) , posy%i%:=Floor(p%i%/wmap)+1
  directionV := posyP-posy%i% = 0 ? "NONE" : ( posyP-posy%i% < 0 ? "Up" : "Down" ) ; vertical direction
  directionH := posxP-posx%i% = 0 ? "NONE" : ( posxP-posx%i% < 0 ? "Left" : "Right" ) ; horizontal direction
  directionC1 := abs(posxP-posx%i%) < abs(posyP-posy%i%) ? directionV : directionH ; long direction
  directionC2 := abs(posxP-posx%i%) >= abs(posyP-posy%i%) ? directionV : directionH ; short direction
  directionC0 := x%i%>3 ? "Up" : ( x%i%>0 ? "Left" : ( x%i%<-3 ? "Down" : "Right" )) ; reverse direction
  if (directionC1 = directionC0)
    directionC1:=directionC2
  if (directionC1="Up")
    x%i%:=-25 , y%i%:=-26 , z%i%:=-24
  if (directionC1="Down")
    x%i%:=25 , y%i%:=24 , z%i%:=26
  if (directionC1="Left")
    x%i%:=-1 , y%i%:=-2 , z%i%:=0
  if (directionC1="Right")
    x%i%:=1 , y%i%:=0 , z%i%:=2
}
else
{
        Random, rnd, 1, 4
        if rnd = 1
          x%i%:=-25 , y%i%:=-26 , z%i%:=-24
        if rnd = 2
          x%i%:=25 , y%i%:=24 , z%i%:=26
        if rnd = 3
          x%i%:=-1 , y%i%:=-2 , z%i%:=0
        if rnd = 4
          x%i%:=1 , y%i%:=0 , z%i%:=2
}

        c%i% := SubStr(map, p%i%+x%i%, 1)
        If ( c%i% = "@" || c%i% = "." || c%i% = " " || c%i% = "~" || c%i% = "o" )
          break
        If a_index > 100
          p%i%:=185+i-x%i%
        }
      }
    If ( c%i% = "@" )
      Goto GameOver
    StringReplace, map, map, %i%, % b%i%
    b%i% := SubStr(map, p%i%+x%i%, 1)
    map := SubStr(map, 1, p%i% + y%i%) . i . SubStr(map, p%i% + z%i%)
    }
  }
Guicontrol,, map, %map%%pts%
return

GameOver:
Guicontrol,, map, `n`n`n`n`n`n`n       GAME OVER`n        %pts%pts
pts:=0 , spd:=175
loop 3
soundbeep, exp(ln(440)-(a_index-1)/12*ln(2)) , 100
sleep 1000
Goto Start

YouWin:
pts+=500 , spd:=spd-(spd/10)
Guicontrol,, map, `n`n`n`n`n`n`n       YOU WIN !`n        %pts%pts
loop 3
soundbeep, exp(ln(440)+(a_index-1)*ln(2)) , 100
sleep 1000
Goto Start

GuiClose:
exitapp


jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006

you could get closer to the open/closed mouth of Pacman... to mimic the original effects.

#NoEnv

SetBatchLines, -1



Gui, Margin, 0

Gui, Color , Black

Gui, Font  , s50 , WebDings

Gui, Add   , Text, cYellow                  vBody , n

Gui, Add   , Text, xp+30 yp BackgroundTrans vMouth, 3

Gui, Font  , s15

Gui, Add   , Text, xp    yp BackgroundTrans vEye  , =

Gui, Show  , w%A_ScreenWidth%



Loop,50

 Gui, Add, Text

    , cWhite x+30 ys+20 BackgroundTrans v%A_Index%, <



SetTimer, Chomp

SetTimer, Move, 50

return

GuiClose:

 ExitApp



Chomp:

 GuiControl,% (t:=!t) ? "Hide":"Show", Mouth

return



Move:

 x += 5

 If !Mod(x,50)

  GuiControl, Hide,% Round(x/50)

 If (x > A_ScreenWidth) {

  x = -50

  Loop,50

   GuiControl, Show, %A_Index%

 }

 GuiControl, MoveDraw, Body ,% "x" x

 GuiControl, MoveDraw, Mouth,% "x" x+30

 GuiControl, MoveDraw, Eye  ,% "x" x+30

return
:lol:

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
@jaco0646: Hahaha nice! :D

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Lol, now I understand that Laszlo said, gratz jaco0646. Perhaps include it just for pacman player :O

I have update my recent post with AI, try it if your are bored, it's realy a challenge... and AI will be perfect for MasterFocus with editable map :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Anybody know how to create a custom font ?


Here is a demo ( not the game ) using ASCII.ttf, embedded into the script

Posted Image

<!-- m -->https://ahknet.autoh... ... f_demo.ahk<!-- m -->

Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Thx SKAN :)

I'm an idiot, the better way to do an ascii art and a pacman game with good char is to use the very old font from IBM, Amstrad, Amiga or other very old computer, monocrhom or VGA...

<!-- m -->http://en.wikipedia....i/Code_page_437<!-- m -->