Jump to content

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

Ahkroid, classic game


  • Please log in to reply
18 replies to this topic
Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
Posted Image

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

; 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


tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Holy crap. Awesome work!

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
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!

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Surprisingly good! The code looks deceptively short. :D

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
impressive :)

it would be nice to be able to move and shoot at the same time
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

TomXIII
  • Members
  • 182 posts
  • Last active: Feb 28 2011 11:42 PM
  • Joined: 14 Apr 2009
Woooahhh!!!
Amazing script with less than 200 lines!
I hope the game is not over!

Carcophan
  • Members
  • 1578 posts
  • Last active: Nov 27 2013 06:46 PM
  • Joined: 24 Dec 2008

Sat Jun 19, 2010 4:14 pm

BEST BIRTHDAY EVER.


This is awesome

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
Wow another classic game created with ahk!
I missed the snake game from Nokia classic =)

Posted Image
Carcophan


Zaelia
  • Members
  • 754 posts
  • Last active: Jan 17 2015 02:38 AM
  • Joined: 31 Oct 2008
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:
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).
; 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...
Posted 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 : <!-- m -->http://www.autohotke...pic.php?t=59265<!-- m -->

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
very nice!
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
Hats off! Very good!

No signature.


Aero98
  • Members
  • 112 posts
  • Last active: Mar 29 2013 03:42 PM
  • Joined: 08 Jan 2009
I added the following sections to give a semi random power upgrade

SetTimer, powerups, 30000

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
  }

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.

justjim
  • Members
  • 36 posts
  • Last active: Oct 27 2011 10:14 PM
  • Joined: 25 Aug 2010
Stellar! :lol:

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Just saw it... Amazing! recently Drugwash mentioned KKrieger to me, and now this.. I'm blown!
Respect.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
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