Search Results

Search found 106 results on 5 pages for 'coin'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • On Screen Coin Animation

    - by Siddharth
    am working with side scrolling skater game. I want to perform coin animation such that as player collect coin it moves upside and attach with currency sprite. My main character and coin present in game scene and currency sprite present in HUD layer. This situation creates problem for me. Directly I can not apply modifier to coin because it is side scrolling game so based on main character speed it reaches at different position. That I have checked. So that I have to generate other coin at same position at game layer coin has, in HUD layer and move upward to it. But I didn't able to get its y position correct though I can able to get x position correctly. Many time main character goes downward so it get minus value many time. I also tried following code float[] position = GameHUD.this .convertSceneCoordinatesToLocalCoordinates(GameManager .getInstance().getCoinX(), GameManager.getInstance() .getCoinY()); But I am getting same coordinate as I provide. No difference in that so please some one provide me guidance in that. Because I am near to complete my game. EDIT: Here game layer and hud layer is totally different. Actual coin present in game layer which player has to collect and at same position I want to generate another coin in hud layer to perform some animation. It is recommended to generate coin in hud layer because through that only I can able to complete my target.

    Read the article

  • Algorithm to determine coin combinations

    - by A.J.
    I was recently faced with a prompt for a programming algorithm that I had no idea what to do for. I've never really written an algorithm before, so I'm kind of a newb at this. The problem said to write a program to determine all of the possible coin combinations for a cashier to give back as change based on coin values and number of coins. For example, there could be a currency with 4 coins: a 2 cent, 6 cent, 10 cent and 15 cent coins. How many combinations of this that equal 50 cents are there? The language I'm using is C++, although that doesn't really matter too much. edit: This is a more specific programming question, but how would I analyze a string in C++ to get the coin values? They were given in a text document like 4 2 6 10 15 50 (where the numbers in this case correspond to the example I gave)

    Read the article

  • How to merge two different Makefiles?

    - by martijnn2008
    I have did some reading on "Merging Makefiles", one suggest I should leave the two Makefiles separate in different folders [1]. For me this look counter intuitive, because I have the following situation: I have 3 source files (main.cpp flexibility.cpp constraints.cpp) one of them (flexibility.cpp) is making use of the COIN-OR Linear Programming library (Clp) When installing this library on my computer it makes sample Makefiles, which I have adjust the Makefile and it currently makes a good working binary. # Copyright (C) 2006 International Business Machines and others. # All Rights Reserved. # This file is distributed under the Eclipse Public License. # $Id: Makefile.in 726 2006-04-17 04:16:00Z andreasw $ ########################################################################## # You can modify this example makefile to fit for your own program. # # Usually, you only need to change the five CHANGEME entries below. # ########################################################################## # To compile other examples, either changed the following line, or # add the argument DRIVER=problem_name to make DRIVER = main # CHANGEME: This should be the name of your executable EXE = clp # CHANGEME: Here is the name of all object files corresponding to the source # code that you wrote in order to define the problem statement OBJS = $(DRIVER).o constraints.o flexibility.o # CHANGEME: Additional libraries ADDLIBS = # CHANGEME: Additional flags for compilation (e.g., include flags) ADDINCFLAGS = # CHANGEME: Directory to the sources for the (example) problem definition # files SRCDIR = . ########################################################################## # Usually, you don't have to change anything below. Note that if you # # change certain compiler options, you might have to recompile the # # COIN package. # ########################################################################## COIN_HAS_PKGCONFIG = TRUE COIN_CXX_IS_CL = #TRUE COIN_HAS_SAMPLE = TRUE COIN_HAS_NETLIB = #TRUE # C++ Compiler command CXX = g++ # C++ Compiler options CXXFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD # additional C++ Compiler options for linking CXXLINKFLAGS = -Wl,--rpath -Wl,/home/martijn/Downloads/COIN/coin-Clp/lib # C Compiler command CC = gcc # C Compiler options CFLAGS = -O3 -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall -Wno-unknown-pragmas -Wno-long-long -DCLP_BUILD # Sample data directory ifeq ($(COIN_HAS_SAMPLE), TRUE) ifeq ($(COIN_HAS_PKGCONFIG), TRUE) CXXFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" CFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatasample`\" else CXXFLAGS += -DSAMPLEDIR=\"\" CFLAGS += -DSAMPLEDIR=\"\" endif endif # Netlib data directory ifeq ($(COIN_HAS_NETLIB), TRUE) ifeq ($(COIN_HAS_PKGCONFIG), TRUE) CXXFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatanetlib`\" CFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --variable=datadir coindatanetlib`\" else CXXFLAGS += -DNETLIBDIR=\"\" CFLAGS += -DNETLIBDIR=\"\" endif endif # Include directories (we use the CYGPATH_W variables to allow compilation with Windows compilers) ifeq ($(COIN_HAS_PKGCONFIG), TRUE) INCL = `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --cflags clp` else INCL = endif INCL += $(ADDINCFLAGS) # Linker flags ifeq ($(COIN_HAS_PKGCONFIG), TRUE) LIBS = `PKG_CONFIG_PATH=/home/martijn/Downloads/COIN/coin-Clp/lib64/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/lib/pkgconfig:/home/martijn/Downloads/COIN/coin-Clp/share/pkgconfig: pkg-config --libs clp` else ifeq ($(COIN_CXX_IS_CL), TRUE) LIBS = -link -libpath:`$(CYGPATH_W) /home/martijn/Downloads/COIN/coin-Clp/lib` libClp.lib else LIBS = -L/home/martijn/Downloads/COIN/coin-Clp/lib -lClp endif endif # The following is necessary under cygwin, if native compilers are used CYGPATH_W = echo # Here we list all possible generated objects or executables to delete them CLEANFILES = clp \ main.o \ flexibility.o \ constraints.o \ all: $(EXE) .SUFFIXES: .cpp .c .o .obj $(EXE): $(OBJS) bla=;\ for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \ $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(LIBS) $(ADDLIBS) clean: rm -rf $(CLEANFILES) .cpp.o: $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$< .cpp.obj: $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi` .c.o: $(CC) $(CFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$< .c.obj: $(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi` The other Makefile compiles a lot of code and makes use of bison and flex. This one is also made by someone else. I am able to alter this Makefile when I want to add some code. This Makefile also makes a binary. CFLAGS=-Wall LDLIBS=-LC:/GnuWin32/lib -lfl -lm LSOURCES=lex.l YSOURCES=grammar.ypp CSOURCES=debug.cpp esta_plus.cpp heap.cpp main.cpp stjn.cpp timing.cpp tmsp.cpp token.cpp chaining.cpp flexibility.cpp exceptions.cpp HSOURCES=$(CSOURCES:.cpp=.h) includes.h OBJECTS=$(LSOURCES:.l=.o) $(YSOURCES:.ypp=.tab.o) $(CSOURCES:.cpp=.o) all: solver solver: CFLAGS+=-g -O0 -DDEBUG solver: $(OBJECTS) main.o debug.o g++ $(CFLAGS) -o $@ $^ $(LDLIBS) solver.release: CFLAGS+=-O5 solver.release: $(OBJECTS) main.o g++ $(CFLAGS) -o $@ $^ $(LDLIBS) %.o: %.cpp g++ -c $(CFLAGS) -o $@ $< lex.cpp: lex.l grammar.tab.cpp grammar.tab.hpp flex -o$@ $< %.tab.cpp %.tab.hpp: %.ypp bison --verbose -d $< ifneq ($(LSOURCES),) $(LSOURCES:.l=.cpp): $(YSOURCES:.y=.tab.h) endif -include $(OBJECTS:.o=.d) clean: rm -f $(OBJECTS) $(OBJECTS:.o=.d) $(YSOURCES:.ypp=.tab.cpp) $(YSOURCES:.ypp=.tab.hpp) $(YSOURCES:.ypp=.output) $(LSOURCES:.l=.cpp) solver solver.release 2>/dev/null .PHONY: all clean debug release Both of these Makefiles are, for me, hard to understand. I don't know what they exactly do. What I want is to merge the two of them so I get only one binary. The code compiled in the second Makefile should be the result. I want to add flexibility.cpp and constraints.cpp to the second Makefile, but when I do. I get the problem following problem: flexibility.h:4:26: fatal error: ClpSimplex.hpp: No such file or directory #include "ClpSimplex.hpp" So the compiler can't find the Clp library. I also tried to copy-paste more code from the first Makefile into the second, but it still gives me that same error. Q: Can you please help me with merging the two makefiles or pointing out a more elegant way? Q: In this case is it indeed better to merge the two Makefiles? I also tried to use cmake, but I gave upon that one quickly, because I don't know much about flex and bison.

    Read the article

  • Project Coin: JSR 334 has a Proposed Final Draft

    - by darcy
    Reaching nearly the last phase of the JCP process, JSR 334 now has a proposed final draft. There have been only a few refinements to the specification since public review: Incorporated language changes into JLS proper. Forbid combining diamond and explicit type arguments to a generic constructor. Removed unusual protocol around Throwable.addSuppressed(null) and added a new constructor to Throwable to allow suppression to be disabled. Added disclaimers that OutOfMemoryError, NullPointerException, and ArithmeticException objects created by the JVM may have suppression disabled. Added thread safely requirements to Throwable.addSuppressed and Throwable.getSuppressed. Next up is the final approval ballot; almost there!

    Read the article

  • coin rotation, as3

    - by VideoDnd
    What's the best way to make a coin rotation? I tried Math.random, but the coin doesn't wobble correctly. starter code //ROTATION addEventListener(Event.ENTER_FRAME, enterFrameHandler); function enterFrameHandler(event:Event):void { /* ADD VELOCITY, GRAVITY, ACCELERATION */ coin.rotationY += 8; } tried this, but it has no gravity or accelleration //ROTATION AND RANDOM MATH function wobble():void { var wobble = ((Math.random()*4)-2); flk.rotationY -= 11+wobble/2; flk.rotationX -= 2+wobble/20; } var myInterval:uint = setInterval (wobble, 40); I took out the work physics from my title:) I want it to behave like its affected by velocity, gravity, and acceleration.

    Read the article

  • Matlab Coin Toss Simulation

    - by user1772959
    I have to write some code in Matlab that simulates tossing a coin 150 times. I have to count how many times the coin lands on heads and create a vector that gives a running percentage of the heads. Then I have to make a table of the number of trials, random 'flips", and the running percentages of heads. I assume random "flips" means heads or tails for that trial. I also have to create a line graph with trials on the x-axis and probabilities (percentages) on the y-axis. I'm assuming the percentages are just the percentage of getting heads. Sorry if this post was long. I figure giving the details now will make it easier to see what I was trying to do with the code. I didn't create the table or plot yet because I'm not even sure how to code for the actual problem. NUM_TRIALS = 150; trials = 1:NUM_TRIALS; heads = 0; t = rand(NUM_TRIALS,1); for i = trials if (t < 0.5) heads = heads + 1; end z = zeros(NUM_TRIALS,1); percent_h = heads/trials; end

    Read the article

  • Issue using Python to solve the Coin problem [closed]

    - by challarao
    I'm attempting to solve a problem commonly known as the Coin problem, but using McNuggets. McNuggets come in boxes containing either 6, 9, or 20 nuggets. I want to write a python script that uses Diophantine equations to determine if a given number of McNuggets n can be exactly purchased in these groupings. For example: 26 McNuggets -- Possible: 1 6-pack, 0 9-packs, 1 20-pack 27 McNuggets -- Possible: 0 6-packs, 3 9-packs, 0 20-packs 28 McNuggets -- Not possible This is my current attempt at writing the solution in Python, but the output is incorrect and I'm not sure what's wrong. n=input("Enter the no.of McNuggets:") a,b,c=0,0,0 count=0 for a in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for b in range(n): if 6*a+9*b+20*c==n: count=count+1 break else: for c in range(n): if 6*a+9*b+20*c==n: count=count+1 break if count>0: print "It is possible to buy exactly",n,"packs of McNuggetss",a,b,c else: print "It is not possible to buy"

    Read the article

  • Python coin-toss

    - by Andy
    i am new to Python, and i can't wrap my head around this. I have following function defined: def FlipCoins(num_flips): heads_rounds_won = 0 for i in range(10000): heads = 0 tails = 0 for j in range(num_flips): dice = random.randint(0,1) if dice==1: heads += 1 else: tails += 1 if heads > tails: heads_rounds_won += 1 return heads_rounds_won Here is what it should do (but apparently doesn't): flip a coin num_flip times, count heads and tails, and see if there are more heads than tails. If yes, increment head_rounds_won by 1. Repeat 10000 times. I would assume that head_rounds_won will approximate 5000 (50%). And it does that for odd numbers as input. For example, 3, 5 or 7 will produce about 50%. However, even numbers will produce much lower results, more like 34%. Small numbers especially, with higher even numbers, like for example 800, the difference to 50% is much narrower. Why is this the case? Shouldn't any input produce about 50% heads/tails?

    Read the article

  • Dynamic programming - Coin change decision problem?

    - by Tony
    I'm reviewing some old notes from my algorithms course and the dynamic programming problems are seeming a bit tricky to me. I have a problem where we have an unlimited supply of coins, with some denominations x1, x2, ... xn and we want to make change for some value X. We are trying to design a dynamic program to decide whether change for X can be made or not (not minimizing the number of coins, or returning which coins, just true or false). I've done some thinking about this problem, and I can see a recursive method of doing this where it's something like... MakeChange(X, x[1..n this is the coins]) for (int i = 1; i < n; i++) { if ( (X - x[i] ==0) || MakeChange(X - x[i]) ) return true; } return false; Converting this a dynamic program is not coming so easily to me. How might I approach this?

    Read the article

  • Is there a touch-friendly casino gambling (poker, roulette, slot machine) application that interfaces with coin acceptors

    - by Pitto
    Hello everybody... Does anyone have experience with gambling games (roulette, poker and so on) on Ubuntu? I would like to setup a touchscreen kiosk in my home with Ubuntu... Anything that works with coin and cash acceptors, reports payouts, lets the administrator set payout rates and so on Any experiences/hints? I am interested in full statistics / pay tweakings / cash flow analysis... Thanks a lot!

    Read the article

  • Android est-il un OS de Geeks ? Il serait fait par des ingénieurs qui travaillent dans leur coin et n'écoutent jamais personne

    Android est-il un OS de Geeks ? Il serait fait par des ingénieurs qui travaillent dans leur coin et qui n'écoutent jamais personne Faîtes un test simple. Prenez une tablette ou un smartphone sous Android. Mettez-le dans les mains du premier venu (vos enfant, votre conjoint, vos grand-parents, peu importe). Et observez. Sauf à ce qu'il travaille dans l'IT ou ait été familiarisé avec l'OS, il y a fort à parier que votre « cobaye » soit vite déboussolé. Recommencez avec un iPad ou un iPhone, et l'avis sera neuf fois sur dix radicalement différent. Je calme tout de suite les fan-boys. Il ne s'agit pas de dire qu'Android est moins bon qu'iOS. ...

    Read the article

  • Assigning two strings together getting Access Read Violation

    - by Jay Bell
    I am trying to pass a string to a class mutator and set the private member to that string here is the code that is sending the string void parseTradePairs(Exchange::Currency *curr, std::string *response, int begin, int exit) { int start; int end; string temp; string dataResponse; CURL *tempCurl; initializeCurl(tempCurl); int location = response->find("marketid", begin); if(location <= exit) { start = location + 11; begin = response->find("label", start); end = begin - start - 3; findStrings(start, end, temp, response); getMarketInfo(tempCurl, temp, dataResponse); curr->_coin->setExch(temp); // here is the line of code that is sending the string dataResponse >> *(curr->_coin); curr->_next = new Exchange::Currency(curr, curr->_position + 1); parseTradePairs(curr->_next, response, begin, exit); } } and here is the mutator within the coin class that is receiving the string and assigning it to _exch void Coin::setExch(string exch) { _exch = exch; } I have stepped through it and made sure that exch has the string in it. "105" but soon as it hits _exch = exch; I get the reading violation. I tried passing as pointer as well. I do not believe it should go out of scope. and the string variable in the class is initialized to zero in the default constructor but again that should matter unless I am trying to read from it instead of writing to it. /* defualt constructor */ Coin::Coin() { _id = ""; _label = ""; _code= ""; _name = ""; _marketCoin = ""; _volume = 0; _last = 0; _exch = ""; } Exchange::Exchange(std::string str) { _exch = str; _currencies = new Currency; std::string pair; std::string response; CURL *curl; initializeCurl(curl); getTradePairs(curl, response); int exit = response.find_last_of("marketid"); parseTradePairs(_currencies, &response, 0, exit); } int main(void) { CURL *curl; string str; string id; Coin coin1; initializeCurl(curl); Exchange ex("cryptsy"); curl_easy_cleanup(curl); system("pause"); return 0; } class Exchange { public: typedef struct Currency { Currency(Coin *coin, Currency *next, Currency *prev, int position) : _coin(coin), _next(next), _prev(prev), _position(position) {} Currency(Currency *prev, int position) : _prev(prev), _position(position), _next(NULL), _coin(&Coin()){} Currency() : _next(NULL), _prev(NULL), _position(0) {} Coin *_coin; Currency *_next; Currency *_prev; int _position; }; /* constructor and destructor */ Exchange(); Exchange(std::string str); ~Exchange(); /* Assignment operator */ Exchange& operator =(const Exchange& copyExchange); /* Parse Cryptsy Pairs */ friend void parseTradePairs(Currency *curr, std::string *response, int begin, int exit); private: std::string _exch; Currency *_currencies; }; here is what i changed it to to fix it. typedef struct Currency { Currency(Coin *coin, Currency *next, Currency *prev, int position) : _coin(coin), _next(next), _prev(prev), _position(position) {} Currency(Currency *prev, int position) : _prev(prev), _position(position), _next(NULL), _coin(&Coin()){} Currency() { _next = NULL; _prev = NULL; _position = 0; _coin = new Coin(); } Coin *_coin; Currency *_next; Currency *_prev; int _position; };

    Read the article

  • How to calculate deceleration rate of a flipping coin (in c)?

    - by Horace Ho
    A flipping coin on table will slow down and drop to the table surface, facing up or down. How can I calculate the flip-per-second declaration rate over time? For example, assuming the coin is at 10 flipping per second when it starts how long will it take to stop? For each second (9, 8, 7, 6 ... 3, 2, 1, stop), how is the flipping rate changed? Friction can be approximated as some real world objects (say, a metallic coin on a wooden table). Thanks!

    Read the article

  • SICP making change

    - by RyanD
    So; I'm a hobbiest who's trying to work through SICP (it's free!) and there is an example procedure in the first chapter that is meant to count the possible ways to make change with american coins; (change-maker 100) = 292. It's implemented something like: (define (change-maker amount) (define (coin-value n) (cond ((= n 1) 1) ((= n 2) 5) ((= n 3) 10) ((= n 4) 25) ((= n 5) 50))) (define (iter amount coin-type) (cond ((= amount 0) 1) ((or (= coin-type 0) (< amount 0)) 0) (else (+ (iter amount (- coin-type 1)) (iter (- amount (coin-value coin-type)) coin-type))))) (iter amount 5)) Anyway; this is a tree-recursive procedure, and the author "leaves as a challenge" finding an iterative procedure to solve the same problem (ie fixed space). I have not had luck figuring this out or finding an answer after getting frustrated. I'm wondering if it's a brain fart on my part, or if the author's screwing with me.

    Read the article

  • Mongoid Embeds_many won't save on nested form

    - by Brandon J McKay
    I've got an embeds_many association I'm trying to set up which I've done successfully before, but I'm trying to do it all in one nested form and I can't figure it out. Let's say we have a pocket model: class Pocket include Mongoid::Document field :title, type: String embeds_many :coins, cascade_callbacks: true end and a Coin Model: class Coin include Mongoid::Document field :name, type: String embedded_in :pocket end in my form for the pocket, I'm using: = f.fields_for @pocket.coins do |coin| = coin.text_field :name My controller is the default scaffolded controller. When I use the console, it saves fine and I can see the new pocket and coin I've created. But when I try to create or update a coin from the form, the pocket saves but the coin remains unchanged. What am I missing here?

    Read the article

  • no more hitcollision at 1 life

    - by user1449547
    So I finally got my implementation of lives fixed, and it works. Now however when I collide with a ghost when I am at 1 life, nothing happens. I can fall to my death enough times for a game over. from what i can tell the problem is that hit collision is not longer working, because it does not detect a hit, I do not fall. the question is why? update if i kill myself fast enough it works, but if i play for like 30 seconds, it stops the hit collision detection on my ghosts. platforms and springs still work. public class World { public interface WorldListener { public void jump(); public void highJump(); public void hit(); public void coin(); public void dying(); } public static final float WORLD_WIDTH = 10; public static final float WORLD_HEIGHT = 15 * 20; public static final int WORLD_STATE_RUNNING = 0; public static final int WORLD_STATE_NEXT_LEVEL = 1; public static final int WORLD_STATE_GAME_OVER = 2; public static final Vector2 gravity = new Vector2(0, -12); public Hero hero; public final List<Platform> platforms; public final List<Spring> springs; public final List<Ghost> ghosts; public final List<Coin> coins; public Castle castle; public final WorldListener listener; public final Random rand; public float heightSoFar; public int score; public int state; public int lives=3; public World(WorldListener listener) { this.hero = new Hero(5, 1); this.platforms = new ArrayList<Platform>(); this.springs = new ArrayList<Spring>(); this.ghosts = new ArrayList<Ghost>(); this.coins = new ArrayList<Coin>(); this.listener = listener; rand = new Random(); generateLevel(); this.heightSoFar = 0; this.score = 0; this.state = WORLD_STATE_RUNNING; } private void generateLevel() { float y = Platform.PLATFORM_HEIGHT / 2; float maxJumpHeight = Hero.hero_JUMP_VELOCITY * Hero.hero_JUMP_VELOCITY / (2 * -gravity.y); while (y < WORLD_HEIGHT - WORLD_WIDTH / 2) { int type = rand.nextFloat() > 0.8f ? Platform.PLATFORM_TYPE_MOVING : Platform.PLATFORM_TYPE_STATIC; float x = rand.nextFloat() * (WORLD_WIDTH - Platform.PLATFORM_WIDTH) + Platform.PLATFORM_WIDTH / 2; Platform platform = new Platform(type, x, y); platforms.add(platform); if (rand.nextFloat() > 0.9f && type != Platform.PLATFORM_TYPE_MOVING) { Spring spring = new Spring(platform.position.x, platform.position.y + Platform.PLATFORM_HEIGHT / 2 + Spring.SPRING_HEIGHT / 2); springs.add(spring); } if (rand.nextFloat() > 0.7f) { Ghost ghost = new Ghost(platform.position.x + rand.nextFloat(), platform.position.y + Ghost.GHOST_HEIGHT + rand.nextFloat() * 3); ghosts.add(ghost); } if (rand.nextFloat() > 0.6f) { Coin coin = new Coin(platform.position.x + rand.nextFloat(), platform.position.y + Coin.COIN_HEIGHT + rand.nextFloat() * 3); coins.add(coin); } y += (maxJumpHeight - 0.5f); y -= rand.nextFloat() * (maxJumpHeight / 3); } castle = new Castle(WORLD_WIDTH / 2, y); } public void update(float deltaTime, float accelX) { updatehero(deltaTime, accelX); updatePlatforms(deltaTime); updateGhosts(deltaTime); updateCoins(deltaTime); if (hero.state != Hero.hero_STATE_HIT) checkCollisions(); checkGameOver(); checkFall(); } private void updatehero(float deltaTime, float accelX) { if (hero.state != Hero.hero_STATE_HIT && hero.position.y <= 0.5f) hero.hitPlatform(); if (hero.state != Hero.hero_STATE_HIT) hero.velocity.x = -accelX / 10 * Hero.hero_MOVE_VELOCITY; hero.update(deltaTime); heightSoFar = Math.max(hero.position.y, heightSoFar); } private void updatePlatforms(float deltaTime) { int len = platforms.size(); for (int i = 0; i < len; i++) { Platform platform = platforms.get(i); platform.update(deltaTime); if (platform.state == Platform.PLATFORM_STATE_PULVERIZING && platform.stateTime > Platform.PLATFORM_PULVERIZE_TIME) { platforms.remove(platform); len = platforms.size(); } } } private void updateGhosts(float deltaTime) { int len = ghosts.size(); for (int i = 0; i < len; i++) { Ghost ghost = ghosts.get(i); ghost.update(deltaTime); if (ghost.state == Ghost.GHOST_STATE_DYING && ghost.stateTime > Ghost.GHOST_DYING_TIME) { ghosts.remove(ghost); len = ghosts.size(); } } } private void updateCoins(float deltaTime) { int len = coins.size(); for (int i = 0; i < len; i++) { Coin coin = coins.get(i); coin.update(deltaTime); } } private void checkCollisions() { checkPlatformCollisions(); checkGhostCollisions(); checkItemCollisions(); checkCastleCollisions(); } private void checkPlatformCollisions() { if (hero.velocity.y > 0) return; int len = platforms.size(); for (int i = 0; i < len; i++) { Platform platform = platforms.get(i); if (hero.position.y > platform.position.y) { if (OverlapTester .overlapRectangles(hero.bounds, platform.bounds)) { hero.hitPlatform(); listener.jump(); if (rand.nextFloat() > 0.5f) { platform.pulverize(); } break; } } } } private void checkGhostCollisions() { int len = ghosts.size(); for (int i = 0; i < len; i++) { Ghost ghost = ghosts.get(i); if (hero.position.y < ghost.position.y) { if (OverlapTester.overlapRectangles(ghost.bounds, hero.bounds)){ hero.hitGhost(); listener.hit(); } break; } else { if(hero.position.y > ghost.position.y) { if (OverlapTester.overlapRectangles(hero.bounds, ghost.bounds)){ hero.hitGhostJump(); listener.jump(); ghost.dying(); score += Ghost.GHOST_SCORE; } break; } } } } private void checkItemCollisions() { int len = coins.size(); for (int i = 0; i < len; i++) { Coin coin = coins.get(i); if (OverlapTester.overlapRectangles(hero.bounds, coin.bounds)) { coins.remove(coin); len = coins.size(); listener.coin(); score += Coin.COIN_SCORE; } } if (hero.velocity.y > 0) return; len = springs.size(); for (int i = 0; i < len; i++) { Spring spring = springs.get(i); if (hero.position.y > spring.position.y) { if (OverlapTester.overlapRectangles(hero.bounds, spring.bounds)) { hero.hitSpring(); listener.highJump(); } } } } private void checkCastleCollisions() { if (OverlapTester.overlapRectangles(castle.bounds, hero.bounds)) { state = WORLD_STATE_NEXT_LEVEL; } } private void checkFall() { if (heightSoFar - 7.5f > hero.position.y) { --lives; hero.hitSpring(); listener.highJump(); } } private void checkGameOver() { if (lives<=0) { state = WORLD_STATE_GAME_OVER; } } }

    Read the article

  • PHP custom function code optimization

    - by Alex
    Now comes the hard part. How do you optimize this function: function coin_matrix($test, $revs) { $coin = array(); for ($i = 0; $i < count($test); $i++) { foreach ($revs as $j => $rev) { foreach ($revs as $k => $rev) { if ($j != $k && $test[$i][$j] != null && $test[$i][$k] != null) { if(!isset($coin[$test[$i][$j]])) { $coin[$test[$i][$j]] = array(); } if(!isset($coin[$test[$i][$j]][$test[$i][$k]])) { $coin[$test[$i][$j]][$test[$i][$k]] = 0; } $coin[$test[$i][$j]][$test[$i][$k]] += 1 / ($some_var - 1); } } } } return $coin; } I'm not that good at this and if the arrays are large, it runs forever. The function is supposed to find all pairs of values from a two-dim array and sum them like this: $coin[$i][$j] += sum_of_pairs_in_array_row / [count(elements_of_row) - 1] Thanks a lot!

    Read the article

  • Physics in carrom like game using cocos2d + Box2D

    - by Raj
    I am working on carrom like game using cocos2d + Box2D. I set world gravity(0,0), want gravity in z-axis. I set following values for coin and striker body: Coin body (circle with radius - 15/PTM_RATIO): density = 20.0f; friction = 0.4f; restitution = 0.6f; Striker body (circle with radius - 15/PTM_RATIO): density = 25.0f; friction = 0.6f; restitution = 0.3f; Output is not smooth. When I apply ApplyLinearImpulse(force,position) the coin movement looks like floating in the air - takes too much time to stop. What values for coin and striker make it look like real carrom?

    Read the article

  • How to implement physical effect, perspective effect on Android

    - by asedra_le
    I'm researching about 2D game for Android to implement an Android Game Project. My project looks nearly like PaperToss. Instance of throwing a page, my game will throw a coin. Suppose that I have a coin put in three-dimensional that have coordinates at A(x,y,z). I throw that point ahead, after 1/100 second, that coin move from A(x,y,z) to A'(x',y',z'). By this way, I have two problems need to solve. Determine the formulas can be used to compute the coordinates of the coin at time t. This problem is under-researching. I have no idea to solve this problem. Mapping three-dimensional points to a two-dimensional and use those new coordinates (a two-dimensional coordinates) to draw our coin on screen. I have found two solutions for this problem: Orthographic projection & Perspective projection However, my old friend said that OpenGL supports to solve problems like my problems. Any body have experiences about my problems? Help me please :) Thank for reading my question.

    Read the article

  • Cocos2d: carom like game

    - by Raj
    Now I am working on carrom like game using cocos2d+Box2d. I set world gravity(0,0), want gravity in z - axis. I set following value for coin striker body: Coin body: density = 20.0f; friction = 0.4f; restitution = 0.6f; Shape Circle with radius - 15/PTM_RATIO Striker body: density = 25.0f; friction = 0.6f; restitution = 0.3f; Shape Circle with radius - 15/PTM_RATIO Output is not smooth, when I apply ApplyLinearImpulse(force,position); Coin movement looks like floating in air....takes too much time to stop... Which value of coin and striker makes it look like real carom?

    Read the article

  • Cocos2D - Detecting collision

    - by Grace
    I am a beginner in cocos2d and im facing a problem with detecting collision for my coins. Sometimes it works sometimes it doesn't. So basically, im creating a game which the user (ship) have to avoid the obstacles and collect coins on the way. The collision of the obstacle works well but not for the coins. I was thinking maybe the loops for creating many coins is the problem but im not sure. Can anyone help? My codes: - (void)update:(ccTime)dt{ double curTime = CACurrentMediaTime(); if (curTime > _nextBridgeSpawn) { float randSecs = [self randomValueBetween:3.0 andValue:5.0]; _nextBridgeSpawn = randSecs + curTime; float randX = [self randomValueBetween:50 andValue:500]; float randDuration = [self randomValueBetween:8.0 andValue:10.0]; CCSprite *bridge = [_bridge objectAtIndex:_nextBridge]; _nextBridge++; if (_nextBridge >= _bridge.count) _nextBridge = 0; [bridge stopAllActions]; bridge.position = ccp(winSize.width/2, winSize.height); bridge.visible = YES; [bridge runAction:[CCSequence actions: [CCMoveBy actionWithDuration:randDuration position:ccp(0, -winSize.height)], [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)], nil]]; this is where i declare my coins (continued from the update method) int randCoin = [self randomValueBetween:0 andValue:5]; _coin = [[CCArray alloc] initWithCapacity:randCoin]; for(int i = 0; i < randCoin; ++i) { coin = [CCSprite spriteWithFile:@"coin.png"]; coin.visible = NO; [self addChild:coin]; [_coin addObject:coin]; } float randCoinX = [self randomValueBetween:winSize.width/5 andValue:winSize.width - (border.contentSize.width *2)]; float randCoinY = [self randomValueBetween:100 andValue:700]; float randCoinPlace = [self randomValueBetween:30 andValue:60]; for (int i = 0; i < _coin.count; ++i) { CCSprite *coin2 = [_coin objectAtIndex:i]; coin2.position = ccp(randCoinX, (bridge.position.y + randCoinY) + (randCoinPlace *i)); coin2.visible = YES; [coin2 runAction:[CCSequence actions: [CCMoveBy actionWithDuration:randDuration position:ccp(0, -winSize.height-2000)], [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)], nil]]; } } this is to check for collision (also in the update method) for (CCSprite *bridge in _bridge) { if (!bridge.visible) continue; if (CGRectIntersectsRect(ship.boundingBox, bridge.boundingBox)){ bridge.visible = NO; [ship runAction:[CCBlink actionWithDuration:1.0 blinks:5]]; } } } //this is the collision for coins which only work at times for (CCSprite *coin2 in _coin) { if (!coin2.visible) continue; if (CGRectIntersectsRect(ship.boundingBox, coin2.boundingBox)) { NSLog(@"Coin collected"); coin2.visible = NO; } } } Thank you.

    Read the article

  • Background changes by itself and procedure repeats many times until I release the mouse button

    - by Robert
    Dear community, I am a student, and I'm working on a little slots game (if the same random number comes up 3 timed, you win). I use Borland Pascal 7. I use graph to make this a bit more visual, but when I start the game my background turns from black to grey, and the other problem is that if I click the game start button, the game runs many times until I release the mouse button. How can I solve this? Here is my full program: program slots; uses mymouse,graph,crt; var gdriver,gmode,coin:integer; m:mouserec; a,b,c,coins:string; procedure gomb(x1,y1,x2,y2:integer;szoveg:string); var j,n:integer; begin setcolor(blue); rectangle(x1,y1,x2,y2); setfillstyle(1,blue); floodfill(x1+2,y1+2,blue); setcolor(0); outtextxy((x1+x2)div 2 -textwidth(szoveg) div 2 ,(y1+y2) div 2-textheight(szoveg) div 2,szoveg); end; procedure randomal(var a,b,c:string); begin randomize; STR(random(2)+1,a); STR(random(2)+1,b); STR(random(2)+1,c); end; procedure menu; begin; settextstyle(0,0,1); outtextxy(20,10,'Meno menu'); gomb(20,20,90,50,'Teglalap'); gomb(20,60,90,90,'Inditas'); gomb(20,100,90,130,'Harmadik'); gomb(20,140,90,170,'Negyedik'); end; procedure teglalap(x1,x2,y1,y2,tinta:integer); begin setcolor(tinta); rectangle(x1,x2,y1,y2); end; procedure jatek(var a,b,c:string;var coin:integer;coins:string); begin; clrscr; menu; randomal(a,b,c); if ((a=b) AND (b=c)) then coin:=coin+1 else coin:=coin-1; settextstyle(0,0,3); setbkcolor(black); outtextxy(200,20,a); outtextxy(240,20,b); outtextxy(280,20,c); STR(coin,coins); outtextxy(400,400,coins); end; procedure eger; begin; mouseinit; mouseon; menu; repeat getmouse(m); if (m.left) and (m.x20) ANd (m.x<90) and (m.y20) and (m.y<50) then teglalap(90,90,300,300,blue); if (m.left) and (m.x20) AND (m.x<90) and (m.y60) and (m.y<90) then jatek(a,b,c,coin,coins); until ((m.left) and (m.x20) ANd (m.x<140) and (m.y140) and (m.y<170)); end; begin coin:=50; gdriver:=detect; initgraph(gdriver, gmode, ''); eger; end. Thank you very much, Robert

    Read the article

1 2 3 4 5  | Next Page >