Anyone fancy adding some bad guys to this?

Miscellaneous Forums/Blitz Showcase/Anyone fancy adding some bad guys to this?

I wrote this to help someone out on another thread... and thought someone might fancy adding things to shoot!

Graphics3D 640,480,32,2

SetBuffer BackBuffer()


camera = CreateCamera()
light = CreateLight()

MoveEntity camera,0,10,-15

; create cannon
base = CreateCylinder(12)
ScaleMesh base,3,1,3
PositionMesh base,0,.5,0
s1 = CreateCube()
s2 = CreateCube()
ScaleMesh s1,.5,2,1
ScaleMesh s2,.5,2,1
PositionMesh s1,-1.5,3.5,0
PositionMesh s2,1.5,3.5,0

AddMesh(s1,base)
AddMesh(s2,base)
FreeEntity s1
FreeEntity s2
EntityColor base,100,150,200

barrel= CreateCylinder(12)
RotateMesh barrel,90,0,0
b2 = CreateCylinder(12)
ScaleMesh b2,.8,1,.8
RotateMesh b2,90,0,0
PositionMesh b2,0,0,2
AddMesh(b2,barrel)
FreeEntity b2

Muzzle = CreatePivot(Barrel)
PositionEntity Muzzle,0,0,4

PositionEntity barrel,0,4,0
EntityParent barrel,base
EntityColor barrel,200,150,100

; Make Ground
Ground = CreatePlane()
i = CreateImage(64,64)
SetBuffer(ImageBuffer(i))
Color 0,0,255:Rect 0,0,32,32:Rect 32,32,32,32
Color 0,100,255:Rect 32,0,32,32:Rect 0,32,32,32
checker = CreateTexture(64,64)
CopyRect 0,0,64,64,0,0,ImageBuffer(i),TextureBuffer(checker )
FreeImage i
ScaleTexture checker ,50,50
EntityTexture ground,checker 

xspin# = 0
yspin# = 0

Repeat

	xspin = xspin - (MouseXSpeed()/15)
	yspin = yspin - (MouseYSpeed()/15)
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45
	
	If yspin > 0 Then yspin = 0
	If yspin < -80 Then yspin = -80
	
	MoveMouse 320,240
	
	RotateEntity base,0,xspin,0
	RotateEntity barrel,yspin,0,0
	
	If MouseHit(1) Then
		NewGrenade(Muzzle)
	EndIf
	
	updategrenade

RenderWorld

Flip

Until KeyHit(1)


Type Grenade
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Function NewGrenade(Launcher)
	C.Grenade = New Grenade
	C\Mesh = CreateSphere(6)
	EntityColor C\Mesh,Rand(100,255),Rand(100,255),Rand(100,255)
	C\Phys = CreatePivot()
	PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
	RotateEntity c\Phys,EntityPitch(Launcher,True),EntityYaw(Launcher,True),EntityRoll(Launcher,True)
	MoveEntity c\phys,0,0,1
	EntityShininess c\mesh,1
	c\Life = 150
	c\explode = True
End Function

Function Clip(x)
	If x>255 Then x=255
	Return x
End Function

Function NewExplode(Launcher)
	For n=1 To 100
		C.Grenade = New Grenade
		C\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite c\mesh,Rnd(1,2),Rnd(1,2)
		EntityColor C\Mesh,Clip(col*2),Clip(col),col/2
		C\Phys = CreatePivot()
		PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
		ScaleEntity c\mesh,Rnd(.1,2),Rnd(.1,2),Rnd(.1,2)
		RotateEntity c\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity c\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess c\mesh,0
		EntityFX c\mesh,1
		EntityBlend c\mesh,3
		c\Life = Rand(20,100)
		c\explode = False
	Next
End Function

Function UpdateGrenade()
	For c.Grenade = Each Grenade
		TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)
		
		TranslateEntity c\phys,0,-.01,0
		
		If EntityY(c\mesh)<.5 Then
			PositionEntity c\mesh,EntityX(c\mesh),.5,EntityZ(c\mesh)
			TranslateEntity c\phys,0,-EntityY(c\phys)*1.5,0			
		EndIf
		
		TurnEntity c\mesh,5,10,15
		
		c\life = c\life - 1 
		
		If c\life = 0 Then
			If c\explode Then NewExplode(c\mesh)
			FreeEntity c\mesh
			FreeEntity c\phys
			Delete c
		EndIf
	Next
End Function


Indeed! Could be a entertaining little game...

Reminds me of Beach Head but with cannons :)

I don't have the 3D module... can't run it.

I don't have the 3D module... can't run it.
Thanks for letting us know as I was beginning to worry why you hadn't responded.
Anyway, you know this is B3D and not a Bmax module... don't you?

lol sorry about that I seem to have forgotten the last half of the post. I meant to ask if maybe he could compile it and put it up, and sorry I don't know what B3D is I just assumed it's blitz3D because it's pretty obvious it's 3D and he posted it in a blitzmax forum... sorry!

and he posted it in a blitzmax forum
The Blitz Showcase is for all flavours of Blitz.

so what exactly is B3D? I would have guessed it was just a blitzmax 3D module as I said but now you're kinda making it sound like it isn't.... :confused:

its Blitz3D

http://www.blitzbasic.com/Products/blitz3d.php

He didn't post it in the BlitzMax Forum

so I was right then. And I meant the company, though I have no clue what the actual company name is thought it was blitzmax or something though lol since that's their main product. Will everyone stop confusing me please? lol

for the company name, look at the top right of this page.

so I was right then.

No, you weren't. It's a standalone product, unconnected to BlitzMax. It has 3D, but the language is much more limited.

Don't you just love it when things stay on topic!

Don't mention topics I'm starving.

ok I think I understand now lol. I'm hungry too almost lunch time here.

Don't mention topics I'm starving.

I take it I shouldn't mention Eric Van Lustbader either then? :)

Don't you just love it when things stay on topic!

Sorry :(

I might consider messing around with this, I liked the 'good ol days' of the community hack fest.

"I liked the 'good ol days' of the community hack fest. "
lol I wish I had LIVED during the good ol days of the community hack fest :P

that all depends on what is being hacked by the community :p

edit:
just fired up blitz for the first time this year to compile this
found myself having the gun at a low level and just letting the balls roll to the end and exploding
that was fun

they explode before coming down on you when you face right up ... which is safe ... you dont want the bomb to land back on you now do you

Really nice code. Thanks.

Had some fun with this. Messy code, simple AI. Use RMB to detonate the projectile. Waves come every 8 seconds.

Graphics3D 640,480,32,0

SetBuffer BackBuffer()

camera = CreateCamera()
CameraZoom camera,.8
light = CreateLight()

MoveEntity camera,0,10,-15

Global timer# = MilliSecs()
Global score

Type enemy
	Field mesh
End Type

CreateEnemies()

; create cannon
base = CreateCylinder(12)
ScaleMesh base,3,1,3
PositionMesh base,0,.5,0
s1 = CreateCube()
s2 = CreateCube()
ScaleMesh s1,.5,2,1
ScaleMesh s2,.5,2,1
PositionMesh s1,-1.5,3.5,0
PositionMesh s2,1.5,3.5,0

AddMesh(s1,base)
AddMesh(s2,base)
FreeEntity s1
FreeEntity s2
EntityColor base,100,150,200

barrel= CreateCylinder(12)
RotateMesh barrel,90,0,0
b2 = CreateCylinder(12)
ScaleMesh b2,.8,1,.8
RotateMesh b2,90,0,0
PositionMesh b2,0,0,2
AddMesh(b2,barrel)
FreeEntity b2

Muzzle = CreatePivot(Barrel)
PositionEntity Muzzle,0,0,4

PositionEntity barrel,0,4,0
EntityParent barrel,base
EntityColor barrel,200,150,100

; Make Ground
Ground = CreatePlane()
i = CreateImage(64,64)
SetBuffer(ImageBuffer(i))
Color 0,0,255:Rect 0,0,32,32:Rect 32,32,32,32
Color 0,100,255:Rect 32,0,32,32:Rect 0,32,32,32
checker = CreateTexture(64,64)
CopyRect 0,0,64,64,0,0,ImageBuffer(i),TextureBuffer(checker)
FreeImage i
ScaleTexture checker ,50,50
EntityTexture ground,checker 

xspin# = 0
yspin# = 0

Repeat

	xspin = xspin - (MouseXSpeed()/15)
	yspin = yspin - (MouseYSpeed()/15)
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45
	
	If yspin > 0 Then yspin = 0
	If yspin < -80 Then yspin = -80
	
	MoveMouse 320,240
	
	RotateEntity base,0,xspin,0
	RotateEntity barrel,yspin,0,0
	
	If MouseHit(1) Then
		NewGrenade(Muzzle)
	EndIf
	
	updategrenade
	updatepoof
	
	For e.enemy = Each enemy
		TurnEntity e\mesh,1,0,0
		MoveEntity e\mesh,0,0,-.4
	Next
	
	If MilliSecs() > timer + 8000
		CreateEnemies()
		timer = MilliSecs()
	EndIf
	
RenderWorld

Text 10,10,"Score: "+score

HidePointer()

Flip

Until KeyHit(1)

Type Grenade
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Type poof
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Function NewGrenade(Launcher)
	C.Grenade = New Grenade
	C\Mesh = CreateSphere(6)
	EntityColor C\Mesh,Rand(100,255),Rand(100,255),Rand(100,255)
	C\Phys = CreatePivot()
	PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
	RotateEntity c\Phys,EntityPitch(Launcher,True),EntityYaw(Launcher,True),EntityRoll(Launcher,True)
	MoveEntity c\phys,0,0,1
	EntityShininess c\mesh,1
	c\Life = 150
	c\explode = True
End Function

Function Clip(x)
	If x>255 Then x=255
	Return x
End Function

Function NewExplode(Launcher)
	For n=1 To 100
		C.Grenade = New Grenade
		C\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite c\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor C\Mesh,Clip(col*2),Clip(col),col/2
		C\Phys = CreatePivot()
		PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
		ScaleEntity c\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity c\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity c\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess c\mesh,0
		EntityFX c\mesh,1
		EntityBlend c\mesh,3
		c\Life = Rand(5,40)
		c\explode = False
	Next
End Function

Function EnemyExplode(e.enemy)
	For n=1 To 50
		p.poof = New poof
		p\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite p\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor p\Mesh,Clip(col*2),Clip(col),col/2
		p\Phys = CreatePivot()
		PositionEntity p\Mesh,EntityX(e\mesh,True),EntityY(e\mesh,True),EntityZ(e\mesh,True)
		ScaleEntity p\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity p\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity p\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess p\mesh,0
		EntityFX p\mesh,1
		EntityBlend p\mesh,3
		p\Life = Rand(5,15)
		p\explode = False
	Next
End Function

Function UpdateGrenade()
	For c.Grenade = Each Grenade
		TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)
		
		TranslateEntity c\phys,0,-.01,0
		
		If EntityY(c\mesh)<.5 Then
			PositionEntity c\mesh,EntityX(c\mesh),.5,EntityZ(c\mesh)
			TranslateEntity c\phys,0,-EntityY(c\phys)*1.5,0			
		EndIf
		
		TurnEntity c\mesh,5,10,15
		
		c\life = c\life - 1 
		
		If c\life = 0 Or MouseHit(2) Then
			If c\explode Then NewExplode(c\mesh)
			CheckEnemy(c) ;time to kill?
			FreeEntity c\mesh
			FreeEntity c\phys
			Delete c
		EndIf
	Next
End Function

Function UpdatePoof()
	For p.poof = Each poof
		TranslateEntity p\Mesh,EntityX(p\phys),EntityY(p\phys),EntityZ(p\phys)
		
		TranslateEntity p\phys,0,-.01,0
		
		If EntityY(p\mesh)<.5 Then
			PositionEntity p\mesh,EntityX(p\mesh),.5,EntityZ(p\mesh)
			TranslateEntity p\phys,0,-EntityY(p\phys)*1.5,0			
		EndIf
		
		TurnEntity p\mesh,5,10,15
		
		p\life = p\life - 1 
		
		If p\life = 0
			FreeEntity p\mesh
			FreeEntity p\phys
			Delete p
		EndIf
	Next
End Function

Function CheckEnemy(c.grenade)
	For e.enemy = Each enemy
		If EntityDistance (c\mesh,e\mesh) < 10
			score = score + 10
			EnemyExplode(e)
			FreeEntity e\mesh
			Delete e
		EndIf
	Next
End Function

Function CreateEnemies()
	x=-45
	y=10
	z=50
	rcol = Rand(100,255)
	gcol = Rand(100,255)
	bcol = Rand(100,255)
		For i = 1 To 72
		e.enemy = New enemy
		e\mesh = CreateCube()
		EntityColor e\mesh,rcol,gcol,bcol
		PositionEntity e\mesh,x,y,z
		x=x+5
			If x = 45
				y = y + 10
				x = -45
			EndIf
		Next
End Function


even at point blank range im having trouble hitting anything with a constant barrage of rmb clicks

Try this instead. Now you have a reason to shoot :). Only 5 groups of baddies spawn, working on waves now.

The projectiles explode in the order they were launched (so if you launch three consecutively you need to click the RMB three times).

Graphics3D 800,600,32,0

SetBuffer BackBuffer()
SeedRnd MilliSecs()

camera = CreateCamera()
CameraZoom camera,.8
light = CreateLight()

MoveEntity camera,0,10,-15

Global timer# = MilliSecs()
Global score
Global madnum
Global wavenum = 1

Type enemy
	Field mesh
	Field id
	Field angry = False
End Type

CreateEnemies()

; create cannon
Global base = CreateCylinder(12)
ScaleMesh base,3,1,3
PositionMesh base,0,.5,0
s1 = CreateCube()
s2 = CreateCube()
ScaleMesh s1,.5,2,1
ScaleMesh s2,.5,2,1
PositionMesh s1,-1.5,3.5,0
PositionMesh s2,1.5,3.5,0

AddMesh(s1,base)
AddMesh(s2,base)
FreeEntity s1
FreeEntity s2
EntityColor base,100,150,200

barrel= CreateCylinder(12)
RotateMesh barrel,90,0,0
b2 = CreateCylinder(12)
ScaleMesh b2,.8,1,.8
RotateMesh b2,90,0,0
PositionMesh b2,0,0,2
AddMesh(b2,barrel)
FreeEntity b2

Muzzle = CreatePivot(Barrel)
PositionEntity Muzzle,0,0,4

PositionEntity barrel,0,4,0
EntityParent barrel,base
EntityColor barrel,200,150,100

; Make Ground
Ground = CreatePlane()
i = CreateImage(64,64)
SetBuffer(ImageBuffer(i))
Color 0,0,255:Rect 0,0,32,32:Rect 32,32,32,32
Color 0,100,255:Rect 32,0,32,32:Rect 0,32,32,32
checker = CreateTexture(64,64)
CopyRect 0,0,64,64,0,0,ImageBuffer(i),TextureBuffer(checker)
FreeImage i
ScaleTexture checker ,50,50
EntityTexture ground,checker 

xspin# = 0
yspin# = 0

Repeat

	xspin = xspin - (MouseXSpeed()/15)
	yspin = yspin - (MouseYSpeed()/15)
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45
	
	If yspin > 0 Then yspin = 0
	If yspin < -80 Then yspin = -80
	
	MoveMouse 320,240
	
	RotateEntity base,0,xspin,0
	RotateEntity barrel,yspin,0,0
	
	If MouseHit(1) Then
		NewGrenade(Muzzle)
	EndIf
	
	updategrenade
	updatepoof
	updateanger
	
	For e.enemy = Each enemy
		If e\angry = False
			TurnEntity e\mesh,1,0,0
			MoveEntity e\mesh,0,0,-.4
		Else
			PointEntity e\mesh,base
				If EntityY(e\mesh) > 10
					MoveEntity e\mesh,0,-1,0
				Else
					MoveEntity e\mesh,0,0,.2
				EndIf
		EndIf
	Next
	
	If MilliSecs() > timer + 8000
		If wavenum <= 5
			CreateEnemies()
		EndIf
		timer = MilliSecs()
	EndIf
	
RenderWorld

Text 10,10,"Score: "+score

HidePointer()

Flip

Until KeyHit(1)

Type Grenade
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Type poof
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Function NewGrenade(Launcher)
	C.Grenade = New Grenade
	C\Mesh = CreateSphere(6)
	EntityColor C\Mesh,Rand(100,255),Rand(100,255),Rand(100,255)
	C\Phys = CreatePivot()
	PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
	RotateEntity c\Phys,EntityPitch(Launcher,True),EntityYaw(Launcher,True),EntityRoll(Launcher,True)
	MoveEntity c\phys,0,0,1
	EntityShininess c\mesh,1
	c\Life = 150
	c\explode = True
End Function

Function Clip(x)
	If x>255 Then x=255
	Return x
End Function

Function NewExplode(Launcher)
	For n=1 To 100
		C.Grenade = New Grenade
		C\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite c\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor C\Mesh,Clip(col*2),Clip(col),col/2
		C\Phys = CreatePivot()
		PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
		ScaleEntity c\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity c\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity c\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess c\mesh,0
		EntityFX c\mesh,1
		EntityBlend c\mesh,3
		c\Life = Rand(5,40)
		c\explode = False
	Next
End Function

Function EnemyExplode(e.enemy)
	For n=1 To 50
		p.poof = New poof
		p\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite p\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor p\Mesh,Clip(col*2),Clip(col),col/2
		p\Phys = CreatePivot()
		PositionEntity p\Mesh,EntityX(e\mesh,True),EntityY(e\mesh,True),EntityZ(e\mesh,True)
		ScaleEntity p\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity p\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity p\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess p\mesh,0
		EntityFX p\mesh,1
		EntityBlend p\mesh,3
		p\Life = Rand(5,15)
		p\explode = False
	Next
End Function

Function UpdateGrenade()
	For c.Grenade = Each Grenade
		TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)
		
		TranslateEntity c\phys,0,-.01,0
		
		If EntityY(c\mesh)<.5 Then
			PositionEntity c\mesh,EntityX(c\mesh),.5,EntityZ(c\mesh)
			TranslateEntity c\phys,0,-EntityY(c\phys)*1.5,0			
		EndIf
		
		TurnEntity c\mesh,5,10,15
		
		c\life = c\life - 1 
		
		If c\life = 0 Or MouseHit(2) Then
			CheckEnemy(c) ;time to kill?
			If c\explode Then NewExplode(c\mesh)
			FreeEntity c\mesh
			FreeEntity c\phys
			Delete c
		EndIf
	Next
End Function

Function UpdatePoof()
	For p.poof = Each poof
		TranslateEntity p\Mesh,EntityX(p\phys),EntityY(p\phys),EntityZ(p\phys)
		
		TranslateEntity p\phys,0,-.01,0
		
		If EntityY(p\mesh)<.5 Then
			PositionEntity p\mesh,EntityX(p\mesh),.5,EntityZ(p\mesh)
			TranslateEntity p\phys,0,-EntityY(p\phys)*1.5,0			
		EndIf
		
		TurnEntity p\mesh,5,10,15
		
		p\life = p\life - 1 
		
		If p\life = 0
			FreeEntity p\mesh
			FreeEntity p\phys
			Delete p
		EndIf
	Next
End Function

Function CheckEnemy(c.grenade)
	For e.enemy = Each enemy
		If EntityDistance (c\mesh,e\mesh) < 10
			If e\angry = False
				score = score + 5
			Else 
				score = score + 10
			EndIf
			EnemyExplode(e)
			FreeEntity e\mesh
			Delete e
		EndIf
	Next
End Function

Function CreateEnemies()
	x=-45
	y=10
	z=50
	rcol = Rand(100,255)
	gcol = Rand(100,255)
	bcol = Rand(100,255)
		For i = 1 To 72
		e.enemy = New enemy
		e\id = i
		e\mesh = CreateCube()
		EntityColor e\mesh,rcol,gcol,bcol
		PositionEntity e\mesh,x,y,z
		x=x+5
			If x = 45
				y = y + 10
				x = -45
			EndIf
		Next
	wavenum = wavenum + 1
End Function

Function updateanger()
	
	For e.enemy = Each enemy
		madnum = Rand(1,3000)
			If e\id = madnum And EntityDistance(e\mesh,base) > 80
				e\angry = True
				EntityColor e\mesh,255,0,0
			EndIf
	Next
	
End Function


One more update. Kinda worn out, have fun! Lots of new additions.

Graphics3D 800,600,32,0

SetBuffer BackBuffer()
SeedRnd MilliSecs()


light = CreateLight()

AmbientLight 100,100,100

Global timer# = MilliSecs()
Global score
Global madnum
Global wavenum = 1
Global intermission = False
Global ecount = 0
Global level = 1

Type enemy
	Field mesh
	Field id
	Field angry = False
End Type

CreateEnemies()

;Spacesphere

;Create the Texture
sptex = CreateTexture(1024,1024,1+8)
SetBuffer TextureBuffer(sptex)
For a = 1 To 200
	Plot Rand(0,1023),Rand(0,1023)
Next
SetBuffer BackBuffer()
TextureBlend sptex,5

;Create the Sphere
Global spbox = CreateSphere(5)
ScaleEntity spbox,1000,1000,1000
EntityTexture spbox,sptex
ScaleTexture sptex,.25,.5
EntityFX spbox,1
FlipMesh spbox
EntityOrder spbox,99999

; create cannon
Global base = CreateCylinder(12)
ScaleMesh base,3,1,3
PositionMesh base,0,.5,0
s1 = CreateCube()
s2 = CreateCube()
ScaleMesh s1,.5,2,1
ScaleMesh s2,.5,2,1
PositionMesh s1,-1.5,3.5,0
PositionMesh s2,1.5,3.5,0

camera = CreateCamera()
MoveEntity camera,0,10,-30

AddMesh(s1,base)
AddMesh(s2,base)
FreeEntity s1
FreeEntity s2
EntityColor base,100,150,200

barrel= CreateCylinder(12)
RotateMesh barrel,90,0,0
b2 = CreateCylinder(12)
ScaleMesh b2,.8,1,.8
RotateMesh b2,90,0,0
PositionMesh b2,0,0,2
AddMesh(b2,barrel)
FreeEntity b2

Muzzle = CreatePivot(Barrel)
PositionEntity Muzzle,0,0,4

PositionEntity barrel,0,4,0
EntityParent barrel,base
EntityColor barrel,200,150,100

; Make Ground
Ground = CreatePlane()
i = CreateImage(64,64)
SetBuffer(ImageBuffer(i))
Color 0,0,0:Rect 0,0,32,32:Rect 32,32,32,32
Color 0,0,255:Rect 32,0,32,32:Rect 0,32,32,32
checker = CreateTexture(64,64)
CopyRect 0,0,64,64,0,0,ImageBuffer(i),TextureBuffer(checker)
FreeImage i
ScaleTexture checker ,50,50
EntityTexture ground,checker 

xspin# = 0
yspin# = 0

Repeat

	xspin = xspin - (MouseXSpeed()/15)
	yspin = yspin - (MouseYSpeed()/15)
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45
	
	If yspin > 0 Then yspin = 0
	If yspin < -80 Then yspin = -80
	
	MoveMouse 320,240
	
	RotateEntity base,0,xspin,0
	RotateEntity barrel,yspin,0,0
	
	If MouseHit(1) Then
		NewGrenade(Muzzle)
	EndIf
	
	updategrenade
	updatepoof
	updateanger
	
	For e.enemy = Each enemy
		If e\angry = False
			TurnEntity e\mesh,1,0,0
			MoveEntity e\mesh,0,0,-.6
		Else
			PointEntity e\mesh,base
				If EntityY(e\mesh) > 2
					MoveEntity e\mesh,0,-1,0
				Else
					MoveEntity e\mesh,0,0,.1
				EndIf
		EndIf
	Next
	
	TurnEntity spbox,.008,0,0
	
RenderWorld

Text GraphicsWidth()/2,40,"SCORE: "+score,1,1

If intermission = False 
	If MilliSecs() > timer + 8000
		If wavenum <= 3
			CreateEnemies()
		EndIf
	EndIf
Else
If MilliSecs() < timer
		Text GraphicsWidth()/2,200,"WAVE "+level+" COMPLETE",1,1
		Text GraphicsWidth()/2,240,"GET READY FOR WAVE "+(level+1),1,1
	Else
		intermission = False
		wavenum = 1
		level = level + 1
		CreateEnemies()
	EndIf
EndIf

HidePointer()

Flip

Until KeyHit(1)

Type Grenade
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Type poof
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Function NewGrenade(Launcher)
	C.Grenade = New Grenade
	C\Mesh = CreateSphere(8)
	ScaleEntity c\mesh,.6,.6,.6
	EntityColor C\Mesh,Rand(100,255),Rand(100,255),Rand(100,255)
	C\Phys = CreatePivot()
	PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
	RotateEntity c\Phys,EntityPitch(Launcher,True),EntityYaw(Launcher,True),EntityRoll(Launcher,True)
	MoveEntity c\phys,0,0,2
	EntityShininess c\mesh,1
	c\Life = 150
	c\explode = True
End Function

Function Clip(x)
	If x>255 Then x=255
	Return x
End Function

Function NewExplode(Launcher)
	For n=1 To 100
		C.Grenade = New Grenade
		C\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite c\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor C\Mesh,Clip(col*2),Clip(col),col/2
		C\Phys = CreatePivot()
		PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
		ScaleEntity c\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity c\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity c\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess c\mesh,0
		EntityFX c\mesh,1
		EntityBlend c\mesh,3
		c\Life = Rand(5,40)
		c\explode = False
	Next
End Function

Function EnemyExplode(e.enemy)
	For n=1 To 50
		p.poof = New poof
		p\Mesh = CreateSprite()
		col = Rand(100,255)
		ScaleSprite p\mesh,Rnd(.1,.2),Rnd(.1,.2)
		EntityColor p\Mesh,Clip(col*2),Clip(col),col/2
		p\Phys = CreatePivot()
		PositionEntity p\Mesh,EntityX(e\mesh,True),EntityY(e\mesh,True),EntityZ(e\mesh,True)
		ScaleEntity p\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		RotateEntity p\mesh,Rand(360),Rand(360),Rand(360)
		PositionEntity p\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityShininess p\mesh,0
		EntityFX p\mesh,1
		EntityBlend p\mesh,3
		p\Life = Rand(5,15)
		p\explode = False
	Next
End Function

Function UpdateGrenade()
	For c.Grenade = Each Grenade
		TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)
		
		TranslateEntity c\phys,0,-.01,0
		
		If EntityY(c\mesh)<.5 Then
			PositionEntity c\mesh,EntityX(c\mesh),.5,EntityZ(c\mesh)
			TranslateEntity c\phys,0,-EntityY(c\phys)*1.5,0			
		EndIf
		
		TurnEntity c\mesh,5,10,15
		
		c\life = c\life - 1 
		
		If c\life = 0 Or MouseHit(2) Then
			CheckEnemy(c) ;time to kill?
			If c\explode Then NewExplode(c\mesh)
			FreeEntity c\mesh
			FreeEntity c\phys
			Delete c
		EndIf
	Next
End Function

Function UpdatePoof()
	For p.poof = Each poof
		TranslateEntity p\Mesh,EntityX(p\phys),EntityY(p\phys),EntityZ(p\phys)
		
		TranslateEntity p\phys,0,-.01,0
		
		If EntityY(p\mesh)<.5 Then
			PositionEntity p\mesh,EntityX(p\mesh),.5,EntityZ(p\mesh)
			TranslateEntity p\phys,0,-EntityY(p\phys)*1.5,0			
		EndIf
		
		TurnEntity p\mesh,5,10,15
		
		p\life = p\life - 1 
		
		If p\life = 0
			FreeEntity p\mesh
			FreeEntity p\phys
			Delete p
		EndIf
	Next
End Function

Function CheckEnemy(c.grenade)
	For e.enemy = Each enemy
		If EntityDistance (c\mesh,e\mesh) < 10
			If e\angry = False
				score = score + 5
			Else 
				score = score + 10
			EndIf
			EnemyExplode(e)
			ecount = ecount - 1
				If ecount = 0
					intermission = True
					timer = MilliSecs() + 6000
				EndIf
			FreeEntity e\mesh
			Delete e
		EndIf
	Next
End Function

Function CreateEnemies()
	x=-45
	y=10
	z=50
		For i = 1 To 72
		e.enemy = New enemy
		ecount = ecount + 1
		e\id = i
		e\mesh = CreateSphere(8)
		ScaleEntity e\mesh,.6,.6,.6
		PositionEntity e\mesh,x,y,z
		x=x+5
			If x = 45
				y = y + 10
				x = -45
			EndIf
		Next
	wavenum = wavenum + 1
	timer = MilliSecs()
End Function

Function updateanger()
	
	For e.enemy = Each enemy
		madnum = Rand(1,3000)
			If e\id = madnum And EntityDistance(e\mesh,base) > 80
				e\angry = True
			EndIf
			If EntityDistance (e\mesh,base) < 4
				EnemyExplode(e)
				FreeEntity e\mesh
				ecount = ecount - 1
				If ecount = 0
					intermission = True
					timer = MilliSecs() + 6000
				EndIf
				Delete e
			EndIf
	Next
	
End Function


Find that kind of hard to hit anything. :o)

Change:

Repeat

	xspin = xspin - (MouseXSpeed()/15)
	yspin = yspin - (MouseYSpeed()/15)
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45


to

Repeat

	xspin = xspin - (MouseXSpeed()/15.0) << make float
	yspin = yspin - (MouseYSpeed()/15.0) << make float
	
	If xspin < -45 Then xspin = -45
	If xspin > 45 Then xspin = 45


It makes the turrent easier to operate :o)

I'm going to have a go at this :D

stayne , could you use a codebox, instead of the code tag. Makes it easier to scroll through this thread :o)

heheh sorry about that *hangs head in shame*.

Looking forward to seeing your efforts :).

Couldn't resist! Added audio, a few meshes, a particle sprite and a few other odds and ends.

http://www.headpile.com/stuff/shootermedia.zip

Graphics3D 800,600,32,0

SetBuffer BackBuffer()
SeedRnd MilliSecs()


light = CreateLight()

AmbientLight 100,100,100

Global timer# = MilliSecs()
Global score
Global madnum
Global wavenum = 1
Global intermission = False
Global ecount = 0
Global level = 0
Global health = 100
Global wavemax
Global gameover = 1
Global launchtimer

Global shot1 = LoadSound("shot1.ogg")
SoundVolume shot1,.4
Global explosion1 = LoadSound("explosion1.ogg")
SoundVolume explosion1,.6
tune1 = LoadSound("shooter1.ogg")
SoundVolume tune1,.3
LoopSound tune1
PlaySound tune1

Global explsprite = LoadSprite("particle.png",1)
HideEntity explsprite

Global enemy1mesh = LoadMesh("enemy1.3ds")
Global enemy1tex = LoadTexture("enemy1tex.jpg")
EntityTexture enemy1mesh,enemy1tex
HideEntity enemy1mesh

Global proj1 = LoadMesh("proj1.3ds")
EntityTexture proj1,enemy1tex
HideEntity proj1

FreeTexture enemy1tex

Type enemy
	Field mesh
	Field id
	Field angry = False
	Field angerspeed#
	Field xrot#
	Field yrot#
	Field mov#
End Type

;Spacesphere

;Create the Texture
sptex = CreateTexture(1024,1024,1+8)
SetBuffer TextureBuffer(sptex)
For a = 1 To 200
	Plot Rand(0,1023),Rand(0,1023)
Next
SetBuffer BackBuffer()
TextureBlend sptex,5

;Create the Sphere
Global spbox = CreateSphere(5)
ScaleEntity spbox,1000,1000,1000
EntityTexture spbox,sptex
ScaleTexture sptex,.25,.5
EntityFX spbox,1
FlipMesh spbox
EntityOrder spbox,99999

camera = CreateCamera()
MoveEntity camera,0,12,-20

; create cannon
Global base = LoadMesh("weap_plat.3ds")
basetex = LoadTexture("weap_plat.png")
EntityTexture base,basetex
ScaleMesh base,.3,.3,.3
EntityFX base,1
EntityAlpha base,.6
PositionEntity base,0,4,0

barrel = LoadMesh("weap_trigun.3ds")
barreltex = LoadTexture("weap_trigun.png")
EntityTexture barrel,barreltex
ScaleEntity barrel,3,3,3
RotateMesh barrel,0,180,0

Muzzle = CreatePivot(Barrel)
PositionEntity Muzzle,0,0,1

PositionEntity barrel,0,8,0
EntityParent barrel,base

; Make Ground
Global Ground = CreatePlane()
i = CreateImage(64,64)
SetBuffer(ImageBuffer(i))
Color 0,0,0:Rect 0,0,32,32:Rect 32,32,32,32
Color 100,100,100:Rect 32,0,32,32:Rect 0,32,32,32
checker = CreateTexture(64,64)
CopyRect 0,0,64,64,0,0,ImageBuffer(i),TextureBuffer(checker)
FreeImage i
ScaleTexture checker ,50,50
EntityTexture ground,checker

Color 0,200,0

xspin# = 0
yspin# = 0

Repeat
	xspin = xspin - (MouseXSpeed()/15.0) ; make Float
	yspin = yspin - (MouseYSpeed()/15.0) ; make Float
	
	If xspin < -55 Then xspin = -55
	If xspin > 55 Then xspin = 55
	
	If yspin > 10 Then yspin = 10
	If yspin < -75 Then yspin = -75
	
	MoveMouse 320,240
	
	RotateEntity base,0,xspin/12,0
	RotateEntity barrel,yspin,xspin,0
	
	RotateEntity camera,yspin/2,xspin/2,0
	
	updategrenade
	updatepoof
	updateanger
		
	If gameover = 0

		If MouseHit(1) Then
			NewGrenade(Muzzle)
			PlaySound shot1
		EndIf
		
		For e.enemy = Each enemy
			If e\angry = False
				TurnEntity e\mesh,e\xrot,e\yrot,0
				MoveEntity e\mesh,0,0,e\mov
				RotateMesh e\mesh,0,.02,0
			Else
				PointEntity e\mesh,base
				MoveEntity e\mesh,0,0,e\angerspeed#
			EndIf
		Next
		
		TurnEntity spbox,.004,0,0
	Else
		mainmenu()
	EndIf
	
RenderWorld

Text GraphicsWidth()/2,60,"SCORE: "+score,1,1
Text GraphicsWidth()/2,80,"LEVEL: "+level+" WAVES: "+wavemax,1,1

Select True
	Case level = 1
		wavemax = 1
	Case level = 2
		wavemax = 2
	Case level = 3
		wavemax = 3
	Case level = 4
		wavemax = 4
	Case level = 5
		wavemax = 5
	Case level = 6
		level = 1
End Select

If intermission = False 
	If MilliSecs() > timer + 6000
		If wavenum < wavemax
			wavenum = wavenum + 1
			CreateEnemies()
		EndIf
	EndIf
Else
If MilliSecs() < timer
		Text GraphicsWidth()/2,220,"GET READY FOR LEVEL "+(level+1),1,1
		wavenum = 1
	Else
		intermission = False
		level = level + 1
		CreateEnemies()
	EndIf
EndIf

HidePointer()

Flip

Until KeyHit(1)

Type Grenade
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Type poof
	Field Mesh
	Field Phys
	Field Life
	Field Explode
End Type

Function MainMenu()
		Text GraphicsWidth()/2,200,"GAME OVER",1,1
		Text GraphicsWidth()/2,240,"PRESS SPACE TO START",1,1
		If KeyHit(57)
			FlushMouse()
			gameover = 0
			score = 0
			timer = MilliSecs() + 6000
			intermission = True
		EndIf
		For e.enemy = Each enemy
			FreeEntity e\mesh
			Delete e
		Next
End Function

Function NewGrenade(Launcher)
	C.Grenade = New Grenade
	C\Mesh = CopyEntity (proj1) ;CreateSphere(8)
	ScaleEntity c\mesh,.4,.4,.4
	C\Phys = CreatePivot()
	PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
	RotateEntity c\Phys,EntityPitch(Launcher,True),EntityYaw(Launcher,True),EntityRoll(Launcher,True)
	MoveEntity c\phys,0,0,2
	EntityShininess c\mesh,1
	c\Life = 150
	c\explode = True
End Function

Function Clip(x)
	If x>255 Then x=255
	Return x
End Function

Function NewExplode(Launcher)
	For n=1 To 100
		C.Grenade = New Grenade
		C\Mesh = CopyEntity (explsprite)
		EntityColor C\Mesh,Rand(100,255),Rand(100,255),0
		C\Phys = CreatePivot()
		PositionEntity C\Mesh,EntityX(Launcher,True),EntityY(Launcher,True),EntityZ(Launcher,True)
		ScaleEntity c\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		PositionEntity c\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityBlend c\mesh,3
		c\Life = Rand(5,40)
		c\explode = False
	Next
		PlaySound explosion1
		
End Function

Function EnemyExplode(e.enemy)
	For n=1 To 50
		p.poof = New poof
		p\Mesh = CopyEntity (explsprite)
		EntityColor p\Mesh,0,Rand(10,255),Rand(10,255)
		p\Phys = CreatePivot()
		PositionEntity p\Mesh,EntityX(e\mesh,True),EntityY(e\mesh,True),EntityZ(e\mesh,True)
		ScaleEntity p\mesh,Rnd(.1,.4),Rnd(.1,.4),Rnd(.1,.4)
		PositionEntity p\Phys,Rnd(-.5,.5),Rnd(-1,1),Rnd(-.5,.5)
		EntityBlend p\mesh,3
		p\Life = Rand(5,20)
		p\explode = False
	Next
End Function

Function UpdateGrenade()
	For c.Grenade = Each Grenade
		TranslateEntity c\Mesh,EntityX(c\phys),EntityY(c\phys),EntityZ(c\phys)
		
		TranslateEntity c\phys,0,-.01,0
		
		If EntityY(c\mesh)<.5 Then
			PositionEntity c\mesh,EntityX(c\mesh),.5,EntityZ(c\mesh)
			TranslateEntity c\phys,0,-EntityY(c\phys)*1.5,0			
		EndIf
		
		TurnEntity c\mesh,1,2,4
		
		c\life = c\life - 1 
		
		If c\life = 0 Or MouseHit(2) Then
			CheckEnemy(c) ;time to kill?
			If c\explode Then NewExplode(c\mesh)
			FreeEntity c\mesh
			FreeEntity c\phys
			Delete c
		EndIf
	Next
End Function

Function UpdatePoof()
	For p.poof = Each poof
		TranslateEntity p\Mesh,EntityX(p\phys)*.4,EntityY(p\phys)*.2,EntityZ(p\phys)*.4

		p\life = p\life - 1 
		
		If p\life = 0
			FreeEntity p\mesh
			FreeEntity p\phys
			Delete p
		EndIf
	Next
End Function

Function CheckEnemy(c.grenade)
	For e.enemy = Each enemy
		If EntityDistance (c\mesh,e\mesh) < 10
			If e\angry = False
				score = score + 5
			Else 
				score = score + 10
			EndIf
			EnemyExplode(e)
			ecount = ecount - 1
				If ecount = 0
					intermission = True
					timer = MilliSecs() + 6000
				EndIf
			FreeEntity e\mesh
			Delete e
		EndIf
	Next
End Function

Function CreateEnemies()
	x=-45
	y=10
	z=100
		For i = 1 To 72
		e.enemy = New enemy
		ecount = ecount + 1
		e\id = i
		e\mesh = CopyEntity(enemy1mesh)
		EntityShininess e\mesh,1
		Select True
			Case wavenum = 1
				EntityColor e\mesh,255,255,0
				e\angerspeed = Rnd(.2,.4)
				e\xrot = .8
				e\yrot = 0
				e\mov = -1
			Case wavenum = 2
				EntityColor e\mesh,0,255,255
				e\angerspeed = Rnd(.2,.6)
				e\xrot = .8
				e\yrot = 0
				e\mov = -1
			Case wavenum = 3
				EntityColor e\mesh,255,255,255
				e\angerspeed = Rnd(.4,.7)
				e\xrot = .8
				e\yrot = 0
				e\mov = -1
			Case wavenum = 4
				EntityColor e\mesh,255,0,255
				e\angerspeed = Rnd(.6,.8)
				e\xrot = .8
				e\yrot = 0
				e\mov = -1
			Case wavenum = 5
				EntityColor e\mesh,0,100,255
				e\angerspeed = Rnd(.6,1)
				e\xrot = .8
				e\yrot = 0
				e\mov = -1
		End Select
		
		ScaleEntity e\mesh,.6,.6,.6
		PositionEntity e\mesh,x,y,z
		x=x+5
			If x = 45
				y = y + 10
				x = -45
			EndIf
		Next
	timer = MilliSecs()
End Function

Function updateanger()
	
	For e.enemy = Each enemy
		madnum = Rand(1,3000)
			If e\id = madnum And EntityDistance(e\mesh,base) > 140 And EntityY(e\mesh) < 100
				e\angry = True
				EntityColor e\mesh,255,0,0
			EndIf
			If EntityDistance (e\mesh,base) < 4
				EnemyExplode(e)
				FreeEntity e\mesh
				level = 0				
				gameover = 1
				ecount = ecount - 1
				If ecount = 0
					intermission = True
					timer = MilliSecs() + 6000
				EndIf
				Delete e
			EndIf
	Next
	
End Function


another update above, enjoy. Seems to be a small bug where sometimes the next level won't come. I'll track it down soon.

hey, looks better, cool editing.

Ideas anyone? Is it mind-numbingly boring? Too easy?

To be honest, I liked the graphics on the first one. Maybe a cel shaded graphics style would look nice...

- How about some different enemy types?
- Different weapons? Rockets, bombs, grenades, lazers, etc
- Make the canon mobile? Mounted on a truck or something...
- Could then make it 2 player or keyboard+mouse control...

I couldn't get higher than level 1 for some reason. Nice particles. The game seems to be some type of "ballerburg" thing. I think you need to add some kind of joke components.

Sorry jfk, not sure what you mean by joke components. Odd that you can't make it past level 1. Hmm...

no matter how much i shoot or where i still cant hit them with the side of a barn

Are you right clicking to set off the projectile when it's near them?

most times im not NOT clicking RMB
they just pass inbetween squares as if they were miles away

edit:
ive been getting my l and r mixed up re mouse buttons
aye when i do rmb and not lmb thinking im rmb as stated above i do get the odd boom here and there

I mean some comedy factor, like attacking donuts, or raining politicans.

Good idea jfk :).

Ginger Tea... you're supposed to detonate them so the blast particles will destroy the baddies. There is no collision before you set it off... only the fragments (particles) after detonating.

At the moment I'm working on scoring according to how many are destroyed with one projectile.

oh i was treating it like space invaders
just shoot shoot shoot

will try again later

edit:
saw something posted about rmb when i first tried it and tbh forgot that we use the lmb all the time so i was firing unexploded balls at it ... no wonder nowt were happening

Nice to see your keep adding to this :o)

Ok, i've been working away on a turret, because i thought i could stick alot of fancy graphics, since the gameworld would be verrrry small. Here's my turret so far. Just desiging a few enemies just now :o) The laser you see coming out the end is the laser the cannon shoots.

EDIT: Image updated



Wow very nice

The turret looks very nice.

The code that stayne put up provided was cool too.
But the one thing i noticed is that the text that tells you your score was only on the screen for about 3/10 of a second at a time, then it was gone. Is this just me...?

the text does flicker
and one of the lines dissapeared i think it might have been click to start or something cos nothing happened till i got bored and started flying vollys all over the show

Using Left Click to shoot and right click to explode works well, just time it. I beat first level, (killed all the yellow/red balls) but it never went to next level, weird.

I like the turret, Ross.

I've replaced the text with bitmap text since last update. I'll post some new code soon.