|
Post by Pizzasgood on Aug 1, 2009 20:31:35 GMT -5
You know your images are wonky, right? You need to use images which have sizes that are a power of 2 (as in 2, 4, 8, 16, 32, 64, 128, 256, 1024...). But if the sprites on the first page are correct, then you're using 38 instead, which is why the sprites are all mutilated looking. Also, instead of trying to get white to be transparent, why not just use real transparency? PNG images have an alpha channel built in. Things just work a lot cleaner that way (no nasty anti-aliasing issues and what-not). Here are some resized and alpha-ized versions so you can see what I mean. (Maybe you use a graphics program that doesn't support that? If so, get a better one. I favor The Gimp personally, which is available for Windows as well as Linux). As for collision detection, you just have to detect if the zombie is touching the player, right? If so, then you would do something like this: if xzom < xplayer+16 and xzom > xplayer-16 then if yzom < yplayer+16 and yzom > yplayer-16 then alive = false endif endif
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 2, 2009 9:14:29 GMT -5
I was, eventually going to do that, thank you.
I did not know I was using "wonky" image sizes, sorry, but thank for everything
xPlayer + 16, because 16 is the radius of these sprites?
Mine were 29, oddly.
Here is the code added:
Textmode(text_buffered) SetTexTransparentCol(255,255,255) 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, alive, xSize, ySize
ResizeSpriteArea(Windowwidth(),WindowHeight()) xSize = 29 ySize = 29 dim Playfield(xSize-1,ySize-1) xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(1) SprSetAnimSpeed(1) SprSetParallax(true)
const numberofzombies = [b]9[/b] dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next
dim Speed# = 4 dim zSpeed# = 1 '------------------------------------
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)
for i = 0 to arraymax(Zombies)
bindsprite(Zombies(i).sprite)
if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# SprSetTexture(zom(2)) elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# SprSetTexture(zom(0))
endif
[b]if Zombies(i).X < xplayer+16 and Zombies(i).X > xplayer-16 then if Zombies(i).Y < yplayer+16 and Zombies(i).Y > yplayer-16 then alive = false endif endif[/b] SprSetPos(Zombies(i).X,Zombies(i).Y) endif
next
DRAWTEXT()
if alive = false then locate 10,19 print "game over" [b]ZSpeed#=9[/b] endif wend '------------------------
I added the changes in bold.
|
|
|
Post by Pizzasgood on Aug 3, 2009 17:20:36 GMT -5
Actually, I was mistaken. The player's radius is 16, but I forgot about the zombie's radius, which is also 16. So the number in the calculation should be 32, or maybe a little bit less than that so that they'll be slightly overlapped before you die. Although the method I used makes most sense when the characters are square... Since you're using circles, it would probably be more logical to just use the Pythagorean Theorem to calculate the actual distance between them and see if it's less than their combined radii.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 3, 2009 18:09:43 GMT -5
It's hard enough to survive when the number is at 16, anyway, so I guess we can leave it at that.
The next thing I want to do is make it so that you can move with the arrow keys, but "aim" with the mouse. I always want Mark to face wherever the mouse is, so he can eventually shoot at zombies while backing up
|
|
|
Post by Adam on Aug 4, 2009 10:00:50 GMT -5
here, I added in a function that Nicky made a while back when i was trying to figure this out.
Textmode(text_buffered) SetTexTransparentCol(255,255,255) 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, alive, xSize, ySize
ResizeSpriteArea(Windowwidth(),WindowHeight()) xSize = 29 ySize = 29 dim Playfield(xSize-1,ySize-1) xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(1) SprSetAnimSpeed(1) SprSetParallax(true)
const numberofzombies = 9 dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next
dim Speed# = 4 dim zSpeed# = 1 '------------------------------------
Function Angle#(x1#,y1#,x2#,y2#) Return 180-ATN2D(x2#-x1#, y2#-y1#) EndFunction
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed#
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed#
else endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer) SprSetAngle(Angle#(SprX()-SprCameraX(),SprY()-SprCameraY(),Mouse_X()*windowwidth(),Mouse_Y()*windowheight()))
for i = 0 to arraymax(Zombies)
bindsprite(Zombies(i).sprite)
if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# SprSetTexture(zom(2)) elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# SprSetTexture(zom(0))
endif
if Zombies(i).X < xplayer+16 and Zombies(i).X > xplayer-16 then if Zombies(i).Y < yplayer+16 and Zombies(i).Y > yplayer-16 then alive = false endif endif SprSetPos(Zombies(i).X,Zombies(i).Y) endif
next
DRAWTEXT()
if alive = false then locate 10,19 print "game over" ZSpeed#=9 endif wend '------------------------
-Adam
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 4, 2009 10:28:44 GMT -5
Thank you, another skill that I can add to my repertoire.
I'm learning a whole bunch, here. Thanks everyone. When it's finished, I'll put all your names on it.- It'll be like a community project or something. I'll make it into a tutorial too, if I have the time
|
|
|
Post by Adam on Aug 4, 2009 10:58:13 GMT -5
plus if you use that function for your zombies and replace the mouse position with the player position you can get rid of the image strips entirely
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 4, 2009 13:38:29 GMT -5
Ahh, ok.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 4, 2009 13:56:21 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, alive, xSize, ySize
ResizeSpriteArea(Windowwidth(),WindowHeight()) xSize = 29 ySize = 29 dim Playfield(xSize-1,ySize-1) xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(1) SprSetAnimSpeed(1) SprSetParallax(true)
const numberofzombies = 9 dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next
dim Speed# = 4 dim zSpeed# = 1 '------------------------------------
Function Angle#(x1#,y1#,x2#,y2#) Return 180-ATN2D(x2#-x1#, y2#-y1#) EndFunction
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed#
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed#
else endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer) SprSetAngle(Angle#(SprX()-SprCameraX(),SprY()-SprCameraY(),Mouse_X()*windowwidth(),Mouse_Y()*windowheight()))
for i = 0 to arraymax(Zombies)
bindsprite(Zombies(i).sprite)
if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# SprSetTexture(zom(2)) elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# SprSetTexture(zom(0))
endif
if Zombies(i).X < xplayer+16 and Zombies(i).X > xplayer-16 then if Zombies(i).Y < yplayer+16 and Zombies(i).Y > yplayer-16 then alive = false endif endif SprSetPos(Zombies(i).X,Zombies(i).Y) SprSetAngle(Angle#(SprX()-SprCameraX(),SprY()-SprCameraY(),xPlayer*windowwidth(),yPlayer*windowheight())) endif
next
DRAWTEXT()
if alive = false then locate 10,19 print "game over" ZSpeed#=9 endif wend '------------------------
Here's part of it, at least. I tried fixing it so that it works correctly, but that just created more problems, like Mark being unable to follow the mouse
|
|
|
Post by shadow008 on Aug 6, 2009 12:30:32 GMT -5
seems like you've got a project on your hands, and since you've stated that your a noob, i wont feel bad about calling you one. and i must say, the almost year ive been here your the first "noob" to actually stick to a project for more than a week, good job.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 6, 2009 14:48:55 GMT -5
Hah, thanks.
I'm going to make a sprite of Mark holding a gun, and a bullet sprite, BRB
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 6, 2009 15:12:07 GMT -5
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 6, 2009 16:30:11 GMT -5
These images are pretty self-explanatory, as to what they should b named. stuff them in "data" Code: 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, alive, xSize, ySize ResizeSpriteArea(Windowwidth(),WindowHeight()) xSize = 29 ySize = 29 dim Playfield(xSize-1,ySize-1) xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= 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 bullet(ImageStripFrames("data\bullet.png") - 1) bullet = LoadImageStrip("data\bullet.png") SprSetParallax(true) dim MarkHG(ImageStripFrames("data\markgun.png") - 1) MarkHG = LoadImageStrip("data\strain.png") dim MarkHGspr = NewSprite(MarkHG(0)) dim HG(ImageStripFrames("data\handgun.png") - 1) HG = LoadImageStrip("data\handgun.png") dim HGspr = NewSprite(Hg(0)) SprSetParallax(true) struc Szombie dim alive dim sprite dim x dim y endstruc x = Windowheight() y = Windowwidth() dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(1) SprSetAnimSpeed(1) SprSetParallax(true) const numberofzombies = 9 dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next dim Speed# = 4 dim zSpeed# = 1 '------------------------------------ Function Angle#(x1#,y1#,x2#,y2#) Return 180-ATN2D(x2#-x1#, y2#-y1#) EndFunction while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed# elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed# else endif endif SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer) SprSetAngle(Angle#(SprX()-SprCameraX(),SprY()-SprCameraY(),Mouse_X()*windowwidth(),Mouse_Y()*windowheight())) bindsprite(HGspr): SprSetPos(X,Y) for i = 0 to arraymax(Zombies) bindsprite(Zombies(i).sprite) if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# endif if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# endif if Zombies(i).X < xplayer+16 and Zombies(i).X > xplayer-16 then if Zombies(i).Y < yplayer+16 and Zombies(i).Y > yplayer-16 then alive = false endif endif SprSetPos(Zombies(i).X,Zombies(i).Y) SprSetAngle(Angle#(SprX()-SprCameraX(),SprY()-SprCameraY(),xPlayer*windowwidth(),yPlayer*windowheight())) endif next DRAWTEXT() if alive = false then locate 10,19 print "game over" ZSpeed#=9 endif wend '------------------------ The gun will spawn off-screen to the south. When you walk over it, I want Mark to change into MarkHG How can I do this? Should I just delete Mark off the screen, and replace him with MarkHG or can I use a structure?
|
|
|
Post by shadow008 on Aug 7, 2009 16:16:31 GMT -5
delete mark off screen and replace
anyways, those links you posted up there dont lead to any pictures, it just shows the url... is that it?
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 7, 2009 22:02:29 GMT -5
delete mark off screen and replace anyways, those links you posted up there dont lead to any pictures, it just shows the url... is that it? Thank you, and I'll get right on that.
|
|