Forums

OverviewFelgo 2 Support (Qt 5) › Pacman Felgo

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18622

    Charlie Hdz

    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.

    #18631

    Marcin

    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 🙂

    #18632

    Marcin

    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.

    #18633

    Charlie Hdz
    #18634

    Alex
    Felgo Team

    Hi Charlie,

    check out the CarChallenge demo, where we fire rockets in the direction the car is facing (space and enter button).

    Cheers,
    Alex

     

    #18663

    Charlie Hdz

    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"
                    }
                ]
            }
        }
    }

     

Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support