|
Post by James :) (aka Madcow) on Jul 29, 2009 16:57:31 GMT -5
The Sprite Engine isn't exactly my strong point but i've had a look though. I can't see whats wrong either, it should work but i'm getting an array is out of range error or something like that, but i'll have another look later but right now i have to be off. talk to you all soon .
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 29, 2009 17:23:49 GMT -5
Hmm, I'm not getting that error at all.
|
|
|
Post by Wayne Rayner on Jul 29, 2009 18:32:09 GMT -5
The Sprite Engine isn't exactly my strong point but i've had a look though. I can't see whats wrong either, it should work but i'm getting an array is out of range error or something like that, but i'll have another look later but right now i have to be off. talk to you all soon . to quote my friend james the error says array size must be 0 or greater Wayne Rayner
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 29, 2009 20:17:13 GMT -5
We're all talking about the code on the first page, right?
Because that works for me, fine, just not with the desired results.
Maybe this feud with xteraco is just a big misunderstanding? He was looking at the wrong piece of code, and was condemning me for a problem that I had long since fixed!
|
|
|
Post by Wayne Rayner on Jul 29, 2009 20:56:41 GMT -5
Ok the code onthe second page the last lot of code says that. It was the last updated code and I'm trying to fix it up
Wayne Rayner
|
|
|
Post by xteraco on Jul 29, 2009 21:02:41 GMT -5
No problem here. BUT I did look in to the error people were talking about. If you forget to rename the files (take the numbers out of the beginning), or forget to create a "data" directory for the files you will get the error.
When I download files I put them in a new directory, not the b4gl directory, and I would imagine that's what is happening to others.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 29, 2009 22:12:18 GMT -5
Ok the code onthe second page the last lot of code says that. It was the last updated code and I'm trying to fix it up Wayne Rayner forget about that, first page has all you need.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 30, 2009 2:30:25 GMT -5
No problem here. BUT I did look in to the error people were talking about. If you forget to rename the files (take the numbers out of the beginning), or forget to create a "data" directory for the files you will get the error. When I download files I put them in a new directory, not the b4gl directory, and I would imagine that's what is happening to others. Could people who have a problem running my code confirm or deny that this will fix the problem? Thank you.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 30, 2009 2:36:11 GMT -5
Oh, and I think I've found the problem.
"Zom" is undimmed, but I can't figure out why.
I did everything for Mark that I did for Zom, minus set the sprite camera on him. Why is he undimmed?
|
|
|
Post by James :) (aka Madcow) on Jul 30, 2009 5:36:35 GMT -5
Textmode(text_buffered) dim textures (TexStripFrames("data\street.png")-1) = LoadTexStrip ("data\street.png")
data 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0
dim tiles(10)(10), x, y for y = 0 to 10 for x = 0 to 10 read tiles(x)(y) next next
dim tile = NewTileMap(textures) SprSetTiles(tiles) SprSetZOrder(1) SprSetSize(200,200)
'------------------------
dim xPlayer, wWin, yPlayer, hWin, xZom, yZom, alive, zalive
ResizeSpriteArea(Windowwidth(),WindowHeight())
xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 xZom=WindowWidth() yZom=Windowheight() alive= true zalive=true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") dim ZomSpr = NewSprite(Zom(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
dim Speed# = 5 dim zSpeed# = 3 '------------------------------------
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# SprSetTexture(mark(1)) elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed# SprSetTexture(mark(3))
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# SprSetTexture(mark(0)) elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed# SprSetTexture(mark(2)) else SPRsettexture(mark(0)) endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer)
bindsprite(zomspr)
if zalive then if xPlayer > xZom then xZom = xZom + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < xZom then xZom = xZom - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > yZom then yZom =yZom + zSpeed# SprSetTexture(zom(0)) elseif Yplayer < yZom then Yzom = Yzom - zSpeed# SprSetTexture(zom(2))
endif
if xzom = xplayer then alive = false endif SprSetPos(Xzom,Yzom) endif
DRAWTEXT()
if alive = false then locate 10,19 print "game over" endif wend '------------------------
The Problem was you were using two while loops to update the player and the zombie but the issue with that is that it would never exit the one designed to update the player until the zombie encountered the player and thus wouldn't update the zombie anyhow i merged the two loops into one and used if statements instead to check if the player and zombie are alive.
compare my code to yours just to see what i've changed and hopefully see what the problem was and why i've changed what i have. also i suggest you learn about the bind sprite command.
atm i think the zombies are sprawnining but you havn't got the game to draw multiple zombie sprites so all but one are invisible.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 30, 2009 11:14:14 GMT -5
Ahh, thank you so much.
See? That's some quality help right there. He explained the problem and fixed it, then gave me suggestions!
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 30, 2009 20:39:14 GMT -5
Quick questions
1. I can't think how I can add multiple enemies. The syntax bothers me.
If I want three zombies, would it be something like:
dim Zom(3)(ImageStripFrames("data\zombie.png") -1)
or would it be
Dim ZomSpr(3) = NewSprite (Zom(0))
I figure the last option, but if there's an easier way to do it, or if I am missing something, feel free to tell me.
2: If you'd notice, when the zombie hits the player, he never really gets to his exact X coordinates, also you end up dying at weird spots when you just happen to be on the same Y coordinate as him, so I'd like to do something with the radius of the sprites.
The radius of both sprites is 29 px, not counting the white pixels (which I can't seem to make transparent, I've tried SetTexTransparent(255,255,255) or whatever, but that doesn't work...Something to do with decimals?) . So I can do something with that, but I'm not sure what.
I've looked at the "felp" topic where Joshy goes into collision detection, but that doesn't quite apply.
So I'm wondering about the correct code for adding more zombies, and getting some good enemy/player hit detection.
|
|
|
Post by Darkjester on Jul 31, 2009 9:54:10 GMT -5
have you tried using a structure for zombie?
struc zombie dim zom dim health dim pos(1) endstruc
dim zombie zombie1 dim zombie zombie2 dim zombie zombie3
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 31, 2009 12:52:58 GMT -5
Hmmm, tell me more about these structures....
I've read the language guide section on it, but how will I mix structures with sprites?
|
|
|
Post by James :) (aka Madcow) on Jul 31, 2009 15:16:20 GMT -5
I would have something like this for the structure: struc Szombie dim alive dim sprite dim x dim y endstruc
then you just need to define a array of those structures: dim Szombie Zombies(X)
then when creating the sprites you do something like this: Zombies(X).Sprite = newsprite(zom)
and each time you want to move the zombie sprite: bindsprite(Zombies(X).Sprite)
'code that moves that sprite sprmovex, sprmovey etc
i hope you can understand how i would do it. i'm not the best at explaning things .
|
|