Sweetgebus Posted 1 hour ago Posted 1 hour ago Hello all, in my attempt to learn scripting in Leadwerks 5, I figured I could start a thread here and update my progress. I have a small understanding of some things so far. I’ve been working on a learning project for the past week. The idea is a Flappy Bird-style game, or an old-school helicopter game if any of you are old enough to remember that game. The player, “Cube,” flies forward at a constant velocity without player input. When the player hits the space key, the cube will jump. If the player hits the ground or any object, they reset to the beginning. Learns goals for this project include Storing the distance traveled by the player. Saving the highest distance traveled as a high score. Adding power-ups, such as momentarily slowed movement, that the player can use for difficult sections. Said power-ups, when collided with, would be stored rather than immediately executed, so the player can use them when they need them. I figured this would be a good starting point for learning. I will post screenshots and code throughout the game's progress, along with the current goal I’m working on. Any help and advice would be greatly appreciated. I’ve always wanted to learn scripting, and once I found Leadwerks, I knew it would be my engine of choice. Quote
Sweetgebus Posted 1 hour ago Author Posted 1 hour ago (edited) So far, I’ve achieved basic player control. The player flies forward at a constant speed. I’ve set the player's starting point via script, and the player successfully resets to that point when it makes contact with the ground or other game objects. I achieved collision detection by checking the struck entity's collision type. This works in this case, but perhaps there is a better way? Utilizing a timer, I’ve successfully added a 3-second delay after opening the game, before the player starts moving forward. This has caused an issue that I’m currently trying to overcome. Gravity still acts even when the timer is active. I thought maybe setting self:SetGravity(0) from the start and calling self:SetGravity(1) after checking if the game has started would be the key, but this has a logic error. Perhaps someone here can offer some advice? -- create start timer gracetimer = CreateTimer(3000) ListenEvent(EVENT_TIMERTICK,gracetimer,OnGraceTimer) -- Enable physics self:SetPhysicsMode(PHYSICS_RIGIDBODY) self:SetCollisionType(COLLISION_PLAYER) self:SetMass(1) -- Create camera self.camera = CreateCamera(self.world) self.camera:SetPosition(self.entity:GetPosition()) --we need to save the position of the entity so that we can reset to it startpos = self:GetPosition() end --timer callbacks function OnGraceTimer() Print("timer Worked") gracetimer:Stop() gamestarted = true end function myPlayer:Sound() hit = LoadSound("Sound/Music/hit.mp3") end -- collision function myPlayer:Collide(entity) if entity:GetCollisionType() == COLLISION_SCENE then hit = LoadSound("Sound/Music/hit.mp3") hit:Play() Print("Game Over!") isgameover = true end end --player movement function myPlayer:Update() local vel = self:GetVelocity() if gamestarted == true then vel.z = self.speed end vel.x = 0 self.entity:SetRotation(0,0,0) if self.window:KeyDown(KEY_SPACE) then vel.y = self.jumpforce end self:SetVelocity(vel) -- Game is over, so lets reset the player back to the starting position and resume after 3 seconds if isgameover == true then self:SetPosition(startpos) isgameover = false end -- Update camera self.camera:SetPosition(self.entity:GetPosition()) self.camera:Move(0,1,-3) end Edited 1 hour ago by Sweetgebus Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.