HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2010
0417
takayaレースゲームでコンピュータを作ろうとしています。6解決


takaya

リンク

2010/4/17(Sat) 12:48:44|NO.32010

#module
#deffunc circlet double x,double y,double r,int a
circle x-r,y-r,x+r,y+r,a
return
#global

dx=ginfo(20)
dy=ginfo(21)
scx=1000
scy=1000
asx=400
asy=300
wa=10

cp=1
cpu=1
minus=-1

mx=550.0;現在X座標
my=150.0;現在Y座標
nx=mx;1つ前X座標
ny=my;1つ前Y座標
mr=3.14;ハンドル方向
mrsp=0.05;ハンドル
mmaxsp=2.0;最高速度
msp=0.0;現在速度
mspup=0.02;アクセル
mspdo=0.1;ブレーキ
mmaxbsp=1.0;バックの最高速度
mspm=0.005;摩擦

if cp=1{
dim cx,5
dim cy,5
c=1
cx(1)=750 ここを目印にして進むようにしようとしています。
cx(2)=800
cx(3)=200
cx(4)=200
cy(1)=200
cy(2)=800
cy(3)=800
cy(4)=250
}

p=3.14159265358979323846
p2=p*2.0
screen 2,scx,scy,0,(dx-asx)/2,(dy-asy-50)/2,asx,asy
*main

gx=mx-asx/2
gy=my-asy/2
if gx<0:gx=0
if gy<0:gy=0
if gx>scx-asx:gx=scx-asx
if gy>scy-asy:gy=scy-asy

groll gx,gy

mx=limitf(mx,0,scx)
my=limitf(my,0,scy)

redraw 0

gmode 4,,,256
color 113,113,113

pos 0,0
celput 20,0,1,1,0.0

if mr>=p:mr=mr-p2
if mr<=p*minus:mr=mr+p2

pos mx,my
celput 11,0,1,1,mr

color 255,255,255
circlet 750,200,5
circlet 800,800,5
circlet 200,800,5
circlet 200,250,5

redraw 1

if cp=1{

mi=0
hi=0
spa=0
b=0

spa=1

ccx=mx-cx(c)
ccy=my-cy(c)
cr=atan(ccy,ccx)
if cr>=p:cr=cr-p2
if cr<=p*minus:cr=cr+p2;:if c=3:stop
if cpu=1{
;if mr<0.0:mr*minus
;if cr<0.0:cr*minus
if mr>cr:hi=1
if mr<cr:mi=1
}
if cpu=2{
cpp=p-(mr+cr)
cpm=mr-cr
if cpp>=p2:cpp=cpp-p2
if cpp<=0.0:cpp=cpp+p2
if cpm>=p2:cpm=cpm-p2
if cpm<=0.0:cpm=cpm+p2
if cpp>cpm:hi=1
if cpp<cpm:mi=1
}
if mr=cr:{
rn=rnd(2)
if rn=0:hi=1
if rn=1:mi=1
}

if cx(c)-5<mx:if cx(c)+5>mx:if cy(c)-5<my:if cy(c)+5>my:c+1

if c>4:c=1

}

if hi=1:mr-mrsp
if mi=1:mr+mrsp
if spa=1:msp+mspup
if b=1:msp-mspdo

if msp>0:msp-mspm
if msp<0:msp+mspm
if msp>mmaxsp:msp=mmaxsp
if msp<mmaxbsp*minus:msp=mmaxbsp*minus

mx=mx+cos(mr-3.14)*msp
my=my+sin(mr-3.14)*msp

await wa
goto *main

これを実行するといきなり1周円を書いて進んで
2週目以降は1つ目の目印で円を書いて進んでしまいます。

どうしたら円を書かないようになるでしょうか?

お願いします。



この記事に返信する


KA

リンク

2010/4/17(Sat) 14:48:56|NO.32012

質問のタイトルも意味不明ですが、質問の内容も把握出来ません。

取りあえず、スクリプトを動かしましたが
 1:コメントは後で書き足したのかな?
 2:69行辺りでエラーが出ます。
 3:質問の”円”自体が描画されません。
 4:どういう動作が正常なのか分かりません。



hatter

リンク

2010/4/17(Sat) 15:43:58|NO.32013

えっと、まだ途中までしかスクリプトを読んでないのですが分からない部分が1つ。
以下の変数の役割はなんでしょうか?
cp=1
cpu=1
minus=-1
推測するにCPU機能のON/OFFのフラグとマイナス値に対するフラグでしょうか?

そもそもこのプログラムがレースプログラムのCPU機能のデモ的なものでしょうか?



takaya

リンク

2010/4/17(Sat) 16:35:03|NO.32014

screen 0,300,100,0,0,0

randomize

#module
#deffunc circlet double x,double y,double r,int a
circle x-r,y-r,x+r,y+r,a
return
#global

dx=ginfo(20)
dy=ginfo(21)
scx=1000
scy=1000
asx=400
asy=300
wa=10

cp=1
cpu=1

pmax=4.0
pa=0.0

font "",20

gpos=""+dir_cur+"\\bmp\\"

color 128,128,128
boxf 0,30,300,50

celload ""+gpos+"title1.bmp",3
redraw 0
color 255,255,255
boxf 0,0,300,20
color 0,0,0
pa=pa+100.0/pmax
pos 0,0
mes ""+pa+"%"
color 0,255,0
boxf 0,30,0+pa*3.0,50
redraw 1

celload ""+gpos+"title2.bmp",4
redraw 0
color 255,255,255
boxf 0,0,300,20
color 0,0,0
pa=pa+100.0/pmax
pos 0,0
mes ""+pa+"%"
color 0,255,0
boxf 0,30,0+pa*3.0,50
redraw 1

celload ""+gpos+"カートライン.bmp",10
redraw 0
color 255,255,255
boxf 0,0,300,20
color 0,0,0
pa=pa+100.0/pmax
pos 0,0
mes ""+pa+"%"
color 0,255,0
boxf 0,30,0+pa*3.0,50
redraw 1

celload ""+gpos+"test.bmp",20
redraw 0
color 255,255,255
boxf 0,0,300,20
color 0,0,0
pa=pa+100.0/pmax
pos 0,0
mes ""+pa+"%"
color 0,255,0
boxf 0,30,0+pa*3.0,50
redraw 1

r1=255
g1=0
b1=0

buffer 11,20,20
color 113,113,113
boxf
color r1,g1,b1
boxf 2,4,15,15
gmode 4,20,20,256
color 113,113,113
pos 0,0
celput 10,0,1,1,0.0

celdiv 11,20,20,10,10

minus=-1

mx=550.0;現在X座標
my=150.0;現在Y座標
nx=mx;1つ前X座標
ny=my;1つ前Y座標
mr=3.14;ハンドル方向
mrsp=0.05;ハンドル
mmaxsp=2.0;最高速度
msp=0.0;現在速度
mspup=0.02;アクセル
mspdo=0.1;ブレーキ
mmaxbsp=1.0;バックの最高速度
mspm=0.005;摩擦

if cp=1{
dim cx,5
dim cy,5
c=1
cx(1)=750
cx(2)=800
cx(3)=200
cx(4)=200
cy(1)=200
cy(2)=800
cy(3)=800
cy(4)=250
}

p=3.14159265358979323846
p2=p*2.0

;bgscr 2,scx,scy,0,(dx-asx)/2,(dy-asy-50)/2,asx,asy
screen 2,scx,scy,0,(dx-asx)/2,(dy-asy-50)/2,asx,asy

*main

gx=mx-asx/2
gy=my-asy/2
if gx<0:gx=0
if gy<0:gy=0
if gx>scx-asx:gx=scx-asx
if gy>scy-asy:gy=scy-asy

groll gx,gy

mx=limitf(mx,0,scx)
my=limitf(my,0,scy)

redraw 0

gmode 4,,,256
color 113,113,113

pos 0,0
celput 20,0,1,1,0.0

if mr>=p:mr=mr-p2
if mr<=p*minus:mr=mr+p2

pos mx,my
celput 11,0,1,1,mr

color 255,255,255
circlet 750,200,5
circlet 800,800,5
circlet 200,800,5
circlet 200,250,5

redraw 1

getkey hi,37
getkey mi,39
getkey spa,32
getkey b,66

if cp=1{

mi=0
hi=0
spa=0
b=0

spa=1

ccx=mx-cx(c)
ccy=my-cy(c)
cr=atan(ccy,ccx)
if cr>=p:cr=cr-p2
if cr<=p*minus:cr=cr+p2;:if c=3:stop
if cpu=1{
;if mr<0.0:mr*minus
;if cr<0.0:cr*minus
if mr>cr:hi=1
if mr<cr:mi=1
}
if cpu=2{
cpp=p-(mr+cr)
cpm=mr-cr
if cpp>=p2:cpp=cpp-p2
if cpp<=0.0:cpp=cpp+p2
if cpm>=p2:cpm=cpm-p2
if cpm<=0.0:cpm=cpm+p2
if cpp>cpm:hi=1
if cpp<cpm:mi=1
}
if mr=cr:{
rn=rnd(2)
if rn=0:hi=1
if rn=1:mi=1
}



if cx(c)-5<mx:if cx(c)+5>mx:if cy(c)-5<my:if cy(c)+5>my:c+1

if c>4:c=1

}

title ""+cpp+","+cpm+","+hi+","+mi+""

if hi=1:mr-mrsp
if mi=1:mr+mrsp
if spa=1:msp+mspup
if b=1:msp-mspdo

if msp>0:msp-mspm
if msp<0:msp+mspm
if msp>mmaxsp:msp=mmaxsp
if msp<mmaxbsp*minus:msp=mmaxbsp*minus

mx=mx+cos(mr-3.14)*msp
my=my+sin(mr-3.14)*msp

await wa
goto *main

これがスクリプト全体です。



takaya

リンク

2010/4/17(Sat) 16:52:22|NO.32016

cpはコンピュータに動作を任せるか任せないかです。1が任せる
cpuは2つ動作を用意しているので選べるように(どちらも出来てない)



木村

リンク

2010/4/17(Sat) 18:21:01|NO.32021

 目標角度と現在角度からハンドルの切り方を算出する部分が間違っていました。修正例は以下

#module #deffunc circlet double x,double y,double r,int a circle x-r,y-r,x+r,y+r,a return #global dx=ginfo_dispx : dy=ginfo_dispy ;画面解像度 scx=1000 : scy=600 ;第2ウィンドウ全体の大きさ asx=400 : asy=300 ;第2ウィンドウ表示部分の大きさ wa=10 cp=1 : cpu=1 : minus=-1 mx=550.0 : my=150.0 ;(mx,my)キャラクター座標 nx=mx : ny=my ;1つ前のキャラクター座標 mr=3.14 ;キャラクターの方向 mrsp=0.05 ;ハンドル[rad] mmaxsp=3.0 ;最高速度[pixel/frame] msp=0.0 ;現在速度[pixel/frame] mspup=0.02 ;アクセル mspdo=0.1 ;ブレーキ mmaxbsp=1.0 ;バックの最高速度[pixel/frame] mspm=0.005 ;摩擦 if cp=1{ ;(cx.k,cy.k) k番目の目標地点 dim cx,5 : cx.0=0,750,800,200,200 dim cy,5 : cy.0=0,200,500,500,250 repeat 5 cx.cnt=rnd(scx) : cy.cnt=rnd(scy) loop c=1 ;目標地点を示す番号 } p=m_pi ;円周率 p2=p*2.0 ;1回転相当値[rad] minus=-1 ; screen 2,scx,scy,0,(dx-asx)/2,(dy-asy-50)/2,asx,asy buffer 1,scx,scy,0 : repeat scx/10 : x=cnt repeat scy/10 : y=cnt color x*255/(scx/10),255,y*255/(scy/10) : boxf x*10,y*10,x*10+9,y*10+9 loop loop *main //キャラクターに従って表示部分を移動させる gsel 2 gx=mx-asx/2 : gy=my-asy/2 ;(gx,gy)キャラクターを中心とした際の左上値 if gx<0 : gx=0 if gy<0 : gy=0 if gx>scx-asx : gx=scx-asx if gy>scy-asy : gy=scy-asy groll gx,gy //フィールドから外れたキャラクターをフィールド内に復元する mx=limitf(mx,0,scx) : my=limitf(my,0,scy) //描画開始 gsel 2 : redraw 0 : gmode 0,scx,scy : pos 0,0 : gcopy 1,0,0 //(113,113,113)色を透明色とした完全コピー gmode 4,,,256 : color 113,113,113 //(0,0)地点を描画 color 128,128,128 : boxf -20,-20,20,20 //キャラクターの進行方向をmr∈(0<=mr<2π)に限定する if mr>=m_pi*2 : mr=mr-m_pi*2 ;方角が360度以上になった際、360度未満に修正 if mr<0 : mr=mr+m_pi*2 ;方角が0度未満になった際、0度以上に修正 //キャラクターを描画 color 0,128,0 : boxf mx-10,my-10,mx+10,my+10 //目標地点を描画 color 64,64,64 : repeat 5 : circlet cx.cnt,cy.cnt,5,1 : loop //描画終了 gsel 2 : redraw 1 if cp=1{ ;CPU操作時の行動指針 //変数定義 mi=0 ;右にハンドルを切るという意味の変数 hi=0 ;左にハンドルを切るという意味の変数 spa=0 ;直後にspa=1があるのに何故定義する? b=0 ;? spa=1 ;? ccx=mx-cx(c) : ccy=my-cy(c) ;(ccx,ccy)目標地点までの距離 cr=atan(ccy,ccx) ;目標地点の方向 if cr>=m_pi : cr=cr-p2 if cr<=p*minus:cr=cr+p2;:if c=3:stop //★★修正部分★★ if cpu=1 { checkr=mr-cr if checkr>m_pi : checkr-=m_pi*2 if checkr<-m_pi : checkr+=m_pi*2 if checkr>0 : hi=0 : mi=1 : else : hi=1 : mi=0 } if (cx(c)-5<mx) & (cx(c)+5>mx) & (cy(c)-5<my) & (cy(c)+5>my) : c+1 if c>4:c=0 } //左ハンドル切って右回転する仕様だったので修正 if hi=1 : mr+mrsp if mi=1 : mr-mrsp if spa=1:msp+mspup if b=1:msp-mspdo if msp>0:msp-mspm if msp<0:msp+mspm if msp>mmaxsp:msp=mmaxsp if msp<mmaxbsp*minus:msp=mmaxbsp*minus mx=mx+cos(mr-m_pi)*msp : my=my+sin(mr-m_pi)*msp ;ハンドル方向に加速 await wa goto *main



takaya

リンク

2010/4/17(Sat) 18:32:32|NO.32022

ありがとうございました。



ONION software Copyright 1997-2023(c) All rights reserved.