Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
need someone to review my code, please. — Gideros Forum

need someone to review my code, please.

MoKaLuxMoKaLux Member
edited April 2019 in General questions
Hello there,

I polished the graphics a little bit using gideros shape class only. Not a single image here B-)

Plus I used "object-oriented" programming instead of putting everything in the level 1 class. I created classes for bird, npc1, river, clouds.

I will post the demo on github so you can tell me if the way I am coding is good enough or could be improved.

Thank you.




my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories

Comments

  • here is the github repository with the shmup code.

    Could you please have a look and tell me if I am doing things right according to gideros standard?

    https://github.com/mokalux/gideros/tree/master/shmup

    I have a doubt about TNTVirtualPad and the hero part. I am creating VirtualPad in the level class and calling functions in the hero class. Is that right?

    Thank you in advance for your time.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • I just add virtual pad as the last thing to the stage, then hide it or reveal it.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • MoKaLuxMoKaLux Member
    edited April 2019
    yes, I forgot to look at the order things appear when launched. I was just happy to get the virtual pad working =)

    I will have a look at that for sure. Thank you sinistersoft.

    Do you think that could do for a gideros 2019 yt tutorial series?

    I feel like I need some more practice though.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • antixantix Member
    edited April 2019 Accepted Answer
    Pretty cool, keep it up man!

    I know it's an accomplishment to use the Shape class for everything but that will cause performance issues down the track. I wouldn't recommend anyone to use a lot of Shape instances in their games.

    I'd also recommend looking at 2d vectors for anything that is related to positioning. Here is some information on vectors from my unfinished Gideros book..

    Better Movement: Vectors
    Storing the variables inside the game object (as in the previous example) is fine and you can continue with that if you wish. However.. if you look about the internet you will find all manner of game coding tutorials and when it comes to moving game objects about you will soon discover that almost everyone stores the related variables inside a construct called a vector. Because nearly everyone else is doing it, you should also do it, because code from another source is always easier to integrate into your own codebase if it shares the same (or similar) basic data structure. Vectors can be manipulated with vector math so you can calculate the distance between vectors, the angle between vectors, and much much more. So what is a vector?

    In mathematics, physics, and engineering, a Euclidean vector (sometimes called a geometric or spatial vector, or (as here) simply a vector) is an object that has magnitude (or length) and direction. Vectors can be added to other vectors according to vector algebra. A Euclidean vector is frequently represented by a line segment with a definite direction, or graphically as an arrow.

    In most game engines, you will find a vector as a description of its 3 components X, Y, Z. For your 2 dimensional games however the Z component will be omitted because it is not required. Time to get right to it and create a few vectors for position and velocities.
    local position = {x = 0, y = 0}
    local velocity = {x = 0, y = 0}

    As you can see a vector is just a table containing variables that correspond to the axes we require. Go ahead and rewrite the previous example that uses vectors for position and velocity.


    Listing 110 Moving objects using vectors
    -- same as the previous example but using vectors to store position and velocity variables
     
    local object = Pixel.new(0x00ff00, 1, 32, 32) -- create a new object
    stage:addChild(object)
    object.position = {x = 0, y = 0} -- position vector
    object.velocity = {x = 135, y = 235} -- velocity vector
    local maxX = application:getDeviceWidth() - 32 -- get display bounds
    local maxY = application:getDeviceHeight() - 32
     
    local function onEnterFrame(event)
      local dt = event.deltaTime
      local p, v = object.position, object.velocity
      local vx, vy = v.x, v.y
      local px = p.x + vx * dt -- move and constrain on x-axis
      if px < 0 then
        px = 0
        v.x = -v.x -- reverse speed
      elseif px > maxX then
        px = maxX
        v.x = -v.x
      end
      local py = p.y + vy * dt -- move and constrain on y-axis
      if py < 0 then
        py = 0
        v.y = -v.y
      elseif py > maxY then
        py = maxY
        v.y = -v.y
      end
      p.x, p.y = px, py -- save position
      object:setPosition(px, py) -- set object position
    end
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

    It might not seem like it now but vectors are going to be of use in so many ways later-on.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited April 2019
    wouaw, that was a read! Next step would be to use vectors for moving things around.

    I know that in godot (yep I used it), everything is done using vectors. I think that doing so in gideros would be the right choice. The yt tutorials would have to wait until I get better at gideros.

    Thank you very much antix for this and I am looking forward to reading your book.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • Apollo14Apollo14 Member
    Accepted Answer
    Nice game example, clean OOP approach. :smile:

    btw you can also juice it up with particles and other stuff :smile:
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • hello there apollo14, the guys are hilarious, thank you for sharing.

    I just want to mention one thing, I am not doing a complete game here. I am learning gideros and lua best coding habit/good practice.

    Then I may do a youtube tutorial series to show that gideros is kicking asses! The lack of tutorials is something I want to help you guys with. But they must be good tutorials.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
  • antixantix Member
    @MoKaLux Since this is not a full game you are making I'd start to give serious thought to code re usability. Have classes that you keep in a library folder that can be reused between projects, and also can gradually be upgraded and optimized.

    I've got a ton of classes now that I just include in every new project (which really is a project template that I copy and then rename). This gives me my splash screen, a main menu, and a game scene.. without having to type a single line of code. This IMHO would be what you are working towards so you can make prototypes rapidly.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • that's right antix, gideros gently leads us towards this kind of behavior.

    Once you find a piece of code that you like, you put it in your myclass.lua and reuse it over and over. The template is also a good idea.

    I put myclass.lua into a separate folder and in my projects I simply link to the classes I need.

    Thank you for your advice.

    Likes: antix

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.