初めてのジャンプアクション

HSPでゲームらしいゲームを作ったことない僕ですが、初めてそれっぽい何かを作ってみました。

HSPでゲームらしいゲームを作ったことない僕ですが、初めてそれっぽい何かを作ってみました。

  • タグ:
  • タグはありません
#cmpopt varinit 1
#const global dispX 640
#const global dispY 480
#const global keyLeft 37
#const global keyRight 39
#const global keyJump 38
#const global margin 50
#const global fieldTop margin
#const global fieldBottom dispY-margin
#const global fieldLeft margin
#const global fieldRight dispX-margin
#module man speed,jumpPower,_width,_height,_x,_y,isAir,isHold,g,jPow
#modcfunc manLeft
return _x-_width/2
#modfunc manSetLeft int left
_x=left+_width/2
return
#modcfunc manRight
return _x+_width/2
#modfunc manSetRight int right
_x=right-_width/2
return
#modcfunc manTop
return _y-_height
#modcfunc x
return _x
#modcfunc y
return _y
#define new(%1,%2,%3,%4,%5,%6,%7) dimtype %1,5:newmod %1,man,%2,%3,%4,%5,%6,%7
#modinit int __speed,int __jumpPower,int __width,int __height,int __x,int __y
speed=__speed
jumpPower=__jumpPower
_width=__width
_height=__height
_x=__x
_y=__y
isAir=1
isHold=0
return
#modfunc manMove
dim keyPress
getkey keyPress,keyLeft
if keyPress: _x-=speed
getkey keyPress,keyRight
if keyPress: _x+=speed
if manLeft(thismod)<=fieldLeft {
manSetLeft thismod,fieldLeft
}
else:if fieldRight<=manRight(thismod) {
manSetRight thismod,fieldRight
}
getkey keyPress,keyJump
if isAir {
if isHold {
if keyPress {
jPow–
if jPow<0: jPow=0
_y-=jPow
}
else: isHold=0
}
g++
_y+=g
if fieldBottom<=_y {
_y=fieldBottom-1
isAir=0
}
}
else:if keyPress {
if 1!isHold {
jPow=jumpPower
_y-=jPow
isHold=1
isAir=1
g=0
}
}
else: isHold=0
return
#modfunc manView
color 0,0,$99
boxf manLeft(thismod),manTop(thismod),manRight(thismod),_y
return
#global
#module Program
#defcfunc gKey int code
dim refGet
getkey refGet,code
return refGet
#deffunc main
screen 0,dispX,dispY
new@man bBox,6,22,32,32,dispX/2,dispY/2
repeat
manMove bBox
redraw 0
color $DD,$EE,$FF
boxf
color $33,$99,$FF
boxf fieldRight
boxf ,fieldBottom
boxf ,,fieldLeft
boxf ,,,fieldTop
manView bBox
color $FF,0,0
pos margin/2,margin/2
mes strf("x:%d y:%d",x(bBox),y(bBox))
redraw 1
wait 2
loop
return
#global
main
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX