Moving the background
Moving the background
Hello CoolBasic masters, i´m quite new in this kind of things and i´m making a space like shooting game and i wanted to put the background spining.
Is that possible in CB?
Thankz
Is that possible in CB?
Thankz
- Attachments
-
- screen.png (56.71 KiB) Viewed 20739 times
Re: Moving the background
If just moving the background as the camera moves is okay, then it's done like this:
If you want to turn the background, then as far as I know, it isn't possible without being extremely slow.
Code: Select all
background=MakeObjectFloor()
backgroundimage=LoadImage("Media\grass.bmp") //replace "grass.bmp" with your own background
PaintObject background, backgroundimage
Re: Moving the background
Thank you for the fast reply, my idea was a moving back and not just when the camera moves.
like this that i have made in LUA
And it works nice.
like this that i have made in LUA
Code: Select all
background= loadimage("fundo.bmp")
spin=0
putimage(0-spean,0,background)
putimage(640-spean,0,background)
spin=spin+1
if spin>=640 then
spin=0
end
Re: Moving the background
Is it possible to move the camera at all in your current engine? Because if it's not, then you can also do it like this:cvirus wrote:Thank you for the fast reply, my idea was a moving back and not just when the camera moves.
Code: Select all
background=MakeObjectFloor()
backgroundimage=LoadImage("Media\grass.bmp") //replace "grass.bmp" with your own background
PaintObject background, backgroundimage
spaceship=LoadObject("Media\cow.bmp") //replace "cow.bmp" with your own spaceship
Repeat
TranslateObject spaceship, 3, 0 //move everything three pixels right
CloneCameraPosition spaceship
//when moving any enemies or bullets, remember to take into account the fact that they're already moving 3 pixels per frame because of the camera thing
DrawScreen
Forever
Re: Moving the background
it´s working very good, the only thing is not working well is the part of the arrows of the movement.
My code so far:
How can i improve it?
Thank you
My code so far:
How can i improve it?
Thank you
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
SetWindow "Ship Battle Game"
FrameLimit 40
ship = LoadObject("nave.png", 72)
PositionObject ship,-220, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.bmp")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
AddText("Space Game")
x=0:y=0
spin=0
Repeat
TranslateObject ship,3,0
CloneCameraPosition ship
If LeftKey() Then TurnObject ship,5
If RightKey() Then TurnObject ship,-5
If UpKey() Then MoveObject ship,2
If DownKey() Then MoveObject ship,-2
If ObjectX (ship)<-250 Then PositionObject ship, -200,ObjectY(ship)
DrawScreen
Until EscapeKey()
Re: Moving the background
In fact, what you were looking for was easier done than I thought it would be. For some reason I didn't think you could move a background, but apparently you can.
Also, I modified the moving part a little. I think it's better now.
Also, I modified the moving part a little. I think it's better now.
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
SetWindow "Ship Battle Game"
FrameLimit 40
ship = LoadObject("nave.png", 72)
ship2 = LoadObject ("media\cow.bmp") //you can remove this line, it's there just to demonstrate how having more objects in there looks like
PositionObject ship,-220, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.png")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
AddText("Space Game")
x=0:y=0
spin=0
Repeat
CloneCameraPosition ship
TranslateObject floor, -1.4, 0 'move the floor
If LeftKey() Then TurnObject ship,5
If RightKey() Then TurnObject ship,-5
If UpKey() Then speed# = CurveValue(4.6, speed#, 13) 'if up arrow is pressed, speed# will be increased smoothly
If DownKey() Then speed# = CurveValue(-2, speed#, 13) '...and if down arrow is pressed, it will be decreased smoothly
speed# = CurveValue (0, speed#, 60) 'this will make sure the ship will eventually stop smoothly if no key is pressed
MoveObject ship, speed# '...and finally, the ship is actually being moved
If ObjectX (ship)<-250 Then PositionObject ship, -200,ObjectY(ship)
DrawScreen
Until EscapeKey()
Re: Moving the background
Thank you very much for the help, the moving still have problems but that´s for later.
Can you explain this:
speed# <- is this an var?
TranslateObject
CloneCameraPosition
CurveValue
Thank you, sorry for this but i have many questions, hope you don´t mind.
Can you explain this:
speed# <- is this an var?
TranslateObject
CloneCameraPosition
CurveValue
Thank you, sorry for this but i have many questions, hope you don´t mind.
Re: Moving the background
speed# is a variable, yes. I use it to determine the supposed speed of the spaceship, then move it speed# pixels front.cvirus wrote:Can you explain this:
speed# <- is this an var?
TranslateObject
CloneCameraPosition
CurveValue
Thank you, sorry for this but i have many questions, hope you don´t mind.
TranslateObject is a command that moves an object regardless of its angle.
CloneCameraPosition is a command that checks the position of an object and puts the camera in the same coordinates (which results the camera "following" that object if it's used in a loop).
CurveValue changes a variable's value to another value smoothly. The first number is the "new" value, the second number is the old value, and the third number tells the function how smooth it should be.
And no, I don't mind at all.
Re: Moving the background
Thank you, i´ll continue to develop the game and enjoy your help, knows where to get free maps and sprites on the web?
Re: Moving the background
I usually draw my own graphics, so I don't know any good site, but at least I found this with some Google searching: http://gamemaking.indiangames.net/index ... rGames.htmcvirus wrote:Thank you, i´ll continue to develop the game and enjoy your help, knows where to get free maps and sprites on the web?
Re: Moving the background
Thanks, which software do you use for make them?
I know that website, but you could know a good resource that gives that for nothing.
By the way to place enemies in the game you call object like the main ship right?
Thanks
I know that website, but you could know a good resource that gives that for nothing.
By the way to place enemies in the game you call object like the main ship right?
Thanks
Re: Moving the background
Adobe Photoshop CS2, GIMP or Microsoft Paint. Depends on my mood.cvirus wrote:Thanks, which software do you use for make them?
Sorry, I don't.I know that website, but you could know a good resource that gives that for nothing.
I'd suggest using types. Like this:By the way to place enemies in the game you call object like the main ship right?
Code: Select all
Type enemies
Field obj 'there is one field, which is called obj and is going to contain the object.
EndType
cow = LoadObject ("Media\cow.bmp")
ShowObject cow, 0 'the cow can be hidden, because being hidden won't be copied when copying an object
For i = 1 to 15 'repeat the following loop 15 times
newEnemy.enemies = New(enemies) 'create a new enemy
newEnemy\obj = CloneObject (cow) 'the field obj is now a copy of the cow
PositionObject newEnemy\obj, Rand(-200,200), Rand (-150,150) 'place the copy to a random location
Next i
Repeat
For iEnemy.enemies = Each enemies 'repeat the following loop for each enemy
TranslateObject iEnemy\obj, Rand (-6,6), Rand (-6,6) 'move the enemy randomly
If Rand (1,500) = 1 Then 'if a randomized number between 1-500 happens to be 1
DeleteObject iEnemy\obj 'delete the object
Delete iEnemy 'it is also important to delete the current member
EndIf
Next iEnemy
DrawScreen
Forever
Any time.Thanks
Re: Moving the background
My code so far, next to it is attached the files so you can see what´s is going one:
The enemie are killing them selves lol, now to be a very basic noob game is puting the collision on the bullets and the explosion sound and sprite.
The enemie are killing them selves lol, now to be a very basic noob game is puting the collision on the bullets and the explosion sound and sprite.
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
SetWindow "Ship Battle Game"
FrameLimit 40
Type ENEMIES
Field obj
End Type
enem = LoadObject("enemy2.png", 72)
ShowObject enem,0
For i = 1 To 15
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
PositionObject newenemie\obj, Rand(-200,200),Rand(-150,150)
Next i
ship = LoadObject("nave.png", 72)
PositionObject ship,-220, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.bmp")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
AddText("Space Game")
x=0:y=0
Repeat
For newenemie.ENEMIES = Each ENEMIES
TranslateObject newenemie\obj, Rand(-6,6), Rand(-6,6)
If Rand(1,500)=1 Then
DeleteObject newenemie\obj
Delete newenemie
EndIf
Next newenemie
CloneCameraPosition ship
TranslateObject floor, -1.4, 0 'move the floor
If LeftKey() Then MoveObject ship, 5
If RightKey() Then MoveObject ship,-5
If UpKey() Then speed# = CurveValue(4.6, speed#, 13) 'if up arrow is pressed, speed# will be increased smoothly
If DownKey() Then speed# = CurveValue(-2, speed#, 13) '...and if down arrow is pressed, it will be decreased smoothly
speed# = CurveValue (0, speed#, 60) 'this will make sure the ship will eventually stop smoothly if no key is pressed
MoveObject ship, speed# '...and finally, the ship is actually being moved
DrawScreen
Until EscapeKey()
- Attachments
-
- CB.zip
- (12.29 KiB) Downloaded 508 times
Re: Moving the background
I have Updated the code, now it contain a bullet, well i´m reading the manual of each command and adapting the code example on it.
I have 2 problems:
The enemies are disappearing by them selves, i think if they move forward the game was more interesting (i think), and i need the bullet to be the same in every direction.
By the way, how the coordinates in CB are represented?
Thank you.
I have 2 problems:
The enemies are disappearing by them selves, i think if they move forward the game was more interesting (i think), and i need the bullet to be the same in every direction.
By the way, how the coordinates in CB are represented?
Thank you.
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
SetWindow "Ship Battle Game"
FrameLimit 40
Type ENEMIES
Field obj
End Type
Type BULLETS
Field obj
End Type
enem = LoadObject("enemy2.png")
ShowObject enem,0
For i = 1 To 15
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
PositionObject newenemie\obj, Rand(-200,200),Rand(-150,150)
Next i
bullet= LoadObject("bullet.png")
ShowObject bullet, OFF
ship = LoadObject("nave.png", 72)
PositionObject ship,-300, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.bmp")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
AddText("Space Game")
SetupCollision ship,enem,1,4,2
x=0:y=0
Repeat
For newenemie.ENEMIES = Each ENEMIES
TranslateObject newenemie\obj, Rand(-6,6), Rand(-6,6)
If Rand(1,500)= 1 Then
DeleteObject newenemie\obj
Delete newenemie
EndIf
Next newenemie
CloneCameraPosition ship
TranslateObject floor, -1.4, 0 'move the floor
If LeftKey() Then TurnObject ship, 5
If RightKey() Then TurnObject ship,-5
If UpKey() Then speed# = CurveValue(4.6, speed#, 13) 'if up arrow is pressed, speed# will be increased smoothly
If DownKey() Then speed# = CurveValue(-2, speed#, 13) '...and if down arrow is pressed, it will be decreased smoothly
speed# = CurveValue (0, speed#, 60) 'this will make sure the ship will eventually stop smoothly if no key is pressed
MoveObject ship, speed# '...and finally, the ship is actually being moved
If KeyDown(cbkeyspace) And reload =0
newbullet.BULLETS = New(BULLETS)
newbullet\obj = CloneObject(bullet)
CloneObjectPosition newbullet\obj,ship
CloneObjectOrientation newbullet\obj,ship
MoveObject newbullet\obj,24
reload=4
EndIf
b=0
For newbullet.BULLETS = Each BULLETS
MoveObject newbullet\obj,6
If Distance2 (newbullet\obj,ship)>200 Then
DeleteObject newbullet\obj
Delete newbullet
EndIf
b=b+1
Next newbullet
If reload >0 Then reload=reload-1
Text 30,30,"Bullets:"+b
DrawScreen
Until EscapeKey()
Re: Moving the background
This is probably closer to what you're wanting to do:
I was too lazy to add comments this time, it's almost 2am in Finland. If there's something you don't understand, just ask and I'll try my best explaining it. I think you should be able to figure out how to make the enemies shoot as well based on this.
Also, I added the text in your game that tells the coordinates of your ship; that's how the coordinates in CB are represented.
For some reason, the SetupCollision for ship and enemies caused a Memory acces violation error, and at the moment I can't come up with a way to fix it myself, so I turned them to comments and now it works fine. They just don't collide
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
FrameLimit 40
Type ENEMIES
Field obj
Field health As Integer
End Type
Type BULLETS
Field obj
End Type
enem = LoadObject("enemy2.png", 72)
ShowObject enem,0
bullet= LoadObject("bullet.png", 72)
ShowObject bullet, OFF
ship = LoadObject("nave.png", 72)
PositionObject ship,-300, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.bmp")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
AddText("Space Game")
For i = 1 To 15
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
newenemie\health = 4
PositionObject newenemie\obj, Rand(-500,500),Rand(-450,450)
'SetupCollision ship,newenemie\obj,1,4,2
Next i
SetWindow "Ship Battle Game"
x=0:y=0
Repeat
SetWindow "Ship Battle Game 1"
For newenemie.ENEMIES = Each ENEMIES
PointObject newenemie\obj, ship
MoveObject newenemie\obj, 1.6
decreasehealth = False
For iBullet.BULLETS = Each BULLETS
If ObjectsOverlap (newenemie\obj, ibullet\obj) Then
decreasehealth = True
DeleteObject ibullet\obj
Delete ibullet
EndIf
Next ibullet
If decreasehealth Then newenemie\health -1
If newenemie\health < 1 Then
DeleteObject newenemie\obj
Delete newenemie
EndIf
Next newenemie
SetWindow "Ship Battle Game 2"
CloneCameraPosition ship
TranslateObject floor, -1.4, 0 'move the floor
If LeftKey() Then TurnObject ship, 5
If RightKey() Then TurnObject ship,-5
If UpKey() Then speed# = CurveValue(4.6, speed#, 13) 'if up arrow is pressed, speed# will be increased smoothly
If DownKey() Then speed# = CurveValue(-3.5, speed#, 13) '...and if down arrow is pressed, it will be decreased smoothly
speed# = CurveValue (0, speed#, 60) 'this will make sure the ship will eventually stop smoothly if no key is pressed
MoveObject ship, speed# '...and finally, the ship is actually being moved
If KeyDown(cbkeyspace) And reload =0
newbullet.BULLETS = New(BULLETS)
newbullet\obj = CloneObject(bullet)
CloneObjectPosition newbullet\obj,ship
CloneObjectOrientation newbullet\obj,ship
MoveObject newbullet\obj,24
reload=7
EndIf
SetWindow "Ship Battle Game 3"
If Rand (1, 100) = 1 Then
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
newenemie\health = 4
PositionObject newenemie\obj, Rand(-200,200),Rand(-150,150)
' SetupCollision ship,newenemie\obj,1,4,2
EndIf
SetWindow "Ship Battle Game 4"
b=0
For ibullet.BULLETS = Each BULLETS
MoveObject ibullet\obj,10
b=b+1
If Distance2 (ibullet\obj,ship)>400 Then
DeleteObject ibullet\obj
Delete ibullet
EndIf
Next ibullet
If reload >0 Then reload=reload-1
DrawGame
Text 30,30,"Bullets: "+b
Text 30,42,"Coordinates: X"+Int(ObjectX (ship))+", Y"+Int(ObjectY (ship))
DrawScreen
Also, I added the text in your game that tells the coordinates of your ship; that's how the coordinates in CB are represented.
For some reason, the SetupCollision for ship and enemies caused a Memory acces violation error, and at the moment I can't come up with a way to fix it myself, so I turned them to comments and now it works fine. They just don't collide
Re: Moving the background
Thank you for the help, if you could explain a little between my code and yours i´d be glad, thank you.
How did you put the bullet firing in the same direction?
By the way the enemies are coming to the ship and they are piling each other.
Thank you
How did you put the bullet firing in the same direction?
By the way the enemies are coming to the ship and they are piling each other.
Thank you
Re: Moving the background
The main difference is this:cvirus wrote:Thank you for the help, if you could explain a little between my code and yours i´d be glad, thank you.
Code: Select all
For newenemie.ENEMIES = Each ENEMIES 'your code
TranslateObject newenemie\obj, Rand(-6,6), Rand(-6,6) 'move the object a random amount to a random direction
If Rand(1,500)= 1 Then 'if a randomly generated number between 1 and 500 is 1...
DeleteObject newenemie\obj '...delete this enemy.
Delete newenemie
EndIf
Next newenemie
Code: Select all
For newenemie.ENEMIES = Each ENEMIES 'my code
PointObject newenemie\obj, ship 'turn the enemy so that it points at the spaceship
MoveObject newenemie\obj, 1.6 'move the enemy to the direction it's facing
decreasehealth = False 'this is a variable that tells if the health should be decreased or not; by default it shouldn't be.
For iBullet.BULLETS = Each BULLETS 'for each bullet...
If ObjectsOverlap (newenemie\obj, ibullet\obj) Then '...if that bullet happens to overlap this enemy,
decreasehealth = True 'the health should be decreased
DeleteObject ibullet\obj 'and the bullet is deleted.
Delete ibullet
EndIf
Next ibullet
If decreasehealth Then newenemie\health -1 'if the health should be decreased, it is decreased
If newenemie\health < 1 Then 'and if the health is 0 or less, the enemy is destroyed.
DeleteObject newenemie\obj
Delete newenemie
EndIf
Next newenemie
Just like you put the spaceship turn around - by adding a rotation value as a parameter for the LoadObject function, and the value in this case is 72 because that's the rotation value you used for your spaceship and they should be equal or the bullet will look odd when fired.How did you put the bullet firing in the same direction?
Why couldn't they? It's in space, and as far as I know, ships can pile in space.By the way the enemies are coming to the ship and they are piling each other.
If you don't want them to pile, you could make a For-loop for all the enemies, and inside the For-loop, there would be another For-loop for all the enemies (in this case, the enemies have to be called with different names, such as aEnemy.ENEMIES and bEnemy.ENEMIES). Then you check if the object in question is the same for both for-loops, and if it is not, if the two objects overlap, move them sideways.
Re: Moving the background
Thank you for the explanation, i will study a little to get everything right.
Just one more thing, if you have a 640 by 480 window how coordinates x an y are represented?
Just one more thing, if you have a 640 by 480 window how coordinates x an y are represented?
Re: Moving the background
A little update with explosion and fire sound, i also put a little explosion sprite but don´t know very well how to put her in every enemies exploding.
And i know the coordinates now.
I want the enemies to fire so i must do somethig like this:
but i´m confused in what place should i put it.
by the way, is it possible to put a variable printed in the screen with the number of enemies?
Thank you once again
And i know the coordinates now.
Code: Select all
'game space shooting
SCREEN 640, 480, cbsizable
FrameLimit 40
Type ENEMIES
Field obj
Field health As Integer
End Type
Type BULLETS
Field obj
End Type
shoot = LoadSound ("Blaster.wav")
boom = LoadSound ("Boom.wav")
enem = LoadObject("enemy2.png", 72)
ShowObject enem,0
bullet= LoadObject("bullet.png", 72)
ShowObject bullet, OFF
explosion = LoadObject("explosion.png", 72)
ShowObject explosion, OFF
ship = LoadObject("nave.png", 72)
PositionObject ship,-300, 0
floor=MakeObjectFloor()
fundo=LoadImage("fundo.bmp")
PaintObject floor,fundo
ClsColor cbBlack
Color cbRed
For i = 1 To 15
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
newenemie\health = 4
PositionObject newenemie\obj, Rand(-500,500),Rand(-450,450)
SetupCollision ship, newenemie\obj,2,2,2
Next i
SetWindow "Ship Battle Game"
x=0:y=0
Repeat
SetWindow "Ship Battle Game 1"
For newenemie.ENEMIES = Each ENEMIES
PointObject newenemie\obj, ship
MoveObject newenemie\obj, 1.6
decreasehealth = False
For iBullet.BULLETS = Each BULLETS
If ObjectsOverlap (newenemie\obj, ibullet\obj) Then
decreasehealth = True
DeleteObject ibullet\obj
Delete ibullet
EndIf
Next ibullet
If decreasehealth Then newenemie\health -1
If newenemie\health < 1 Then
ShowObject explosion, ON
CloneObjectPosition newenemie\obj, explosion
UpdateGame
PlaySound boom,100
DeleteObject newenemie\obj
Delete newenemie
EndIf
Next newenemie
CloneCameraPosition ship
TranslateObject floor, -1.4, 0 'move the floor
If LeftKey() Then TurnObject ship, 5
If RightKey() Then TurnObject ship,-5
If UpKey() Then speed# = CurveValue(4.6, speed#, 13) 'if up arrow is pressed, speed# will be increased smoothly
If DownKey() Then speed# = CurveValue(-3.5, speed#, 13) '...and if down arrow is pressed, it will be decreased smoothly
speed# = CurveValue (0, speed#, 60) 'this will make sure the ship will eventually stop smoothly if no key is pressed
MoveObject ship, speed# '...and finally, the ship is actually being moved
If KeyDown(cbkeyspace) And reload =0
PlaySound shoot,20
newbullet.BULLETS = New(BULLETS)
newbullet\obj = CloneObject(bullet)
CloneObjectPosition newbullet\obj,ship
CloneObjectOrientation newbullet\obj,ship
MoveObject newbullet\obj,24
reload=7
EndIf
SetWindow "Ship Battle Game 3"
If Rand (1, 100) = 1 Then
newenemie.ENEMIES = New(ENEMIES)
newenemie\obj = CloneObject (enem)
newenemie\health = 1
PositionObject newenemie\obj, Rand(-200,200),Rand(-150,150)
SetupCollision ship,newenemie\obj,2,2,2
EndIf
SetWindow "Ship Battle Game 4"
b=0
For ibullet.BULLETS = Each BULLETS
MoveObject ibullet\obj,10
b=b+1
If Distance2 (ibullet\obj,ship)>400 Then
DeleteObject ibullet\obj
Delete ibullet
EndIf
Next ibullet
If reload >0 Then reload=reload-1
DrawGame
Text 30,30,"Bullets: "+b
Text 30,42,"Coordinates: X"+Int( (ship))+", Y"+Int(ObjectY (ship))
DrawScreen
Until EscapeKey()
Code: Select all
enemiebullet.BULLETS = New(BULLETS)
enemiebullet\obj = CloneObject(bullet)
CloneObjectPosition enemiebullet\obj,newenemie\obj
CloneObjectOrientation enemiebullet\obj,newenemie\obj
MoveObject enemiebullet\obj,24
by the way, is it possible to put a variable printed in the screen with the number of enemies?
Thank you once again
Re: Moving the background
I have tried several things, but with no luck , i have to put every single enemies shooting the ship, i must do a function and update the enemies but don´t know how to.
If a nice soul could give a little help i would appreciate.
Thank you
If a nice soul could give a little help i would appreciate.
Thank you