AutoHotkey Community

It is currently May 27th, 2012, 11:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Ahkroid, classic game
PostPosted: June 19th, 2010, 4:14 pm 
Offline
User avatar

Joined: October 31st, 2008, 9:39 am
Posts: 641
Location: France
Image

AHK_B or more, don't need extra things, arrow for move, space for shot, have fun !

Code:
; heart form for your girl friend...
; formR1:="0,-20,8,-28,20,-28,28,-20,28,-8,16,12,0,28,-16,12,-28,-8,-28,-20,-20,-28,-8,-28,0,-20"
; formR2:="0,-10,4,-14,10,-14,14,-10,14,-4,8,6,0,14,-8,6,-14,-4,-14,-10,-10,-14,-4,-14,0,-10"
; formR3:="0,-5,2,-7,5,-7,7,-5,7,-2,4,3,0,7,-4,3,-7,-2,-7,-5,-5,-7,-2,-7,0,-5"

#SingleInstance Force
#Persistent
#NoEnv
Process, Priority, , High
SetBatchLines, -1
OnExit, ExitSub

Left:="Left"        ; turn left
Right:="Right"      ; turn right
Up:="Up"            ; move forward
Down:="Down"        ; move backward
Space:="Space"      ; use weapon

VarSetCapacity(ptWin, 16, 0)
NumPut(W:=512, ptWin, 8) , NumPut(H:=384, ptWin, 12)
Gui, Show, w%W% h%H%, Ahkroid
  hdcWin := DllCall("GetDC", "UInt", hwnd:=WinExist("A"))
  hdcMem := DllCall("CreateCompatibleDC", "UInt", hdcWin)
  hbm := DllCall("CreateCompatibleBitmap", "uint", hdcWin, "int", W, "int", H)
DllCall("SelectObject", "uint", hdcMem, "uint", hbm)

X:=W/2 , Y:=H/2 , Vx:=Vy:=Va:=cd:=score:=0 , shield:="||||||||||" , nRoid:=6
  formS1:="0,0,10,5,0,-15,-10,5,0,0"
  formS2:="0,10,10,5,0,-15,-10,5,0,10"
VarSetCapacity(ptShip, 40)

  formB1:="-1,0,0,-1,1,0,0,1,-1,0"
VarSetCapacity(ptBall, 40)

  formR1:="-12,-28,0,-20,16,-28,28,-16,16,-8,28,8,12,28,-8,20,-16,28,-28,16,-20,0,-28,-16,-12,-28"
  formR2:="-6,-14,0,-10,8,-14,14,-8,8,-4,14,4,6,14,-4,10,-8,14,-14,8,-10,0,-14,-8,-6,-14"
  formR3:="-3,-7,-0,-5,4,-7,7,-4,4,-2,7,2,3,7,-2,5,-4,7,-7,4,-5,0,-7,-4,-3,-7"
VarSetCapacity(ptRoid, 104)
loop %nRoid%
  listRoid .= "|1," rand(0, W, X) "," rand(0, H, Y) "," rand(0.0, 6)-3 "," rand(0.0, 6)-3

SetTimer, Update, 25
return

; --------------------------------

Update:
Critical

DllCall("FillRect", "uint", hdcMem, "uint", &ptWin, "uint", 0)

DllCall("TextOut", "uint", hdcMem, "uint", 16, "uint", 8, "uint", &score, "uint", StrLen(score))
DllCall("TextOut", "uint", hdcMem, "uint", 16, "uint", 24, "uint", &shield, "uint", StrLen(shield))

; ----

Va += GetKeyState(Left) ? -0.1 : GetKeyState(Right) ? 0.1 : 0
formS0:="" , form := GetKeyState(Up) ? formS2 : formS1
loop, parse, form, `,
  a_index & 1 ? i1:=a_loopfield : formS0 .= i1*cos(Va)-a_loopfield*sin(Va) "," i1*sin(Va)+a_loopfield*cos(Va) ","

Vs := GetKeyState(Up) ? 0.4 : GetKeyState(Down) ? -0.2 : 0
Vx:=Vx*0.95+sin(Va)*Vs , Vy:=Vy*0.95-cos(Va)*Vs
X:= X<0 ? W : X>W ? 0 : X+Vx , Y:= Y<0 ? H : Y>H ? 0 : Y+Vy

DllCall("DeleteObject", "UInt", hShip)
loop, parse, formS0, `,
    NumPut(a_loopfield+(a_index & 1 ? X : Y), ptShip, a_index*4-4)
DllCall("Polyline", "uint", hdcMem, "uint", &ptShip, "int", 5)
hShip := DllCall("CreatePolygonRgn", "uint", &ptShip, "int", 4, "int", 1)

; ----

cd-= cd>0 ? 1 : 0
if ( GetKeyState(Space) && cd=0 )
  cd:=5 , listBall .= "|" a_tickcount "," X+sin(Va)*10 "," Y-cos(Va)*10 "," Va

loop, parse, listBall, |
{
  if a_index=1
    continue
  loop, parse, a_loopfield, `,
    i%a_index%:=a_loopfield
  if (i1+1000 < a_tickcount) {
    StringReplace, listBall, listBall, % "|" i1 "," i2 "," i3 "," i4 ,
    continue
  }
    iX:=i2+sin(i4)*8 , iY:=i3-cos(i4)*8
    iX:= iX<0 ? W : iX>W ? 0 : iX , iY:= iY<0 ? H : iY>H ? 0 : iY
    StringReplace, listBall, listBall, % "|" i1 "," i2 "," i3 "," i4 , % "|" i1 "," iX "," iY "," i4
    loop, parse, formB1, `,
      NumPut(a_loopfield+(a_index & 1 ? iX : iY), ptBall, a_index*4-4)
    DllCall("Polyline", "uint", hdcMem, "uint", &ptBall, "int", 5)
}

; ----

loop, parse, listRoid, |
{
  id:=a_index-1
  if a_index=1
    continue
  loop, parse, a_loopfield, `,
    i%a_index%:=a_loopfield
  iX:= i2+i4<0 ? W : i2+i4>W ? 0 : i2+i4 , iY:= i3+i5<0 ? H : i3+i5>H ? 0 : i3+i5
  StringReplace, listRoid, listRoid, % "|" i1 "," i2 "," i3 "," i4 "," i5 , % "|" i1 "," iX "," iY "," i4 "," i5
  loop, parse, formR%i1%, `,
    NumPut(a_loopfield+(a_index & 1 ? iX : iY), ptRoid, a_index*4-4)
  DllCall("Polyline", "uint", hdcMem, "uint", &ptRoid, "int", 13)
  hRoid := DllCall("CreatePolygonRgn", "uint", &ptRoid, "int", 12, "int", 1)

  loop, parse, listBall, |
  {
    if a_index=1
      continue
    loop, parse, a_loopfield, `,
      t%a_index%:=a_loopfield
    if ( DllCall("PtInRegion", "uint", hRoid, "uint", t2, "uint", t3) <> 0 )
    {
      StringReplace, listBall, listBall, % "|" t1 "," t2 "," t3 "," t4 ,
      StringReplace, listRoid, listRoid, % "|" i1 "," iX "," iY "," i4 "," i5 ,
      score+=i1*5
      if (i1<3) {
        i1++
        loop 2
          listRoid .= "|" i1 "," iX "," iY "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
      }
    }
  }

  if ( DllCall("CombineRgn", "uint", hRoid, "uint", hRoid, "uint", hShip, "int", 1) <> 1 ) {
  Vx:=i4 , Vy:=i5
  shield := SubStr(shield, 1, -1)
    if (shield="") {
      msgbox %score% points
      Reload
    }
  StringReplace, listRoid, listRoid, % "|" i1 "," iX "," iY "," i4 "," i5 ,
    if (i1<3) {
      i1++
      loop 2
        listRoid .= "|" i1 "," iX "," iY "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
    }
  }

DllCall("DeleteObject", "UInt", hRoid)
}

; -----

if (id<nRoid-1) {
nRoid++ , shield.="|"
loop %nRoid%
  listRoid .= "|1," rand(0, W, X) "," rand(0, H, Y) "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
}

DllCall("BitBlt", "uint", hdcWin, "int", 0, "int", 0, "int", W, "int", H, "uint", hdcMem, "int", 0, "int", 0, "uint", 0xCC0020)
return

; --------------------------------

Rand(min=0, max=1, mask="") {
loop {
  Random, result, min, max
  if ( mask="" || result<mask-100 || result>mask+100 )
    return result
  }
}

ExitSub:
guiclose:
  DllCall("DeleteObject", "UInt", hShip)
  DllCall("DeleteObject", "UInt", hRoid)
  DllCall("DeleteObject", "UInt", hbm)
  DllCall("DeleteDC", "UInt", hdcMem)
  DllCall("ReleaseDC", "UInt", hwnd, "UInt", hdcWin)
exitapp


Last edited by Zaelia on May 13th, 2012, 7:00 pm, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2010, 4:27 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
Holy crap. Awesome work!

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2010, 5:02 pm 
Offline

Joined: July 30th, 2007, 11:32 pm
Posts: 581
Very well made! A few suggestions:
- Instead of having new asteroids appear out of nowhere, can't you make them come in from the sides?
- How about a few powerups? Like spread-fire, rapid-fire, bombs...

Great work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 3:11 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Surprisingly good! The code looks deceptively short. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 11:33 am 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
impressive :)

it would be nice to be able to move and shoot at the same time

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 12:08 pm 
Offline

Joined: April 14th, 2009, 10:40 am
Posts: 182
Woooahhh!!!
Amazing script with less than 200 lines!
I hope the game is not over!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 2:47 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Quote:
Sat Jun 19, 2010 4:14 pm

BEST BIRTHDAY EVER.


This is awesome


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 6:59 pm 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1718
Location: Somewhere near you
Wow another classic game created with ahk!
I missed the snake game from Nokia classic =)

Image
Carcophan

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2010, 11:43 pm 
Offline
User avatar

Joined: October 31st, 2008, 9:39 am
Posts: 641
Location: France
Thanks all for your positive comments.

I made some choices that may be objectionable, I want to do a game with a good efficiency, like the arcade version of Asteroid...

@ TheGood : roid don't appear from nowhere I include a "mask" to my random function for prevent collision, it's like a safe area around the ship. However if you want a shoot em up with a "scroll scene" ( for example space invader, xenon,... ) it's possible of course:
Code:
listRoid .= "|1," rand(0, W, X) "," rand(0, H, Y) "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
; AddToListRoid = polygon form , x pos, y pos, x part of speed, y part of speed ( like a vector )

listRoid .= "|1," rand(0, W) ",1," rand(0.0, 6)-3 "," rand(0.0, 3)
; roid appears at top front line , and have speed to go to bottom
; if you want that roid don't respawn like a miror you need to escape some tests ( roid>W ? 0 , roid > H ? 0 ... )

For add other weapon or bonus, yes I want but it's hard to implement with simplicity and dllcall with multipolygon burn CPU very fast, ahk have limitation too, the most important is memory leak with region handle (it's a strange bug, but that's why I don't keep all handle and use the same handle for combine region).
Code:
 ; tri shoot weapon, and you see limit of this script with lag (too much bullet and roid , PtInRegion is faster than other detection collision but false with hight speed and bullet is only one point != form than I draw)
; That's why I use Polyline() and not Polygon for have a not full ( but no colored) polygon, require to add one point for finish the form (start point=finish point) and it's faster...
if ( GetKeyState("Space") ) ; don't use cd variable (cd=cooldown)
  {
  listBall .= "|" a_tickcount "," X+sin(Va)*10 "," Y-cos(Va)*10 "," Va
  listBall .= "|" a_tickcount "," X+sin(Va+1.57)*10 "," Y-cos(Va+1.57)*10 "," Va   ; 1.57 = pi/2 <=> left or right of ship
  listBall .= "|" a_tickcount "," X+sin(Va-1.57)*10 "," Y-cos(Va-1.57)*10 "," Va
  }


@ evl , TomXIII : yes, I love tiny concept :o

@ Delusion : yes, you can, but keyboard is "strange" that's why I include custom key. For example if I use space for shoot I can't use left+up+space on my french keyboard that's why I choice control for shoot, try to change keys for shoot and move because windows can intercept this key and depends of your keyboard manufacture (however, I will try to use a hook). In other word, the game allow you to move and shoot, if they are problem it's your computer and press 3 key at same time is always a problem :) ...
edit: the common reason is your hardware, problem is the keyboard matrix circuit...
Image
Other thing, bullet have a fix speed, so at high speed of the ship your bullet is slow relatively to ship... dunno if I will change this for to add the magnitude of ship vector to bullet vector...

@ Carcophan : happy birthday :)
I do this script for "fathers day" (in France), which reminds me all the time I spend with my father has to play original Asteroid on Atari 7800, we could play with 2 ships on the same game!

@ tomoe_uehara : hum, I have already view a snake game at autohotkey.net WIKI (game section) but not sure...

If you want to know more about my compact script I asked help here : http://www.autohotkey.com/forum/viewtopic.php?t=59265


Last edited by Zaelia on May 17th, 2012, 2:53 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 21st, 2010, 4:06 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
very nice!

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2010, 12:52 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Hats off! Very good!

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Quick change
PostPosted: September 21st, 2010, 2:38 pm 
Offline

Joined: January 9th, 2009, 12:06 am
Posts: 85
Location: Oklahoma City
I added the following sections to give a semi random power upgrade

Code:
SetTimer, powerups, 30000


Code:
if Powerup = 5
{
if ( GetKeyState("Space") ) ; don't use cd variable (cd=cooldown)
  {
  listBall .= "|" a_tickcount "," X+sin(Va+1.25)*10 "," Y-cos(Va+1.25)*10 "," Va   ; 1.57 = pi/2 <=> left or right of ship
  listBall .= "|" a_tickcount "," X+sin(Va-1.25)*10 "," Y-cos(Va-1.25)*10 "," Va
  }
}
Else if Powerup = 4
{
if ( GetKeyState("Space") ) ; don't use cd variable (cd=cooldown)
  {
  listBall .= "|" a_tickcount "," X+sin(Va)*10 "," Y-cos(Va)*10 "," Va
  listBall .= "|" a_tickcount "," X+sin(Va+1.57)*10 "," Y-cos(Va+1.57)*10 "," Va   ; 1.57 = pi/2 <=> left or right of ship
  listBall .= "|" a_tickcount "," X+sin(Va-1.57)*10 "," Y-cos(Va-1.57)*10 "," Va
  }
}
else
if ( GetKeyState("Space") ) ; don't use cd variable (cd=cooldown)
  {
  if ( GetKeyState(Space) && cd=0 )
  cd:=5 , listBall .= "|" a_tickcount "," X+sin(Va)*10 "," Y-cos(Va)*10 "," Va
  }


Code:
Powerups:
if powerup > 3
  SetTimer, powerups, 30000
 
 
Random, powerup, 0, 5
if powerup > 3
  SetTimer, powerups, 10000

_________________
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2010, 3:00 pm 
Offline

Joined: August 25th, 2010, 2:32 pm
Posts: 36
Stellar! :lol:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 13th, 2012, 5:54 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Just saw it... Amazing! recently Drugwash mentioned KKrieger to me, and now this.. I'm blown!
Respect.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 14th, 2012, 1:40 am 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 365
Location: north bay, california
I guess i never expressed my awe in this thread after seeing this either, but super impressive (and not just because i collect old arcade games)

thanks
gwarble

_________________
Notify() | Compile() | Instance() | LV_Group()
EitherMouse
Recommended: AHK_L (don't forget its a superset of _Basic)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: rrhuffy and 54 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group