Ei toimi.
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