hedgewars moving plateform test n°1

4 replies [Last post]
sphrix
sphrix's picture
User offline. Last seen 1 day 25 min ago. Offline
Joined: 2011-04-07
Posts: 207
Hello, just a small post for anyone interested in this, https://www.youtube.com/watch?v=ZGOMHp2pYkI Thanks to nemo for the help ! Smile It is not perfect, but i hope it might give you some ideas ! One problem, as seen in video, the hedgehog doesnt move with the girder, might be possible to find a solution with setgearvelocity and gearisinbox but i had no sucess for now, Same problem with the Portals, in this state it is not ready to implement in a portal mission :p But for some map mission, shooting mission etc... might be cool ! CODE : hover with your mouse to expand the code [quote]girderswitch = false PlaceSprite(xgirder, ygirder, sprAmGirder, 4) function onGameTick20() if CurrentHedgehog ~= nil then if (xgirder <= 750) and (girderswitch == false) then EraseSprite(xgirder, ygirder, sprAmGirder, 4) xgirder = xgirder+1 PlaceSprite(xgirder, ygirder, sprAmGirder, 4) if (xgirder == 750) then girderswitch = true end end if (xgirder >= 300) and (girderswitch == true) then EraseSprite(xgirder, ygirder, sprAmGirder, 4) xgirder = xgirder-1 PlaceSprite(xgirder, ygirder, sprAmGirder, 4) if (xgirder == 300) then girderswitch = false end end end end[/quote] edit, thanks to nemo i have now this code : if (xgirder <= 750) and (girderswitch == false) then EraseSprite(xgirder, ygirder, sprAmGirder, 4) xgirder = xgirder+1 PlaceSprite(xgirder, ygirder, sprAmGirder, 4) if gearIsInBox(player, xgirder-90, ygirder-20, 180, 10) then -- SetGearVelocity(player, dx+1, dy+0) SetGearPosition(player, xplayer+1, yplayer) end if (xgirder == 750) then girderswitch = true end end allow your hog to move with the girder ! not perfect when you try to walk to the left (when the girder is going to the right), but let say it is because it is magic... :p
[center] the beachs hogs surfin hedgewars [/center] [IMG]http://imgur.com/HJSMewv[/IMG]
nemo
nemo's picture
User offline. Last seen 21 hours 55 min ago. Offline
Joined: 2009-01-28
Posts: 1861
So... why not move the hog and the portal while you are moving the girder by moving their X offset? SetX(GetX+10)
-- Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev
nemo
nemo's picture
User offline. Last seen 21 hours 55 min ago. Offline
Joined: 2009-01-28
Posts: 1861
And, yeah, as noted on IRC, this might be more efficient CPU-wise if you moved smaller chunks like a chain belt. So make some custom sprites in form of [][][][][][][][[][] and delete one from left when adding one to right using Place/Erase Sprite. Maybe plus some smoke effect or something - sparks to indicate synthesising/destroying blocks Smile It wouldn't be as smooth a movement as current incremental moving of girder, but would avoid repeatedly updating and rewriting land array/textures which could get expensive over time with a lot of girders. since it isn't just a sprite move. Oooh. Make the platform itself just invisible collision pixels and animate something moving smoothly over it.
-- Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev
sphrix
sphrix's picture
User offline. Last seen 1 day 25 min ago. Offline
Joined: 2011-04-07
Posts: 207
i first tried with something like this : dx, dy = GetGearVelocity(CurrentHedgehog) if gearIsInBox(player, xgirder, ygirder, 180, 30) then SetGearVelocity(player, dx-1, dy+0) end because i thought using SetX would "prevent" the hog from walking I'll give it a try, but for the portal i would need to find how to get his (x,y) not sure how yet, problem for future me :p edit, Smoke effect could be interesting, would give a steampunk feeling
[center] the beachs hogs surfin hedgewars [/center] [IMG]http://imgur.com/HJSMewv[/IMG]
nemo
nemo's picture
User offline. Last seen 21 hours 55 min ago. Offline
Joined: 2009-01-28
Posts: 1861
I'd have to look up what conditions prevent a hog from moving, but setting X shouldn't unless you trigger falling. If you only move X and not Y I wouldn't think that would happen since the hog is already settled on the girder... I mean, that's how portals work right. And... Portals are pretty simple. They have an X/Y that is exactly in the centre of the disc that is fetched same as any other gear.. The portal's angle really doesn't matter for your purposes since you'll always be moving it along the same angle, which is probably horizontal. BTW, in terms of portal's rules, a portal ball stops when it hits a pixel, it then tries to get a slope (which single pixels fail at, which is why the line of single pixels above a bouncy surface works). If it gets a slope it shifts to the disc mode, but if that single pixel is destroyed, the portal vanishes ☺ So, if you want to be sure moving with lua doesn't destroy it, be sure it has an X/Y that is in collision with something. It should work fine even if 1px below the surface. You could even use PlaceSprite or any other terrain creator to make a pixel for it to rest on.
-- Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev
Copyright © 2004-2023 Hedgewars Project. All rights reserved. [ contact ]