Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- ; #Warn ; Enable warnings to assist with detecting common errors.
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- #Include,<gdip>
- SetBatchLines, -1
- pToken := Gdip_Startup()
- global game:={h:500,w:500,x:100,y:100,t:700}
- global snake:={w:22,l:5}
- global pre_length:=5
- gui,1: -caption +lastfound -dpiscale +E0x80000 +AlwaysOnTop
- GUI,1:Show,% "x" game.x " y" game.y " w" game.w " h" game.h
- hwndl:=WinExist()
- pbrush1:=Gdip_BrushCreateSolid("0xffaf0c0b")
- pbrush2:=Gdip_BrushCreateSolid("0xff00ff00")
- pbrush3:=Gdip_BrushCreateSolid("0xff0000ff")
- pbrush4:=Gdip_BrushCreateSolid("0x00ffffff")
- pbrush5:=Gdip_BrushCreateSolid("0xffffffff")
- pbrush6:=Gdip_BrushCreateSolid("0xff0c00b0")
- pPen1 := Gdip_CreatePenFromBrush(pBrush1, 30)
- pPen2 := Gdip_CreatePenFromBrush(pBrush2, 4)
- hbm := CreateDIBSection(game.w, game.h)
- hdc:=CreateCompatibleDC()
- obm:=SelectObject(hdc,hbm )
- G := Gdip_GraphicsFromHDC(hdc)
- Gdip_SetSmoothingMode(G, 4)
- ;~ Gdip_DrawRoundedRectangle(g, pPen1, 30, 30, 270, 270, 80)
- Gdip_FillRectangle(g, pBrush6, 0, 0, game.w, game.h)
- ;~ ***********************************************************************
- ;~ ************************************************************************
- ;~ *************************************************************************
- global press:=[]
- press[1]:=1
- global x_border_left:=[]
- x_border_left[1]:=1
- global x_border_right:=[]
- x_border_right[1]:=20
- global y_border_up:=[]
- y_border_up[1]:=1
- global y_border_down:=[]
- y_border_down[1]:=20
- global x_pos:=[]
- x_pos:= {1:7 ,2:7 ,3:7,4:7,5:7 }
- global y_pos:=[]
- y_pos:= {1:7 ,2:8 ,3:9,4:10,5:11 }
- global x_direction:= []
- x_direction:= [0,0,0,0,0]
- global y_direction:=[]
- y_direction:= [-1,-1,-1,-1,-1]
- global im_treasure:=[]
- im_treasure:= {1:0 ,2:0 ,3:0,4:0,5:0 }
- global treasure_x:=[]
- global treasure_y:=[]
- treasure_x:=[5,7]
- treasure_y:=[7,4]
- global pBitmapWin1 := Gdip_CreateBitmapFromFile("head_1200_no.png")
- global pBitmapWin2 := Gdip_CreateBitmapFromFile("head_0300_no.png")
- global pBitmapWin3 := Gdip_CreateBitmapFromFile("head_0600_no.png")
- global pBitmapWin4 := Gdip_CreateBitmapFromFile("head_0900_no.png")
- global pBitmapWin5 := Gdip_CreateBitmapFromFile("body_1200_no.png")
- global pBitmapWin6 := Gdip_CreateBitmapFromFile("body_0300_no.png")
- global pBitmapWin7 := Gdip_CreateBitmapFromFile("body_0130_no.png")
- global pBitmapWin8 := Gdip_CreateBitmapFromFile("body_0430_no.png")
- global pBitmapWin9 := Gdip_CreateBitmapFromFile("body_0730_no.png")
- global pBitmapWin10 := Gdip_CreateBitmapFromFile("body_1030_no.png")
- global pBitmapWin11 := Gdip_CreateBitmapFromFile("tail_1200_no.png")
- global pBitmapWin12 := Gdip_CreateBitmapFromFile("tail_0300_no.png")
- global pBitmapWin13 := Gdip_CreateBitmapFromFile("tail_0600_no.png")
- global pBitmapWin14 := Gdip_CreateBitmapFromFile("tail_0900_no.png")
- global pBitmapWin1y := Gdip_CreateBitmapFromFile("head_1200_yes.png")
- global pBitmapWin2y := Gdip_CreateBitmapFromFile("head_0300_yes.png")
- global pBitmapWin3y := Gdip_CreateBitmapFromFile("head_0600_yes.png")
- global pBitmapWin4y := Gdip_CreateBitmapFromFile("head_0900_yes.png")
- global pBitmapWin5y := Gdip_CreateBitmapFromFile("body_1200_yes.png")
- global pBitmapWin6y := Gdip_CreateBitmapFromFile("body_0300_yes.png")
- global pBitmapWin7y := Gdip_CreateBitmapFromFile("body_0130_yes.png")
- global pBitmapWin8y := Gdip_CreateBitmapFromFile("body_0430_yes.png")
- global pBitmapWin9y := Gdip_CreateBitmapFromFile("body_0730_yes.png")
- global pBitmapWin10y := Gdip_CreateBitmapFromFile("body_1030_yes.png")
- global pBitmapWin11y := Gdip_CreateBitmapFromFile("tail_1200_yes.png")
- global pBitmapWin12y := Gdip_CreateBitmapFromFile("tail_0300_yes.png")
- global pBitmapWin13y := Gdip_CreateBitmapFromFile("tail_0600_yes.png")
- global pBitmapWin14y := Gdip_CreateBitmapFromFile("tail_0900_yes.png")
- global pBitmapWin_treasure := Gdip_CreateBitmapFromFile("black.png")
- global snake_mass:=[]
- snake_mass:= [pBitmapWin1,pBitmapWin5,pBitmapWin5,pBitmapWin5,pBitmapWin5]
- ;~ d0:=30
- ;~ x0:=30
- ;~ y0:=30
- ;~ w0:=270
- ;~ h0:=270
- ;~ pPen1 := Gdip_CreatePenFromBrush(pBrush1, d0)
- ;~ Gdip_DrawRectangle(g, pPen1, x0+d0/2, y0+d0/2, w0-d0, h0-d0)
- loop % x_border_left.MaxIndex() {
- ;~ pbrush=pbrush_border%A_Index%
- pbrush:=pbrush%A_Index%
- d0:=snake.w
- x0:=d0*x_border_left[A_Index]
- y0:=d0*y_border_up[A_Index]
- w0:=(x_border_right[A_Index] - x_border_left[A_Index] + 1)*d0
- h0:=(y_border_down[A_Index] - y_border_up[A_Index] + 1)*d0
- ;~ MsgBox,% x0 " , " y0 " , " w0 " , " h0 " , " d0
- Gdip_DrawRectangle_2(g,pbrush,x0,y0,w0,h0,d0)
- }
- ;~ x:=x0
- ;~ loop 2 {
- ;~ y:=y0
- ;~ loop 2 {
- ;~ Gdip_DrawEllipse(g, pPen2, x, y, 3, 3)
- ;~ y+=h0
- ;~ }
- ;~ x+=w0
- ;~ }
- ;~ draw_snake(g,pbrush2,pbrush3)
- UpdateLayeredWindow(hwndl, hdc, game.x, game.y, game.w, game.h)
- settimer,tool,1
- SetTimer,game_loop,% game.t
- ;~ SetTimer,game_loop ,0
- return
- tool:
- ToolTip, % game.t
- return
- game_loop:
- press[1]:=1
- set_pos()
- bump_itself()
- loop % x_border_left.MaxIndex() {
- d0:=snake.w
- x0:=d0*x_border_left[A_Index] +d0
- y0:=d0*y_border_up[A_Index] + d0
- w0:=(x_border_right[A_Index] - x_border_left[A_Index] - 1 )*d0
- h0:=(y_border_down[A_Index] - y_border_up[A_Index] - 1 )*d0
- ;~ MsgBox,% x0 " , " y0 " , " w0 " , " h0 " , " d0
- Gdip_FillRectangle(g, pBrush6, x0, y0, w0, h0)
- }
- set_im_treasure()
- draw_treasure(g)
- set_direction()
- set_snake_mass()
- draw_snake(g,pbrush2,pbrush3)
- UpdateLayeredWindow(hwndl, hdc, game.x, game.y, game.w, game.h)
- max:=im_treasure.MaxIndex()
- if(im_treasure[max] and pre_length = snake.l){
- snake.l+=1
- im_treasure.Insert(0)
- x_pos.insert(x_pos[max]-x_direction[max])
- y_pos.insert(y_pos[max]-y_direction[max])
- x_direction.insert(x_direction[max])
- y_direction.insert(y_direction[max])
- }
- else{
- pre_length:=snake.l
- }
- press[1]:=0
- return
- GuiClose:
- GuiEscape:
- *x::
- Gdip_Shutdown(pToken)
- ExitApp
- Gdip_DrawRectangle_2(g,brush,x0,y0,w0,h0,d0){
- pPen1 := Gdip_CreatePenFromBrush(Brush, d0)
- Gdip_DrawRectangle(g, pPen1, x0+d0/2, y0+d0/2, w0-d0, h0-d0)
- ;~ pbrush:=Gdip_BrushCreateSolid("0xff000ff0")
- ;~ x:=x0
- ;~ loop 2 {
- ;~ y:=y0
- ;~ loop 2 {
- ;~ Gdip_fillEllipse(g, pbrush, x, y, 7, 7)
- ;~ y+=h0
- ;~ }
- ;~ x+=w0
- ;~ }
- }
- ;~ draw_snake(g,brush_head,brush_body){
- ;~ Gdip_fillRectangle(g,brush_head,x_pos[1]*snake.w,y_pos[ 1]*snake.w,snake.w,snake.w)
- ;~ loop % snake.L - 1 {
- ;~ Gdip_fillRectangle(g,brush_body,x_pos[A_Index + 1]*snake.w,y_pos[A_Index + 1]*snake.w,snake.w,snake.w)
- ;~ }
- ;~ }
- draw_snake(g,brush_head,brush_body){
- loop % snake.L {
- ;~ Gdip_fillRectangle(g,brush_body,x_pos[A_Index + 1]*snake.w,y_pos[A_Index + 1]*snake.w,snake.w,snake.w)
- Gdip_DrawImage(g, snake_mass[a_index],x_pos[A_Index ]*snake.w,y_pos[A_Index ]*snake.w,snake.w,snake.w)
- }
- }
- ;~ C:\Users\Admin\Desktop\gdip_snake\gdip_snake.ahk
- treasure(){
- qua:=treasure_x.MaxIndex()
- tt:=0
- loop %qua% {
- tt++
- if(treasure_x[tt] = x_pos[1] and treasure_y[tt] = y_pos[1]){
- treasure_x[tt]:=-12
- treasure_y[tt]:=-12
- return true
- }
- }
- return false
- }
- set_snake_mass(){
- for i,val_x in x_direction {
- val_y:=y_direction[i]
- if(i<>1 and i<>snake.L){
- base_turn(me,i)
- if(im_treasure[i]=0){
- (me="0730")?(val_x:=pBitmapWin7):(me="1030")?(val_x:=pBitmapWin8):(me="0130")?(val_x:=pBitmapWin9):(me="0430")?(val_x:=pBitmapWin10):(me="1200")?(val_x:=pBitmapWin5):(me="0300")?(val_x:=pBitmapWin6)
- }
- else{
- (me="0730")?(val_x:=pBitmapWin7y):(me="1030")?(val_x:=pBitmapWin8y):(me="0130")?(val_x:=pBitmapWin9y):(me="0430")?(val_x:=pBitmapWin10y):(me="1200")?(val_x:=pBitmapWin5y):(me="0300")?(val_x:=pBitmapWin6y)
- }
- }
- else if(i==1){
- if(im_treasure[i]=0){
- (val_y=-1)?(val_x:=pBitmapWin1):(val_y=1)?(val_x:=pBitmapWin3):(val_x=-1)?(val_x:=pBitmapWin4):(val_x=1)?(val_x:=pBitmapWin2)
- }
- else{
- (val_y=-1)?(val_x:=pBitmapWin1y):(val_y=1)?(val_x:=pBitmapWin3y):(val_x=-1)?(val_x:=pBitmapWin4y):(val_x=1)?(val_x:=pBitmapWin2y)
- }
- }
- else if(i==snake.l) {
- if(im_treasure[i]=0){
- (val_y=-1)?(val_x:=pBitmapWin11):(val_y=1)?(val_x:=pBitmapWin13):(val_x=-1)?(val_x:=pBitmapWin14):(val_x=1)?(val_x:=pBitmapWin12)
- }
- if(im_treasure[i]=1){
- (val_y=-1)?(val_x:=pBitmapWin11y):(val_y=1)?(val_x:=pBitmapWin13y):(val_x=-1)?(val_x:=pBitmapWin14y):(val_x=1)?(val_x:=pBitmapWin12y)
- }
- }
- snake_mass[i]:=val_x
- }
- }
- preset_pos(){
- for i,value in x_pos {
- x_pos[i]+=x_direction[i]
- y_pos[i]+=y_direction[i]
- }
- }
- set_direction(){
- max:=x_direction.MaxIndex()
- loop % max - 1 {
- x_direction[max -A_Index + 1 ]:=x_direction[max - A_Index]
- y_direction[max - A_Index + 1 ]:=y_direction[max - A_Index]
- }
- }
- bump_itself(){
- for i,value in x_pos {
- if(i == 1)
- continue
- if(x_pos[1]==value and y_pos[1]==y_pos[i])
- {
- SoundBeep,250,1200
- SetTimer,game_loop,off
- }
- }
- }
- find_pitch(x,y){
- ;~ qua:=teleport.MaxIndex()
- qua:=x_border_left.MaxIndex()
- t:=0
- loop %qua% {
- t++
- if( ( x <= x_border_right[t] ) and ( x >= x_border_left[t] ) and ( y <= y_border_down[t] ) and ( y >= y_border_up[t] ) )
- return t
- }
- MsgBox,wrong pitch
- }
- set_pos(){
- preset_pos()
- x:=x_pos[1]
- y:=y_pos[1]
- pitch :=find_pitch( x ,y )
- out_of_border(pitch)
- }
- out_of_border( pitch ){
- for i,value in x_pos {
- x:=x_pos[i]
- y:=y_pos[i]
- if(x = x_border_left[pitch] ){
- x:=x_border_right[pitch] - 1
- }
- if(x = x_border_right[pitch] ){
- x:=x_border_left[pitch] + 1
- }
- if(y = y_border_up[pitch] ){
- y:=y_border_down[pitch] - 1
- }
- if(y = y_border_down[pitch] ){
- y:=y_border_up[pitch] + 1
- }
- x_pos[i]:=x
- y_pos[i]:=Y
- }
- }
- ;~ ***********************************************************************************************
- base_turn_6(ByRef turn , y_d, y_d_t){
- if( y_d =0 and y_d_t = 0 )
- turn:="0300"
- }
- base_turn_5(ByRef turn , x_d, x_d_t){
- if( x_d =0 and x_d_t = 0 )
- turn:="1200"
- }
- base_turn_1(ByRef turn,x_d, x_d_t, y_d , y_d_t){
- if((x_d = 1 and y_d_t = 1) or (y_d = -1 and x_d_t = -1))
- turn:="0130"
- }
- base_turn_2(ByRef turn,x_d, x_d_t, y_d , y_d_t){
- if((y_d = 1 and x_d_t = -1) or (x_d = 1 and y_d_t = -1))
- turn:="0430"
- }
- base_turn_3(ByRef turn,x_d, x_d_t, y_d , y_d_t){
- if((x_d = -1 and y_d_t = -1) or (y_d = 1 and x_d_t = 1))
- turn:="0730"
- }
- base_turn_4(ByRef turn,x_d, x_d_t, y_d , y_d_t){
- if((y_d = -1 and x_d_t = 1) or (x_d = -1 and y_d_t = 1))
- turn:="1030"
- }
- base_turn(ByRef turn,n){
- x_d:=x_direction[n]
- x_d_t:=x_direction[n+1]
- y_d:=y_direction[n]
- y_d_t:=y_direction[n+1]
- base_turn_1(turn,x_d,x_d_t,y_d,y_d_t)
- base_turn_2(turn,x_d,x_d_t,y_d,y_d_t)
- base_turn_3(turn,x_d,x_d_t,y_d,y_d_t)
- base_turn_4(turn,x_d,x_d_t,y_d,y_d_t)
- base_turn_5(turn,x_d,x_d_t)
- base_turn_6(turn,y_d,y_d_t)
- }
- ;~ ******************************************************
- set_im_treasure(){
- ;~ list:=""
- max:=im_treasure.MaxIndex()
- for i,value in im_treasure {
- if(i == 1) {
- }
- else {
- im_treasure[max+2-i]:= im_treasure[max+1-i]
- }
- ;~ list.=i " , " im_treasure[i] "`n"
- }
- im_treasure[1]:=0
- if(treasure()){
- im_treasure[1]:=1
- }
- ;~ tooltip,% game.t "`n" list
- }
- a::
- X1:=x_direction[1]
- Y1:=Y_direction[1]
- if( x1 = 0 and press[1] = 0){
- y1:=0
- x1:=-1
- }
- x_direction[1]:=X1
- Y_direction[1]:=Y1
- return
- d::
- X1:=x_direction[1]
- Y1:=Y_direction[1]
- if( x1 = 0 and press[1] = 0){
- y1:=0
- x1:=1
- }
- x_direction[1]:=X1
- Y_direction[1]:=Y1
- return
- w::
- X1:=x_direction[1]
- Y1:=Y_direction[1]
- if( Y1 = 0 and press[1] = 0){
- y1:=-1
- x1:=0
- }
- x_direction[1]:=X1
- Y_direction[1]:=Y1
- return
- S::
- X1:=x_direction[1]
- Y1:=Y_direction[1]
- if( Y1 = 0 and press[1] = 0){
- y1:=1
- x1:=0
- }
- x_direction[1]:=X1
- Y_direction[1]:=Y1
- return
- 1::
- game.t-=5
- if(game.t < 5 )
- game.t:=5
- SetTimer,game_loop,% game.t
- return
- 2::
- game.t+=5
- if(game.t > 3500 )
- game.t:=3500
- SetTimer,game_loop,% game.t
- return
- 3::
- game.t-=1
- if(game.t < 1 )
- game.t:=1
- SetTimer,game_loop,% game.t
- return
- 4::
- game.t+=1
- if(game.t > 3500 )
- game.t:=3500
- SetTimer,game_loop,% game.t
- return
- draw_treasure(g){
- for i,value in treasure_x {
- Gdip_DrawImage(g, pBitmapWin_treasure,value*snake.w,treasure_y[i ]*snake.w,snake.w,snake.w)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement