Re: Tyhmät kysymykset
Posted: Sun Jan 13, 2008 12:11 pm
olen muistanut käyttää maailman kordinaatteja mutta jotenkin se täytyis saada pysähtymään seinään
Game Making Should Be Easy...
https://www.coolbasic.com/phpBB3/
Liikuta sitä pikseli kerrallaan, kuten aiemmassa viestissäni opastin. Näin se ei mene sisään. Ja törmäyksen sattuessa liikuta pikselin verran taaksepäin ja poistu loopista.cheeshelmet.jr wrote:olen muistanut käyttää maailman kordinaatteja mutta jotenkin se täytyis saada pysähtymään seinään
Code: Select all
alku:
Repeat
If KeyHit(cbkeya) Then Goto peli
Text 0,0, "Reaktiotesteri - paina näppäintä a aloittaaksesi"
Text 0,15, "Ohjeet:"
Text 0,30, "Reaktiotesteri testaa nopeutesi."
DrawScreen
Forever
Text 0,45, "Jos vasemmalta lukien ensimmäinen pallo on täytetty, pitää sinun painaa 1, jos toinen, paina 2,"
Text 0,60, "jos kolmas, paina 3 ja jos viimeinen, paina 4."
peli:
i=Rand(1,4)
Repeat
Circle 10,30,10,0
Circle 30,30,10,0
Circle 50,30,10,0
Circle 70,30,10,0
If i=1 And KeyHit(cbkey1) Then Goto peli
If i<>1 And KeyHit(cbkey1) Then Goto gameover
If i=2 And KeyHit(cbkey2) Then Goto peli
If i<>2 And KeyHit(cbkey2) Then Goto gameover
If i=3 And KeyHit(cbkey3) Then Goto peli
If i<>3 And KeyHit(cbkey3) Then Goto gameover
If i=4 And KeyHit(cbkey4) Then Goto peli
If i<>4 And KeyHit(cbkey4) Then Goto gameover
If i=1 Then Circle 10,30,10
If i=2 Then Circle 30,30,10
If i=3 Then Circle 50,30,10
If i=4 Then Circle 70,30,10
DrawScreen
Forever
gameover:
Text 0,0, "Hävisit, voit koittaa uudestaan painamalla mitä tahansa näppäintä."
DrawScreen
WaitKey
Goto alku
Pistähän clearkeys peli:n alkuun jotta vanhat painallukset eivät olisi muistissa ja näin peli luulisi, että olet jo painanut jotain näppäinät. Tähän tapaan:Late wrote: Miksi heti ensimmäinen painallus tuottaa gameoverin? Siis vaikka painaisi oikein?
Jos olen oikein ajatellut, kohta "If i<>1 And KeyHit(cbkey1) Then Goto gameover" tarkoittaa hieman selkeämmin:
"Jos i on_eri_suuri_kuin 1 Ja Painetaan_Näppäintä_1 Niin Mennään_kohtaan gameover"? Jos näin on, ei periaatteessa pitäisi olla mitään vikaa? Mutta nähtävästi siellä on joku ongelma. Vai onko se jossain muualla? Kiitos jo etukäteen.
Code: Select all
Repeat
If KeyHit(cbkeya) Then Goto peli
Text 0,0, "Reaktiotesteri - paina näppäintä a aloittaaksesi"
Text 0,15, "Ohjeet:"
Text 0,30, "Reaktiotesteri testaa nopeutesi."
DrawScreen
Forever
Text 0,45, "Jos vasemmalta lukien ensimmäinen pallo on täytetty, pitää sinun painaa 1, jos toinen, paina 2,"
Text 0,60, "jos kolmas, paina 3 ja jos viimeinen, paina 4."
peli:
i=Rand(1,4)
ClearKeys
Repeat
Circle 10,30,10,0
Circle 30,30,10,0
Circle 50,30,10,0
Circle 70,30,10,0
If i=1 And KeyHit(cbkey1) Then Goto peli
If i<>1 And KeyHit(cbkey1) Then Goto gameover
If i=2 And KeyHit(cbkey2) Then Goto peli
If i<>2 And KeyHit(cbkey2) Then Goto gameover
If i=3 And KeyHit(cbkey3) Then Goto peli
If i<>3 And KeyHit(cbkey3) Then Goto gameover
If i=4 And KeyHit(cbkey4) Then Goto peli
If i<>4 And KeyHit(cbkey4) Then Goto gameover
If i=1 Then Circle 10,30,10
If i=2 Then Circle 30,30,10
If i=3 Then Circle 50,30,10
If i=4 Then Circle 70,30,10
DrawScreen
Forever
gameover:
Text 0,0, "Hävisit, voit koittaa uudestaan painamalla mitä tahansa näppäintä."
DrawScreen
WaitKey
Code: Select all
SCREEN 700,30
Repeat
If havitty Then
Text 5,5,"Peli loppui. Sait " + pisteet + " pistettä."
Else
Text 5,5,"Paina kuvan osoittamaa numeronäppäintä. Paina jotain näppäintä aloittaaksesi."
EndIf
DrawScreen : WaitKey
havitty = 0 : pisteet = 0
Repeat
i = Rand(1,4)
'Text 0,0,i
For x = 1 To 4
Circle 300 + x*20,5,15,x=i
Next x
Text 5,2,"Pisteet: " + pisteet
DrawScreen
painettu = WaitKey() - 1
If painettu = i Then pisteet + 1 Else havitty = 1 : Exit
Forever
Forever
Code: Select all
Type SHOT
Field obj 'object is saved here
End Type
Type ENEMY
Field obj 'object is saved here
Field health 'enemys health variable
End Type
FrameLimit 40 'limit speed
player=LoadObject("Media\soldier.bmp",72) 'player object
'master object, all other enemies are cloned from this one
master_enemy=LoadObject("Media\guy.bmp",72)
ShowObject master_enemy, OFF 'hide the master objecet
bullet_obj=LoadObject("Media\bullet.bmp") ' master bullet object
ShowObject bullet_obj,OFF
AddText " Move with arrows, CTRL to shoot."
AddText ""
AddText " Add enemies with your mouse."
Repeat
'Control player object with arrows
If LeftKey() Then TurnObject player,5
If RightKey() Then TurnObject player,-5
If UpKey() Then MoveObject player,2
If DownKey() Then MoveObject player,-2
'Shooting system
If KeyDown(cbKeyRControl) And reload=0 Then
newbullet.SHOT = New(SHOT) 'create a new shot
newbullet\obj=CloneObject(bullet_obj) 'clone from master bullet
'place the bullet on the player
CloneObjectPosition newbullet\obj,player
'put it on right orientation
CloneObjectOrientation newbullet\obj,player
reload=5 'weapon reload
EndIf
'update shooting
If reload>0 Then reload=reload-1
If MouseHit(1) Then ' If mouse is clicked
newenemy.ENEMY = New(ENEMY) ' create a New enemy
newenemy\obj = CloneObject(master_enemy) ' clone it from the master object
newenemy\health = 75 'enemy health
PositionObject newenemy\obj,MouseWX(),MouseWY() 'ON the mouse world coordinates
RotateObject newenemy\obj,Rand(360) ' random direction
EndIf
'Update all the bullets
For newbullet.SHOT = Each SHOT 'Loop through all the bullets
MoveObject newbullet\obj,6
If ObjectX(newbullet\obj)<-180 Or ObjectX(newbullet\obj)>180 Or ObjectY(newbullet\obj)<-130 Or ObjectY(newbullet\obj)>130 Then
'bullet goes outside play-area --> mark it to be destroyed
kill_this_bullet = 1
EndIf
'The trick is To update te enemies inside the bullet loop
For newenemy.ENEMY = Each ENEMY 'Loop through all the bullets
If ObjectsOverlap(newenemy\obj,newbullet\obj) Then 'If objects overlap eachother
newenemy\health - 25 'reduce some health from the enemy
kill_this_bullet = 1 'mark the bullet To be removed
EndIf
' the actual AI And health check starts ON row 78
Next newenemy
If kill_this_bullet = 1 Then ' you cant just remove the bullet, it will cause MAV
DeleteObject newbullet\obj 'remove the object
Delete newbullet 'remove the whole bullet
kill_this_bullet = 0 ' back To Default value
EndIf
Next newbullet
' And now update the ai And stuff
For newenemy.ENEMY = Each ENEMY 'Loop through all the bullets
'some great AI
MoveObject newenemy\obj,1
'If enemy leaves the boundaries
If ObjectX(newenemy\obj)<-180 Or ObjectX(newenemy\obj)>180 Or ObjectY(newenemy\obj)<-130 Or ObjectY(newenemy\obj)>130 Then
MoveObject newenemy\obj,-3 'move it back
TurnObject newenemy\obj,180 'rotate it To the opposite direction
EndIf
If newenemy\health < 0 Then kill_this_enemy = 1 'If health goes below zero -> kill
If kill_this_enemy = 1 Then 'If the enemy is marked To die, kill it now :(
DeleteObject newenemy\obj
Delete newenemy
kill_this_enemy = 0
EndIf
Next newenemy
'this before screen graphics (box)
DrawGame
'draw the game boundaries
Color cbOrange
Box 20,20,360,260,OFF
DrawScreen
Until EscapeKey()
Code: Select all
Pointobject vihu, pelaaja
Code: Select all
FrameLimit 40
tähtäys=LoadImage("media\cursor.bmp")
heppu=LoadObject("media\soldier.bmp")
Repeat
TranslateObject heppu ,RightKey()*2,0
TranslateObject heppu, -LeftKey()*2,0
TranslateObject heppu,0,UpKey()*2
TranslateObject heppu,0, -DownKey()*2
PointObject heppu,tähtäys
ShowMouse tähtäys
DrawScreen
Until EscapeKey()
Code: Select all
RotateObject objGuy, GetAngle(ObjectX(objGuy),-ObjectY(objGuy),MouseWX(),-MouseWY())
Code: Select all
FrameLimit 40
tähtäys=LoadObject("media\cursor.bmp")
heppu=LoadObject("media\soldier.bmp")
Repeat
PositionObject tähtäys,mouseWX(),mouseWY()
TranslateObject heppu ,RightKey()*2,0
TranslateObject heppu, -LeftKey()*2,0
TranslateObject heppu,0,UpKey()*2
TranslateObject heppu,0, -DownKey()*2
PointObject heppu,tähtäys
DrawScreen
Until EscapeKey()
No nyt joku ymmärsi kuinka tyhmä olen! Kiitokset kaikille kolmelle siitä, että jaksoitte nähdä vaivaa.Jonez wrote:Johtuu siitä että objektille "heppu" ei ole asetettu käännösarvoa, eli se voi osoittaa vain yhteen suuntaan. Muuta sen hepun lataus tällaiseksi:
heppu=LoadObject("media\soldier.bmp", 72)