Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: billy bob on July 04, 2009

Title: Blitz2D, first program HELP!
Post by: billy bob on July 04, 2009
Hello!

I have encountered a problem in my game >:( :'(!
(with blitz 2D)

The aliens are supposed to come back when I shoot them with bullets, but it isn't working, they just don't come back (and the levels aren't going up either).

Does anyone know what I have done wrong?

And as a bonus does anyone know how to make borders so you can't go off screen because you can cheat.......

(The sound and images and DATs are correct because they work.)

Here is the game code so far:


Code: [Select]
;Graphics
Graphics 640,480,16,2

;Timer.
timer = CreateTimer(30)

;load highscore
If ReadFile("score.dat") = 0 Then
highscore = 100
Else
file_score = ReadFile("score.dat")
highscore = ReadInt(file_score)
CloseFile (file_score)
EndIf

;Images.
AutoMidHandle True
img_alien = LoadImage("alien.png")
img_smile = LoadImage("smile.png")
img_bullet = LoadImage("bullet.png")
img_bomb = LoadImage("bomb.png")

;Load sounds.
snd_Bulletsound = LoadSound("Bulletsound.wav")
snd_Loselife = LoadSound("Loselife.wav")
snd_Bombsound = LoadSound("Bombsound.wav")
snd_Aliendeath = LoadSound("Aliendeath.wav")

;Bullet.
Type bullet
Field x
Field y
End Type

x= 300
y= 400

;Bomb.
Type bomb
Field x
Field y
End Type

;Alien.
Type alien
Field x
Field y
End Type

;Lives.
Lives = 3

;Level to start on
level = 0

;set number of aliens at start.
numaliens = 0

;Set alien speed.
aspeed = 2
amx = aspeed
chdir = False

;Reset score.
score = 0

;Buffers.
SetBuffer BackBuffer()


While Not KeyDown(1)

If numaliens = 0 Then

level = level + 1
;Alien number.
For z = 1 To 9
For w = 1 To 2
a.alien = New alien
a\x = 100 + 50*z
a\y = -70 + 120*w
Next
Next
End If

Cls

DrawImage img_smile,x,y

;Keys.
If KeyDown(200) Then y = y - 6
If KeyDown(208) Then y = y + 6
If KeyDown(203) Then x = x - 6
If KeyDown(205) Then x = x + 6
If KeyHit (207) Then End
If KeyDown(2) Then Flip
If KeyDown(3) Then Flip
If KeyDown(4) Then Flip
If KeyDown(5) Then Flip
If KeyDown(6) Then Flip
If KeyDown(7) Then Flip
If KeyDown(8.) Then Flip (ignore the dot after the eight it was only there to disable a smiley.)
If KeyDown(9) Then Flip
If KeyDown(10) Then Flip
If KeyDown(11) Then Flip
If KeyDown(17) Then y = y - 6
If KeyDown(30) Then x = x - 6
If KeyDown(31) Then y = y + 6
If KeyDown(32) Then x = x + 6
If KeyHit (57) Then

;About bullets
PlaySound (snd_Bulletsound)
b.bullet = New bullet
b\x = x
b\y = y - 5
EndIf

;More about bullets
For b.bullet = Each bullet
b\y = b\y - 5
DrawImage img_bullet,b\x,b\y
If b\y < 0 Then Delete b
Next

;Extra alien movement.
If chdir = True Then
amx = -amx
EndIf
chdir = False

numalien = 0
;Alien movement.
For a.alien = Each alien
;Count aliens
numaliens = numaliens + 1
;Main alien movement.
a\x = a\x + amx
If a\x > 620 Then chdir = True
If a\x < 20 Then chdir = True

;Aliens drop.
If Rand(200) = 25 Then
PlaySound(snd_Bombsound)
bombs.bomb = New bomb
bombs\x = a\x
Bombs\y = a\y
EndIf

;Images collide "bullet" with "alien".
DrawImage img_alien,a\x,a\y
For b.bullet = Each bullet
If ImagesCollide (img_bullet,b\x,b\y,0,img_alien,a\x,a\y,0) Then
PlaySound (snd_Aliendeath)
Delete b
Delete a
score = score + 10
If score > highscore Then highscore = score
Exit
EndIf
Next
Next

;About bombs.
For bombs.bomb = Each bomb
bombs\y = bombs\y + 4
DrawImage img_bomb,bombs\x,bombs\y
If bombs\y > 500 Then Delete bombs

;Images colide "bomb" with "smile".
If ImagesCollide (img_bullet,bombs\x,bombs\y,0,img_smile,x,y,0)
PlaySound(snd_Loselife)
Delete bombs
lives = lives - 1
ElseIf bombs\y > 475 Then
Delete bombs
EndIf
Next

;What happens when less lives.
If lives=0 Then

;save highscore
file_score = WriteFile("score.dat")
WriteInt(file_score,highscore)
CloseFile file_score

Text 320,100,"GAME OVER",1,1
Text 320,115,"Try again!",1,1
Flip
Delay 3000
End
EndIf


Text 50,420,"LIVES: " + Lives

;Draw score.
Text 530,420,"SCORE: " + score
Text 510,430,"Nice score! "

;Draw highscpre.
Text 320,50,"HIGHSCORE: " + highscore,1,1

;Draw level number.
Text 320,440,"LEVEL: " + level,1

;Wait game timer.
WaitTimer(timer)

;Flip screen monitor.
Flip

Wend

;End game.
End

[Tags Added - Sw.]
Title: Re: Blitz2D, first program HELP!
Post by: Shockwave on July 04, 2009
Four things :)

1: First of all, a warm welcome to DBF :)
2: I will have to move this into the Blitz part of the forum in a bit, I'll leave it here for now so you can find it.
3: It would help if you upload the images and sounds for your game too (just put them in a zip file and attach them to your post (additional options tab on the post form) ).
4: And once again, a warm welcome to DBF.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 04, 2009
OK, here is the blitz pictures and sounds and DAT. ;)
Title: Re: Blitz2D, first program HELP!
Post by: Shockwave on July 04, 2009
I am sure that one of the Blitz guys here will help you out, if you don't get any replies by tomorrow afternoon I'll reinstall blitz and fix it for you :)
Title: Re: Blitz2D, first program HELP!
Post by: ferris on July 04, 2009
Fixed :)

1. Returning aliens & level up: You had a typo before the aliens are counted. "numalien = 0" was supposed to be "numaliens = 0" ... you forgot the "s" ;) .
2. "Borders": To do this, you really only have to check if the player has gone too far to the left or right, and if they have, move them back on screen.

A couple of typos were fixed too, and all the fixes are commented:

Code: [Select]
;Graphics
Graphics 640,480,16,2

;Timer.
timer = CreateTimer(30)

;load highscore
If ReadFile("score.dat") = 0 Then
highscore = 100
Else
file_score = ReadFile("score.dat")
highscore = ReadInt(file_score)
CloseFile (file_score)
EndIf

;Images.
AutoMidHandle True
img_alien = LoadImage("alien.png")
img_smile = LoadImage("smile.png")
img_bullet = LoadImage("bullet.png")
img_bomb = LoadImage("bomb.png")

;Load sounds.
snd_Bulletsound = LoadSound("Bulletsound.wav")
snd_Loselife = LoadSound("Loselife.wav")
snd_Bombsound = LoadSound("Bombsound.wav")
snd_Aliendeath = LoadSound("Aliendeath.wav")

;Bullet.
Type bullet
Field x
Field y
End Type

x= 300
y= 400

;Bomb.
Type bomb
Field x
Field y
End Type

;Alien.
Type alien
Field x
Field y
End Type

;Lives.
Lives = 3

;Level to start on
level = 0

;set number of aliens at start.
numaliens = 0

;Set alien speed.
aspeed = 2
amx = aspeed
chdir = False

;Reset score.
score = 0

;Buffers.
SetBuffer BackBuffer()


While Not KeyDown(1)

If numaliens = 0 Then

level = level + 1
;Alien number.
For z = 1 To 9
For w = 1 To 2
a.alien = New alien
a\x = 100 + 50*z
a\y = -70 + 120*w
Next
Next
End If

Cls

DrawImage img_smile,x,y

;Keys.
If KeyDown(200) Then y = y - 6
If KeyDown(208) Then y = y + 6
If KeyDown(203) Then x = x - 6
If KeyDown(205) Then x = x + 6
; Limit player movement {
tiw = ImageWidth(img_smile) / 2
If x < tiw Then x = tiw
If x >= 640 - tiw Then x = 640 - tiw - 1
; }
If KeyHit (207) Then End
If KeyDown(2) Then Flip
If KeyDown(3) Then Flip
If KeyDown(4) Then Flip
If KeyDown(5) Then Flip
If KeyDown(6) Then Flip
If KeyDown(7) Then Flip
If KeyDown(8) Then Flip
If KeyDown(9) Then Flip
If KeyDown(10) Then Flip
If KeyDown(11) Then Flip
If KeyDown(17) Then y = y - 6
If KeyDown(30) Then x = x - 6
If KeyDown(31) Then y = y + 6
If KeyDown(32) Then x = x + 6
If KeyHit (57) Then

;About bullets
PlaySound (snd_Bulletsound)
b.bullet = New bullet
b\x = x
b\y = y - 5
EndIf

;More about bullets
For b.bullet = Each bullet
b\y = b\y - 5
DrawImage img_bullet,b\x,b\y
If b\y < 0 Then Delete b
Next

;Extra alien movement.
If chdir = True Then
amx = -amx
EndIf
chdir = False

numaliens = 0 ; You had a typo here....you had "numalien = 0" without the "s" ;)
;Alien movement.
For a.alien = Each alien
;Count aliens
numaliens = numaliens + 1
;Main alien movement.
a\x = a\x + amx
If a\x > 620 Then chdir = True
If a\x < 20 Then chdir = True

;Aliens drop.
If Rand(200) = 25 Then
PlaySound(snd_Bombsound)
bombs.bomb = New bomb
bombs\x = a\x
Bombs\y = a\y
EndIf

;Images collide "bullet" with "alien".
DrawImage img_alien,a\x,a\y
For b.bullet = Each bullet
If ImagesCollide (img_bullet,b\x,b\y,0,img_alien,a\x,a\y,0) Then
PlaySound (snd_Aliendeath)
Delete b
Delete a
score = score + 10
If score > highscore Then highscore = score
Exit
EndIf
Next
Next

;About bombs.
For bombs.bomb = Each bomb
bombs\y = bombs\y + 4
DrawImage img_bomb,bombs\x,bombs\y
If bombs\y > 500 Then Delete bombs

;Images colide "bomb" with "smile".
If ImagesCollide (img_bullet,bombs\x,bombs\y,0,img_smile,x,y,0)
PlaySound(snd_Loselife)
Delete bombs
lives = lives - 1
ElseIf bombs\y > 475 Then
Delete bombs
EndIf
Next

;What happens when less lives.
If lives=0 Then

;save highscore
file_score = WriteFile("score.dat")
WriteInt(file_score,highscore)
CloseFile file_score

Text 320,100,"GAME OVER",1,1
Text 320,115,"Try again!",1,1
Flip
Delay 3000
End
EndIf


Text 50,420,"LIVES: " + Lives

;Draw score.
Text 530,420,"SCORE: " + score
Text 510,430,"Nice score! "

;Draw highscpre.
Text 320,50,"HIGHSCORE: " + highscore,1,1

;Draw level number.
Text 320,440,"LEVEL: " + level,1

;Wait game timer.
WaitTimer(timer)

;Flip screen monitor.
Flip

Wend

;End game.
End

Good job on your first game, and hope all other projects go well :)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 04, 2009

    Thanks so much!!

    I am real pleased now....

    I would be totally stuck without your help.

   Thanks! :kewl:

   If I have anymore problems I will definitely post them on this useful forum.
Title: Re: Blitz2D, first program HELP!
Post by: Shockwave on July 04, 2009
   If I have anymore problems I will definitely post them on this useful forum.

Stick around you're welcome here :)
Title: Re: Blitz2D, first program HELP!
Post by: ferris on July 05, 2009
Glad to help :D More is always welcome here.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 06, 2009
Hey, another question: "How do I put backgrounds in my game?".



Title: Re: Blitz2D, first program HELP!
Post by: Clyde on July 06, 2009
If you want just an image for your background, then you'd simply have a variable ( Global if it's to be used in Functions ) called for example my_background=loadimage("namoffile.ext") and draw that first before any of your other gfx stuff.

if it's something more exotic and interactive then, I would suggest you post in the Blitz area about a specific thang, btw also do a search as there's quite a few different ways of doing starfields that might be of help to you, as always do please ask.

Happy Coding,
Clyde.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 06, 2009
Thanks clyde, but after writing that no background has shown up.

I am expecting that their is more code To be written To make this background show up.

Please tell me what To do Or what I am doing wrong.

And also what size And extention do you suggest?☺
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on July 07, 2009
in Blitz i would recommend a png image file as they are much smaller.

make sure you draw the image after the cls ( clear screen ) command, also make sure your image is the same size as your Graphics width,height setup, or if you have a smaller image you can use tileimage.

btw, if you need help with the calls to any commands, press F1 at the beginning of the command, press F1 again for some examples that might give you a hand, if not post back.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 07, 2009

    Thanks clyde, now its working! :)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 07, 2009
    Although starting to lag a lot now, here is the new code:

Code: [Select]
   
;Graphics
Graphics 640,480,16,2

;Timer.
timer = CreateTimer(30)

;load highscore
If ReadFile("score.dat") = 0 Then
highscore = 100
Else
file_score = ReadFile("score.dat")
highscore = ReadInt(file_score)
CloseFile (file_score)
EndIf

;Load Images.
AutoMidHandle True
img_alien = LoadImage("alien.png")
img_smile = LoadImage("smile.png")
img_bullet = LoadImage("bullet.png")
img_bomb = LoadImage("bomb.png")
img_power = LoadImage("power.png")

;Load sounds.
snd_gameover = LoadSound("Gameover.wav")
snd_Bulletsound = LoadSound("Bulletsound.wav")
snd_Loselife = LoadSound("Loselife.wav")
snd_Bombsound = LoadSound("Bombsound.wav")
snd_Aliendeath = LoadSound("Aliendeath.wav")

;Load background.
img_background = LoadImage("background.png")

;Bullet.
Type bullet
Field x
Field y
End Type

;power
Type power
End Type

x= 300
y= 400

;Bomb.
Type bomb
Field x
Field y
End Type

;Alien.
Type alien
Field x
Field y
End Type

;Lives.
Lives = 3

;Level to start on
level = 0

;set number of aliens at start.
numaliens = 0

;Set alien speed.
aspeed = 2
amx = aspeed
chdir = False

;Reset score.
score = 0

;Buffers.
SetBuffer BackBuffer()


While Not KeyDown(1)

If numaliens = 0 Then

level = level + 1

;Alien number.
For z = 1 To 9
For w = 1 To 2
a.alien = New alien
a\x = 100 + 50*z
a\y = -70 + 120*w
Next
Next
End If


Cls

backdrop=LoadImage("background.png")

TileBlock backdrop

DrawImage img_smile,x,y

;Keys.
If KeyDown(200) Then y = y - 6
If KeyDown(208) Then y = y + 6
If KeyDown(203) Then x = x - 6
If KeyDown(205) Then x = x + 6
; Limit player movement {
tiw = ImageWidth(img_smile) / 2
If x < tiw Then x = tiw
If x >= 640 - tiw Then x = 640 - tiw - 1
If y < tiw Then y = tiw
If y >= 485 - tiw Then y = 485 - tiw - 1
; }
If KeyHit (207) Then End
If KeyDown(2) Then Flip
If KeyDown(3) Then Flip
If KeyDown(4) Then Flip
If KeyDown(5) Then Flip
If KeyDown(6) Then Flip
If KeyDown(7) Then Flip
If KeyDown(8.) Then Flip (ignore the dot after the eight it was only their to disable a smiley)
If KeyDown(9) Then Flip
If KeyDown(10) Then Flip
If KeyDown(11) Then Flip
If KeyDown(17) Then y = y - 6
If KeyDown(30) Then x = x - 6
If KeyDown(31) Then y = y + 6
If KeyDown(32) Then x = x + 6
If KeyHit (57) Then

;About bullets
PlaySound (snd_Bulletsound)
b.bullet = New bullet
b\x = x
b\y = y - 5
EndIf

;More about bullets
For b.bullet = Each bullet
b\y = b\y - 5
DrawImage img_bullet,b\x,b\y
If b\y < 0 Then Delete b
Next

;Extra alien movement.
If chdir = True Then
amx = -amx
EndIf
chdir = False

numaliens = 0
;Alien movement.
For a.alien = Each alien
;Count aliens
numaliens = numaliens + 1
;Main alien movement.
a\x = a\x + amx
If a\x > 620 Then chdir = True
If a\x < 20 Then chdir = True

;Aliens drop.
If Rand(200) = 25 Then
PlaySound(snd_Bombsound)
bombs.bomb = New bomb
bombs\x = a\x
Bombs\y = a\y
EndIf

;Images collide "bullet" with "alien".
DrawImage img_alien,a\x,a\y
For b.bullet = Each bullet
If ImagesCollide (img_bullet,b\x,b\y,0,img_alien,a\x,a\y,0) Then
PlaySound (snd_Aliendeath)
Delete b
Delete a
score = score + 10
If score > highscore Then highscore = score
Exit
EndIf
Next
Next

;About bombs.
For bombs.bomb = Each bomb
bombs\y = bombs\y + 4
DrawImage img_bomb,bombs\x,bombs\y
If bombs\y > 500 Then Delete bombs

;Images colide "bomb" with "smile".
If ImagesCollide (img_bullet,bombs\x,bombs\y,0,img_smile,x,y,0)
PlaySound(snd_Loselife)
Delete bombs
lives = lives - 1
ElseIf bombs\y > 475 Then
Delete bombs
EndIf

Next

;What happens when less lives.
If lives=0 Then

;save highscore
file_score = WriteFile("score.dat")
WriteInt(file_score,highscore)
CloseFile file_scored
PlaySound(snd_Gameover)
Text 320,100,"GAME OVER",1,1
Text 320,115,"Try again!",1,1
Flip
Delay 3000
End
EndIf

Text 50,420,"LIVES: " + Lives

;Draw score.
Text 530,420,"SCORE: " + score
Text 510,430,"Nice score! "

;Draw highscpre.
Text 320,50,"HIGHSCORE: " + highscore,1,1

;Draw level number.
Text 320,440,"LEVEL: " + level,1

;Wait game timer.
WaitTimer(timer)

;Flip screen monitor.
Flip

Wend

;End game.
End

And here is the new attachments (some of them will need overwriting).
Title: Re: Blitz2D, first program HELP!
Post by: Jim on July 07, 2009
Hi Billy Bob, Thanks for your code, and welcome to the forum!
I've just edited your post to add the [ code] [ /code] BB tags.  These mean that the forum doesn't ruin your code formatting and break a bunch of things.  It's a bit like using the < pre> tag in html.

Jim
Title: Re: Blitz2D, first program HELP!
Post by: zawran on July 07, 2009
You are loading the background image each frame in the main loop, that is why it is lacking. You only need to load the image once, outside the loop, and then draw it when needed.
Title: Re: Blitz2D, first program HELP!
Post by: Hotshot on July 07, 2009
that what zawran mean

Wrong - You are loading the background image each frame in the main loop, that is why it is lacking.
Code: [Select]
const Press_Esc=1
Graphics 640,480,16,2
Setbuffer Backbuffer()

; Main Loop
While not keydown(Press_Esc)
      My_Background=Loadimage("MyBackground.png")
      Drawimage MY_Background,0,0
      flip
wend

Corrections
========

Right - You only need to load the image once, outside the loop, and then draw it when needed.
Code: [Select]
const Press_Esc=1
Graphics 640,480,16,2
Setbuffer Backbuffer()   

; Loading the Background Once  :)
My_Background=Loadimage("MyBackground.png")

; Main Loop
While not keydown(Press_Esc)
      Drawimage MY_Background,0,0
      flip
wend


Hope that give you good understanding  :)
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on July 07, 2009
Billy Bob, you are only making the same mistakes that we all went through whilst learning, so good on you for sticking at it. Typos I still do to this very day. Also the word you are looking for is lagging.

Just a tip. I would suggest that you put in comments and use the tab key to indent your code. Reason I suggest this, as from a couple months time when you go to look over things, you'll probably not know what things are doing, especially usefull for when your projects get bigger and you start progressing and have alot of programs on your hard drive.

Cheers and have a blast with learning and looking forward to your future projects and questions,
Clyde.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 07, 2009
Thanks!

it is working now, and it seems really fast. :kewl:

Sorry I didn't reply in a while, it was because I was reloading page 1, and I didn't know that you were posting on a different page!

Thanks again! :kewl:
Title: Re: Blitz2D, first program HELP!
Post by: ferris on July 09, 2009
Quick tidbit: If your background fills the whole screen, why do you need your 'Cls' command at all ;) ?

Also DrawBlock is faster than DrawImage because it doesn't support pixel transparency, which is unnecessary for a background unless multiple (parallaxing?) images are used for the background.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 09, 2009
Another question: How do you make different things happen when levels go up?  ???

Sorry, I am probably getting annoying asking these questions.
Title: Re: Blitz2D, first program HELP!
Post by: Jim on July 09, 2009
Well, for instance you can make the baddies go twice as fast by multiplying their speed by the level number. :)  In general, you can use the level number as a difficulty factor.

Jim
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 09, 2009

    Thanks, could I have the code for that, and where to put it ???

    I will understand this when someone tells me and I will not post as many questions.

    Thanks! :)

   
Title: Re: Blitz2D, first program HELP!
Post by: zawran on July 09, 2009
Quote
could I have the code for that, and where to put it

Sorry for being a bit off the topic, but thats usually not the way to go about things. Please try something out first, then if that does not work, post back with what you got and someone will assist with making things right.

I fully understand that it can be difficult to get started with programming, but getting things served on a platter does not help on your overall understanding of how things work. If your project seems a bit too much, then perhaps try something simpler and work your way up.

I hope you do not feel like I am stepping on toes here, its truely ment as a constructive comment.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 09, 2009
Yes, I have actually tried lots of things already, I took this opportunity of asking as a last resort. ;)

What I meant to say is: "Could you tell me the code for that and tell me the place to put it."

And I do observe your help lots.

What do you suggest would be simpler? :kewl:
Title: Re: Blitz2D, first program HELP!
Post by: Jim on July 09, 2009
If your level goes 1,2,3,4,5 etc, this will make the aliens move faster
a\x = a\x + amx * level

Jim
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on July 10, 2009

    OK, I have calculated where to put it, it is now done, and it also makes sense. :kewl:

    Estimation of what it means: a\x means alien going across x axis and equaling speed multiplied by amount of levels.

   I hope my estimation is true.  ;) :D
Title: Re: Blitz2D, first program HELP!
Post by: Shockwave on July 10, 2009
Sounds about right Billy Bob! :)
Title: Re: Blitz2D, first program HELP!
Post by: ferris on July 23, 2009
And don't at all think that asking questions here is annoying...that's what this board was built for!!
Title: More problems.
Post by: billy bob on November 04, 2009
It's been a while and I have had a couple of problems.

1. I'm trying to get an image to randomly appear on screen (called "Power"), but I don't know how to, I have tried allot of things.

2. I want to replace "While Not KeyDown(1)" with "If Keyhit(1) then lives = lives - 3" but then an error comes up instead of the result I looking for.

Sorry if I am asking for too much help.

Title: Re: More problems.
Post by: Clyde on November 04, 2009
when you say randomly appear, are you meaning pixels of a certain size ( eg rectangles / tiles ) need to fade onto the screen to form the full image, and these portions are randomly chosen?

it looks to me if your using Blitz, infact Blitz Max; with your key stuff 1 is escape in BMAX, previous Blitz versions used 27. so i'd recommend using a different key for incrementing your lives variable.
Title: Re: More problems.
Post by: billy bob on November 05, 2009
when you say randomly appear, are you meaning pixels of a certain size ( eg rectangles / tiles ) need to fade onto the screen to form the full image, and these portions are randomly chosen?

Sorry, I don't quite understand what you mean.

What I meant was:

"I want a full image to randomly appear on screen in different places every twenty seconds, I also want that image to disappear when the image has been there for four seconds."

Just say if you still don't know what I mean.

it looks to me if your using Blitz, infact Blitz Max; with your key stuff 1 is escape in BMAX, previous Blitz versions used 27. so i'd recommend using a different key for incrementing your lives variable.

OK, thanks.
Title: Re: Blitz2D, first program HELP!
Post by: Jim on November 05, 2009
You can try something like this (not real code, but you can work it)
Code: [Select]
mode=0 (0 == waiting to display, 1 == displaying)
endtime = millisecs()+20000   (this is 20 seconds after now)
repeat
  if millisecs() > endtime then
    if mode=0 then
      display_random_picture()
      endtime=millisecs()+4000  (this is 4 seconds after now)
      mode=1
   else if mode = 1 then
      turn_off_picture()
      endtime=millisecs()+20000
      mode=0
   end if
  end if
until keydown
end

function display_random_picture()
  x=rand(0,640)
  y=rand(0,480)
  drawimage image,x,y
end function

Jim
Title: (...)
Post by: billy bob on November 05, 2009
Thanks Jim, people really are helpful here. :D

Hopefully I can make your help turn into proper blitz2D code.  ;)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on November 05, 2009
Well, there is an error I can't fix.

I have changed your code into:

mode=0 ;(0 == waiting To display, 1 == displaying)
endtime = MilliSecs()+20000   ;(this is 20 seconds After now)
Repeat
  If MilliSecs() > endtime Then
    If mode=0 Then
      display_random_picture()
      endtime=MilliSecs()+4000  ;(this is 4 seconds After now)
      mode=1
   Else If mode = 1 Then
      turn_off_picture()
      endtime=MilliSecs()+20000
      mode=0
   End If MilliSecs
  End If
Until KeyDown
End

  If Function display_random_picture()
  x=Rand(0,640)
  y=Rand(0,480)
  DrawImage image,x,y
End Function

Also, the error that comes up is: "Expecting expression".
Title: Re: Blitz2D, first program HELP!
Post by: Jim on November 05, 2009
I'm guessing it's here
Until KeyDown
I think Blitz wants the key
Until KeyDown(1)
or something.

Jim


Title: Re: Blitz2D, first program HELP!
Post by: Clyde on November 05, 2009
your getting a little lost dude, I'll have a go for you.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on November 05, 2009
I think Blitz wants the key
Until KeyDown(1)

Thanks, but it still doesn't work.....
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on November 05, 2009
Try this on for size dude :)

Code: [Select]
Graphics 640,480
SetBuffer BackBuffer()
SeedRnd MilliSecs()

; create test image
image_one=CreateImage(64,64)

SetBuffer ImageBuffer(image_one)
For a=0 To 2000
Color Rand(0,255),Rand(0,255),Rand(0,255)
Plot Rand(0,ImageWidth(image_one)-1),Rand(0,ImageHeight(image_one)-1)
Next
SetBuffer BackBuffer()

;DrawImage image_one,0,0
;Flip
;WaitKey

ESC_KEY=1
mode=0

image_x=Rand(0,639-ImageWidth (image_one))
image_y=Rand(0,439-ImageHeight(image_one))

picture_timer=MilliSecs()

While Not KeyDown(ESC_KEY)
Cls

If ( picture_timer + 20000 ) <=MilliSecs()
If mode=0 Then
image_x=Rand(0,639-ImageWidth (image_one))
image_y=Rand(0,439-ImageHeight(image_one))
mode=1
picture_timer=MilliSecs();
End If
End If

If ( picture_timer + 4000 ) <=MilliSecs()
If mode=1 Then
mode=0
picture_timer=MilliSecs()
End If
End If

If mode=0 Then DrawImage( image_one, image_x, image_y)

Flip
Wend

Havent used Blitz in years.
Clyde.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on November 06, 2009
Thanks Clyde :) , I will try to put that into the rest of the code, I will ask for help if I can't. ;)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 06, 2010
Sorry I can't put this code with the other code, its been a while since I last did this but I did try lots (also sorry for posting two times in a row).
Title: Re: Blitz2D, first program HELP!
Post by: Jim on February 06, 2010
If you can post up your latest attempt we can definitely help you fix it up :)
Jim
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 08, 2010
I would like to upload my attempts but I deleted them in November.

I would give you the recentest version, but when I try it gives me an error.

Would it be OK if I uploaded it in an attachment?
Title: Re: Blitz2D, first program HELP!
Post by: Jim on February 08, 2010
Sure, you can attach a zip file to your post.  If you hit Additional Options under the post window there's an option to attach files.
Jim
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 09, 2010
OK it is in the attachment below.

Also in the previous version there was a glitch: If you collected two or more bombs at the same time then you would get an amount of lives that were below 0. That glitch no longer occurs in the new version.
Title: Re: Blitz2D, first program HELP!
Post by: Jim on February 13, 2010
OK, I've joined up what clyde did with your stuff.  I've commented by 2 bits with ;JIM

Jim
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 14, 2010
Thank you so much Jim! :D
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 15, 2010
I've been trying to put an image collision with the "power" image and the "smile" image, but haven't succeeded. My guess is it is something like this (but of course it isn't ???):


If ImagesCollide (img_bullet,power\x,power\y,0,img_smile,x,y,0)
mode=1
score + 50
EndIf


Help please? :)
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on October 15, 2010
Can you attach your images and sound files ( any media used ) please, and if your source ( don't know what changes have been made, etc )

Tiz been a long time since doing anything with blitz; I'll see if I can assist.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 15, 2010
The attachment is above.
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on October 15, 2010
All i can see are txt documents. do you have a zip or rar file with the lastest bits and pieces.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 16, 2010
All the things are in the attachment below.
Title: Re: Blitz2D, first program HELP!
Post by: Jim on October 16, 2010
Thanks! K+
Jim
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on October 18, 2010
From what I've seen is that the collision is working but not as intended. I had to swerve to get it to do its thang.

ps, could an admin move this. it's quite hard to rememeber where this blitz post is. cheers
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 20, 2010
When I try it says "variable must be a type". Unless I have put it in the wrong place. ;)

But if you have got it working, could you help me please? :kewl:
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on October 20, 2010
I copy and pasted the .txt doc of you source ( you know you can include .bb in zips ) and into Blitz3D. I dont know where my copy of blitz basic is at the moment ) and ran it, and it worked.

What are you using to compile with? Blitz Basic, Blitz3D, Blitz Plus?

I think you've got some local and global variable issues dude. And maybe have player as a type.

Global means that you can use the variable anywhere within your code, and the data it stored won't be lost on exitting a function. Locals are generally used in functions and will lose any values once the function has finished.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 20, 2010
What are you using to compile with? Blitz Basic, Blitz3D, Blitz Plus?
At this moment I'm using Blitz Basic (it (sort of) says in the title).
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 21, 2010
(Sorry for posting two times in a row but I realized if I edited my last then not many people would read it until the next post comes.)
I copy and pasted the .txt doc of you source ( you know you can include .bb in zips ) and into Blitz3D. I don't know where my copy of blitz basic is at the moment ) and ran it, and it worked.
I misunderstood this.  ;) If you download it, it does work. But the thing is is that I want it so there is an image collision between Smile and Power. :kewl: Look at my previous post:
I've been trying to put an image collision with the "power" image and the "smile" image, but haven't succeeded. My guess is it is something like this (but of course it isn't ???):


If ImagesCollide (img_bullet,power\x,power\y,0,img_smile,x,y,0)
mode=1
score + 50
EndIf


Help please? :)
Title: Re: Blitz2D, first program HELP!
Post by: Rbz on October 21, 2010
Hi, if I'd understand it correctly, this is what you are looking for (attached).
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on October 22, 2010
Hi, if I'd understand it correctly, this is what you are looking for (attached).
Thanks a lot of lots! :D

I also had to alter it slightly. I changed it into

    If ImagesCollide (img_smile,x,y,0,img_power,image_x,image_y,0) Then
      image_x=Rand(0,843-ImageWidth (img_power))
      image_y=Rand(0,585-ImageHeight(img_power))
      mode=1
      score = score + 50
   End If

End If

 ;)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on January 16, 2011
I've been understanding things a lot more and have upgraded the game lots! :D

Although I still have a problem. :(

The smile is able to reach the aliens. And the power is able to be in the alien area. This is a problem because you can cheat by terminating aliens on the top row then go to the top row then you are safe there. I've been editing the code (for months) which makes it so the smile can't go off the edge but I haven't been able to do it. :( Help please? :)
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on January 30, 2011
It's been two weeks and I still haven't solved it. Can anyone help?

Please?
Title: Re: Blitz2D, first program HELP!
Post by: Rbz on January 30, 2011
Plz post your latest code for people to take a look.

Anyway I think checking smile and aliens collision may fix this problem.
Or you can lock smile and power to a certain "y" position, ie below your aliens. Well, it all depends on how you want your game work.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on January 31, 2011
The smile not being able to reach the area where the aliens are was what I was hoping for. Seeming as you could still cheat. ;)

The game is here though. :)
Title: Re: Blitz2D, first program HELP!
Post by: Rbz on February 01, 2011
Ok, on the line:
Code: [Select]
If y < tiw Then y = tiwchange it to:
Code: [Select]
If y < 240 Then y = 240
This will limit player y position below of aliens positions.

Also you may want to limit power y position, just change this line:
Code: [Select]
image_y=Rnd(0,585+ImageHeight(img_power))to
Code: [Select]
image_y=Rnd(240,585+ImageHeight(img_power))
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 01, 2011
Thank you! ;D :D ;D
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 04, 2011
I've been trying to create a pause mechanism but it only almost works:



If KeyHit(28) Or KeyHit(156) Then
Goto Pause
EndIf
Goto Resume
.Pause
If KeyHit(1) Then
lives = 0
Goto Resume
EndIf
If KeyHit(28) Or KeyHit(156) Then
FlushKeys
Goto Resume
EndIf
Goto Pause
.Resume



It doesn't work because if you keep it on pause then if there is power then the power goes when resumed and if there isn't power then if you keep it on pause then when resumed the power appears and if the speed = 2 then if you keep it on pause then when resumed the speed = 1.

This is another thing I've been trying to work out for months.
Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 08, 2011
Could anyone help? :'(
Title: Re: Blitz2D, first program HELP!
Post by: Rbz on February 09, 2011
Insert this code before "Flip" command:

Code: [Select]
;Pause game
If KeyHit(25) Then ;Press "P" to pause
While Not KeyHit(25)
Text 425,300,"Game Paused",1,1
Flip
Wend
EndIf

When you press "P" it'll enter on infinite loop and a text message will be show to the user, pressing "P" again will exit this loop, hope that help :)

Title: Re: Blitz2D, first program HELP!
Post by: billy bob on February 09, 2011
Thanks, but, sorry. That wasn't the problem. It doesn't work because if you keep it on pause then if there is power then the power goes when resumed and if there isn't power then if you keep it on pause then when resumed the power appears and if the speed = 2 then if you keep it on pause then when resumed the speed = 1.
Title: Re: Blitz2D, first program HELP!
Post by: Clyde on April 16, 2011
Anyone's first program is always a real git, unless that is your perfect at everything & how are you doing with this Billy Bob?