Advertisement
pastamaker

simple ninja 1

Jun 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {   ;standart stuff that creates automaticly when you create new ahk  script : CHANGED working dir to make access to sprites more easyly
  2. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  3. ; #Warn  ; Enable warnings to assist with detecting common errors.
  4. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  5. SetWorkingDir %A_ScriptDir%\png ; easy way to find images
  6. }
  7.  
  8.  
  9.  
  10. #SingleInstance,force
  11. SetBatchLines,-1
  12. #Include,<hellbents_gdip>
  13. popUp:=Layered_Window_SetUp(4,50,50,A_ScreenWidth,A_ScreenHeight,1,"+alwaysontop")
  14. UpdateLayeredWindow(popUp.hwnd, popUp.hdc, popUp.x, popUp.y, popUp.w, popUp.h)
  15.  
  16. gosub setStuff
  17.  
  18.  
  19. SetTimer,gameLoop,% 1000/24
  20.  
  21. return
  22. setStuff:
  23. backg:= new Back
  24. backg.set()
  25.  
  26. alex:= new Ninja
  27. alex.set(250,250,100,200,"000ff0",10,25,50,backg)
  28.  
  29. return
  30. gameLoop:
  31. Gdip_GraphicsClear(popUp.g)
  32.    
  33. backg.draw(popup.g)
  34. alex.main(popup.g)
  35.  
  36. UpdateLayeredWindow(popUp.hwnd, popUp.hdc)
  37. return
  38.  
  39. class Ninja {
  40.    
  41.     set(x1,y1,w,h,colour,g,vxmax,vymax,Backscene){
  42.         this.w:=w
  43.         this.h:=h
  44.         this.x1:=x1
  45.         this.y1:=y1
  46.         This.x2 := x1 + w
  47.         This.y2 := y1 + h
  48.  
  49.         this.vx:=0
  50.         this.vy:=0
  51.         this.gmax:=g
  52.         this.g:=0
  53.         this.vxmax:=vxmax
  54.         this.vymax:=vymax
  55.         this.Backscene:=Backscene
  56.        
  57.         map := Gdip_CreateBitmap(w, h)                    
  58.         g := Gdip_GraphicsFromImage(map)
  59.         Gdip_SetSmoothingMode(g, 4)
  60.         Fill_Boxx(g,colour,0,0,w,h)
  61.         this.map:=map
  62.        
  63.         this.BW:=false
  64.         this.BS:=false
  65.         this.BA:=false
  66.         this.BD:=false
  67.         this.look:=1
  68.     }
  69.     readButtons(){
  70.         this.BW:=false
  71.         this.BS:=false
  72.         this.BA:=false
  73.         this.BD:=false
  74.        
  75.         if(GetKeyState("A"))
  76.             this.BA:=true
  77.         else if(GetKeyState("D"))
  78.             this.BD:=true
  79.        
  80.         if(GetKeyState("S"))
  81.             this.BS:=true
  82.         else if (GetKeyState("W"))
  83.             this.BW:=true
  84.     }
  85.     setlook(){
  86.     if(this.vx > 0)
  87.         this.look := 1
  88.  
  89.    
  90.     else if(this.vx < 0)
  91.         this.look := 2
  92.            
  93.     }
  94.     main(g){
  95.         this.readButtons()
  96.         this.setv()
  97.         this.setlook()
  98.         this.setxy()
  99.        
  100.         this.smthUNDER()
  101.         this.border()
  102.        
  103.         this.draw(g)
  104.         this.vx:=0
  105.        
  106.        
  107.     }
  108.     smthUNDER(){
  109.         this.g:=this.gmax
  110.        
  111.         if(this.y2 >= this.Backscene.y2){
  112.             this.y2:=this.Backscene.y2
  113.             this.y1:=this.y2 - this.h
  114.             this.vy:=0
  115.             this.g:=0
  116.             this.BS:=false
  117.         }
  118.     }
  119.     border(){
  120.         if(this.x1 <= this.Backscene.x1){
  121.             this.x1:=this.Backscene.x1
  122.             this.x2:=this.x1 + this.w
  123.             this.vx:=0
  124.             this.BA:=false
  125.         }
  126.         else if(this.x2 >= this.Backscene.x2){
  127.             this.x2:=this.Backscene.x2
  128.             this.x1:=this.x2 - this.w
  129.             this.vx:=0
  130.             this.BD:=false
  131.         }
  132.         if(this.y1 <= this.Backscene.y1){
  133.             this.y1:=this.Backscene.y1
  134.             this.y2:=this.y1 + this.h
  135.             this.vy:=0
  136.             this.BW:=false
  137.         }
  138.     }
  139.    
  140.     setxy(){
  141.         this.setx()
  142.         this.sety()
  143.     }
  144.     setX(){
  145.         this.x1+=this.vx
  146.         this.x2:=this.x1 + this.w
  147.        
  148.     }
  149.     sety(){
  150.        
  151.         this.y2+=this.vy
  152.         this.y1:=this.y2 - this.h
  153.     }
  154.     setv(){
  155.         this.setvx()
  156.         this.setvy()
  157.     }
  158.     setVx(){
  159.         vx:=this.vxmax
  160.         if(this.BA){
  161.             this.vx:=-vx
  162.             this.BA:=false
  163.         }
  164.         else if(this.BD){
  165.             this.vx:=vx
  166.             this.BD:=false
  167.         }
  168.     }
  169.     setVy(){
  170.        
  171.         this.vy+=this.g
  172.        
  173.         vy:=this.vymax
  174.         vx:=this.vxmax
  175.         if(this.vy <> 0){
  176.         if(this.look = 1)
  177.             this.vx:=vx
  178.         else
  179.             this.vx:=-vx
  180.         }
  181.         if(this.BW and this.vy = 0 and this.g = 0){
  182.            
  183.             this.vy:=-vy
  184.        
  185.         }
  186.         if(this.BS and this.g <> 0){
  187.             this.vy:=vy
  188.            
  189.         }
  190.     }
  191.    
  192.     draw(g){
  193.         Gdip_DrawImage(g, this.map, THIS.X1,this.y1, this.w, this.h)
  194.     }
  195.    
  196. }
  197.  
  198. class Back {
  199.     set(){
  200.             back:=Gdip_CreateBitmapFromFile("back.png")
  201.             this.back:=back
  202.             Gdip_GetImageDimensions(back,  w,  h)
  203.             this.w:=w
  204.             this.h:=h
  205.             delta:=14
  206.             This.x1 := delta
  207.             This.x2 := w - delta
  208.             This.y1 := delta
  209.             This.y2 := h - delta
  210.     }
  211.     draw(g){
  212.         Gdip_DrawImage(g, this.back, 0,0, this.w, this.h)
  213.     }
  214.  
  215. }
  216. a::
  217. return
  218. s::
  219. return
  220. d::
  221. return
  222. w::
  223. return
  224. x::
  225. Layered_Window_ShutDown(popUp)
  226. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement