読者です 読者をやめる 読者になる 読者になる

hspで作ったゲームのソースコードver1

この度hspという言語を使ってゲームらしきものを作ったので公開しようと思う

 

randomize
buffer 1
picload "img.bmp"
buffer 2
picload "img.bmp"
mmload "attack.wav",0
mmload "glow.wav",1
mmload "bgm.wav",2,1
mmload "cit.wav",3
mmload "bgm2.wav",4,1
mmload "bgm3.wav",5,1
screen 0,512,512

mapx = 8
mapy = 8
bglen = 64
cpx = 8
cpy = 8
catx = 8
caty = 8

grass = 0
forest = 1
town = 2
city = 4

enecon = 0
bgmdo = 0
ovg = 0
stsr = 0
point = 0
clock = 0

 

dim map, mapx, mapy
 repeat mapy
  C = cnt
  repeat mapx
   stgr = 0
   stp = rnd( 40 ) + 1
   if (stp > 20) : stgr + 1
   map( cnt, C ) = stgr
  loop
 loop
 
 
dim compost, cpx, cpy
 repeat cpy
  C = cnt
  repeat cpx
   cpp = 0
   cpq = map( cnt , C )
   if cpq = grass{
    cpp = rnd( 30 )
   }else{
    if cpq = forest{
     cpp = 40
    }
   }
   compost( cnt, C ) = cpp
  loop
 loop
 
 
dim cit, catx, caty
 repeat caty
  C = cnt
  repeat catx
   cit( cnt, C ) = 0
  loop
 loop
 

;game start

*start
 cls
 clrobj
 pos 200,200
 mes "CONQUEST GAME"
 pos 220,300
 button "start", *stage
 pos 220,330
 button "nobgmstart", *nobgm
 pos 220,360
 button "bgmselect", *prbgmch
 stop

*stage
 cls
 clrobj
 pos 120,200
 mes "STAGE SELECT"
 pos 120,300
 button "stage1", *st1
 pos 240,300
 button "stage2", *st2
 pos 360,300
 button "FLEE PLAY", *main
 pos 120,400
 button "back", *start
 stop
 
*st1
 cls
 clrobj
 stsr + 1
 pos 180,200
 mes "[MISSION]YOU MUST MAKE 5 CITIES!"
 pos 200,300
 button "ready", *main
 stop
 
*st2
 cls
 clrobj
 stsr + 2
 pos 100,200
 mes "[MISSION]YOU MUST MAKE 10 CITIES AND 20 TOWNS!"
 pos 200,300
 button "ready", *main
 stop

;main
 
*main
 clrobj
 clock + 1
 redraw 0
 if bgmdo = 0{
  gosub *bgmadmin
 }
 gosub *drawmap
 gosub *mpcnt
 gosub *controll
 gosub *canspawn
 if enecon = 0{
  gosub *enespawn
  }else{
   if enecon = 1{
    gosub *eneadmin
   }
  }
 if ovg = 1{
  goto *gameover
 }
 redraw 1
 await 60
 goto *main
 

;bgm sec

*nobgm
 cls
 bgmdo + 3
 goto *stage

*prbgmch
 cls
 goto *bgmch

*bgmch
 mmstop
 pos 150,200
 mes "YOU CAN CHOOSE 3BGMS"
 pos 200,300
 button "bgm1", *prbgm1
 pos 200,330
 button "bgm2", *prbgm2
 pos 200,360
 button "bgm3", *prbgm3
 pos 200,390
 button "back", *prst
 stop
 
*prst
 cls
 mmstop
 goto *start
 
*prbgm1
 mmplay 2
 goto *bgm1
 
*prbgm2
 mmplay 4
 bgmdo + 1
 goto *bgm1
 
*prbgm3
 mmplay 5
 bgmdo + 2
 goto *bgm1
 
*bgm1
 pos 150,250
 button "stop", *bgmch
 pos 250,250
 button "select" , *stage
 stop
 
*bgm2
 pos 150,250
 button "back", *bgmch
 pos 250,250
 button "select",  *stage
 stop
 
*bgm3
 pos 150,250
 button "back", *bgmch
 pos 250,250
 button "select" , *stage
 stop
 
*bgmadmin
 if (bgmdo = 0){
 mmplay 2
 bgmdo + 3
}else{
 if (bgmdo = 1){
  mmplay 4
  bgmdo + 3
 }else{
  if (bgmdo = 2){
   mmplay 5
   bgmdo + 3
  }
 }
}
return

;map drawing sec
 
*drawmap
 color 255,255,255:boxf
 repeat mapy
  C = cnt
  repeat mapx
   pos cnt * bglen, C * bglen
   gcopy 1, map( cnt, C ) * 64, 128, bglen, bglen
  loop
 loop
 return


;mouse point counter sec

*mpcnt
 X = mousex / bglen
 Y = mousey / bglen
 color 0, 0, 0
 title str( X ) + "," + str( Y ) + "," + compost(X , Y) + "time" + clock
 return


;player controll sec

*controll
 stick key
 if key = 256{
  psx = mousex / bglen
  psy = mousey / bglen
  if (psx = spawnx && psy = spawny){
   gosub *attack
  }else{
   if map(psx,psy) == forest{
    mmplay 1
    map(psx,psy) + 1
   }else{
    map(psx,psy) + 0
   }
  }
  if ( 0 < psx && psx < 7 && 0 < psy && psy < 7 ) {
   if (map(psx,psy) == town) & (map(psx,psy-1) == town) & (map(psx-1,psy) == town) & (map(psx+1,psy) == town) & (map(psx,psy+1) = town){
    mmplay 3
    map(psx,psy) + 2
    cit(psx,psy) + 1
    cit(psx-1,psy) + 1
    cit(psx+1,psy) + 1
    cit(psx,psy-1) + 1
    cit(psx,psy+1) + 1
    }else
    map(psx,psy) + 0
    }
    }
  return
 
*attack
 mmplay 0
 enecon - 1
 compost(psx , psy)  + 40
 if compost(psx , psy) > 39 && map(psx , psy) = grass{
  map(psx , psy) + 1
 }
 return


;enemy section

*enespawn
 spawnx = rnd(8)
 spawny = rnd(8)
 if map(spawnx, spawny) == forest{
  pos spawnx * bglen, spawny * bglen
  gmode 2
  gcopy 2, 128, 256, bglen, bglen
  enecon + 1
 }else{
  enecon + 0
 }
 return


*eneadmin
 if enecon = 1{
  pos spawnx * bglen, spawny * bglen
  gmode 2
  gcopy 2, 128, 256, bglen, bglen
  gosub *enemove
  gosub *eneattack
 }
 return

*enemove
 move = rnd(60)
 move = move - 1
 if move = 0{
  if spawnx > 0{
   spawnx - 1
  }
 }else : if move = 10{
  if spawnx < 7{
   spawnx + 1
  }
 }else : if move = 20{
  if spawny > 0{
   spawny - 1
  }
 }else : if move = 30{
  if spawny < 7{
   spawny + 1
  }
 }
return
 

*eneattack
  if (map(spawnx , spawny) == town) & (cit(spawnx , spawny) = 0){
   map(spawnx , spawny) - 2
   compost(spawnx , spawny) = 0
  }
return


*canspawn
 F = 0
 S = 0
 T = 0
 repeat length(map)
  C = cnt
  repeat length2(map)
   if map(C,cnt) = forest{
    F = 1
    }
   if map(C,cnt) = city{
    S + 1
    }
   if map(C,cnt) = town{
    T + 1
    }
   if (stsr = 1) && (S > 4){
    goto *gameclear
    }
   if (stsr = 2) && (S > 9) && (T > 19){
    goto *gameclear
    }
  loop
 loop
 if (F = 0){
  goto *gameover
 }
 return
   
*gameover
 cls
 repeat length(map)
  C = cnt
  repeat length2(map)
  if map(C,cnt) = forest{
   point + 10
  }else{
   if map(C,cnt) = town{
    point + 100
   }else{
    if map(C,cnt) = city{
     point + 1000
    }
   }
  }
  loop
 loop
 tp = 5000 - clock
 score = point + tp
 pos 200,200
 mes "GAME OVER"
 pos 200,250
 mes "SCORE" + " " + score
 pos 100,300
 mes "[RESULT]" +"  " + "YOU MADE " + S + " CITIES AND " + T + " TOWNS"
 stop
 
*gameclear
 cls
 repeat length(map)
  C = cnt
  repeat length2(map)
  if map(C,cnt) = forest{
   point + 20
  }else{
   if map(C,cnt) = town{
    point + 200
   }else{
    if map(C,cnt) = city{
     point + 2000
    }
   }
  }
  loop
 loop
 tp = 5000 - clock
 score = point + tp + 100000
 pos 200,200
 mes "gameclear!"
 pos 200,250
 mes "SCORE" + " " + score
 s