Real basic FPS questions
Blitz3D Forums/Blitz3D Programming/Real basic FPS questions
| ||
Hi everyone, I've been trying to learn as much as I could in the last few weeks, and can't take much credit at all for most of the below code, but I have a few questions. I have been trying to spawn multiple enemies, I started on arrays (Yes MIDIMASTER I have failed) and am only able to make one enemy spawn at a time with the same name. I have simplified everything as much as possible below for anyone that has any ideas. Also, I cannot get what I am doing wrong with trying to make the Bullets a TYPE, so I can add them to collisions to process. Here's where I'm up too. ;Im Using a lot of the code that I found on the Blitz3d site from the Author below ;Simple 3d Maze Generator by Kevin Lee Legge (kevin8084@...) ;And a lot of other code that is from here and there. ; Kind of a Doom thing happening at the moment. ;No assetts needed yet. ; Set up the graphics Graphics3D 1024,768 SetBuffer BackBuffer() Dim maze(19,19) ;Set Types Const player_type=1 Const scene_type=2 Const enemy_type=3 Plane=CreatePlane() EntityAlpha Plane,0.8 PlaneTexture=CreateTexture(128,128,9) ClsColor 0,0,255 Cls Color 255,255,255 Rect 0,0,64,64,1 Rect 64,64,64,64,1 CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture) ScaleTexture PlaneTexture,40,40 EntityTexture Plane,PlaneTexture,0,0 EntityType plane,scene_type Global player=CreateCamera() PositionEntity player,0,10,0 CameraRange player,.1,500 EntityType player,player_type EntityRadius player,1 Dim enemy%(10) enemy(1)=CreateCube() ScaleEntity enemy(1),.5,1.5,.5 EntityColor enemy(1),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(1),enemy_type enemy(2)=CreateCube() ScaleEntity enemy(2),.5,1.5,.5 EntityColor enemy(2),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(2),enemy_type ;LIGHT light=CreateLight() PositionEntity light,150,150,150 RotateEntity light,90,0,0 readData() Dim Bullet%(10) Global NextBullet%=1 ;COLLISIONS ;Player to wall Collisions player_type,scene_type,2,2 ;Player to Enemy Collisions player_type,enemy_type,2,2 ;Enemy to wall Collisions enemy_type,scene_type,2,2 ;Enemy to Enemy Collisions enemy_type,enemy_type,2,2 ;Bullet to Enemy Collisions bullet_type,scene_type,2,2 ;EntityType bullet%,bullet_type << Identifier Bullet cant be used like this :( While Not KeyHit(1) If KeyDown(200) Then MoveEntity player,0,0,.1 If KeyDown(208) Then MoveEntity player,0,0,-.1 If KeyDown(203) Then TurnEntity player,0,2,0 If KeyDown(205) Then TurnEntity player,0,-2,0 If KeyHit(57) ;Space to fire. NextBullet=NextBullet+1 If NextBullet=11 Then NextBullet=1 If Bullet(NextBullet)>0 Then FreeEntity Bullet(NextBullet) Bullet(NextBullet)=CreateCube(player) EntityColor Bullet(NextBullet),222,0,0 ;ScaleEntity bullet,1,1,1 EntityParent Bullet(NextBullet), 0 EndIf For i%=1 To 10 If Bullet(i)>0 MoveEntity Bullet(i), 0, 0, 1 If EntityDistance(player, Bullet(i))>200 FreeEntity Bullet(i) Bullet(i)=0 EndIf EndIf Next TranslateEntity player,0,-1,0 ; ARRAY ENEMY SETUP If enemy(1) If EntityDistance(enemy(1),player)>10 PointEntity enemy(1), player MoveEntity enemy(1),0,0,Rnd(0,.5) EndIf EndIf If enemy(2) If EntityDistance(enemy(2),player)>10 PointEntity enemy(2), player MoveEntity enemy(2),0,0,Rnd(0,.5) EndIf EndIf UpdateWorld RenderWorld Text 0,0,"Use cursor keys to move and Space to fire" Text 0,20,"player X: "+x Text 0,30,"Enemy 1 Y:" Text 0,40,"Enemy 1 x:" Flip Delay 5 Wend End Function readData() Restore mazeData Read xValue,zValue For z=zValue-1 To 0 Step-1 For x=0 To xValue-1 Read maze(x,z) Select maze(x,z) Case 0 ; WALL cube=CreateCube() ScaleEntity cube,5,4,5 PositionEntity cube,x*10,4,z*10 EntityColor cube,Rnd(255),Rnd(255),Rnd(255) EntityType cube,scene_type Case 4 ; PLAYER PositionEntity player,x*10,4,z*10 Case 3 ; ENEMY 1 PositionEntity enemy(1),x*10,1,z*10 EntityType enemy(1),enemy_type Case 5 ; ENEMY 2 PositionEntity enemy(2),x*10,1,z*10 EntityType enemy(2),enemy_type End Select Next Next End Function .mazeData Data 20,20 ; Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 Data 0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,0,1,0,0,0,1,1,1,1,0 Data 0,1,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,1,0 Data 0,0,1,1,1,1,5,1,1,0,0,0,1,1,1,0,1,0,1,0 Data 0,1,0,1,1,1,1,1,1,1,0,3,1,0,0,0,1,0,1,0 Data 0,1,0,0,0,0,1,4,1,3,1,0,1,0,0,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,1,0,1,0 Data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,0,0,1,1,1,1,1,0 Data 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| ||
Enemy Array: your code looks good! The enemy array is correct, also the handling of the enemies looks like "working good". I can see two enemies. When I walk around they are facing me and follow me until they are 10meters away... But they are walking to fast. When you do your first look arounf they are already at the 10m dictance position Change Delay 5 into Delay 50 and you will see the movement. Where do you see problems? |
| ||
Some fundamental ARRAY knowledge. Working with a lot of enemies in array normally is not handled by individual code line, but with Counting Variables or in FOR/NEXT loops: your code: Function readData() Restore mazeData Read xValue,zValue For z=zValue-1 To 0 Step-1 For x=0 To xValue-1 Read maze(x,z) Select maze(x,z) Case 0 ..... Case 3 ; ENEMY 1 PositionEntity enemy(1),x*10,1,z*10 EntityType enemy(1),enemy_type Case 5 ; ENEMY 2 PositionEntity enemy(2),x*10,1,z*10 EntityType enemy(2),enemy_type End Select Next Next End Function with a Counting Variable n (like "number") solution: Function readData() Restore mazeData Read xValue,zValue N%=0 ;Counting Variable For z=zValue-1 To 0 Step-1 For x=0 To xValue-1 Read maze(x,z) Select maze(x,z) Case 0 ..... Case 3 ; ENEMY N= N+1 PositionEntity enemy(N), x*10,1, z*10 EntityType enemy(N), enemy_type End Select Next Next End Function your code: Dim enemy%(10) enemy(1)=CreateCube() ScaleEntity enemy(1),.5,1.5,.5 EntityColor enemy(1),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(1),enemy_type enemy(2)=CreateCube() ScaleEntity enemy(2),.5,1.5,.5 EntityColor enemy(2),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(2),enemy_type with For/Next: Dim enemy%(10) For n%=1 to 2 enemy(n)=CreateCube() ScaleEntity enemy(n),.5,1.5,.5 EntityColor enemy(n),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(n),enemy_type Next This will make the code shorter if you work with more than 2 enemies. Even with 100 enemies the code will not become longer! inside your main loop: ; ARRAY ENEMY SETUP If enemy(1) If EntityDistance(enemy(1),player)>10 PointEntity enemy(1), player MoveEntity enemy(1),0,0,Rnd(0,.5) EndIf EndIf If enemy(2) If EntityDistance(enemy(2),player)>10 PointEntity enemy(2), player MoveEntity enemy(2),0,0,Rnd(0,.5) EndIf EndIf ...will become: ; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.5) EndIf EndIf Next |
| ||
OMG!.. I mean I have spent the best part of the entire day trying to get this to work, and you owned it in no time!.... Honestly can't thank you enough. I will have to go over this again and again to let it sink in, but thank you so much for taking the time to help me out with this. REALLY APPRECIATED :D You guys must eat and breath code I think. I have a looong way to go :) and the assistance given in these forums is extremely good!. I wish I had known about Blitz3d years ago. Below is the Updated code cheers to MIDIMASTER!!! Hopefully it will help others as well. ;I'm Using a lot of the code that I found on the Blitz3d site from the Author below ;Simple 3d Maze Generator by Kevin Lee Legge (kevin8084@...) ;And a lot of other code that is from here and there. ; Kind of a Doom thing happening at the moment. ;No assetts needed yet. ; Set up the graphics Graphics3D 1024,768 SetBuffer BackBuffer() Dim maze(19,19) ;Set Types Const player_type=1 Const scene_type=2 Const enemy_type=3 Plane=CreatePlane() EntityAlpha Plane,0.8 PlaneTexture=CreateTexture(128,128,9) ClsColor 0,0,255 Cls Color 255,255,255 Rect 0,0,64,64,1 Rect 64,64,64,64,1 CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture) ScaleTexture PlaneTexture,40,40 EntityTexture Plane,PlaneTexture,0,0 EntityType plane,scene_type Global player=CreateCamera() PositionEntity player,0,10,0 CameraRange player,.1,500 EntityType player,player_type EntityRadius player,1 Dim enemy%(10) For n%=1 To 5 enemy(n)=CreateCube() ScaleEntity enemy(n),.5,1.5,.5 EntityColor enemy(n),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(n),enemy_type Next ;LIGHT light=CreateLight() PositionEntity light,150,150,150 RotateEntity light,90,0,0 readData() Dim Bullet%(10) Global NextBullet%=1 ;COLLISIONS ;Player to wall Collisions player_type,scene_type,2,2 ;Player to Enemy Collisions player_type,enemy_type,2,2 ;Enemy to wall Collisions enemy_type,scene_type,2,2 ;Enemy to Enemy Collisions enemy_type,enemy_type,2,2 ;Bullet to Enemy Collisions bullet_type,scene_type,2,2 ;EntityType bullet%,bullet_type << Identifier Bullet cant be used like this :( While Not KeyHit(1) If KeyDown(200) Then MoveEntity player,0,0,.1 If KeyDown(208) Then MoveEntity player,0,0,-.1 If KeyDown(203) Then TurnEntity player,0,2,0 If KeyDown(205) Then TurnEntity player,0,-2,0 If KeyHit(57) ;Space to fire. NextBullet=NextBullet+1 If NextBullet=11 Then NextBullet=1 If Bullet(NextBullet)>0 Then FreeEntity Bullet(NextBullet) Bullet(NextBullet)=CreateCube(player) EntityColor Bullet(NextBullet),222,0,0 ;ScaleEntity bullet,1,1,1 EntityParent Bullet(NextBullet), 0 EndIf For i%=1 To 10 If Bullet(i)>0 MoveEntity Bullet(i), 0, 0, 1 If EntityDistance(player, Bullet(i))>200 FreeEntity Bullet(i) Bullet(i)=0 EndIf EndIf Next TranslateEntity player,0,-1,0 ; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.5) EndIf EndIf Next UpdateWorld RenderWorld Text 0,0,"Use cursor keys to move and Space to fire" Text 0,20,"player X: "+x Text 0,30,"Enemy 1 Y:" Text 0,40,"Enemy 1 x:" Flip Delay 5 Wend End Function readData() Restore mazeData Read xValue,zValue N%=0 ;Counting Variable For z=zValue-1 To 0 Step-1 For x=0 To xValue-1 Read maze(x,z) Select maze(x,z) Case 0 ; WALL cube=CreateCube() ScaleEntity cube,5,4,5 PositionEntity cube,x*10,4,z*10 EntityColor cube,Rnd(255),Rnd(255),Rnd(255) EntityType cube,scene_type Case 4 ; PLAYER PositionEntity player,x*10,4,z*10 Case 3 ; ENEMY N= N+1 PositionEntity enemy(N), x*10,1, z*10 EntityType enemy(N), enemy_type End Select Next Next End Function .mazeData Data 20,20 ; Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 Data 0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,0,1,0,0,0,1,1,1,1,0 Data 0,1,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,1,0 Data 0,0,1,1,1,1,3,1,1,0,0,0,1,1,1,0,1,0,1,0 Data 0,1,0,1,1,1,1,1,1,1,0,3,1,0,0,0,1,0,1,0 Data 0,1,0,0,0,0,1,4,1,3,1,0,1,0,0,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,3,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,0,0,0,0,0,0,1,1,1,3,1,1,1,0,1,0,1,0 Data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,0,0,1,1,1,1,1,0 Data 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| ||
works nice and smooth too! |
| ||
The .DataMap stuff, it reminds me my beginnings. :) |
| ||
Yeah RemniD, the beginnings is where I am now :P This DataMap format makes it easy to set up levels... I guess you can make it as big as you want, and its easy to follow too. I'm still trying to get my bullet colissions going, but won't be able to look at it today. I'll update when I have some success. Cheers! |
| ||
@Phodis>>there is another easy quick way to position entities on a grid : using an image, and it is faster to draw on an image in an image editor than to have to modify your .DataMap;for example, for a map of 100x100z, you use an image of 100width100height ;your image represents the map viewed from top to down, so the top of the image is +Z the bottom of the image is -Z, the left of the image is -X, the right of the image is +X ;then to position your entities : ;go on the imagebuffer ;read the properties (color) of each pixel like this : For PX% = 0 to 99 step 1 For PY% = 0 to 99 step 1 ;convert the pixel position (px,py) into the grid position (gx,gz) GX% = PX GZ% = 100-1-PY ;read the color of the pixel ;depending on the color, create a different kind of entity (wall, trap, item, character) ;position the entity at GX+0.5,0,GZ+0.5 (+0.5 so that it is at the center of the cell) Next Next try it ! |
| ||
That looks promising, I will give this a go as soon as I get back from work tonight, might be a way to combine a terrain map with drawing walls :P On a side note.. there is an array error with my quick and dirty attempt to get the enemy to shoot bahh never enough time ; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.5) EndIf EndIf Next ; ENEMY SHOOT If enemy(n) If EntityDistance(enemy(n),player)<10 ebullet=CreateCube(enemy(n)) EntityColor ebullet,255,0,0 ScaleEntity ebullet, 0.2, 0.04, 0.2 PositionEntity ebullet,enemy(n),2,enemy(n) EntityParent ebullet,0 EndIf EndIf If ebullet MoveEntity ebullet, 0, 0, 5 EndIf ;XXXXXXXXXXXXXXXXXXXXXX END MAIN LOOP XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX UpdateWorld RenderWorld |
| ||
The counting variable "n" is only useful inside the FOR/NEXT loop. But you want to use it outside. Better position for the code:; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.5) Else ; ENEMY SHOOT If ebullet=0 ebullet=CreateCube(enemy(n)) EntityColor ebullet,255,0,0 ScaleEntity ebullet, 0.2, 0.04, 0.2 EntityParent ebullet,0 Endif EndIf EndIf Next In your grid one of your enemies stands to closed to the position 70/90, where you define the player. So you will not see any bullet and be dead in the very first moment. what do you want to do with this line? PositionEntity ebullet,enemy(n),2,enemy(n) Start using the command DEBUGLOG to understand what is happening in the code. In the IDE-menu activate "Programm - Debug enabled?", then place DEBUGLOG commands in your code to get Printouts to the debug console of your variables. It is better to use a TIMER than DELAY. Typical use: Global FPS=CreateTimer(60) While Not KeyHit(1) ; your code ..... UpdateWorld Renderworld Flip 0 WaitTimer FPS Wend End "60" defines normal game speed on all computers of the world. Use "10" to get only 10 frames a second like a "Slow Motion". Use DELAY to get a "Super Slow Motion" in certain moments of the game Finally, here are my changes (printed bold) ;I'm Using a lot of the code that I found on the Blitz3d site from the Author below ;Simple 3d Maze Generator by Kevin Lee Legge (kevin8084@...) ;And a lot of other code that is from here and there. ; Kind of a Doom thing happening at the moment. ;No assetts needed yet. ; Set up the graphics Graphics3D 1024,768 SetBuffer BackBuffer() Dim maze(19,19) ;Set Types Const player_type=1 Const scene_type=2 Const enemy_type=3 Plane=CreatePlane() EntityAlpha Plane,0.8 PlaneTexture=CreateTexture(128,128,9) ClsColor 0,0,255 Cls Color 255,255,255 Rect 0,0,64,64,1 Rect 64,64,64,64,1 CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture) ScaleTexture PlaneTexture,40,40 EntityTexture Plane,PlaneTexture,0,0 EntityType plane,scene_type Global player=CreateCamera() PositionEntity player,0,10,0 CameraRange player,.1,500 EntityType player,player_type EntityRadius player,1 Dim enemy%(10) For n%=1 To 5 enemy(n)=CreateCube() ScaleEntity enemy(n),.5,1.5,.5 EntityColor enemy(n),Rnd(255),Rnd(255),Rnd(255) EntityType enemy(n),enemy_type Next ;LIGHT light=CreateLight() PositionEntity light,150,150,150 RotateEntity light,90,0,0 readData() Dim Bullet%(10) Global NextBullet%=1 Global EBullet% ;COLLISIONS ;Player to wall Collisions player_type,scene_type,2,2 ;Player to Enemy Collisions player_type,enemy_type,2,2 ;Enemy to wall Collisions enemy_type,scene_type,2,2 ;Enemy to Enemy Collisions enemy_type,enemy_type,2,2 ;Bullet to Enemy Collisions bullet_type,scene_type,2,2 ;EntityType bullet%,bullet_type << Identifier Bullet cant be used like this :( Global FPS=CreateTimer(10) While Not KeyHit(1) If KeyDown(200) Then MoveEntity player,0,0,.1 If KeyDown(208) Then MoveEntity player,0,0,-.1 If KeyDown(203) Then TurnEntity player,0,2,0 If KeyDown(205) Then TurnEntity player,0,-2,0 If KeyHit(57) ;Space to fire. NextBullet=NextBullet+1 If NextBullet=11 Then NextBullet=1 If Bullet(NextBullet)>0 Then FreeEntity Bullet(NextBullet) Bullet(NextBullet)=CreateCube(player) EntityColor Bullet(NextBullet),222,0,0 ;ScaleEntity bullet,1,1,1 EntityParent Bullet(NextBullet), 0 EndIf For i%=1 To 10 If Bullet(i)>0 MoveEntity Bullet(i), 0, 0, 1 If EntityDistance(player, Bullet(i))>200 FreeEntity Bullet(i) Bullet(i)=0 EndIf EndIf Next TranslateEntity player,0,-1,0 ; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.5) Else ; ENEMY SHOOT If ebullet=0 DebugLog "Shoot" ebullet=CreateCube(enemy(n)) EntityColor ebullet,255,0,0 ScaleEntity ebullet, 0.2, 0.02, 0.2 EntityParent ebullet,0 DebugLog "From Enemy N=" +n+ " X/Z=" + EntityX(enemy(n)) +"/" + EntityZ(enemy(n)) DebugLog EntityZ(Ebullet) +" " + EntityZ(Ebullet) EndIf EndIf EndIf Next UpdateWorld RenderWorld Text 0,0,"Use cursor keys to move and Space to fire" Text 0,20,"player X: "+x Text 0,30,"Enemy 1 Y:" Text 0,40,"Enemy 1 x:" If ebullet DebugLog "Player X/Z=" + EntityX(Player) +"/" + EntityZ(Player) MoveEntity ebullet, 0, 0, 1 DebugLog "Bullet X/Z=" + EntityX(Ebullet) +"/" + EntityZ(Ebullet) Delay 100 EndIf Flip 0 WaitTimer FPS Wend End Function readData() Restore mazeData Read xValue,zValue N%=0 ;Counting Variable For z=zValue-1 To 0 Step-1 For x=0 To xValue-1 Read maze(x,z) Select maze(x,z) Case 0 ; WALL cube=CreateCube() ScaleEntity cube,5,4,5 PositionEntity cube,x*10,4,z*10 EntityColor cube,Rnd(255),Rnd(255),Rnd(255) EntityType cube,scene_type Case 4 ; PLAYER PositionEntity player,x*10,4,z*10 DebugLog "CREATE PLAYER AT " + EntityX(Player) +"/" + EntityZ(Player) Case 3 ; ENEMY N= N+1 PositionEntity enemy(N), x*10,1, z*10 EntityType enemy(N), enemy_type DebugLog "CREATE ENEMY AT " + EntityX(enemy(N)) +"/" + EntityZ(enemy(N)) End Select Next Next End Function .mazeData Data 20,20 ; Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 Data 0,1,0,0,0,0,1,1,1,0,1,1,0,1,1,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,0,0,1,0,0,0,1,1,1,1,0 Data 0,1,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,1,0 Data 0,0,1,1,1,1,3,1,1,0,0,0,1,1,1,0,1,0,1,0 Data 0,1,0,1,1,1,1,1,1,1,0,3,1,0,0,0,1,0,1,0 Data 0,1,0,0,0,0,1,4,1,0,1,0,1,0,0,0,1,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,3,1,1,1,1,1,1,1,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,0,0,0,0,0,0,1,1,1,3,1,1,1,0,1,0,1,0 Data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0 Data 0,1,1,1,1,0,1,0,1,1,1,1,0,0,1,1,1,1,1,0 Data 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| ||
AWESOME, MIDIMASTER! You have really made this so much easier.. well.. basically by re-writing so much of it and EXPLAINING in as well. I am very thankful. So far I have learned with the above code, how to shoot in 3d space, and have AI respond by shooting back... along with ARRAYS and varios other tid-bits that work hand in hand. I like to think I may have eventually gotten the enemy to shoot back, but damnit it didn't occur to use a next statement, I was kinda close but no cigar. MIDIMASTER: what do you want to do with this line? PositionEntity ebullet,enemy(n),2,enemy(n) Phodis: .... basically what you accomplished with ..... ebullet=CreateCube(enemy(n)) ... I don't know what I was thinking.... looking at your code seems to logical to work. I thought I needed the X,Y,Z location to spawn the bullet. Bahh!. I discovered a book for Blitz3d that I am sure will get to help me get the hang of this. And will be ordering it ASAP!.. CHEERS AGAIN: I will now try and actually UNDERSTAND the code you have supplied and use it as best I can. :D Hopefully this thread has helped others too. |
| ||
All's working well now. I put a small timer on the bullet counter so the enemies will all shoot when in range repeatedly. t=t+1 If t>50 ebullet=0 t=0 EndIf TranslateEntity player,0,-1,0 ; ARRAY ENEMY SETUP For n%= 1 To 10 If enemy(n) If EntityDistance(enemy(n),player)>10 PointEntity enemy(n), player MoveEntity enemy(n),0,0,Rnd(0,.1) Else ; ENEMY SHOOT If ebullet=0 DebugLog "Shoot" ebullet=CreateCube(enemy(n)) EntityColor ebullet,255,0,0 ScaleEntity ebullet, 0.2, 0.02, 0.2 EntityParent ebullet,0 DebugLog "From Enemy N=" +n+ " X/Z=" + EntityX(enemy(n)) +"/" + EntityZ(enemy(n)) DebugLog EntityZ(Ebullet) +" " + EntityZ(Ebullet) EndIf EndIf EndIf Next If ebullet MoveEntity ebullet,0,0,.5 a=0 EndIf |
| ||
sorry, double post... |
| ||
normally you should handle the eBullets like you did with the player bullets. You can use also an array to handle 10 shoots at the same time. and if you wish to use a time interval for the bullets, why not use the Millisecs() timer? It returns the game time in Millseconds! Graphics 800,600 Global LastShootTime%=MilliSecs() Global Interval%=1000 ;=1sec While Not KeyHit(1) Cls Text 100,100," Game Time=" + MilliSecs() Text 100,150," Bullet fired at" + LastShootTime If KeyDown(57) If LastShootTime< MilliSecs() LastShootTime= MilliSecs() + Interval ; your bullet fire code here EndIf EndIf Flip 1 Wend |
| ||
This from my early days may be useful... http://www.blitzbasic.com/Community/posts.php?topic=96742#1120520 Best of luck on your beginnings.. |
| ||
Pretty cool to see someone learning like this, putting the effort in and coming up with solutions as a result... and also choosing to code these days, instead of "point and click"! Timing-wise, use timers and MilliSecs like Midimaster says, as counting to 50 (as in your shooting code above) will happen at different speeds on different PCs. Good luck! |