Показать сообщение отдельно
Старый 30.06.2012, 16:58   #5
Okay
Знающий
 
Регистрация: 21.11.2011
Сообщений: 284
Написано 17 полезных сообщений
(для 74 пользователей)
Ответ: Гравитация в 2D

Вот весь код
Graphics 840,640,16,2
SetBuffer BackBuffer()

Global sBegin

Global mBack = LoadImage("media/menu/back.bmp")
Global mExit = LoadImage("media/menu/exit.bmp")

Global mBegin = LoadImage("media/menu/mBegin.bmp")
Global mSettings = LoadImage("media/menu/settings.bmp")
Global mgSettings = LoadImage("media/menu/settings1.bmp")
Global millibegin = MilliSecs()
Global mgBegin = LoadImage("media/menu/mgBegin.bmp")
Global sg1 = LoadImage("media/menu/startgame.bmp")
Global menuok = False
Global sg2 = LoadImage("media/menu/startgame1.bmp")
Global sgg = False
Global cursor = LoadImage("media/menu/cursor.bmp")
Global player1 = LoadImage("media/skins/player1.bmp")
Global block = LoadImage("media/level1/wall.bmp")
Global ttt = MilliSecs()
Global gravity = 1
Global velgra = 5

Global left1, right1, left2, right2

HidePointer
AppTitle "Mario War 0.1 'LOG'"

Global StartTeam = 0
Global StartTColor = 0
Global StartSkin1 = 0

Type player
Field lives
Field gun
Field kills
Field team
Field skin
Field corx
Field cory
Field tcolor
Field vely
Field accel
Field jumping
End Type 

Global nplayer1.player = New player
nplayer1\lives = 0
nplayer1\gun = 0
nplayer1\kills = 0
nplayer1\team = 0
nplayer1\skin = 0
nplayer1\corx = 0
nplayer1\cory = 0
nplayer1\vely = 0
nplayer1\accel = 10
nplayer1\jumping = False
nplayer1\tcolor = 0

Global nplayer2.player = New player
nplayer2\lives = 0
nplayer2\gun = 0
nplayer2\kills = 0
nplayer2\team = 0
nplayer2\skin = 0
nplayer2\corx = 0
nplayer2\cory = 0
nplayer2\tcolor = 0



While Not KeyDown(56) And KeyDown(62)
Cls

If menuok = True Then
    DrawImage mBegin,0,0
    If sgg = False Then
        DrawBlock sg1,220,210
        DrawBlock mSettings,220,320
        DrawBlock mExit,550,550
        If ImagesCollide(sg1,220,210,0,cursor,MouseX(),MouseY(),0) Then
            DrawBlock sg2,220,210
            If MouseHit(1) Then
                Gosub changeplayers
            EndIf
        EndIf
        If ImagesCollide(mSettings,220,320,0,cursor,MouseX(),MouseY(),0) Then
            DrawBlock mgSettings,220,320
            If MouseHit(1) Then
                Gosub settings
            EndIf
        EndIf
        If MouseHit(1) Then
            If ImagesCollide(mExit,550,550,0,cursor,MouseX(),MouseY(),0) Then
                End
            Else
            
            EndIf
        EndIf
    EndIf 
EndIf


While MilliSecs() < millibegin + 3000
DrawImage mgBegin,0,0
Wend menuok = True

FlushKeys
DrawImage cursor,MouseX(),MouseY()
Flip
Wend

.changeplayers
While Not KeyDown(56) And KeyDown(62)
Cls

If menuok = True Then
    DrawImage mBegin,0,0
    DrawBlock mBack,550,550
    If MouseHit(1) Then
        If ImagesCollide(mBack,550,550,0,cursor,MouseX(),MouseY(),0) Then
            Return
        Else
  
        EndIf
    EndIf
EndIf

If KeyDown(28) Then
    Gosub StartGame
    gravity = 1
EndIf 


FlushKeys
DrawImage cursor,MouseX(),MouseY()
Flip
Wend



.settings
While Not KeyDown(56) And KeyDown(62)
Cls

If menuok = True Then
    DrawImage mBegin,0,0
    DrawBlock mBack,550,550
    If MouseHit(1) Then
        If ImagesCollide(mBack,550,550,0,cursor,MouseX(),MouseY(),0) Then
            Return
        Else

        EndIf
    EndIf
EndIf


FlushKeys
DrawImage cursor,MouseX(),MouseY()
Flip
Wend 


.StartGame
OnPlayer1Spawn()
OnPlayer2Spawn()
Global speedss = 5
Repeat
Cls

nplayer1\cory = nplayer1\cory + velgra
velgra = 5

If right1 = 1 Then
    DrawImageRect player1,nplayer1\corx,nplayer1\cory,0,0,25,31
EndIf 

If left1 = 2 Then
    DrawImageRect player1,nplayer1\corx,nplayer1\cory,78,0,103,31
EndIf 

DrawBlock block,300,600

If KeyDown(203) Then
    nplayer1\corx = nplayer1\corx - 1.6
    right1 = 2
    left1 = 2
EndIf

If KeyDown(205) Then
    nplayer1\corx = nplayer1\corx + 1.6
    right1 = 1
    left1 = 1
EndIf

If KeyDown(203) And KeyDown(77) Then
    nplayer1\corx = nplayer1\corx - 2.3
    right1 = 2
    left1 = 2
EndIf

If KeyDown(205) And KeyDown(77) Then
    nplayer1\corx = nplayer1\corx + 2.3
    right1 = 1
    left1 = 1
EndIf

If KeyHit(82) Then

	nplayer1\vely = 70
	nplayer1\jumping = True
	
EndIf  



If nplayer1\jumping = True

	If nplayer1\vely > -100   
             nplayer1\vely = nplayer1\vely - nplayer1\accel
             nplayer1\cory = nplayer1\cory - nplayer1\vely
	EndIf

EndIf

If nplayer1\cory <= 0

	nplayer1\vely = 0
	nplayer1\jumping = False
EndIf

If ImagesCollide(player1,nplayer1\corx,nplayer1\cory,0,block,300,600,0) Then
        velgra = 0
EndIf

If nplayer1\cory > 640 Then
    nplayer1\cory = 0
EndIf

FlushKeys
Flip
Forever



Function OnPlayer1Spawn()

right1 = 1
left1 = 1 

Local Spawnx = Rnd(1,840)
Local Spawny = Rnd(1,640)

nplayer1\corx = Spawnx
nplayer1\cory = Spawny

StartLocalGame()

gravity = 1
End Function



Function OnPlayer2Spawn()

Local Spawnx = Rnd(0,840)
Local Spawny = Rnd(0,640) 

nplayer1\corx = Spawnx
nplayer1\cory = Spawny

StartLocalGame()

End Function


Function StartLocalGame()

nplayer1\lives = StartLives
nplayer1\kills = StartKills
nplayer1\team = StartTeam1
nplayer1\tcolor = StartTColor1

nplayer2\lives = StartLives
nplayer2\kills = StartKills
nplayer2\team = StartTeam2
nplayer2\tcolor = StartTColor2

End Function


Function OnPlayer1Death()

nplayer1\lives = nplayer1\lives - 1
OnPlayer1Spawn()

End Function


Function OnPlayer2Death()

nplayer2\lives = nplayer2\lives - 1
OnPlayer2Spawn()

End Function 


Function AI()

If nplayer1\cory > nplayer2\cory Then Jump()

If nplayer1\corx > nplayer2\corx Then GoRight()
If nplayer1\corx < nplayer2\corx Then GoLeft()

If nplayer1\cory = nplayer2\cory Then JumpAttack()

If nplayer2\gun = 1 And 2 And 3 Then Attack()

End Function
 


Function Jump()

Local jn1cory
Local trt = MilliSecs()
    Repeat
    If ImagesCollide(player1,nplayer1\corx,nplayer1\cory,0,block,300,600,0) Then
            nplayer1\cory = nplayer1\cory - (3*2)
            
    Else

    EndIf
    Until MilliSecs() < (trt + 2000)
End Function




Function GoLeft()

nplayer2\corx = nplayer2\corx - 0.1

End Function


Function GoRight()

nplayer2\corx = nplayer2\corx + 0.1

End Function


Function JumpAttack()

End Function


Function Attack()

End Function
(Offline)
 
Ответить с цитированием