Strategiespiel
Übersicht

![]() |
Commander-TobiBetreff: Strategiespiel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo bin blutiger anfänger in Blitz.
Ich habe vor ein kleines Strategie Spiel zu Proggen und habe dazu den folgenden Quelltext gefunden. Kann den mir bitte einer so kürzen und kommentieren das er was verständlicher für newbies ist? THX Code: [AUSKLAPPEN] ;features: ;minimap ;moving the screen via the minimap ;moving units via the minimap ;smooth scrolling ;any amount of units ;different unit kinds with differend moving speeds ;different kinds of tiles that take different amounts of time to move through ;A*-ish pathfinding ;pathfinder still finds the shortest time path ;everything is in types ;code has no globals except type pointers and the map array ;code has a lot of comments ;its easy to add kinds of units and kinds of tiles ;mouse system with mouse\button\released that never fails ;bools will either equal yes or null Type bool End Type Global yes.bool=New bool ;fps Type fps ;draws per second Field dps ;draws so far this second Field draws ;the millisecs of the last second Field drawtime End Type Global fps.fps=New fps Type screen ;resolution width and height Field w,h ;windowed mode Field mode ;color bit depth Field depth ;where the 'camera' is Field x,y ;if the grid is on Field grid.bool ;how many tiles you can see Field vieww,viewh ;the space around the viewing area Field lbound,rbound,dbound,ubound ; Field scrollspeed# ; Field speedx#,speedy# End Type Global screen.screen=New screen ;minimap Type mini ;where the mini is drawn Field x,y ;the size of each tile on the map Field size# ;the image that everything is drawn to Field image ;did minimap update Field got.bool ;where the minimap is Field drawx,drawy End Type Global mini.mini=New mini Type dir ;how your position changes when going this dir Field x,y ;the dir that would make you go the opposite way Field opposite.dir End Type ;these are not needed in this program ;holds all of the dirs ;r=right l=left u=up d=down Type dirs Field r.dir Field l.dir Field u.dir Field d.dir Field ul.dir Field ur.dir Field dl.dir Field dr.dir End Type Global dirs.dirs=New dirs ;do not use mousex(),mousey(),mousehit() Type mouse ;where the cursor is on the screen Field x,y ;what tile the cursor is over Field mapx,mapy ; Field lb.mousebutton,rb.mousebutton End Type Global mouse.mouse=New mouse mouse\x=screen\w/2 mouse\y=screen\h/2 ;get rid of the speed MouseXSpeed() MouseYSpeed() Type mousebutton ;lb=1 rb=2 Field index ;where the cursor was when the button was pressed down Field startx,starty ;what tile the cursor was over when the button was pressed down Field startmapx,startmapy ;if this button was on the view when it was pressed Field startonview.bool ;if this button was on the minimap when it was pressed Field startonmini.bool ;if this button is down Field down.bool ;if this button was pressed down this loop Field hit.bool ;if this button was released this loop Field released.bool ;internal, to make released work Field checkhit.bool End Type mouse\lb=New mousebutton mouse\lb\index=1 mouse\rb=New mousebutton mouse\rb\index=2 ;something that you move around Type unit ;where it is on the map Field x,y ;where its target is Field tarx,tary ;if its moving Field moving.bool ;how it is into the tile its moving into Field moveinto ;the dir its heading Field dir.dir ;if its selected Field selected ;how mant loops left to wait, when moving and it paused Field wait ; Field kind.unitkind End Type Type unitkind ;like "longbowman", or "tank" Field name$ ;how fast this kind of unit moves, 1 is the slowest Field speed End Type Type unitkinds Field fattank.unitkind Field infantry.unitkind Field jeep.unitkind End Type Global unitkinds.unitkinds=New unitkinds ;for the pathfinder Type node ;where it is on the map Field x,y ;which node created this Field parent.node ;amount of loops it would take for a unit of speed 1 to get to this spot Field cost End Type ; Type path ;where it is on the map Field x,y ;which unit is going to walk this path Field owner.unit End Type ;map array of types Type maptile ;if there is a node here Field node ;the unit on this tile Field unit.unit ;what kind of tile this is Field tilekind.tilekind End Type ;each map tile does not create an instance of tilekind ;each map tile points to one of the few instances of tilekind Type tilekind ;like "plains", or "mud" Field name$ ;how many loops its takes a unit of speed 1 to move across this tile Field speed ;what color dot the minimap draws for this tile Field minicolor ;if a ground unit can go through this tile Field walkable.bool End Type Type tilekinds Field grass.tilekind Field water.tilekind Field swamp.tilekind End Type Global tilekinds.tilekinds=New tilekinds ;shows the unit destination that you choose Type tarspot ;where it is on the map Field x,y ;how many loops until it disappears Field life End Type Global tarspot.tarspot=New tarspot Type map ;size of the map Field w,h ;tile size Field ts ;I wish ;Field array.maptile[0,0] ;redim later End Type Global map.map=New map map\ts=32 Dim maparray.maptile(0,0) ;redim later screensetup() dirsmake() tilekindsmake() unitkindsmake() mapload() minisetup() unitmake(10,10,unitkinds\fattank) unitmake(11,10,unitkinds\fattank) unitmake(10,11,unitkinds\fattank) unitmake(11,11,unitkinds\fattank) unitmake(12,12,unitkinds\jeep) unitmake(13,13,unitkinds\jeep) unitmake(14,14,unitkinds\infantry) unitmake(15,15,unitkinds\infantry) mainloop() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function ScreenSetup() screen\w=800 screen\h=600 screen\mode=2 screen\depth=0 screen\lbound=map\ts*0 screen\rbound=map\ts*20 screen\ubound=map\ts*1 screen\dbound=map\ts*18 screen\vieww=screen\rbound/map\ts-screen\lbound/map\ts+1 screen\viewh=screen\dbound/map\ts-screen\ubound/map\ts+1 screen\scrollspeed=3 Graphics screen\w,screen\h,screen\depth,screen\mode SetBuffer BackBuffer() HidePointer SeedRnd MilliSecs() ; Dim drawx(screen\vieww) ; Dim drawy(screen\viewh) ; ; For z=1 To screen\vieww ; drawx(z)=(z - 1) * map\ts + screen\lbound ; Next ; For z=1 To screen\viewh ; drawy(z)=(z - 1) * map\ts + screen\ubound ; Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function MainLoop() Local timer timer=CreateTimer(40) Repeat updates=WaitTimer(timer) ;update everything For z=1 To updates unitsupdate() mouseupdate() mousestuff() screenupdate() fpsupdate() Next ;draw everything mapdraw() drawstuff() Flip ;no need for cls, the whole screen is redrawn If KeyHit(1) Then End If KeyHit(34) Then If screen\grid=Null Then screen\grid=yes Else screen\grid=Null EndIf EndIf Forever End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______UNITS____________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function UnitMake.unit(x,y,uk.unitkind) Local u.unit If mapcan(x,y)=Null Then Return Null u=New unit u\x=x u\y=y u\kind=uk maparray(u\x,u\y)\unit=u Return u End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function UnitKindsMake() Local uk.unitkind uk=New unitkind uk\name="fat tank" uk\speed=8 unitkinds\fattank=uk uk=New unitkind uk\name="jeep" uk\speed=40 unitkinds\jeep=uk uk=New unitkind uk\name="infantry" uk\speed=22 unitkinds\infantry=uk End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;deselects all the units Function UnitsDeselectAll() Local u.unit For u.unit=Each unit u\selected=0 Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;updates the units Function UnitsUpdate() Local u.unit For u=Each unit If u\moving=yes Then If u\wait>0 Then u\wait=u\wait-1 EndIf If u\wait<=1 Then If u\wait=1 Then ;just finished waiting, its already moved all the way into the tile, so dont add to moveinto u\wait=0 Else u\moveinto=u\moveinto+u\kind\speed EndIf If u\moveinto>=maparray(u\x,u\y)\tilekind\speed Then ;finished moving into tile unitpathstep(u) EndIf EndIf EndIf Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;sets the dir of the unit to next path node Function UnitPathStep(u.unit) Local p.path If (u\x=u\tarx And u\y=u\tary) Then ;got to target u\moveinto=0 u\moving=Null Return EndIf p=Last path ;get its last path While p\owner<>u p=Before p Wend If mapcan(p\x,p\y)=yes Then ;set dir u\dir=dirget(p\x-u\x,p\y-u\y) ;move unit to next tile maparray(u\x,u\y)\unit=Null u\x=p\x u\y=p\y maparray(p\x,p\y)\unit=u Delete p u\moveinto=0 Else If p\x=u\tarx And p\y=u\tary Then ;the target is unwalkable, but the unit is touching it, so its done u\moving=Null Delete p u\moveinto=0 Else ;something got in the way Local mu.unit mu=maparray(p\x,p\y)\unit If mu<>Null Then ;if the thing in the way is going to move soon If mu\moving=yes And mu\wait=0 Then ;wait for it to move out of the way u\wait=map\ts+1 EndIf EndIf ;the thing in the way is not going anywhere, so find a path around it If u\wait=0 Then u\moveinto=0 unitfindpath(u,yes) EndIf EndIf EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;makes path nodes for the unit to its target Function UnitFindPath(u.unit,inpathstep.bool) Local n.node,n2.node,n3.node Local endnode.node,p.path Local dir.dir,newx,newy,done.bool ;clear old path For p=Each path If p\owner=u Then Delete p Next u\wait=0 ;targeted the unit itself If maparray(u\tarx,u\tary)\unit=u Then Return EndIf ;frist node on the unit n=New node n\x=u\x n\y=u\y ;for A* discipline regulators: ;nodes after n are considered the open (not updated yet) list ;nodes before n are considered the closed (expanded) list For n=Each node For dir=Each dir newx=n\x+dir\x newy=n\y+dir\y ;if the new spot is in bounds If newx>=0 If newy>=0 If newx<=map\w If newy<=map\h Then ;if there isnt a node there already If maparray(newx,newy)\node=0 Then ;if tile is walkable or is the target If mapcan(newx,newy)=yes Or (newx=u\tarx And newy=u\tary) Then n2=New node n2\x=newx n2\y=newy n2\parent=n n2\cost=n\cost+maparray(newx,newy)\tilekind\speed maparray(newx,newy)\node=1 ;this node was created on the target, so exit right here If newx=u\tarx And newy=u\tary Then done=yes endnode=n2 Exit EndIf ;insert the node in order ;the closest to the front of the list have the least cost, and they are the first to be updated ;go until we find a node of greater cost than the new one and put the new one before that one. n3=After n Repeat If n3\cost>n2\cost Then Exit n3=After n3 If n3=Null Then Exit Forever ;if n3 is null, then the new node has the greatest cost, therfore it shall stay at the end of the list If n3<>Null Then Insert n2 Before n3 EndIf EndIf EndIf EndIf Next If done=yes Then Exit Next If done=yes Then ;make path from target to unit, going back through the endnode's parent ancestry While endnode<>Null p=New path p\x=endnode\x p\y=endnode\y p\owner=u endnode=endnode\parent Wend Delete Last path EndIf ;clear the nodemap For n=Each node maparray(n\x,n\y)\node=0 Delete n Next If done=yes Then;take first step If inpathstep=yes Or u\moving=Null Then u\moving=yes unitpathstep(u) EndIf Else;cant get to target If inpathstep=yes Then u\moving=Null Else ;unit doesnt stop moving this instant because its inbetween tiles u\tarx=u\x u\tary=u\y EndIf EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______MAP______________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function MapLoad() Local s$ ;find the map size Read s map\w=Len(s) map\h=1 Repeat Read s If s="" Then Exit map\h=map\h+1 Forever Dim maparray(map\w,map\h) Restore mapdata ;load the map Local x,y y=0 Repeat Read s If s="" Then Return y=y+1 For x=1 To map\w maparray(x,y)=New maptile Select Mid(s,x,1) Case "g" maparray(x,y)\tilekind=tilekinds\grass Case "s" maparray(x,y)\tilekind=tilekinds\swamp Case "w" maparray(x,y)\tilekind=tilekinds\water Default RuntimeError "" End Select Next Forever End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;tells if a tile is walkable Function MapCan.bool(x,y) If x<=0 Then Return Null If y<=0 Then Return Null If x>map\w Then Return Null If y>map\h Then Return Null If maparray(x,y)\tilekind\walkable=Null Then Return Null If maparray(x,y)\unit<>Null Then Return Null Return yes End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;draws the tiles in view and the units on them Function MapDraw() Local mx,my Local mtk.tilekind ;draw tiles For my=1 To screen\viewh For mx=1 To screen\vieww putx=(mx - 1) * map\ts+screen\lbound - screen\x Mod map\ts puty=(my - 1) * map\ts+screen\ubound - screen\y Mod map\ts mtk=maparray(mx+screen\x/map\ts,my+screen\y/map\ts)\tilekind Color 0,0,mtk\minicolor Rect putx,puty,map\ts,map\ts Next Next Local far# ;draw units For my=1 To screen\viewh For mx=1 To screen\vieww putx=(mx - 1) * map\ts+screen\lbound - screen\x Mod map\ts puty=(my - 1) * map\ts+screen\ubound - screen\y Mod map\ts mu.unit=maparray(mx+screen\x/map\ts,my+screen\y/map\ts)\unit If mu<>Null Then If mu\moving=yes Then far=Float(mu\moveinto) / maparray(mu\x,mu\y)\tilekind\speed * map\ts - map\ts putx=putx+mu\dir\x*(far) puty=puty+mu\dir\y*(far) EndIf Color 255,0,0 If mu\selected Then Color 0,255,255 Oval putx,puty-map\ts/3,map\ts,map\ts+map\ts/3 Color 0,0,0 Oval putx,puty-10,map\ts,map\ts+10,0 Text putx,puty,mu\kind\name EndIf Next Next ;draw grid If screen\grid=yes Then ;the rects are actually just lines that go across the whole screen, but its faster this way For my=1 To screen\viewh Color 0,0,0 puty=(my-1)*map\ts+screen\ubound - screen\y Mod map\ts Rect screen\lbound,puty,screen\rbound-screen\lbound,1 Next For mx=1 To screen\vieww putx=(mx-1)*map\ts+screen\lbound - screen\x Mod map\ts Color 0,0,0 Rect putx,screen\ubound,1,screen\dbound-screen\ubound Next EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______MINIMAP__________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function MiniSetup() mini\drawx=660 mini\drawy=10 mini\size=2 mini\image=CreateImage(map\w*mini\size,map\h*mini\size) End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;draws the minimap with units on it Function MiniUpdate() Local fx,fy Local u.unit If mini\got=Null Then ;draw the terrain on it once and save the image SetBuffer ImageBuffer(mini\image) Color 0,0,0 Rect 0,0,map\w*mini\size,map\h*mini\size Color 255,255,255 For fy=1 To map\h For fx=1 To map\w Color 0,0,maparray(fx,fy)\tilekind\minicolor Rect (fx-1)*mini\size,(fy-1)*mini\size,mini\size,mini\size Next Next mini\got=yes SetBuffer BackBuffer() Else DrawBlock mini\image,mini\drawx,mini\drawy EndIf ;draw dots for each unit For u.unit=Each unit Color 255,0,0 If u\selected Then Color 0,255,0 Rect u\x*mini\size+mini\drawx,u\y*mini\size+mini\drawy,mini\size,mini\size Next ;the screen rectangle Color 255,255,0 x=(screen\x/map\ts)*mini\size+mini\drawx+1 y=(screen\y/map\ts)*mini\size+mini\drawy+1 Rect x,y,screen\vieww*mini\size+1,screen\viewh*mini\size+1,0 End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;tells if a spot is on the mini Function OnMini.bool(onx,ony) If RectsOverlap(mini\drawx,mini\drawy,mini\size*map\w-1,mini\size*map\h-1,onx,ony,1,1) Then Return yes Else Return Null EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______DIRECTIONS______l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function DirsMake() Local d.dir d=New dir d\x=+1 d\y=0 dirs\r=d d=New dir d\x=0 d\y=+1 dirs\d=d d=New dir d\x=-1 d\y=0 dirs\l=d d=New dir d\x=0 d\y=-1 dirs\u=d d=New dir d\x=+1 d\y=+1 dirs\dr=d d=New dir d\x=-1 d\y=+1 dirs\dl=d d=New dir d\x=-1 d\y=-1 dirs\ul=d d=New dir d\x=+1 d\y=-1 dirs\ur=d ;this is not used dirs\r \opposite=dirs\l dirs\l \opposite=dirs\r dirs\u \opposite=dirs\d dirs\d \opposite=dirs\u dirs\dr\opposite=dirs\ul dirs\ul\opposite=dirs\dr dirs\dl\opposite=dirs\ur dirs\ur\opposite=dirs\dl End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;returns the dir with this x and y step Function DirGet.dir(x,y) Local dir.dir For dir=Each dir If dir\x=x And dir\y=y Then Return dir Next RuntimeError "dirget: "+x+" "+y End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______MOUSE___________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;updates the position and status Function MouseUpdate() Local z mouse\x=mouse\x+MouseXSpeed() mouse\y=mouse\y+MouseYSpeed() MoveMouse screen\w/2,screen\h/2 ;the mouse cant go off the screen mouse\x=keepin(mouse\x,1,screen\w-1) mouse\y=keepin(mouse\y,1,screen\h-1) If mouse\lb\down=yes Then ;mouse cant go out of border if selecting If mouse\lb\startonview=yes Then mouse\x=keepin(mouse\x,screen\lbound,screen\rbound-1) mouse\y=keepin(mouse\y,screen\ubound,screen\dbound-1) EndIf ;mouse cant go out of minimap if moving screen via minimap If mouse\lb\startonmini=yes Then mouse\x=keepin(mouse\x,mini\drawx,mini\drawx+(map\w-1)*mini\size) mouse\y=keepin(mouse\y,mini\drawy,mini\drawy+(map\h-1)*mini\size) EndIf EndIf ;internal mouse stuff Local mb.mousebutton For mb=Each mousebutton If MouseHit(mb\index) Then mb\hit=yes Else mb\hit=Null EndIf If MouseDown(mb\index) Then mb\down=yes Else mb\down=Null EndIf If mb\checkhit=Null Then mb\checkhit=mb\hit If mb\checkhit=yes And mb\down=Null Then mb\released=yes mb\checkhit=Null Else mb\released=Null EndIf If mb\hit=yes Then mb\startx=mouse\x mb\starty=mouse\y mb\startmapx=mouse\mapx mb\startmapy=mouse\mapy mb\startonview=onview(mouse\x,mouse\y) mb\startonmini=onmini(mouse\x,mouse\y) EndIf Next End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;does the stuff when you click Function MouseStuff() Local u.unit,mu.unit If mouse\lb\down=yes Then ;move the screen to where you click on the mini If onmini(mouse\x,mouse\y)=yes Then screen\x=keepin( ((mouse\x-mini\drawx)/mini\size-screen\vieww/2)*map\ts, 0, (map\w-screen\vieww)*map\ts ) screen\y=keepin( ((mouse\y-mini\drawy)/mini\size-screen\viewh/2)*map\ts, 0, (map\h-screen\viewh)*map\ts ) EndIf EndIf If mouse\lb\released=yes Then If onview(mouse\x,mouse\y)=yes Then If mouse\lb\startonview=yes Then;select cx2 =(mouse\x +screen\x-screen\lbound)/map\ts+1 cy2 =(mouse\y +screen\y-screen\ubound)/map\ts+1 cstartx2=(mouse\lb\startx+screen\x-screen\lbound)/map\ts+1 cstarty2=(mouse\lb\starty+screen\y-screen\ubound)/map\ts+1 ;make selx1 the leftmost and sely1 the topmost selx1=lowest (cx2,cstartx2) selx2=highest(cx2,cstartx2) sely1=lowest (cy2,cstarty2) sely2=highest(cy2,cstarty2) For fy=sely1 To sely2 For fx=selx1 To selx2 mu=maparray(fx,fy)\unit If mu<>Null Then If firstsel=0 Then unitsdeselectall() mu\selected=1 firstsel=1 EndIf Next Next EndIf EndIf EndIf If mouse\rb\released=yes Then If onview(mouse\x,mouse\y)=yes Then ;move selected units For u=Each unit If u\selected=1 Then u\tarx=(mouse\x+screen\x-screen\lbound)/map\ts+1 u\tary=(mouse\y+screen\y-screen\ubound)/map\ts+1 unitfindpath(u,Null) tarspot\life=20 tarspot\x=u\tarx tarspot\y=u\tary EndIf Next Else ;right click on mini to move units If onmini(mouse\x,mouse\y)=yes Then For u=Each unit If u\selected=1 Then u\tarx=(mouse\x-mini\drawx)/mini\size+1 u\tary=(mouse\y-mini\drawy)/mini\size+1 If u\tarx>0 And u\tary>0 Then unitfindpath(u,Null) tarspot\life=20 tarspot\x=u\tarx tarspot\y=u\tary EndIf EndIf Next EndIf EndIf EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______MISC____________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function ScreenUpdate() ;chang the screen's speed If KeyDown(200) Or (mouse\y<=1 And mouse\lb\down=Null) Then screen\speedy=screen\speedy-screen\scrollspeed EndIf If KeyDown(208) Or (mouse\y>=screen\h-1 And mouse\lb\down=Null) Then screen\speedy=screen\speedy+screen\scrollspeed EndIf If KeyDown(205) Or (mouse\x>=screen\w-1 And mouse\lb\down=Null) Then screen\speedx=screen\speedx+screen\scrollspeed EndIf If KeyDown(203) Or (mouse\x<=1 And mouse\lb\down=Null) Then screen\speedx=screen\speedx-screen\scrollspeed EndIf ;move the screen screen\x=keepin( screen\x+screen\speedx, 0, (map\w-screen\vieww)*map\ts ) screen\y=keepin( screen\y+screen\speedy, 0, (map\h-screen\viewh)*map\ts ) ;slow down the screen screen\speedx=curveto(screen\speedx,0, 10) screen\speedy=curveto(screen\speedy,0, 10) End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;draws the stuff above map Function DrawStuff() Local p.path ;show unit path Color 0,0,255 For p=Each path x=(p\x-1)*map\ts+map\ts/2+screen\lbound-screen\x y=(p\y-1)*map\ts+map\ts/2+screen\ubound-screen\y Rect x,y,4,4 Next ;draws the unit destination If tarspot\life>0 Then Color 255,255,0 For f=1 To tarspot\life Mod 10+8 Step 4 x=(tarspot\x-1)*map\ts-f+map\ts/2+screen\lbound-screen\x y=(tarspot\y-1)*map\ts-f+map\ts/2+screen\ubound-screen\y Oval x,y,f*2,f*2,0 Next tarspot\life=tarspot\life-1 EndIf ;draw cursor selection box If mouse\lb\down=yes And mouse\lb\startonview=yes Then Color 250,250,0 Line mouse\lb\startx,mouse\lb\starty,mouse\x ,mouse\lb\starty Line mouse\lb\startx,mouse\lb\starty,mouse\lb\startx,mouse\y Line mouse\x ,mouse\y ,mouse\lb\startx,mouse\y Line mouse\x ,mouse\y ,mouse\x ,mouse\lb\starty EndIf ;border around map viewing area Color 100,50,50 Rect 0 ,0 ,screen\lbound,screen\dbound;left Rect screen\lbound,0 ,screen\rbound,screen\ubound;up Rect screen\rbound,0 ,screen\w ,screen\dbound;right Rect 0 ,screen\dbound,screen\w ,screen\h ;down Color 0,0,0 miniupdate() ;show the draws per second Color 0,255,255 Text 0,0,"FPS:"+fps\dps ;draw the cursor Color 255,255,0 Rect mouse\x,mouse\y,6,6 End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function FPSUpdate() If MilliSecs()-fps\drawtime>=1000 Then fps\dps=fps\draws fps\draws=0 fps\drawtime=MilliSecs() Else fps\draws=fps\draws+1 EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;tells if a spot is inside the screen border Function OnView.bool(onx,ony) If (onx>=screen\lbound And ony>=screen\ubound And onx<=screen\rbound And ony<=screen\dbound) Return yes Else Return Null EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function TileKindsMake() Local tk.tilekind tk=New tilekind tk\name="grass" tk\speed=200 tk\minicolor=rgb(0,200,0) tk\walkable=yes tilekinds\grass=tk tk=New tilekind tk\name="swamp" tk\speed=300 tk\minicolor=rgb(40,110,40) tk\walkable=yes tilekinds\swamp=tk tk=New tilekind tk\name="water" tk\speed=0 tk\minicolor=rgb(0,0,200) tk\walkable=Null tilekinds\water=tk End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function l_______NUMBER__________l() End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function RGB(r,g,b) Return (r Shl 16) Or (g Shl 8) Or (b ) End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;keep number in bounds Function KeepIn#(num#,min#,max#) If num<min Then Return min ElseIf num>max Return max EndIf Return num End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;wrap number Function Wrap#(num#,min#,max#) If num<min Then Repeat num=num+(max-min+1) Until num>=min ElseIf num>max Then Repeat num=num-(max-min+1) Until num<=max EndIf Return num End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function CurveTo#(num#,dest#,speed#) If num<dest Then Return num+Abs(dest-num)/speed ElseIf num>dest Then Return num-Abs(dest-num)/speed EndIf End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function Highest#(a#,b#) If a>b Then Return a Return b End Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function Lowest#(a#,b#) If a<b Then Return a Return b End Function .mapdata Data "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" Data "wggggggggggggggggggggggggggggggggggggggggggggw" Data "wggggggggggggggggggggggggggggggggggggggggggwww" Data "wggggggggggggggggggggwgggwwgggggggggwggggwwwww" Data "wggggwwgwgwwgggggggggwgwwwgggggggggggwgggwwggw" Data "wgggwwwwwwwwwwwwgggggwgwgwwgggssgssggggggwgwgw" Data "wgggwwwwwwwwwwwwwwwwwwwwwwwggssgswsggwwggwgwgw" Data "wggggwwwwwwwwwwwwwwwwwwwwwwswsssssggggwggwggww" Data "wggggggwwwwwwwwwwwwwwwwwwwswssssssswgwgggggwww" Data "wgggggggwgggwwwwwwwwwwwwwwwwsssssgswwgggwwwwww" Data "wgggggggggggggwwwwwwwwwwwwwwgssggssggwggwwwwww" Data "wgggwggggggggggggggggggggggwgsggsgsgggggggswww" Data "wgggwgggggggggggggggggggggwwwwwsgggggggwwwwwww" Data "wgggwwwgggggggggggggggggggwwwwwggggggwgwwwwwww" Data "wgggwwwwgggggggggggggggggggwwgwggggggggggggwww" Data "wwwwwwwwwgggggggggggggssggggwwggggggggwwwwwgww" Data "wgwwwwwwwgggggggggggggsssggggggggggggwwwwwwgww" Data "wwwwwwwggggggggggggggggggggggggggggggwwgwwwgww" Data "wggggwgggwwwwwwwwggggggggggggggggggggwgwwwwgww" Data "wgggggggwwwwwwwwwwwggwwgggggggggggggggggwwwgww" Data "wggggggggggwwwwwwwwwwgggggggggggggggggggwwwggw" Data "wgggggggggggggsssssggggggggggsggggwwwwwwwwwwgw" Data "wggggggggggggggggsggggggggggsgggggggggggwwwwgw" Data "wgggggggggggggggggggggggggggssggggggggggwwwwgw" Data "wggggggggggggggggggggggggggsssggsgsggggggggggw" Data "wgggggwswwwwggggggggggggggggwwggsssssssggwwggw" Data "wgggwwwswwwwwwwwwwwwwwwwggggwgggsssssssggwwggw" Data "wgggwwwswwwwwwwwwwwwwwwwggggwgssssssssssgwwggw" Data "wggggwwswwwwwggggggggggggggwsssssssssssgggwgww" Data "wgggggggggggggggggggggggggwgwwwwwwssssggggwgww" Data "wgggggggggggggggggggggggggwgwwwwwwsgggggggwgww" Data "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" Data "" |
||
ChristianH |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Das wird wohl keiner machen. ![]() Aber ich kann die einen guten Tipp geben: Fang mit etwas kleinerem an, wenn du damit nicht klar kommst. Es ist noch kein Meister vom Himmel gefallen. |
||
dubitat |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
bei diesem code, so übersichtlich er auch sein mag, wird dir leider keiner helfen! ich verstehe von fremden codes auch immer nur die hälfte...
mein tipp: versuch es mit einem spaceshooter am Anfang! das ist schon schwer genug und ich bereue es das ich nicht damit angefangen habe! |
||
Erare humanum est - Irren ist Menschlich |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group