Giter Site home page Giter Site logo

Comments (18)

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024 1

@vtereshkov I still don't know, how to make it work though. The most problem I have is with types. Enemy needs to have a projectile, but projectile needs to use the enm type when colliding. How should I do that? I tried making a new file for types, but you can't make a function for a foreign type (that is in go too). Only other thing, that I think of is handling the collision in gamescn.um, but what if there will be a case, where this isn't possible?

I suppose you may need a small 2D vector math library as a part of tophat. Then your getdist() will become a nice candidate to be included into it.

When I finnish this game, I will take stuff like getdist(), collisions and stuff like that and implement it into tophat.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

Will have a look on April 1-2

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

I put the function in another file, and it works now. Is it possible, that files with main function or files loaded by umkaInit can;t be used as a module?

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

This is not an intended behavior. However, I cannot guarantee that this doesn't happen.

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

This applies to variable too. There are also some cases, when one specific file can't use functions from other files. Idk why.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

By the way, are you sure you don't have circular imports here?

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

It seems like I do. I'm probably just used to go. Are there solutions to this?

My source code is available here.
It tried to use enemy.enm in projectile.um.

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

@vtereshkov it it possible in umka, to have something like go, where all variables, functions and types are shared among one package (in this case folder). I think circular import is unavoidable, if I try to recreate this by just importing.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

@marekmaskarinec I think the problem is indeed with circular imports. There is no package concept in Umka. What you have done with separating global.um from game.um is a right approach. Moreover, I suppose you may need a small 2D vector math library as a part of tophat. Then your getdist() will become a nice candidate to be included into it.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

I still cannot believe that circular dependencies are unavoidable, but I can suggest using interfaces. For example, you need to pass an enemy.enm to fn (p: ^prj) handle() and change its hp field (I don't know if this is your case). Then you can declare in projectile.um:

type hpchanger* = interface {
	sethp(hp: int)
}

fn (p: ^prj) handle*(e: hpchanger): bool {...}

and in enemy.um:

fn (e: ^enm) sethp*(hp: int) {e.hp = hp}

Then in gamescn.um you can call prj[i].handle(&e) where e is an enemy.enm. Pass it by address, otherwise you'll pass its copy.
Please also update the Umka version.

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

I don't neeed that. I don't know, which enemy the projectile will collide with. But I think, I can handle this in the game loop, if I return the id from the handle function.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

It seems to be sensible. But you probably need an ID of any entity, not necessarily enemy, since a projectile may hit a tree or another object.

Anyway, interfaces can be useful for manipulating objects whose actual types are yet undefined. I have to think whether I should recommend this as a proper solution or just as a temporary workaround.

The Go approach is difficult, since it requires multiple compilation passes. Umka has a single-pass compiler.

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

I'm able to distinguish, what type of entity it is based on the ID. Player is -1, fire is -10, enemy is > 200 etc. Trees don't generate, when a village is active and even if they did, they would not be added to the scene array. I think interfaces could be a good solution.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

Using interfaces to break possible import cycles is also encouraged in Go, though it is applied to different packages, not to different files within the same package:

https://medium.com/@ishagirdhar/import-cycles-in-golang-b467f9f0c5a0

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

Ok. Thanks. I will study a bit on interfaces (never really used them before).

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

The interface concept is Go's alternative to C++/Java classes with virtual functions. You can call interface's methods without even knowing the actual type of the variable converted to the interface. The only requirement is that all the methods declared in the interface are implemented for that type.

Umka follows the same path. See my raytracer.um example to see how interfaces work. I just iterate through the array of bodies and call intersect() for each body. But the bodies are of different sorts: boxes, spheres, etc. Each has its own implementation of intersect(). So I actually call different methods without knowing it.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 12, 2024

@marekmaskarinec Is this issue still relevant?

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 12, 2024

Anyway, interfaces can be useful for manipulating objects whose actual types are yet undefined. I have to think whether I should recommend this as a proper solution or just as a temporary workaround.

This along with the use of tophat's signals and proper thought given to the structure are good ways to mitigate cyclic imports. I think this can be closed.

from umka-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.