Warning: Undefined array key "keywords_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 234 Warning: Undefined array key "description_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 235 Warning: Undefined array key "commercials" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 261 Tutorial 10

Tutorial 10

GL (very) Basic Tutorial

aka "so, you want to write a game, do you?"
© 2008 PeeJay

Lesson 10 - Great Oaks Grow From Little Acorns

Like I said, it is the little details that make a good game great - now although this little game is never going to be great as it stands, a bit more work and suddenly we could end up with a huge berzerk style game. It wouldn't take too much imagination to turn this basic idea into a fun little romp really, would it? And having shown you how to move a tiled background in sympathy with your player movements, now, if you imagined the player staying still in the centre of the screen, and the background moving around him, you can see how giant scrolling play areas are achieved.
So, what is wrong with our code as it was? Well, there was nothing wrong with it as such, but there is a little detail that has been overlooked - so let's put that right now.
Imagine our player walking from left to right. The background neatly scrolls from right to left, and everything looks wonderful, except for one thing - really, the enemy movement should also be affected by what our player is doing on screen. So, now have another look in the updateplayer function. We have added the following lines:
	FOREACH en IN enemies[]
		en.enx=en.enx-dirx
		en.eny=en.eny-diry
		IF en.enx<-32 OR en.enx>640 OR en.eny<-32 OR en.eny>480 THEN DELETE en
	NEXT
Now for each movement the player does, just as the background move in sympathy, so do the enemies. There, it easy enough to do, but if you try running it again you will see it makes a big difference to the overall impression to the game.

http://www.glbasic.com/files/tutorial/ImgLesson10.png
For the next lesson, we'll look at adding music and sound, as firing a gun without a bang is a bit dull, isn't it?
Download the Source Code and Media Files
Previous Lession
Next Lession