How to create a cutscene?

Blitz3D Forums/Blitz3D Beginners Area/How to create a cutscene?

Mr.Bob94(Posted 2006) [#1]
Hi all,
I posted this in the BlitzMax Beginner's forum by accident, so I'm going to reexplain my problem here.
I'm working on a 3D program, and I would like to know how I would start a cutscene (with 2D images) by colliding with an object ( for example, a house or tree)
I've tried a bunch of methods, none of which have worked. I would be very grateful for some help.
Thanks.


Rob Farley(Posted 2006) [#2]
So basically if entity a hits entity b you need it to do something?

Is blitz collision no good?

count collisions on entity a, then test with entitycollided for entity b


octothorpe(Posted 2006) [#3]
The cutscene only involves fullscreen 2d images being displayed in a sequence with a variable delay on each frame?

Describe your cutscenes as linked lists of frames. Load all your frame images as textures during initialization to eliminate in-game delays. Create a quad the size of your screen (you can use so-called "pixel perfect" sprite libraries to do this, or do the math yourself.) Lock out player input, enemy updating, and everything else you don't want happening while the player is helplessly watching the cutscene (you'll probably do this with a state in your main game loop's state machine.) Set the quad's texture to the first frame in the list and start counting milliseconds.


Mr.Bob94(Posted 2006) [#4]
@octothorpe: No... this isn't about seeing the images. I need to get the cutscene to start.
@Rob Farley: Can you give me an example of the code?


Sir Gak(Posted 2006) [#5]
Starting the cutscene should be triggered by your collision. Rob Farley's suggestion is pretty good. When you collide, just look for the entity you collided with. When it matches what you want, then do your Function or Subroutine to accomplish the cut scene.

If you have a hundred trees and want the cutscene to trigger when you collide with ANY of them, then maybe use a Type and the For...Each loop.

Try this:
const wall=1, tree=2, house=3 ;etc
Type entity    ;a type to tell us what entity category we're looking at 
	Field entity
	Field kind    ;wall, tree, door, fountian, etc
End Type


When you set up your objects in your game, create a new instance of the type:
myentity.entity=new entity

Then, when you put in a tree, do something like:
myentity\kind = tree ;using previously defined constant


When collision occurs (as per Rob Farley), do a For..Each loop:
For myentity.entity = Each entity
  If myentity\entity=pickedentity ;if list entity is same as picked/collided entity
If e\kind = tree;if entity type is a tree
					f
				EndIf
			Next



Mr.Bob94(Posted 2006) [#6]
I did that, but now I get my image whenever the game loads.
I may just give up on it, as this is a school project that's due Tuesday. Thanks for the help everyone, and if anybody does have an idea as to what I'm doing wrong, I would still appreciate it.


jhocking(Posted 2006) [#7]
code plz


Mr.Bob94(Posted 2006) [#8]
@jhocking: Here...
;base game engine for school project
.beginworld
;loads graphics buffer and resolution
AppTitle "Rome: Rich vs. Poor
Graphics3D 1024,768
SetBuffer BackBuffer ()
.openworldprog
;Particle emitter by Wiebo de Wit 
Include "include_school.bb"
p_setup
p_setwind(-45,0.0005)

;GLOBALS
Global floor1
Global x#,y#,z#,terra_y#,zz#,ww#
Global camera_pivot
Global health# = 100,numhi,numlo
Global endGame = LoadImage("endgame.png")
Dim roads(15)
Dim seto(17)
Global alive = True
Global ascend# = 6
Global camflip = False
Global waitum =12


;collision globals
Global 	SCENERY  = 1
Global 	PLAYER     = 2
Global 	PROPS      = 4
Global 	CARPET    = 5
Global  bldg1    = 6

;other files to include
Include "numbers.bb"
Include "schoolprops.bb"

;light
Global light = CreateLight()
RotateEntity light, 90,0,0

;camera time
camera_pivot= CreatePivot()
;this caused error EntityRadius camera_pivot,1.4,1
EntityRadius camera_pivot,1.4
EntityType camera_pivot,PLAYER

Global camera = CreateCamera(camera_pivot)
CameraRange camera,1,1000
CameraFogMode camera,1
CameraFogRange camera,60,200

Global cam2 = CreateCamera(camera_pivot)
;rotate it
RotateEntity cam2, 0,180,0
;hide it
HideEntity cam2
;specify viewport
CameraViewport cam2,30,40,160,110


;sky view
Global sky = CreateSphere(16,camera_pivot)
FlipMesh sky
ScaleEntity sky,100,100,100
PositionEntity sky, 0,50,0
sky_tex = LoadTexture("sky.bmp")
EntityTexture sky,sky_tex

;terrain view
Global terrain = LoadTerrain("height2.jpg")
TerrainDetail terrain,2500,True
ScaleEntity terrain, 3,15,3
PositionEntity terrain,-1000,0,-530
ter_tex = LoadTexture("mossyground.bmp")
EntityTexture terrain,ter_tex
EntityRadius terrain,0.2
EntityType terrain,SCENERY

;Position the camera
PositionEntity camera_pivot, 71.7469,6.73231,103.762

;Collision Handling
Collisions CARPET,SCENERY,2,1
Collisions PLAYER,PROPS,2,1
;Collisions PLAYER,CARPET,2,3
Collisions PLAYER,PLAYER,2,1

;cutscene initiation example code
;If EntityX(camera_pivot) = 60 And EntityY(camera_pivot) = 7 And EntityZ(camera_pivot) = 100
;Graphics3D 1024,768
;imgtest = LoadImage ("victory.jpg")
;DrawImage imgtest,0,0
;Flip
;WaitKey
;Goto beginworld
;EndIf 

Const bldg = 1, bldg2 = 2, bldg3 = 3
Type bldg 
	Field bldg
	Field howto
End Type

For blgdtest.bldg = Each bldg
	If blgdtest\bldg = pickedbldg
	Graphics3D 1024,768
	imgtest = LoadImage ("victory.jpg")
	DrawImage imgtest,0,0
	Flip 
	WaitKey
	Goto beginworld
	EndIf 
Next

	

;======================;
;                This is our main loop.                  ;
;======================;
.main2
While Not KeyHit(1)
If alive
If KeyDown(200) MoveEntity camera_pivot,0,0,0.09
If KeyDown(208)	MoveEntity camera_pivot,0,0,-0.05
End If
If KeyDown(203) TurnEntity camera_pivot,0,2,0
If KeyDown(205)TurnEntity camera_pivot,0,-2,0

x#=EntityX(camera_pivot)
y#=EntityY(camera_pivot)
z#=EntityZ(camera_pivot)



;# 14 Press space to show/hide camera 2 
If Not waitum
   If KeyDown(57)
      If camflip 
         HideEntity cam2
         camflip = False
         waitum = 12
      Else
         ShowEntity cam2
         camflip = True
         waitum = 12 
      End If
   End If
End If 
If waitum waitum = waitum -1

;#14 images
Select holding
   Case 1
      DrawImage imgLamp,700,450
   Case 2
      DrawImage imgJar,700,450
   Case 3
      DrawImage imgNacar,700,450
   Case 4
      DrawImage imgankh,700,450
End Select 

UpdateWorld
RenderWorld
If KeyDown (2)
Text 10,10, "X = " + x#
Text 10,25, "Y = " + y#
Text 10,40, "Z = " + z#
EndIf

If Not alive
    DrawImage endgame,0,0
    If finaltimer < MilliSecs() Then Exit
End If
Flip
Wend

Props file:
;include file props.bb
;================

;a floor
cube_tile = LoadTexture("Floor.jpg")
floor1 = CreateCube()
	ScaleEntity floor1,8,0.06,13
	ScaleTexture cube_tile,.5,.5
	EntityTexture floor1,cube_tile
EntityType floor1,CARPET
EntityRadius floor1,.4
PositionEntity floor1, 67,5,120
;fence time! :)
thefence = LoadMesh ("woodenfence.b3d")
PositionEntity thefence, 60,5.8,109
RotateEntity thefence, 0,-90,0
ScaleEntity thefence, 0.1,0.1,0.1
texfence = LoadTexture ("woodfence.bmp")
EntityTexture thefence,texfence
EntityType thefence,PROPS
EntityRadius thefence,1
;more fennces
;the other side
fence6 = CopyEntity(thefence)
PositionEntity fence6, 60,5.8,109
fence7 = CopyEntity(thefence)
PositionEntity fence7, 60,5.8,113
fence8 = CopyEntity(thefence)
PositionEntity fence8, 60,5.8,117
fence9 = CopyEntity(thefence)
PositionEntity fence9, 60,5.8,121
fence10 = CopyEntity(thefence)
PositionEntity fence10, 60,5.8,125
fence11= CopyEntity(thefence)
PositionEntity fence11, 60,5.8,129

fence12 = CopyEntity(thefence)
PositionEntity fence12, 60,5.8,107
RotateEntity fence12, 0,180,0
fence13 = CopyEntity(fence12)
PositionEntity fence13, 64,5.8,107
fence14 = CopyEntity(fence12)
PositionEntity fence14, 68.5,5.8,107
;few more fences
fence16 = CopyEntity(fence12)
PositionEntity fence16, 65,5.8,131
fence17 = CopyEntity(fence12)
PositionEntity fence17, 69,5.8,131
fence18 = CopyEntity(fence12)
PositionEntity fence18, 72.5,5.8,131
fence20 = CopyEntity(fence18)
PositionEntity fence20, 61.5,5.8,130
;final fences
fence21 = CopyEntity(fence18)
PositionEntity fence21, 73.5,5.8,130
RotateEntity fence21, 0,-90,0
fence22 = CopyEntity(fence18)
PositionEntity fence22, 73.5,5.8,126
RotateEntity fence22, 0,-90,0
fence23 = CopyEntity(fence18)
PositionEntity fence23, 73.5,5.8,122
RotateEntity fence23, 0,-90,0
fence24 = CopyEntity(fence18)
PositionEntity fence24, 73.5,5.8,118
RotateEntity fence24, 0,-90,0
fence25 = CopyEntity(fence18)
PositionEntity fence25, 73.5,5.8,114
RotateEntity fence25, 0,-90,0
fence26 = CopyEntity(fence18)
PositionEntity fence26, 73.5,5.8,110
RotateEntity fence26, 0,-90,0
fence27 = CopyEntity(fence26)
PositionEntity fence27, 73.5,5.8,106
fence28 = CopyEntity (fence18)
PositionEntity fence28, 71.8197,5.8,100.995 
;fence29 = CopyEntity (fence18)
;PositionEntity fence29

;building time
blgdtest.bldg = New bldg
bldgtest = LoadMesh ("shop.3ds")
PositionEntity bldgtest, 65.5081,6.2,105.07
RotateEntity bldgtest,0,90,0
ScaleEntity bldgtest, 0.08,0.08,0.08
bldgtex = LoadTexture ("comedy.jpg")
EntityTexture bldgtest,bldgtex
EntityType bldgtest,PROPS
EntityRadius bldgtest,1.10

Hope this helps.


jhocking(Posted 2006) [#9]
So... where's EntityCollided? That is, when are you checking for the collision?


WolRon(Posted 2006) [#10]
Mr.Bob94, use the [code] or [codebox] commands when posting code.


Mr.Bob94(Posted 2006) [#11]
@WolRon: Ok... I didn't know that those were the commands.
@jhocking: I tried EntityCollided, but I didn't work... could you give me an example of what to put...


jhocking(Posted 2006) [#12]
Sir Gak already told you what to do. I'd just be repeating what he said. When I asked for your code, I meant the code that isn't working. In other words, show us how you tried to use EntityCollided so that we can explain where your mistake is.


Mr.Bob94(Posted 2006) [#13]
Ok. Here's the EntityCollided code I tried.
If EntityCollided camera_pivot, bldg
Graphics3D 1024,768
imgtest = LoadImage ("victory.jpg")
DrawImage imgtest, 0,0
Flip
WaitKey
Goto beginworld
EndIf

And how cam I get the codebox to appear? I tried [codebox] and it dosen't seem to work.
Thanks for your help everyone. I'm sorry if I'm acting like a complete n00b, because I probably am...


jhocking(Posted 2006) [#14]
First off, EntityCollided is actually not the right command. I just looked it up in the manual because those parameters don't look right, and that's when I noticed the command you want is the similar sounding but different CollisionEntity. To use that, you'll first need to use CountCollisions to detect if a collision happened; then use the collsion ID returned by that command to check if CollisionEntity is the one you are after.

Second, the placement of that code matters, of course. Specifically, it needs to be in the main loop after UpdateWorld, since that is when collision detection happens.


WolRon(Posted 2006) [#15]
And how cam I get the codebox to appear? I tried [codebox] and it dosen't seem to work.
What are the forum codes?


Mr.Bob94(Posted 2006) [#16]
I did that, and I got the error "Collision Index Out Of Range"
Here's my code:

 
CountCollisions camera_pivot

If CollisionEntity (camera_pivot,bldgtest)
Graphics3D 1024,768
imgtest = LoadImage ("victory.jpg")
DrawImage imgtest,0,0
Flip
WaitKey
Goto beginworld
EndIf



@WolRon: Thanks!


WolRon(Posted 2006) [#17]
numcol = CountCollisions camera_pivot
For iter = 1 to numcol
	If CollisionEntity (camera_pivot, iter) = bldgtest
	Graphics3D 1024,768
	imgtest = LoadImage ("victory.jpg")
	DrawImage imgtest,0,0
	Flip
	WaitKey
	Goto beginworld
EndIf
Next



Mr.Bob94(Posted 2006) [#18]
Thanks!! It's working great now! I'm very grateful to you for all your help!


jhocking(Posted 2006) [#19]
You have to keep track of the result of CountCollisions. For example, WolRon stores the number of collisions in a variable called numcol. Then, when calling CollisionEntity you use the collision number, not the entity being checked for. CollisionEntity tells you what entity was involved in a given collision, not whether a given entity was involved in a collision.