Hiya,
I would like to create a pacman using Felgo, I got the way to move the character and QML basics, but I couldn’t find a Felgo example where is related to a grid enabling some spaces to move and other like walls.
Thanks in advance.
Tagged: Pacman Grid
Hiya,
I would like to create a pacman using Felgo, I got the way to move the character and QML basics, but I couldn’t find a Felgo example where is related to a grid enabling some spaces to move and other like walls.
Thanks in advance.
Hi Charlie,
One way to do is to use Level Editor.
You can treat the “blocks/walls” as a normal element in your level editor, for example use Collider with Body.Static, and so on.
Search for platformer/level editor example, maybe it will help you.
For sure there are other ways to do it but this seems like a good place to look at.
I am not sure what perspective are you going to use, for example.
This decision can complicate your life a little 🙂
If you want more examples from Felgo, definitely Squaby demo is quite similar in many cases to Pac Mac.
The code is a little old and it is quite advanced so keep this in mind Squaby demo
Something much simpler that also uses grid approach is Juicy – like candy crush demo.
Game is quite different but there are plenty of grid calculations.
Hi Marcin thank you for your quick response,
actually I’m planning to create something more similar like this:
https://www.youtube.com/watch?v=MPsA5PtfdL0&feature=youtu.be&t=53
which is not that Grid approach.
I think I can create it step by step… For example, how can I “fire” something?
Thanks in Advance
Hi Charlie,
check out the CarChallenge demo, where we fire rockets in the direction the car is facing (space and enter button).
Cheers,
Alex
Thanks Alex, I could make it work by the following code:
import Felgo 3.0
import QtQuick 2.0
GameWindow{
id:gameWindow
Rectangle{
id: background
anchors.fill: parent
}
onSplashScreenFinished:{
mov.running=true
world.running=true
}
EntityManager{
id:mng
entityContainer: scene
}
Scene{
id: scene
Component{
id: wrapBullet
EntityBase{
id: bullet
entityId: "bullet1"
entityType: "bullet"
property int firingX:0
property int firingY:0
Component.onCompleted: {
anim.running= true
console.log("A"+firingX)
console.log("S"+firingY)
}
Rectangle{
id:bulletRect
color:"red"
width:10; height: 10
}
MovementAnimation{
id:anim
running: false
property: "pos"
target: parent
velocity: Qt.point(parent.firingX, parent.firingY)
}
}
}
EntityBase{
Rectangle{
id:tank
width: 32; height:32;
color: "blue"
focus: true
property string direction: "Down"
Keys.onPressed: {
if(event.key === Qt.Key_Up){
console.log("Going Up")
y=y-5
tank.direction="Up"
}
else if(event.key === Qt.Key_Down){
console.log("Going Down")
y=y+5
tank.direction="Down"
}
else if(event.key === Qt.Key_Left)
{
console.log("Going Left")
x=x-5
tank.direction="Left"
}
else if(event.key === Qt.Key_Right){
console.log("Going Right")
x=x+5
tank.direction="Right"
}
else if(event.key === Qt.Key_Space){
//Create Entity
var bulletPoint=mapToItem(parent,tank.x,tank.y)
//Fire entity
if(tank.direction==="Up"){
console.log("Firing Up")
mng.createEntityFromComponentWithProperties(wrapBullet,
{"x":tank.x,
"y": tank.y,
"firingX": 0,
"firingY": -200});}
else if(tank.direction==="Down"){
console.log("Firing Down")
mng.createEntityFromComponentWithProperties(wrapBullet,
{"x":tank.x,
"y": tank.y,
"firingX": 0,
"firingY": 200});}
else if(tank.direction==="Left"){
console.log("Firing Left")
mng.createEntityFromComponentWithProperties(wrapBullet,
{"x":tank.x,
"y": tank.y,
"firingX": -200,
"firingY": 0});}
else if (tank.direction==="Right"){
console.log("Firing Right")
mng.createEntityFromComponentWithProperties(wrapBullet,
{"x":tank.x,
"y": tank.y,
"firingX": 200,
"firingY": 0});}
}
}
}
states:[
State{
name: "Up"
when: tank.direction=="Up"
},
State{
name: "Up"
when: tank.direction=="Up"
},
State{
name: "Down"
when: tank.direction=="Down"
},
State{
name: "Left"
when: tank.direction=="Left"
},
State{
name: "Right"
when: tank.direction=="Right"
}
]
}
}
}
You must be logged in to reply to this topic.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: