Can anyone explain this for me ??
Blitz3D Forums/Blitz3D Beginners Area/Can anyone explain this for me ??
| ||
Scuse the length of this lot but I thought you might need to see it all....The problem I,m having is that the compiler is telling me that the "missile\x or missile\y fields cannot be found...(these are arrowed in the "checkinput() function" near the bottom of the code) Ive only just started the prog so it needs more work of course but i,m just wondering if I need to change the way or the place that I,m defining types and / or using them ?? Excuse the rest of the code ..I,m still a beginner !! ;------------------------ ;Variables and constants- ;------------------------ Const width = 1024 ;Graphics height Const height = 768 ;Graphics width Const quit =1 ;Escape key scancode Const leftkey = 203 ;left arrow key scancode Const rightkey = 205 ;right arrow key scancode Const firekey = 57 ;spacebar scancode Const playerspeed = 10 ;Speed that player moves Const enemyspeed = 5 ;Speed that alien moves Const missilespeed = 10 ;Speed of bullet SeedRnd MilliSecs () ;Set the random number ;----------------------------------------------------------------------- ;-------------- ;SOUND EFFECTS- ;-------------- Global clip=LoadSound ("C:/blitzsounds/assholes.wav") Global gunshot=LoadSound ("C:/blitzsounds/gunshot.wav") ;----------------------------------------------------------------------- SetBuffer BackBuffer() Graphics width,height,32,1 ; set graphics to 1024 x 768 and run at 32 bit colour in fullscreen mode ;----------------------------------------------------------------------- ;------ ;TYPES- ;------ Type ship Field xpos Field ypos Field startposx Field startposy Field hits Field image End Type Type alien Field x,y Field directionx,directiony Field hits Field image End Type Type bullet Field xpos Field ypos Field image End Type Global player.ship = New ship player\xpos=512 player\ypos =700 player\hits = 0 player\image = LoadImage("c:/blitzpics/spaceship001.jpg") Global enemy.alien = New alien enemy\directionx=Rand (-3,3) enemy\directiony=Rand (3,6) enemy\hits =0 enemy\x = 512 enemy\y =0 enemy\image= LoadImage ("c:/blitzpics/alien001.jpg") ;----------------------------------------------------------------------- ;--------------- ;Main game loop- ;--------------- ;drawtitlescreen() ; call the drawtitlescreen function While Not KeyHit(quit) drawgamescreen() ; call the drawgamescreen function moveenemy() checkInput() Flip Wend ;------------------- ;End main game loop- ;------------------- ;----------------------------------------------------------------------- ;---------- ;FUNCTIONS- ;---------- Function drawtitlescreen() ; Define function for the titlescreen titlescreen = LoadImage("c:\blitzpics\titlescreen.jpg") ;load the title screen DrawImage titlescreen ,0,0 PlaySound clip Delay 5000 Text 80,60,"RIGHT ARROW KEY TO MOVE SHIP RIGHT" Delay 2000 Text 80,80,"LEFT ARROW KEY TO MOVE SHIP LEFT " Delay 2000 Text 80,100,"SPACE TO FIRE" Delay 2000 Text 80,140,"ESCAPE KEY WILL QUIT IF YOU CANT TAKE IT!!!" Delay 2000 Text 80,180,"PRESS ANY KEY TO CONTINUE....." WaitKey End Function ;----------------------------------------------------------------------- Function drawgamescreen() ; Draw the starting screen Cls DrawImage player\image,player\xpos,player\ypos DrawImage enemy\image,enemy\x,enemy\y End Function ;---------------------------------------------------------------------------------------------------------------| Function checkinput() ; Check for keys pressed... If KeyHit(firekey) PlaySound gunshot missile.bullet= New bullet CANT FIND THIS ?? ---> missile\xpos = player\xpos OR THIS ?? -----------> missile\ypos = player\ypos EndIf If KeyDown (rightkey) player\xpos = player\xpos + playerspeed If player\xpos > width - 80 ; 80 is the player image width...this stops it going offscreen player\xpos= width -80 EndIf EndIf If KeyDown (leftkey) player\xpos = player\xpos - playerspeed If player\xpos <0 player\xpos=0 EndIf EndIf End Function ;---------------------------------------------------------------------------------------------------------------| Function moveenemy() ;Function for moving the enemy ship enemy\x = enemy\x + enemy\directionx ;Need to sort this out..movement is no good..not really random ?? enemy\y = enemy\y + enemy\directiony If enemy\y > 768 enemy\y =-10 If enemy\y < 0 enemy\y =0 EndIf EndIf If enemy\x < 0 enemy\x =enemy\x + enemy\directionx If enemy\x > 1020 enemy\x = enemy\x - enemy\directionx EndIf EndIf End Function |
| ||
This code work for me. I don't have any problems. |
| ||
Reducing your problem is an excellent debugging skill to have; the benefits are twofold: (1) you can often figure out the problem yourself and (2) you can state the problem in more concise terms when asking for help. To reduce your problem, remove code that isn't directly related to the issue at hand until you've got the smallest possible program which demonstrates the problem. |
| ||
OK ....thanks for your help guys |
| ||
Have to love those game sounds! :-) In case you could use some examples, check out my website... |