예제 #1
0
void IntroState::Update(GameEngine *game)
{
    if( SDL_TICKS_PASSED(SDL_GetTicks(), m_startTime + m_timeToNextScreen) )
    {
        std::cout << "Change state to gameplay please" << std::endl;
        game->ChangeState(GameplayState::Instance());
    }
}
예제 #2
0
void Game::spawnFood()
{
	static constexpr int minPos = 20;
	static constexpr int maxPos = 570;

	int spawnFood = 0;
	int randPos = 0;
	int spawnXPos = 0;
	int spawnYPos = 0;
	bool validSpawn = false;

	/*
	Javawag: so takes a random point, divides by 25... but coz its an int it rounds down
Javawag: so imagine its 30.... 30 / 25 = 1 (it drops the .whatever)
Javawag: and then 1 x 25 = 25 :D
Javawag: doesnt work with floats though, obv :D

	
	
	*/

    //https://pastee.org/uazs2

	Uint32 currentTime = SDL_GetTicks();
	if (SDL_TICKS_PASSED(currentTime, m_nextFoodSpawn))
	{
		while (!validSpawn)
		{
			//Get 'X' position
			spawnXPos = getRandomNumber(minPos, maxPos) / 25 * 25;
			//while (spawnXPos % 25 != 0) {
			//	spawnXPos = getRandomNumber(minPos, maxPos);
			//}

			//Get 'Y' Position
			spawnYPos = getRandomNumber(minPos, maxPos) / 25 * 25;
			//while (spawnYPos % 25 != 0) {
			//	spawnYPos = getRandomNumber(minPos, maxPos);
			//}
			//Check to see if food is on requested position
			for (auto &i : m_food)
			{
				if (spawnXPos == i.m_pos.x && spawnYPos == i.m_pos.y) {
					validSpawn = false;
					break;
				}
			}
			//If there is no food on requested position
			validSpawn = true;
		}
		m_food.push_back(Entity(spawnXPos, spawnYPos));
		m_nextFoodSpawn += FOOD_SPAWN_TIME;

	}

}
예제 #3
0
void SDL_SYS_JoystickDetect()
{
    /* Support for device connect/disconnect is API >= 16 only,
     * so we poll every three seconds
     * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
     */
    static Uint32 timeout = 0;
    if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
        timeout = SDL_GetTicks() + 3000;
        Android_JNI_PollInputDevices();
    }
}
예제 #4
0
void chat_draw()
{
	if (network_get_mode() == NETWORK_MODE_NONE || network_get_status() != NETWORK_STATUS_CONNECTED || network_get_authstatus() != NETWORK_AUTH_OK) {
		gChatOpen = false;
		return;
	}
	rct_drawpixelinfo *dpi = (rct_drawpixelinfo*)RCT2_ADDRESS_SCREEN_DPI;
	_chatLeft = 10;
	_chatTop = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 40 - ((CHAT_HISTORY_SIZE + 1) * 10);
	_chatRight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - 10;
	_chatBottom = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 45;
	char lineBuffer[CHAT_INPUT_SIZE + 10];
	char* lineCh = lineBuffer;
	int x = _chatLeft;
	int y = _chatBottom - (15 * 2);
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0;
	for (int i = 0; i < CHAT_HISTORY_SIZE; i++, y -= 15) {
		if (!gChatOpen && SDL_TICKS_PASSED(SDL_GetTicks(), chat_history_get_time(i) + 10000)) {
			break;
		}
		safe_strcpy(lineBuffer, chat_history_get(i), CHAT_INPUT_SIZE + 10);
		gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer), y + 12);
		gfx_draw_string(dpi, lineBuffer, 255, x, y);
	}
	if (gChatOpen) {
		lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
		lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
		safe_strcpy(lineCh, _chatCurrentLine, CHAT_INPUT_SIZE);
		y = _chatBottom - 15;
		gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer) + 7, y + 12);
		gfx_draw_string(dpi, lineBuffer, 255, x, y);
		if (_chatCaretTicks < 15) {
			memcpy(lineBuffer, _chatCurrentLine, gTextInput.selection_offset);
			lineBuffer[gTextInput.selection_offset] = 0;
			int caretX = x + gfx_get_string_width(lineBuffer);
			int caretY = y + 15;

			gfx_fill_rect(dpi, caretX, caretY, caretX + 6, caretY + 1, 0x38);
		}
	}
}
예제 #5
0
	std::size_t AudioDevice::audioCleanup()
	{
		// Perform cleanup if interval has passed
		if(SDL_TICKS_PASSED(SDL_GetTicks(), m_lastCleanupTick))
		{
			// Set tick for next cleanup
			m_lastCleanupTick = SDL_GetTicks() + CleanupMSInterval;

			std::vector<std::size_t> soundIndicesToRemove, streamIndicesToRemove;
			std::size_t soundsRemoved = 0;

			for(std::size_t i = 0; i < m_sounds.size(); i++)
			{
				SoundHandle &handle = m_sounds[i];
				if(handle.use_count() == 1 && !handle->isPlaying())
				{
					soundIndicesToRemove.push_back(i);
					++soundsRemoved;
				}
			}
			for(std::size_t i = 0; i < m_streams.size(); i++)
			{
				StreamHandle &handle = m_streams[i];
				if(handle.use_count() == 1 && !handle->isPlaying())
				{
					streamIndicesToRemove.push_back(i);
					++soundsRemoved;
				}
			}
			for(auto& index : soundIndicesToRemove)
				m_sounds.erase(m_sounds.begin() + index);
			for(auto& index : streamIndicesToRemove)
				m_streams.erase(m_streams.begin() + index);

			JL_DEBUG_LOG("Removed %i sounds", soundsRemoved);

			return soundsRemoved;
		}
		

		return 0;
	}
예제 #6
0
void render_bird(GameData* data, DrawConfig* config){
    SDL_Rect source = config->bird_texture_array[config->bird_index];
    SDL_Rect dest = {
        scale_x_to_userspace(data,config,get_bird_x(data)) - 16,
        scale_y_to_userspace(data,config,get_bird_y(data)) - 16,
        32, /*Prolly shouldn't hardcode this*/
        32
    };

    if(SDL_RenderCopyEx(config->renderer,config->bird_sprite_sheet,&source,&dest,0,NULL,SDL_FLIP_HORIZONTAL) != 0){
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Error Rendering bird texture %d: %s\n",config->bird_index, SDL_GetError());
    }


    Uint32 currentTime = SDL_GetTicks();
    if(SDL_TICKS_PASSED(currentTime,config->last_bird_change + config->bird_tick_length)){
        config->last_bird_change = currentTime;
        config->bird_index = (config->bird_index + 1)%BIRD_SPRITE_NUM;
    }
}
예제 #7
0
/* Since XInput doesn't offer a way to vibrate for X time, we hook into
 *  SDL_PumpEvents() to check if it's time to stop vibrating with some
 *  frequency.
 * In practice, this works for 99% of use cases. But in an ideal world,
 *  we do this in a separate thread so that:
 *    - we aren't bound to when the app chooses to pump the event queue.
 *    - we aren't adding more polling to the event queue
 *    - we can emulate all the haptic effects correctly (start on a delay,
 *      mix multiple effects, etc).
 *
 * Mostly, this is here to get rumbling to work, and all the other features
 *  are absent in the XInput path for now.  :(
 */
static int SDLCALL
SDL_RunXInputHaptic(void *arg)
{
    struct haptic_hwdata *hwdata = (struct haptic_hwdata *) arg;

    while (!SDL_AtomicGet(&hwdata->stopThread)) {
        SDL_Delay(50);
        SDL_LockMutex(hwdata->mutex);
        /* If we're currently running and need to stop... */
        if (hwdata->stopTicks) {
            if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_TICKS_PASSED(SDL_GetTicks(), hwdata->stopTicks)) {
                XINPUT_VIBRATION vibration = { 0, 0 };
                hwdata->stopTicks = 0;
                XINPUTSETSTATE(hwdata->userid, &vibration);
            }
        }
        SDL_UnlockMutex(hwdata->mutex);
    }

    return 0;
}
예제 #8
0
파일: player.cpp 프로젝트: wlejon/sdl-maze
void Player::handleEvent(SDL_Event *e)
{
    switch (e->type) {
        case SDL_KEYDOWN: {
            keyDown = e->key.keysym.sym;
            moveToCell(getCellForKey(keyDown));
            break;
        }
        case SDL_KEYUP: {
            if (e->key.keysym.sym == keyDown) {
                keyDown = 0;
            }
        }
        default:
            break;
    }

    if (keyDown && SDL_TICKS_PASSED(SDL_GetTicks(), keyTimeout)) {
        moveToCell(getCellForKey(keyDown));
    }
}
예제 #9
0
void Joystick::getVibration(float &left, float &right)
{
	if (vibration.endtime != SDL_HAPTIC_INFINITY)
	{
		// With some drivers, the effect physically stops at the right time, but
		// SDL_HapticGetEffectStatus still thinks it's playing. So we explicitly
		// stop it once it's done, just to be sure.
		if (SDL_TICKS_PASSED(SDL_GetTicks(), vibration.endtime))
		{
			setVibration();
			vibration.endtime = SDL_HAPTIC_INFINITY;
		}
	}

	// Check if the haptic effect has stopped playing.
	int id = vibration.id;
	if (!haptic || id == -1 || SDL_HapticGetEffectStatus(haptic, id) != 1)
		vibration.left = vibration.right = 0.0f;

	left = vibration.left;
	right = vibration.right;
}
예제 #10
0
void
SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
{
    HRESULT result;
    XINPUT_STATE_EX XInputState;
    XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;

    if (!XINPUTGETSTATE)
        return;

    result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
    if (result == ERROR_DEVICE_NOT_CONNECTED) {
        return;
    }

    SDL_zero(XBatteryInformation);
    if (XINPUTGETBATTERYINFORMATION) {
        result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
    }

    /* only fire events if the data changed from last time */
    if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
        if (SDL_XInputUseOldJoystickMapping()) {
            UpdateXInputJoystickState_OLD(joystick, &XInputState, &XBatteryInformation);
        } else {
            UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
        }
        joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
    }

    if (joystick->hwdata->rumble_expiration) {
        Uint32 now = SDL_GetTicks();
        if (SDL_TICKS_PASSED(now, joystick->hwdata->rumble_expiration)) {
            SDL_XINPUT_JoystickRumble(joystick, 0, 0, 0);
        }
    }
}
예제 #11
0
int
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
{
    int retval;
#ifdef HAVE_SEM_TIMEDWAIT
    struct timeval now;
    struct timespec ts_timeout;
#else
    Uint32 end;
#endif

    if (!sem) {
        return SDL_SetError("Passed a NULL semaphore");
    }

    /* Try the easy cases first */
    if (timeout == 0) {
        return SDL_SemTryWait(sem);
    }
    if (timeout == SDL_MUTEX_MAXWAIT) {
        return SDL_SemWait(sem);
    }

#ifdef HAVE_SEM_TIMEDWAIT
    /* Setup the timeout. sem_timedwait doesn't wait for
    * a lapse of time, but until we reach a certain time.
    * This time is now plus the timeout.
    */
    gettimeofday(&now, NULL);

    /* Add our timeout to current time */
    now.tv_usec += (timeout % 1000) * 1000;
    now.tv_sec += timeout / 1000;

    /* Wrap the second if needed */
    if ( now.tv_usec >= 1000000 ) {
        now.tv_usec -= 1000000;
        now.tv_sec ++;
    }

    /* Convert to timespec */
    ts_timeout.tv_sec = now.tv_sec;
    ts_timeout.tv_nsec = now.tv_usec * 1000;

    /* Wait. */
    do {
        retval = sem_timedwait(&sem->sem, &ts_timeout);
    } while (retval < 0 && errno == EINTR);

    if (retval < 0) {
        if (errno == ETIMEDOUT) {
            retval = SDL_MUTEX_TIMEDOUT;
        } else {
            SDL_SetError(strerror(errno));
        }
    }
#else
    end = SDL_GetTicks() + timeout;
    while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) {
        if (SDL_TICKS_PASSED(SDL_GetTicks(), end)) {
            break;
        }
        SDL_Delay(1);
    }
#endif /* HAVE_SEM_TIMEDWAIT */

    return retval;
}
// Update: draw Above Player
update_status ModuleSceneIntroAbove::Update()
{
	App->renderer->Blit(Freezer, 297, 217);
	App->renderer->Blit(Babidi, 303, 122);
	App->renderer->Blit(Cell, 365, 165);
	App->renderer->Blit(Buu, 227, 155);

	App->renderer->Blit(ship_top, 470, 101);
	App->renderer->Blit(kame_house_top, 28, 501);

	// Draw in case of contact
	if (App->scene_intro->magic_bean.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->magic_bean.hit_timer) == false)
		{
			App->renderer->Blit(bean_tex, 112, 122);
			LOG("Drawing Bean!");
		}
		else
		{
			App->scene_intro->magic_bean.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper1.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper1.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper1.texture, 227, 155);
		else
		{
			App->scene_intro->bumper1.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper2.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper2.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper2.texture, 297, 217);
		else
		{
			App->scene_intro->bumper2.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper3.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper3.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper3.texture, 303, 122);
		else
		{
			App->scene_intro->bumper3.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper4.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper4.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper4.texture, 365, 165);
		else
		{
			App->scene_intro->bumper4.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper_left.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper_left.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper_left.texture, 145, 785);
		else
		{
			App->scene_intro->bumper_left.hit_timer = 0;
		}
	}

	if (App->scene_intro->bumper_right.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), App->scene_intro->bumper_right.hit_timer) == false)
			App->renderer->Blit(App->scene_intro->bumper_right.texture, 425, 785);
		else
		{
			App->scene_intro->bumper_right.hit_timer = 0;
		}
	}

	return UPDATE_CONTINUE;
}
예제 #13
0
파일: palette.c 프로젝트: sdlpal/sdlpal
VOID
PAL_SceneFade(
   INT         iPaletteNum,
   BOOL        fNight,
   INT         iStep
)
/*++
  Purpose:

    Fade in or fade out the screen. Update the scene during the process.

  Parameters:

    [IN]  iPaletteNum - number of the palette.

    [IN]  fNight - whether use the night palette or not.

    [IN]  iStep - positive to fade in, nagative to fade out.

  Return value:

    None.

--*/
{
   SDL_Color            *palette, newpalette[256];
   int                   i, j;
   DWORD                 time;

   palette = PAL_GetPalette(iPaletteNum, fNight);

   if (palette == NULL)
   {
      return;
   }

   if (iStep == 0)
   {
      iStep = 1;
   }

   gpGlobals->fNeedToFadeIn = FALSE;

   if (iStep > 0)
   {
      for (i = 0; i < 64; i += iStep)
      {
         time = SDL_GetTicks() + 100;

         //
         // Generate the scene
         //
         PAL_ClearKeyState();
         g_InputState.dir = kDirUnknown;
         g_InputState.prevdir = kDirUnknown;
         PAL_GameUpdate(FALSE);
         PAL_MakeScene();
         VIDEO_UpdateScreen(NULL);

         //
         // Calculate the current palette...
         //
         for (j = 0; j < 256; j++)
         {
            newpalette[j].r = (palette[j].r * i) >> 6;
            newpalette[j].g = (palette[j].g * i) >> 6;
            newpalette[j].b = (palette[j].b * i) >> 6;
         }
         VIDEO_SetPalette(newpalette);

         PAL_ProcessEvent();

         while (!SDL_TICKS_PASSED(SDL_GetTicks(), time))
         {
            PAL_ProcessEvent();
            SDL_Delay(5);
         }
      }
   }
   else
   {
      for (i = 63; i >= 0; i += iStep)
예제 #14
0
int
SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    int posted;
    Uint32 type;
    Uint32 buttonstate = mouse->buttonstate;
    SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
    Uint8 click_count;

    /* Figure out which event to perform */
    switch (state) {
    case SDL_PRESSED:
        type = SDL_MOUSEBUTTONDOWN;
        buttonstate |= SDL_BUTTON(button);
        break;
    case SDL_RELEASED:
        type = SDL_MOUSEBUTTONUP;
        buttonstate &= ~SDL_BUTTON(button);
        break;
    default:
        /* Invalid state -- bail */
        return 0;
    }

    /* We do this after calculating buttonstate so button presses gain focus */
    if (window && state == SDL_PRESSED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    if (buttonstate == mouse->buttonstate) {
        /* Ignore this event, no state change */
        return 0;
    }
    mouse->buttonstate = buttonstate;

    if (clickstate) {
        if (state == SDL_PRESSED) {
            Uint32 now = SDL_GetTicks();

            if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
                SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
                SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
                clickstate->click_count = 0;
            }
            clickstate->last_timestamp = now;
            clickstate->last_x = mouse->x;
            clickstate->last_y = mouse->y;
            if (clickstate->click_count < 255) {
                ++clickstate->click_count;
            }
        }
        click_count = clickstate->click_count;
    } else {
        click_count = 1;
    }

    /* Post the event, if desired */
    posted = 0;
    if (SDL_GetEventState(type) == SDL_ENABLE) {
        SDL_Event event;
        event.type = type;
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
        event.button.which = mouseID;
        event.button.state = state;
        event.button.button = button;
        event.button.clicks = click_count;
        event.button.x = mouse->x;
        event.button.y = mouse->y;
        posted = (SDL_PushEvent(&event) > 0);
    }

    /* We do this after dispatching event so button releases can lose focus */
    if (window && state == SDL_RELEASED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    return posted;
}
예제 #15
0
// Update: draw background
update_status ModuleSceneIntro::Update()
{
	App->renderer->Blit(graphics, 0, 0);

	if(bouncer1.hit_timer > 0)
	{
		if(SDL_TICKS_PASSED(SDL_GetTicks(), bouncer1.hit_timer) == false)
			App->renderer->Blit(bouncer1.texture, 237, 155);
		else
		{
			bouncer1.hit_timer = 0;
			score += 10;
		}
	}

	if(bouncer2.hit_timer > 0)
	{
		if(SDL_TICKS_PASSED(SDL_GetTicks(), bouncer2.hit_timer) == false)
			App->renderer->Blit(bouncer2.texture, 323, 150);
		else
		{
			bouncer2.hit_timer = 0;
			score += 10;
		}
	}

	if(side_bouncer1.hit_timer > 0)
	{
		if(SDL_TICKS_PASSED(SDL_GetTicks(), side_bouncer1.hit_timer) == false)
			App->renderer->Blit(side_bouncer1.texture, 84, 729);
		else
		{
			side_bouncer1.hit_timer = 0;
			score += 10;
		}
	}

	if(side_bouncer2.hit_timer > 0)
	{
		if(SDL_TICKS_PASSED(SDL_GetTicks(), side_bouncer2.hit_timer) == false)
			App->renderer->Blit(side_bouncer2.texture, 357, 729);
		else
		{
			side_bouncer2.hit_timer = 0;
			score += 10;
		}
	}


	for(uint i = 0; i < lights.Count(); ++i)
	{
		if(lights[i].on == true)
		{
			App->renderer->Blit(lights[i].texture, lights[i].x, lights[i].y);
		}
	}

	// Update title with score
	char title[50];
	sprintf_s(title, "Balls: %d Score: %06d Last Score: %06d", lives, score, last_score);
	App->window->SetTitle(title);

	return UPDATE_CONTINUE;
}
예제 #16
0
파일: emulator.c 프로젝트: plandis/chip8
int main(int argc, const char * argv[])
{
    if(2 != argc) {
        printf("Usage: ./chip8 filename\n");
        return 1;
    }

    // This should be the file to load
    const char* filename = argv[1];

    // Init the system
    chip8* cpu = (chip8 *) malloc(sizeof(chip8));
    initialize(cpu);
    initialize_sdl();

    SDL_Window* window;
    SDL_Renderer* renderer;
    if(SDL_CreateWindowAndRenderer(640, 320, SDL_WINDOW_SHOWN, &window, &renderer) == -1) {
        printf("Failed to generate SDL video, %s", SDL_GetError());
        SDL_Quit();
    }

    // Load the specified game
    load_game(cpu, filename);

    int quit = 0;
    Uint32 delay = 2;
    while(!quit) {
        Uint32 timeout = SDL_GetTicks() + 16;
        while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {

            // Debugging to dump the state of the emulator
            dump_state(cpu);

            SDL_Event event;
            // Consume key queue
            while (SDL_PollEvent(&event) != 0) {
                //User requests quit
                if (event.type == SDL_QUIT) {
                    quit = 1;
                } else if(event.type == SDL_KEYDOWN) {
                    switch(event.key.keysym.sym) {
                        case SDLK_RIGHT:
                            delay += 10;
                            break;
                        case SDLK_LEFT:
                            if(delay<11) {
                                delay = 1;
                            } else {
                                delay-=10;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            process_delayRegister(cpu);
            process_soundRegister(cpu);

            // Execute the next instruction
            uint16_t opcode = fetch(cpu);
            execute(cpu, opcode);

            SDL_Delay(delay);
            printf("Delay=%d\n", delay);
        }

        // Draw the state of the world
        if(cpu->shouldDraw) {
            render(cpu, window, renderer);
            cpu->shouldDraw = false;
        }

    }

    deinitialize_sdl();

    return 0;
}
예제 #17
0
// Update: draw background
update_status ModuleSceneIntro::Update()
{ 

	//Draw stuff
	
	App->renderer->Blit(table, 0, 0);

	//Bouncer reactions stuff

			//Side Bouncers
	if(bouncer_right_body.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), bouncer_right_body.hit_timer) == false)
		{
			App->renderer->Blit(bouncer_right_texture, 401-55, 766);
		}
		else
		{
			bouncer_right_body.hit_timer = 0;
			score += 100;
		}
	}

	if (bouncer_left_body.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), bouncer_left_body.hit_timer) == false)
		{
			App->renderer->Blit(bouncer_left_texture, 111-5, 766);
		}
		else
		{
			bouncer_left_body.hit_timer = 0;
			score += 100;
		}
	}

		// Green Bouncers
	if (green_bouncer1.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), green_bouncer1.hit_timer) == false)
		{
			App->renderer->Blit(green_bouncer_texture, 464 - 50, 375 - 50);
		}
		else
		{
			green_bouncer1.hit_timer = 0;
			score += 100;
		}
	}

	if (green_bouncer2.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), green_bouncer2.hit_timer) == false)
		{
			App->renderer->Blit(green_bouncer_texture, 322 - 50, 499 - 50);
		}
		else
		{
			green_bouncer2.hit_timer = 0;
			score += 100;
		}
	}
		// Grey bouncers

	if (grey_bouncer1.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer1.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 471-11, 756-11);
			App->renderer->Blit(points_texture, 471-15, 756-15);
		}
		else
		{
			grey_bouncer1.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer2.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer2.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 130-11, 298-11);
			App->renderer->Blit(points_texture, 130 - 15, 298 - 15);
		}
		else
		{
			grey_bouncer2.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer3.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer3.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 510-11, 248-11);
			App->renderer->Blit(points_texture, 510 - 15, 248 - 15);
		}
		else
		{
			grey_bouncer3.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer4.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer4.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 264-11, 148-11);
			App->renderer->Blit(points_texture, 264 - 15, 148 - 15);
		}
		else
		{
			grey_bouncer4.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer5.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer5.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 344-11, 144-11);
			App->renderer->Blit(points_texture, 344 - 15, 144 - 15);
		}
		else
		{
			grey_bouncer5.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer6.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer6.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 477-11, 144-11);
			App->renderer->Blit(points_texture, 477 - 15, 144 - 15);
		}
		else
		{
			grey_bouncer6.hit_timer = 0;
			score += 100;
		}
	}

	if (grey_bouncer7.hit_timer > 0)
	{
		if (SDL_TICKS_PASSED(SDL_GetTicks(), grey_bouncer7.hit_timer) == false)
		{
			App->renderer->Blit(grey_bouncer_texture, 420-11, 79-11);
			App->renderer->Blit(points_texture, 420 - 15, 79 - 15);
		}
		else
		{
			grey_bouncer7.hit_timer = 0;
			score += 100;
		}
	}

	for (uint i = 0; i < lights.Count(); ++i)
	{
		if (lights[i].on == true)
		{
			App->renderer->Blit(lights[i].texture, lights[i].x, lights[i].y);
			
		}
	}

	if (counter_box > 5)
	{
		score += 1000;

		for (uint i = 0; i < lights.Count(); ++i)
		{
			if (lights[i].on == true && lights[i].type == orange_box || lights[i].type == blue_box || lights[i].type == green_box || lights[i].type == red_box || lights[i].type == pink_box || lights[i].type == yellow_box)
			{
				lights[i].on = false;
				counter_box = 0;
				App->audio->PlayFx(color_box_5_fx);
				
			}
		}
	}

	if (counter_char_box > 1)
	{
		score += 1000;

		for (uint i = 0; i < lights.Count(); ++i)
		{
			if (lights[i].on == true && lights[i].type == boy_light || lights[i].type == girl_light)
			{
				lights[i].on = false;
				counter_char_box = 0;
				App->audio->PlayFx(char_touch_fx);
				

			}
		}
	}

	if (counter_yellow_lights > 7)
	{
		score += 5000;

		for (uint i = 0; i < lights.Count(); ++i)
		{
			if (lights[i].on == true && lights[i].type == yellow_light)
			{
				lights[i].on = false;
				counter_yellow_lights = 0;
				App->audio->PlayFx(char_touch_fx);

			}
		}
	}

	if (counter_green_rectangles > 1)
	{
		score += 1000;
		lives += 1;

		for (uint i = 0; i < lights.Count(); ++i)
		{
			if (lights[i].on == true && lights[i].type == green_rectangle)
			{
				lights[i].on = false;
				counter_green_rectangles = 0;
				App->audio->PlayFx(green_rectangle_2_fx);

			}
		}
	}


/////////////////////////////////////////////////////////////////

	char title[100];
	sprintf_s(title, "Balls: %d Score: %06d Last Score: %06d" , lives, score, last_score);
	App->window->SetTitle(title);

	return UPDATE_CONTINUE;
}
예제 #18
0
// Update: draw background
update_status ModuleSceneIntro::Update()
{
	static int puntuation = 0;


	if (App->input->GetKey(SDL_SCANCODE_SPACE) == KEY_DOWN)
	{
		ray_on = !ray_on;
		ray.x = App->input->GetMouseX();
		ray.y = App->input->GetMouseY();
	}

	if (App->input->GetKey(SDL_SCANCODE_1) == KEY_DOWN)
	{
		circles.add(App->physics->CreateCircle(App->input->GetMouseX(), App->input->GetMouseY(), 10, b2_dynamicBody));
		// TODO 8: Make sure to add yourself as collision callback to the circle you creates
	}

	////////////////////////////////////////////////////////////////
		

		iPoint mouse;
		mouse.x = App->input->GetMouseX();
		mouse.y = App->input->GetMouseY();
		int ray_hit = ray.DistanceTo(mouse);

		fVector normal(0.0f, 0.0f);

		// All draw functions ------------------------------------------------------
		p2List_item<PhysBody*>* c = circles.getFirst();

		while (c != NULL)
		{
			int x, y;
			c->data->GetPosition(x, y);

			App->renderer->Blit(circle, x, y, NULL, 1.0f, c->data->GetRotation());
			c = c->next;
		}


		

		c = pinballObjects.getFirst();
		while (c != NULL)
		{
			int x, y;
			c->data->GetPosition(x, y);
			App->renderer->Blit(pinball_texture, x, y, NULL, 1.0f, c->data->GetRotation());
			c = c->next;
		}

		int x, y;
		App->player->support->GetPosition(x, y);
		App->renderer->Blit(pivot, x, y, NULL, 1.0f, App->player->support->GetRotation());


		// ray -----------------
		if (ray_on == true)
		{
			fVector destination(mouse.x - ray.x, mouse.y - ray.y);
			destination.Normalize();
			destination *= ray_hit;

			App->renderer->DrawLine(ray.x, ray.y, ray.x + destination.x, ray.y + destination.y, 255, 255, 255);

			if (normal.x != 0.0f)
				App->renderer->DrawLine(ray.x + destination.x, ray.y + destination.y, ray.x + destination.x + normal.x * 25.0f, ray.y + destination.y + normal.y * 25.0f, 100, 255, 100);
		}


		if (left_bouncer.hit_timer > 0)
		{
			if (SDL_TICKS_PASSED(SDL_GetTicks(), left_bouncer.hit_timer) == false)
				App->renderer->Blit(left_bouncer.bouncer_tex, 228, 487);
			else
			{
				left_bouncer.hit_timer = 0;
				score += 10;
			}
		}

		if (right_bouncer.hit_timer > 0)
		{
			if (SDL_TICKS_PASSED(SDL_GetTicks(), right_bouncer.hit_timer) == false)
				App->renderer->Blit(right_bouncer.bouncer_tex, 397, 487);
			else
			{
				right_bouncer.hit_timer = 0;
				score += 10;
			}
		}

		if (volt1_bouncer.hit_timer > 0)
		{
			if (SDL_TICKS_PASSED(SDL_GetTicks(), volt1_bouncer.hit_timer) == false)
				App->renderer->Blit(volt1_bouncer.bouncer_tex, 333, 160);
			else
			{
				right_bouncer.hit_timer = 0;
				score += 10;
			}
		}

		if (volt2_bouncer.hit_timer > 0)
		{
			if (SDL_TICKS_PASSED(SDL_GetTicks(), volt2_bouncer.hit_timer) == false)
				App->renderer->Blit(volt2_bouncer.bouncer_tex, 278, 183);
			else
			{
				right_bouncer.hit_timer = 0;
				score += 10;
			}
		}

		if (volt3_bouncer.hit_timer > 0)
		{
			if (SDL_TICKS_PASSED(SDL_GetTicks(), volt3_bouncer.hit_timer) == false)
				App->renderer->Blit(volt3_bouncer.bouncer_tex, 320, 225);
			else
			{
				right_bouncer.hit_timer = 0;
				score += 10;
			}
		}


		for (uint i = 0; i < lights.Count(); ++i)
		{
			if (lights[i].check == true)
			{
				App->renderer->Blit(light, lights[i].x - 9, lights[i].y - 9);
			}
		}

		


		char title[50];
		sprintf_s(title, "Balls: %d, Score: %d  ", App->player->GetLives(), score);
		App->window->SetTitle(title);
		
		return UPDATE_CONTINUE;
}
예제 #19
0
static int
SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    int posted;
    Uint32 type;
    Uint32 buttonstate = mouse->buttonstate;

    /* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */
    if (mouse->mouse_touch_events) {
        if (mouseID != SDL_TOUCH_MOUSEID && button == SDL_BUTTON_LEFT) {
            if (state == SDL_PRESSED) {
                track_mouse_down = SDL_TRUE;
            } else {
                track_mouse_down = SDL_FALSE;
            }
            if (window) {
                float fx = (float)mouse->x / (float)window->w;
                float fy = (float)mouse->y / (float)window->h;
                SDL_SendTouch(SDL_MOUSE_TOUCHID, 0, track_mouse_down, fx, fy, 1.0f);
            }
        }
    }

    /* Figure out which event to perform */
    switch (state) {
    case SDL_PRESSED:
        type = SDL_MOUSEBUTTONDOWN;
        buttonstate |= SDL_BUTTON(button);
        break;
    case SDL_RELEASED:
        type = SDL_MOUSEBUTTONUP;
        buttonstate &= ~SDL_BUTTON(button);
        break;
    default:
        /* Invalid state -- bail */
        return 0;
    }

    /* We do this after calculating buttonstate so button presses gain focus */
    if (window && state == SDL_PRESSED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    if (buttonstate == mouse->buttonstate) {
        /* Ignore this event, no state change */
        return 0;
    }
    mouse->buttonstate = buttonstate;

    if (clicks < 0) {
        SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
        if (clickstate) {
            if (state == SDL_PRESSED) {
                Uint32 now = SDL_GetTicks();

                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
                    SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
                    SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
                    clickstate->click_count = 0;
                }
                clickstate->last_timestamp = now;
                clickstate->last_x = mouse->x;
                clickstate->last_y = mouse->y;
                if (clickstate->click_count < 255) {
                    ++clickstate->click_count;
                }
            }
            clicks = clickstate->click_count;
        } else {
            clicks = 1;
        }
    }

    /* Post the event, if desired */
    posted = 0;
    if (SDL_GetEventState(type) == SDL_ENABLE) {
        SDL_Event event;
        event.type = type;
        event.button.windowID = mouse->focus ? mouse->focus->id : 0;
        event.button.which = mouseID;
        event.button.state = state;
        event.button.button = button;
        event.button.clicks = (Uint8) SDL_min(clicks, 255);
        event.button.x = mouse->x;
        event.button.y = mouse->y;
        posted = (SDL_PushEvent(&event) > 0);
    }

    /* We do this after dispatching event so button releases can lose focus */
    if (window && state == SDL_RELEASED) {
        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    }

    return posted;
}