Hiiren seuraaminen

Voit pyytää apua ohjelmointiongelmiin täältä.
Post Reply
KimmyMan
Newcomer
Posts: 4
Joined: Sat Jun 18, 2011 11:02 pm

Hiiren seuraaminen

Post by KimmyMan » Sat Jun 18, 2011 11:15 pm

Jep, elikkä ideana olisi että pelaajan hahmo katsoisi kokoajan hiiren suuntaan.

Ei toimi. :evil:

En saa hahmon ja hiiren välistä kulmaa jostain syystä oikein. Niillä on kokonaan eri koordinaatit.
Alussa pelaaja sijaitsee koordinaateilla 100,100 ja hiiri on ruudun ylävasemmassa mutta senkin koordinaatit ovat 100,100?

Vaikea selittää, laitan koodit tohon nii voitte kopioida ja katsoa ite.

Kannattaa ajaa ohjelma ensin. Niin ongelman huomaa parhaiten, ja sitten voi perehtyä kirjoittamiini sotkuihin.



Code: Select all

SCREEN 800,580,32
    
    

   
    MUSIC = PlaySound("data\SK_battle2.mp3") 
    
    Type ENEMIES
    Field grunt
    Field hp    
    Field berserk
    EndType
   
   
    Type AMMO
    Field obj
    Field pati9mm
    End Type
    
    Type GUNS
    Field pistol
    End Type
    
    Type OBSTACLE
    Field obj2
      End Type
   
    stamina = 1000 
    wallspawn = 5 
    enemyspawn = 20

    shot=LoadSound("data\gun1.wav")
    death=LoadSound("data\scream2.wav")
     
   cursor=LoadImage("data\target.bmp")
   
    character = LoadObject("data\soldier.bmp", 360)
    
    pistol9mm = LoadObject("data\ase.bmp")
    vihu = LoadObject("data\enemy.bmp", 360)
    muuri = LoadObject("data\wall.bmp")
    bullet = LoadObject("data\bullet.bmp")

    
    ShowObject bullet, OFF
    ShowObject muuri, OFF
    ShowObject pistol9mm, OFF


    FrameLimit 60
    



'MAIN MENU--------------------------------------------------------------------------------------------------------------------
Menu:

ShowMouse cursor

ShowObject character, OFF
ShowObject vihu, OFF

Repeat



Text 500,0, "MouseX: " + MouseX()
Text 500,20, "MouseY: " +MouseY()

Text 100,100, "Start Game"
Text 100,150, "Exit Game"

Color cbred

'START-BAR
If MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 Then Box 95,95,100,25,0



'EXIT-BAR
If MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then Box 95,145,100,25,0


DrawScreen
If MouseHit(1) And MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then End
Until MouseHit(1) And MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 









'THE ACTUAL GAME---------------------------------------------------------------------------------------------------------------
Game:
        'shows the objects which were hidden in the menu
ShowObject vihu, ON
ShowObject pistol9mm, ON
ShowObject character, ON






    ase.GUNS = New (GUNS)
    ase\pistol=CloneObject(pistol9mm)                   'guns must be spawned before the 
    PositionObject ase\pistol, 200,300                ' "repeat" command, for we only
                                                        'intend to spawn one


WEAPON1=0                        'Stuff that is pickable is first set to zero, of course
WIELD=1

    
Repeat


If WIELD=1 Then Circle 690,23,5
If WIELD=2 Then Circle 690,40,5


If KeyHit(2) Then WIELD=1
If KeyHit(3) and WEAPON1=1 Then WIELD=2


'WEAPON DAMAGES are randomized trhouhgout the whole gaming:
pistol22=Rand(5,35)
pistol9=Rand(15,60)



'SPAWNING STUFF:

If Not SoundPlaying (MUSIC) Then
music=PlaySound("data\SK_battle2.mp3")   'Makes sure the music keeps playing
EndIf
  
    gr.ENEMIES = New (ENEMIES)
    gr\grunt=CloneObject(vihu)   'Making enemies...
    
    If enemyspawn > 0 Then
    PositionObject gr\grunt, Rand (600),Rand(-600)
    gr\hp=100
    gr\berserk=0
    enemyspawn=enemyspawn-1            '...and spawning them all around de map
    EndIf
    
    wall.OBSTACLE = New (OBSTACLE)
    wall\obj2=CloneObject(muuri)           'same with de walls
    
    If wallspawn > 0 Then
    PositionObject wall\obj2, Rand(1000),Rand(-1000)
    wallspawn = wallspawn - 1
    EndIf
    
    
'------------------------------------------------ 
    
    
    For gr.ENEMIES = Each ENEMIES
    PointObject gr\grunt, character           'makes the grunts to point at the player
    Next gr
    
    

   
'-------------------------------------------------------------------------------------------------------------------------

'CAMERA, MOVEMENT AND HUD:

   'the camera follows the player..
CloneCameraPosition character

'HUD:------------------------------
Color cbred
Text 0,0, "Stamina: " + stamina     'displays the stamina
Text 0,20, "RELOAD: " +rate         'reloading Time And
Text 0,40, "FPS: " +FPS()           'game speed (frames per second)

Text 700,0, "Weapons:"

Text 700,20, ".22 Pistol"
Box 700,15,100,20,0

Text 700,40, "9mm Pistol"
If WEAPON1=1 Then Box 700,37,100,20,0



If stamina > 99 Then stamina = 100         'makes sure the players stamina wont go over 100
If stamina < 1 Then stamina = 0            'or below zero


'   CONTROLS and MOVEMENT:-------------------------------------
  
 Text 100,100, "Mouse X: "+MouseX()
 Text 100,80, "Mouse Y: "+MouseY()
 Text 100,120, "Character X: "+ObjectX(character)
 Text 100,135, "Character Y: "+ObjectY(character)
 


MouseLocation#=GetAngle(ObjectX(character),ObjectY(character),MouseX(),MouseY())


Line ObjectX(character),ObjectY(character),MouseX(),MouseY() 
 
 RotateObject character, MouseLocation#
  
  
  If KeyDown(17) Then TranslateObject character, 0,2
    If KeyDown(31) Then TranslateObject character, 0,-2
    
    If KeyDown(30) Then TranslateObject character, -2,0
    If KeyDown(32) Then TranslateObject character, 2,0                      'de keys, including sprint
    
    If KeyDown(17) And KeyDown(42)and stamina > 0 Then MoveObject character, 1      'spritning only possible if player has stamina 
    If KeyDown(17) And KeyDown(42) Then stamina = stamina -1                      'sprinting absorbs stamina
    
    If Not KeyDown(42) Then stamina = stamina +1                 'if not sprinting, stamina will refill
    
    If ObjectsOverlap (character, wall\obj2, 2) Then
    PositionObject character, 100,100
    EndIf
    
  
 
 'SHOOTING:----------------------------------------------------------------------------------------------
 
 



 
 If MouseDown(1) And rate = 0 Then

       
       projectile.AMMO = New (AMMO)
       projectile\obj=CloneObject(bullet)
       
       CloneObjectPosition projectile\obj, character
       CloneObjectOrientation projectile\obj, character
       PlaySound shot
       rate = 15
       
       
       EndIf
       
    If rate > 0 Then rate = rate -1
       
       
       For projectile.AMMO = Each AMMO 
       MoveObject projectile\obj, 10
       
       If Distance2 (projectile\obj, character)>500 Then   'bullets will be deleted when they are outside the line of sight.
       DeleteObject projectile\obj                          'thus they wont wander outside the screen and cause memory problems
       Delete projectile
       EndIf
       
       Next projectile
       

    
      
'OBJECT PROPERTIES-------------------------------------------------------------------------------------------------


'OBSTACLES:-------------------------------------------------
'Wall:


   For wall.OBSTACLE = Each OBSTACLE  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, wall\obj2) Then
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next wall 
      


'SUPPLIES:--------------------------------------------------
'9mm Pistol:

   
    for ase.GUNS = Each GUNS
    If ObjectsOverlap(ase\pistol, character) Then
    WEAPON1=1
    DeleteObject ase\pistol
    Delete ase
    EndIf
    Next ase



 'ENEMIES:---------------------------------------------------------
 'Grunt:
 
 
   For gr.ENEMIES = Each ENEMIES  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, gr\grunt) Then
        gr\berserk=1                                               'if a grunt gets shot, it will go berserk
        gr\hp = gr\hp - pistol22
        Text 385, 245,  + pistol22 +"!"
               
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next gr
 
      
      
         For gr.ENEMIES = Each ENEMIES
   
If berserk=0 And Distance2(character, gr\grunt) < 150 Then MoveObject gr\grunt, 1   'normal grunts only attack from short distance
  If gr\berserk=1 Then MoveObject gr\grunt,2                                        'berserked grunts run towards the player
   Next gr                                                                          'fast! - no matter the distance
      
      
      For gr.ENEMIES = Each ENEMIES
      If gr\hp < 1 Then                                                           'if a grunts health is reduced below zero it will die :(
      DeleteObject gr\grunt
      Delete gr
      
      EndIf
      Next gr
   
    
      
    UpdateGame
DrawGame        
DrawScreen


Forever

KimmyMan
Newcomer
Posts: 4
Joined: Sat Jun 18, 2011 11:02 pm

Ainiiin, perhana

Post by KimmyMan » Sat Jun 18, 2011 11:19 pm

koodissa on vaihdeltu tiedostonimiä ja hakemistoja mistä kuvat ja äänet haetaan..
siinä nyt ei kauaa kuitenkaan pitäisi mennä kun ne vaihtaa takaisin :D

sorry guys

User avatar
Latexi95
Guru
Posts: 1164
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: Hiiren seuraaminen

Post by Latexi95 » Sat Jun 18, 2011 11:34 pm

KimmyMan wrote:Jep, elikkä ideana olisi että pelaajan hahmo katsoisi kokoajan hiiren suuntaan.

Ei toimi. :evil:

En saa hahmon ja hiiren välistä kulmaa jostain syystä oikein. Niillä on kokonaan eri koordinaatit.
Alussa pelaaja sijaitsee koordinaateilla 100,100 ja hiiri on ruudun ylävasemmassa mutta senkin koordinaatit ovat 100,100?

Vaikea selittää, laitan koodit tohon nii voitte kopioida ja katsoa ite.

Kannattaa ajaa ohjelma ensin. Niin ongelman huomaa parhaiten, ja sitten voi perehtyä kirjoittamiini sotkuihin.



Code: Select all

SCREEN 800,580,32
    
    

   
    MUSIC = PlaySound("data\SK_battle2.mp3") 
    
    Type ENEMIES
    Field grunt
    Field hp    
    Field berserk
    EndType
   
   
    Type AMMO
    Field obj
    Field pati9mm
    End Type
    
    Type GUNS
    Field pistol
    End Type
    
    Type OBSTACLE
    Field obj2
      End Type
   
    stamina = 1000 
    wallspawn = 5 
    enemyspawn = 20

    shot=LoadSound("data\gun1.wav")
    death=LoadSound("data\scream2.wav")
     
   cursor=LoadImage("data\target.bmp")
   
    character = LoadObject("data\soldier.bmp", 360)
    
    pistol9mm = LoadObject("data\ase.bmp")
    vihu = LoadObject("data\enemy.bmp", 360)
    muuri = LoadObject("data\wall.bmp")
    bullet = LoadObject("data\bullet.bmp")

    
    ShowObject bullet, OFF
    ShowObject muuri, OFF
    ShowObject pistol9mm, OFF


    FrameLimit 60
    



'MAIN MENU--------------------------------------------------------------------------------------------------------------------
Menu:

ShowMouse cursor

ShowObject character, OFF
ShowObject vihu, OFF

Repeat



Text 500,0, "MouseX: " + MouseX()
Text 500,20, "MouseY: " +MouseY()

Text 100,100, "Start Game"
Text 100,150, "Exit Game"

Color cbred

'START-BAR
If MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 Then Box 95,95,100,25,0



'EXIT-BAR
If MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then Box 95,145,100,25,0


DrawScreen
If MouseHit(1) And MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then End
Until MouseHit(1) And MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 









'THE ACTUAL GAME---------------------------------------------------------------------------------------------------------------
Game:
        'shows the objects which were hidden in the menu
ShowObject vihu, ON
ShowObject pistol9mm, ON
ShowObject character, ON






    ase.GUNS = New (GUNS)
    ase\pistol=CloneObject(pistol9mm)                   'guns must be spawned before the 
    PositionObject ase\pistol, 200,300                ' "repeat" command, for we only
                                                        'intend to spawn one


WEAPON1=0                        'Stuff that is pickable is first set to zero, of course
WIELD=1

    
Repeat


If WIELD=1 Then Circle 690,23,5
If WIELD=2 Then Circle 690,40,5


If KeyHit(2) Then WIELD=1
If KeyHit(3) and WEAPON1=1 Then WIELD=2


'WEAPON DAMAGES are randomized trhouhgout the whole gaming:
pistol22=Rand(5,35)
pistol9=Rand(15,60)



'SPAWNING STUFF:

If Not SoundPlaying (MUSIC) Then
music=PlaySound("data\SK_battle2.mp3")   'Makes sure the music keeps playing
EndIf
  
    gr.ENEMIES = New (ENEMIES)
    gr\grunt=CloneObject(vihu)   'Making enemies...
    
    If enemyspawn > 0 Then
    PositionObject gr\grunt, Rand (600),Rand(-600)
    gr\hp=100
    gr\berserk=0
    enemyspawn=enemyspawn-1            '...and spawning them all around de map
    EndIf
    
    wall.OBSTACLE = New (OBSTACLE)
    wall\obj2=CloneObject(muuri)           'same with de walls
    
    If wallspawn > 0 Then
    PositionObject wall\obj2, Rand(1000),Rand(-1000)
    wallspawn = wallspawn - 1
    EndIf
    
    
'------------------------------------------------ 
    
    
    For gr.ENEMIES = Each ENEMIES
    PointObject gr\grunt, character           'makes the grunts to point at the player
    Next gr
    
    

   
'-------------------------------------------------------------------------------------------------------------------------

'CAMERA, MOVEMENT AND HUD:

   'the camera follows the player..
CloneCameraPosition character

'HUD:------------------------------
Color cbred
Text 0,0, "Stamina: " + stamina     'displays the stamina
Text 0,20, "RELOAD: " +rate         'reloading Time And
Text 0,40, "FPS: " +FPS()           'game speed (frames per second)

Text 700,0, "Weapons:"

Text 700,20, ".22 Pistol"
Box 700,15,100,20,0

Text 700,40, "9mm Pistol"
If WEAPON1=1 Then Box 700,37,100,20,0



If stamina > 99 Then stamina = 100         'makes sure the players stamina wont go over 100
If stamina < 1 Then stamina = 0            'or below zero


'   CONTROLS and MOVEMENT:-------------------------------------
  
 Text 100,100, "Mouse X: "+MouseX()
 Text 100,80, "Mouse Y: "+MouseY()
 Text 100,120, "Character X: "+ObjectX(character)
 Text 100,135, "Character Y: "+ObjectY(character)
 


MouseLocation#=GetAngle(ObjectX(character),ObjectY(character),MouseX(),MouseY())


Line ObjectX(character),ObjectY(character),MouseX(),MouseY() 
 
 RotateObject character, MouseLocation#
  
  
  If KeyDown(17) Then TranslateObject character, 0,2
    If KeyDown(31) Then TranslateObject character, 0,-2
    
    If KeyDown(30) Then TranslateObject character, -2,0
    If KeyDown(32) Then TranslateObject character, 2,0                      'de keys, including sprint
    
    If KeyDown(17) And KeyDown(42)and stamina > 0 Then MoveObject character, 1      'spritning only possible if player has stamina 
    If KeyDown(17) And KeyDown(42) Then stamina = stamina -1                      'sprinting absorbs stamina
    
    If Not KeyDown(42) Then stamina = stamina +1                 'if not sprinting, stamina will refill
    
    If ObjectsOverlap (character, wall\obj2, 2) Then
    PositionObject character, 100,100
    EndIf
    
  
 
 'SHOOTING:----------------------------------------------------------------------------------------------
 
 



 
 If MouseDown(1) And rate = 0 Then

       
       projectile.AMMO = New (AMMO)
       projectile\obj=CloneObject(bullet)
       
       CloneObjectPosition projectile\obj, character
       CloneObjectOrientation projectile\obj, character
       PlaySound shot
       rate = 15
       
       
       EndIf
       
    If rate > 0 Then rate = rate -1
       
       
       For projectile.AMMO = Each AMMO 
       MoveObject projectile\obj, 10
       
       If Distance2 (projectile\obj, character)>500 Then   'bullets will be deleted when they are outside the line of sight.
       DeleteObject projectile\obj                          'thus they wont wander outside the screen and cause memory problems
       Delete projectile
       EndIf
       
       Next projectile
       

    
      
'OBJECT PROPERTIES-------------------------------------------------------------------------------------------------


'OBSTACLES:-------------------------------------------------
'Wall:


   For wall.OBSTACLE = Each OBSTACLE  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, wall\obj2) Then
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next wall 
      


'SUPPLIES:--------------------------------------------------
'9mm Pistol:

   
    for ase.GUNS = Each GUNS
    If ObjectsOverlap(ase\pistol, character) Then
    WEAPON1=1
    DeleteObject ase\pistol
    Delete ase
    EndIf
    Next ase



 'ENEMIES:---------------------------------------------------------
 'Grunt:
 
 
   For gr.ENEMIES = Each ENEMIES  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, gr\grunt) Then
        gr\berserk=1                                               'if a grunt gets shot, it will go berserk
        gr\hp = gr\hp - pistol22
        Text 385, 245,  + pistol22 +"!"
               
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next gr
 
      
      
         For gr.ENEMIES = Each ENEMIES
   
If berserk=0 And Distance2(character, gr\grunt) < 150 Then MoveObject gr\grunt, 1   'normal grunts only attack from short distance
  If gr\berserk=1 Then MoveObject gr\grunt,2                                        'berserked grunts run towards the player
   Next gr                                                                          'fast! - no matter the distance
      
      
      For gr.ENEMIES = Each ENEMIES
      If gr\hp < 1 Then                                                           'if a grunts health is reduced below zero it will die :(
      DeleteObject gr\grunt
      Delete gr
      
      EndIf
      Next gr
   
    
      
    UpdateGame
DrawGame        
DrawScreen


Forever
Juu tuo ongelma juhtuu siitä, että hiiren koordinaatit ovat ikkunakoordinaatteja eli (0,0) on ruudun vasemmassa yläkulmassa ja oikea alakulmassa on (ScreenWidth()-1,ScreenHeight()) piste. Objectit taas ovat maailmakoordinaateissa, jolloin (0,0) on keskelle pelikentää eli keskellä ruutua kun kamera on keskellä. Hiiren maailmakoordinaatit saadaan komennoilla MouseWX() ja MouseWY(), ja täältä löytyvät funktiot objectin ikkunakoordinaattejen saamiseen. Huomaa, että GetAngle on tarkoitettu kulmien mittaamiseen ruutukoordinaateista, joten jos haluat mitata kulman maailmakoordinaateissa se onnistuu vaihtamalla toinen y-koordinaatti miinuksen puoleiseksi. esim.

Code: Select all

GetAngle(ObjectX(ukkeli),ObjectY(ukkeli),MouseWX(),-MouseWY())
Joskus koodaminen on turhauttavaa kun ei meinaa onnistua, mutta ihan mielenkiintoiseltahan tuo koodisi näytti. En kylläkään ruvennut kokeilemaan sillä minulla ei ole tarvittavaa grafiikkaa. Ensi kerralla kannattaa laittaa foorumeille versio joka toimii pelkillä cb:n omilla grafiikoilla (esim. "Media/gun1.wav"), jos kysymys on jostain haastavammasta ongelmasta, niin vastaus tulee paljon nopeammin.

KimmyMan
Newcomer
Posts: 4
Joined: Sat Jun 18, 2011 11:02 pm

Re: Hiiren seuraaminen

Post by KimmyMan » Sun Jun 19, 2011 10:35 am

Ei auttanut tuokaan :|

Luulen että vika on jossain muualla, sen huomaa kun pelin ajaa.
Kokeilkaapa iha huviksenne.

Nyt olen myös korjannut hakemisto- ja tiedostonimet eli grafiikka
ja äänet löytyvät sieltä CB:n Media- kansiosta :)

Elikkäs, pistin ohjelmaan pari indikaattoria näyttämään missä hiiren ja
pelaajan screen- ja worldkoordinaatit ovat.

Please, have a look.

Code: Select all


' Move with WASD, aim and shoot with MOUSE, swap between weapons with NUMBER keys.

SCREEN 800,580,32
    
   
    MUSIC = PlaySound("media\SK_battle2.mp3") 
    
    Type ENEMIES
    Field grunt
    Field hp    
    Field berserk
    EndType
   
   
    Type AMMO
    Field obj
    Field pati9mm
    End Type
    
    Type GUNS
    Field pistol
    End Type
    
    Type OBSTACLE
    Field obj2
      End Type
   
    stamina = 1000 
    wallspawn = 5 
    enemyspawn = 20

    shot=LoadSound("media\gun 1.wav")
    death=LoadSound("media\scream2.wav")
     
   cursor=LoadImage("media\target.bmp")
   
    character = LoadObject("media\soldier.bmp", 360)
    
    pistol9mm = LoadObject("media\bigbullet.bmp")
    vihu = LoadObject("media\ukkeli2.bmp", 360)
    muuri = LoadObject("media\buttoni.bmp")
    bullet = LoadObject("media\bullet.bmp")

    
    ShowObject bullet, OFF
    ShowObject muuri, OFF
    ShowObject pistol9mm, OFF


    FrameLimit 60
    



'MAIN MENU--------------------------------------------------------------------------------------------------------------------
Menu:

ShowMouse cursor

ShowObject character, OFF
ShowObject vihu, OFF

Repeat



Text 500,0, "MouseX: " + MouseX()
Text 500,20, "MouseY: " +MouseY()

Text 100,100, "Start Game"
Text 100,150, "Exit Game"

Color cbred

'START-BAR
If MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 Then Box 95,95,100,25,0



'EXIT-BAR
If MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then Box 95,145,100,25,0


DrawScreen
If MouseHit(1) And MouseX() > 95 And MouseY() > 145 And MouseX() < 180 And MouseY() < 165 Then End
Until MouseHit(1) And MouseX() > 95 And MouseY() > 95 And MouseX() < 180 And MouseY() < 120 









'THE ACTUAL GAME---------------------------------------------------------------------------------------------------------------
Game:
        'shows the objects which were hidden in the menu
ShowObject vihu, ON
ShowObject pistol9mm, ON
ShowObject character, ON






    ase.GUNS = New (GUNS)
    ase\pistol=CloneObject(pistol9mm)                   'guns must be spawned before the 
    PositionObject ase\pistol, 200,300                ' "repeat" command, for we only
                                                        'intend to spawn one


WEAPON1=0                        'Stuff that is pickable is first set to zero, of course
WIELD=1

    
Repeat


If WIELD=1 Then Circle 690,23,5
If WIELD=2 Then Circle 690,40,5


If KeyHit(2) Then WIELD=1
If KeyHit(3) and WEAPON1=1 Then WIELD=2


'WEAPON DAMAGES are randomized trhouhgout the whole gaming:
pistol22=Rand(5,35)
pistol9=Rand(15,60)



'SPAWNING STUFF:

If Not SoundPlaying (MUSIC) Then
music=PlaySound("data\SK_battle2.mp3")   'Makes sure the music keeps playing
EndIf
  
    gr.ENEMIES = New (ENEMIES)
    gr\grunt=CloneObject(vihu)   'Making enemies...
    
    If enemyspawn > 0 Then
    PositionObject gr\grunt, Rand (600),Rand(-600)
    gr\hp=100
    gr\berserk=0
    enemyspawn=enemyspawn-1            '...and spawning them all around de map
    EndIf
    
    wall.OBSTACLE = New (OBSTACLE)
    wall\obj2=CloneObject(muuri)           'same with de walls
    
    If wallspawn > 0 Then
    PositionObject wall\obj2, Rand(1000),Rand(-1000)
    wallspawn = wallspawn - 1
    EndIf
    
    
'------------------------------------------------ 
    
    
    For gr.ENEMIES = Each ENEMIES
    PointObject gr\grunt, character           'makes the grunts to point at the player
    Next gr
    
    

   
'-------------------------------------------------------------------------------------------------------------------------

'CAMERA, MOVEMENT AND HUD:

   'the camera follows the player..
CloneCameraPosition character

'HUD:------------------------------
Color cbred
Text 0,0, "Stamina: " + stamina     'displays the stamina
Text 0,20, "RELOAD: " +rate         'reloading Time And
Text 0,40, "FPS: " +FPS()           'game speed (frames per second)

Text 700,0, "Weapons:"

Text 700,20, ".22 Pistol"
Box 700,15,100,20,0

Text 700,40, "9mm Pistol"
If WEAPON1=1 Then Box 700,37,100,20,0



If stamina > 99 Then stamina = 100         'makes sure the players stamina wont go over 100
If stamina < 1 Then stamina = 0            'or below zero


'   CONTROLS and MOVEMENT:-------------------------------------
  
  
  Text 100, 60, "Mouse W X: " +MouseWX()
  Text 100, 75, "Mouse W Y: "+MouseWY()
 Text 100,100, "Mouse X: "+MouseX()
 Text 100,120, "Mouse Y: "+MouseY()
 Text 100,140, "Character X: "+ObjectX(character)
 Text 100,155, "Character Y: "+ObjectY(character)
 Text 100,170, "Character to Mouse Angle: "+MouseLocation#
 


MouseLocation#=GetAngle(ObjectX(character),ObjectY(character),MouseX(),MouseY())


Line ObjectX(character),ObjectY(character),MouseX(),MouseY() 
 
 RotateObject character, MouseLocation#
  
  
  If KeyDown(17) Then TranslateObject character, 0,2
    If KeyDown(31) Then TranslateObject character, 0,-2
    
    If KeyDown(30) Then TranslateObject character, -2,0
    If KeyDown(32) Then TranslateObject character, 2,0                      'de keys, including sprint
    
    If KeyDown(17) And KeyDown(42)and stamina > 0 Then MoveObject character, 1      'spritning only possible if player has stamina 
    If KeyDown(17) And KeyDown(42) Then stamina = stamina -1                      'sprinting absorbs stamina
    
    If Not KeyDown(42) Then stamina = stamina +1                 'if not sprinting, stamina will refill
    
    If ObjectsOverlap (character, wall\obj2, 2) Then
    PositionObject character, 100,100
    EndIf
    
  
 
 'SHOOTING:----------------------------------------------------------------------------------------------
 
 



 
 If MouseDown(1) And rate = 0 Then

       
       projectile.AMMO = New (AMMO)
       projectile\obj=CloneObject(bullet)
       
       CloneObjectPosition projectile\obj, character
       CloneObjectOrientation projectile\obj, character
       PlaySound shot
       rate = 15
       
       
       EndIf
       
    If rate > 0 Then rate = rate -1
       
       
       For projectile.AMMO = Each AMMO 
       MoveObject projectile\obj, 10
       
       If Distance2 (projectile\obj, character)>500 Then   'bullets will be deleted when they are outside the line of sight.
       DeleteObject projectile\obj                          'thus they wont wander outside the screen and cause memory problems
       Delete projectile
       EndIf
       
       Next projectile
       

    
      
'OBJECT PROPERTIES-------------------------------------------------------------------------------------------------


'OBSTACLES:-------------------------------------------------
'Wall:


   For wall.OBSTACLE = Each OBSTACLE  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, wall\obj2) Then
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next wall 
      


'SUPPLIES:--------------------------------------------------
'9mm Pistol:

   
    for ase.GUNS = Each GUNS
    If ObjectsOverlap(ase\pistol, character) Then
    WEAPON1=1
    DeleteObject ase\pistol
    Delete ase
    EndIf
    Next ase



 'ENEMIES:---------------------------------------------------------
 'Grunt:
 
 
   For gr.ENEMIES = Each ENEMIES  
     For projectile.AMMO = Each AMMO      
              If ObjectsOverlap (projectile\obj, gr\grunt) Then
        gr\berserk=1                                               'if a grunt gets shot, it will go berserk
        gr\hp = gr\hp - pistol22
        Text 385, 245,  + pistol22 +"!"
               
        DeleteObject projectile\obj
        Delete projectile        
EndIf
Next projectile
Next gr
 
      
      
         For gr.ENEMIES = Each ENEMIES
   
If berserk=0 And Distance2(character, gr\grunt) < 150 Then MoveObject gr\grunt, 1   'normal grunts only attack from short distance
  If gr\berserk=1 Then MoveObject gr\grunt,2                                        'berserked grunts run towards the player
   Next gr                                                                          'fast! - no matter the distance
      
      
      For gr.ENEMIES = Each ENEMIES
      If gr\hp < 1 Then                                                           'if a grunts health is reduced below zero it will die :(
      DeleteObject gr\grunt
      Delete gr
      
      EndIf
      Next gr
   
    
      
    UpdateGame
DrawGame        
DrawScreen


Forever


 



Jeps, eli nyt on tosiaan grafiikat revitty sieltä CoolBasicin Media- kansiosta eli peli voi olla vähän.. hassun näköinen :D
Anyways, oleellisin on tuo hiiren seuraamisongelma.

Pelissä on kaikennäköistä muutakin bugia yms schaissee mutta älkää antako sen häiritä :D

User avatar
Jonez
Devoted Member
Posts: 575
Joined: Mon Aug 27, 2007 8:37 pm

Re: Hiiren seuraaminen

Post by Jonez » Sun Jun 19, 2011 11:10 am

Muuta se MouseLocationin kohta koodia tällaiseksi:

Code: Select all

MouseLocation#=GetAngle(ObjectX(character),-ObjectY(character),MouseWX(),-MouseWY())

DrawToWorld ON
Line ObjectX(character),ObjectY(character),MouseWX(),MouseWY() 
DrawToWorld OFF

RotateObject character, MouseLocation#
GetAngle() kertoo pisteiden välisen kulman, ja ottaa parametreiksi kuvakoordinaatit. Koska objektikoordinaattien y-akseli on kuville vastakkainen, joutuu molemmat y-kohdat muuttamaan miinusmerkkiseksi.

DrawToWorld muuttaa kuvien jne. piirtokoordinaatit maailmakoordinaateiksi.
-Vuoden 2008 aloittelijan ystävä -palkinnon voittaja-
Image <- protestipelikilpailun voittaja.
Space War

User avatar
valscion
Moderator
Moderator
Posts: 1587
Joined: Thu Dec 06, 2007 8:46 pm
Location: Espoo
Contact:

Re: Hiiren seuraaminen

Post by valscion » Sun Jun 19, 2011 12:13 pm

Kannattaa lukea manuaalista Perusteet-kohta (jos siis et ole sitä vielä lukenut / täydellisesti sisäistänyt). Viimeisellä sivulla selitellään vielä maailmankoordinaattien ja ruutukoordinaattien eroa.
cbEnchanted, uudelleenkirjoitettu runtime. Uusin versio: 0.4.1 — Nyt myös sorsat GitHubissa!
NetMatch - se kunnon nettimättö-deathmatch! Avoimella lähdekoodilla varustettu
vesalaakso.com

KimmyMan
Newcomer
Posts: 4
Joined: Sat Jun 18, 2011 11:02 pm

Re: Hiiren seuraaminen

Post by KimmyMan » Sun Jun 19, 2011 1:03 pm

Jes, kiitoksia paljon, nyt se toimii! ^^

juu, täytyisi varmaan vähän perehtyä enemmän noihin beisikseihin.. Muttakun ei malta :P

User avatar
Timblex
Advanced Member
Posts: 252
Joined: Sun Apr 11, 2010 10:37 am
Location: Kouvola

Re: Hiiren seuraaminen

Post by Timblex » Thu Jun 23, 2011 6:39 pm

Eikö koko homman voisi tehdä niin että hiiren kohdalle laitettaisiin näkymätön objekti ja sitä kohti käännyttäisiin komennolla pointobject
Entinen timpe99...
Demokisa 2013 demo valmis, Check it out!

User avatar
Wingman
Devoted Member
Posts: 594
Joined: Tue Sep 30, 2008 4:30 pm
Location: Ruudun toisella puolella

Re: Hiiren seuraaminen

Post by Wingman » Thu Jun 23, 2011 6:45 pm

timpe99 wrote:Eikö koko homman voisi tehdä niin että hiiren kohdalle laitettaisiin näkymätön objekti ja sitä kohti käännyttäisiin komennolla pointobject
juu, voisi toki ja näin saisi hiirelle myös kuvan helposti (piilottaisi hiiren ja maalaisi näkymättömään objektiin sitten hiirelle haluamansa kuvan)
- - - -

Post Reply